Recently, the company's business needs, the original order APK form CPE. Penetrates the framework layer. This was stripped of the CPE, engaged in quite a long period, and finally had time to write a blog, write down the problems encountered, the future.
The first problem is that the original apk has some things to transplant after the framework layer. Different environments, we have to make some changes.
Like what
1.ContentProvider, because it is not provided to other program data sharing, or removed. All changes to SQLite are called directly. Or peel this contentprovider out. form an apk. Fixed to the framework. Provide ContentProvider to CPE.
2.SharedPreferences, after entering the framework, sharedpreferences no place to store the XML file generated by it, so also to be removed, and then how to save it to save the data, such as terminal startup information and initialization information. Finally make sure to use a file to save. Depending on the properties of this tool class read and write data, properties initially encountered the problem of writing data, and later still conquered. The main is Mproperties.setproperty (name,value); Just write the data to the memory, and not write to the file, tangled for half a day, changed the code. It's OK.
try {
Os=new FileOutputStream (Configpath);
Mproperties.setproperty (Name,value);
Mproperties.store (OS, NULL);
} catch (Exception e) {
E.printstacktrace ();
} finally{
try {
Os.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
3.CPE the original configuration file. After the framework layer, the folder structure is not the same, you have to find a place to store these configuration files. Changed the folder where these profiles were referenced, and finally migrated to the/system/etc/cpe/folder.
4.CPE relies on the third-party jar package, the CPE into the framework, which itself is a jar form exists, only by the systemservice into the context of other it. The third-party jar package that the CPE relies on is also required to enter the framework, starting with all imports into the framework, after compiling and executing. I found an apk on the board that also quoted the CPE jar I imported, which was a conflict. To avoid this problem. Decide to change the package name of the CPE.
5. Like the db file generated by sharedpreferences,apk. The default is under the/data/data/package name/database/folder. And after entering the framework. DB file to find a place to store, in order to solve the problem, find a lot of information, tested for half a day, and finally implemented, and the db file is stored in the/data/cpe/folder. Because it is the APK in the test, did not break into the framework, the Board folder is not authorized to write data, only can be tested with a U disk, write/sdcard/folder test. Said for a long while. That is, the specified folder holds the db file.
Define helper classes to inherit Sqliteopenhelper:
public class Databasehelper extends Sqliteopenhelper
Construction Method:
private static final String PATH = "/SDCARD/CPE";
Public Databasehelper (Context context, String name) {
Super (new Custompathdatabasecontext (context, PATH), name, NULL, VERSION);
}
Note the Custompathdatabasecontext.java in the construction method:
public class Custompathdatabasecontext extends contextwrapper{
private static final String TAG = CustomPathDatabaseContext.class.getSimpleName ();
Private String Mdirpath;
Public Custompathdatabasecontext (Context base,string name) {
Super (base);
Mdirpath = name;
}
@Override
Public File Getdatabasepath (String name) {
File result = new file (Mdirpath + file.separator + name);
if (!result.getparentfile (). exists ())
{
Result.getparentfile (). Mkdirs ();
}
return result;
}
@Override
Public sqlitedatabase openorcreatedatabase (String name, int mode, Cursorfactory Factory)
{
LOG.D (TAG, "openorcreatedatabase");
Return Sqlitedatabase.openorcreatedatabase (Getdatabasepath (name), factory);
}
@Override
Public sqlitedatabase openorcreatedatabase (String name, int mode, Cursorfactory factory, Databaseerrorhandler ErrorHandler) {
LOG.D (TAG, "openorcreatedatabase ...");
Return Sqlitedatabase.openorcreatedatabase (Getdatabasepath (name). GetAbsolutePath (), factory, ErrorHandler);
}
}
Why do you define this? To view the source code, Contextwrapper is the implementation class for the context. After Getreadabledatabase (), or getwriteabledatabase () is called, The Openorcreatedatabase () is run, and a second openorcreatedatabase () is run after the 4.0 version number , which specifies the db clamp.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
After the CPE transplant framework, the. Existing database for problem resolution