Restore factory settings Core code:
Sendbroadcast (New Intent ("Android.intent.action.MASTER_CLEAR"));
That is to send a broadcast that needs to be configured in Androidmanifest.xml
<receiver android:name= "Com.android.server.MasterClearReceiver" android:permission= "Android.permission.MASTER_CLEAR" android:priority= " > " <intent-filter> <!-- for checkin, settings, etc.: action=master_clear --> <action android: Name= "Android.intent.action.MASTER_CLEAR" /> <!-- MCS always uses REMOTE_INTENT: category=MASTER_CLEAR --> <category android:name= " Android.intent.category.MASTER_CLEAR_NOTIfication " /> </ Intent-filter> </receiver>
and add permissions
<uses-permission android:name= "Android.permission.MASTER_CLEAR"/>
Basically the above can be implemented to restore the factory settings. The system Setup function is to complete the factory reset, but there are a lot of problems in this process, mainly due to permissions.
The most obvious problem is that you will get an error when adding Android.permission.MASTER_CLEAR permissions.
Permission is only granted to system apps
This explains the difference between restoring factory settings and restoring the system settings.
This error is very well solved, only need to project\clean a bit to remove the mistake
However, when running the program, of course, does not restore the factory, the prompt is insufficient permissions,
E/androidruntime (2562): java.lang.SecurityException:Permission Denial:not allowed to send broadcast Android.intent.action.MASTER_CLEAR_NOTIFICATION from pid=2562, uid=10027
Depending on the prompt you can see that the permission is broadcast, but we have declared the permission
android:permission= "Android.permission.MASTER_CLEAR"
In the Frameworks/base/core/res/androidmanifest.xml file, you can see
<!--================================================--
<!--special broadcasts that only the system can send--
<!--================================================--
<protected-broadcast android:name= "Android.intent.action.MASTER_CLEAR_NOTIFICATION"/>
Of course, there are a lot of similar
Which means we can't use this broadcast, but there's no other way to get rid of this rock.
Just put this comment off, then recompile the system, burn it, and then you can go ahead and
Continue running you will find a new error
E/masterclear (1060): Can ' t perform master clear/factory reset
E/masterclear (1060): java.io.FileNotFoundException:/cache/recovery/command:open failed:eacces (Permission denied)
is still a permissions issue, that is, there is no /cache/recovery/folder operation permissions
There are several solutions on the Internet, I only say the way I finally solve the problem
(1) Androidmanifest.xml add android:shareduserid= "Android.uid.system"
(2) Android.mk Add Local_certificate: = Platform
At this point, the program is not installed, prompting the error:
Installation error:install_failed_shared_user_incompatible
Probably meant to add system permissions to the APK.
I use the system to bring my own
Signapk.jar +. X509.pem +. PK8 signed application with Android
Find signature files such as Platform.pk8 Platform.x509.pem in platform/build/target/product/security/
Signapk.jar: Compiled by/platform/build/tools/signapk/output, can be found in/out/host/linux-x86/framework/
Put these files and apk into the same directory, command line execution
Java-jar Signapk.jar Platform.x509.pem platform.pk8 mydemo.apk mydemo_signed.apk
after installing the mydemo_signed.apk, it was found that it could not be installed.
Error failure [install_failed_dexopt]
This is because the apk under System\app is optimized, and the Dex file is not packaged into the APK, and the Dex file is optimized to generate the Odex file .
Here is the program after compiling the. Odex and. APK two files generated under workspace/out/target/product/generic/system/app/
Install:out/target/product/generic/system/app/xxx.odex
install:out/target/product/generic/system/app/xxx.apk
When you install the APK, the Dex file is missing, resulting in an error [install_failed_dexopt].
find the APK that is not optimized, that is, the Find the app below out/target/product/generic/obj/apps/: package.apk.unaligned
of course you can rename it. package.apk.unaligned ———— >package.apk
Complete after installation
This article is from the "Young Wind" blog, please be sure to keep this source http://5656020.blog.51cto.com/5646020/1546297
Android Restore factory settings