Today, a user has a special requirement for "settings", namely:
1. The "Developer Options" and the "USB Debug" switch ("Developer options"-"USB debugging") are displayed by default when the boot is turned on.
2. Turn on the "safe" and "unknown Source" switch ("Security"---> "Unknown sources") by default when booting
1, first resolve the "Settings" screen default display "Developer Options" problem
View Source code: Packages/apps/settings/src/com/android/settings/settingsactivity.java
In the Updatetileslist (list<dashboardcategory> target) method, you can find the code related to "developer Options":
else if (id = = r.id.development_settings) { log.d (Log_tag, "=================oyp k=" +showdev); if (!showdev | | um.hasuserrestriction ( usermanager.disallow_debugging_features)) { removetile = true; }
Where the Showdev variable is defined at the beginning of the method
Final Boolean Showdev = Mdevelopmentpreferences.getboolean ( developmentsettings.pref_show, Android.os.Build.TYPE.equals ("eng"));
So in order for a particular customer to display the developer options directly, change the value of Showdev to the following code:
Added by Ouyang 2015-11-10 set Developmentsettings.pref_show=true if model is J5 if ( Android.os.SystemProperties.isJ5Version ()) { sharedpreferences.editor editor=mdevelopmentpreferences.edit (); Editor.putboolean (Developmentsettings.pref_show, true); Editor.commit (); LOG.D (Log_tag, "=================OYP set Developmentsettings.pref_show=true if model is J5"); } Added by Ouyang 2015-11-10 End Final Boolean showdev = Mdevelopmentpreferences.getboolean ( Developmentsettings.pref_show, android.os.Build.TYPE.equals ("eng"));
That is, if the value of Developmentsettings.pref_show is set to True before the Showdev variable is initialized, then Showdev will also be true. This will open the developer options by default. That judgment is J5 the client's approach is defined in/frameworks/base/core/java/android/os/systemproperties.java.
public static Boolean isj5version () {return systemproperties.get ("Ro.product.model"). Contains ("J5");}
2. Solve "developer Options"--"USB Debug" switch
First View Packages/apps/settings/src/com/android/settings/developmentsettings.java
In the Updatealloptions () method, there is a logical processing of "USB debugging".
M:CR ALPS00244115. Lock and Unlock screen, the "USB debugging" is unchecked. Boolean isChecked = (Madbdialog! = null && madbdialog.isshowing ())? true: (Settings.Global.getInt (CR, Settings.Global.ADB_ENABLED, 0)! = 0); Updateswitchpreference (MENABLEADB, isChecked); M:update USB Preference Again mext.customusbpreference (MENABLEADB);
void Updateswitchpreference (Switchpreference switchpreference, Boolean value) { switchpreference.setchecked ( value); Mhavedebugsettings |= value; }
Where menableadb is the "USB debug" switch control. At first I was forced to set the ischecked variable to True, as shown in the following code
M:CR ALPS00244115. Lock and Unlock screen, the "USB debugging" is unchecked. Boolean isChecked = (Madbdialog! = null && madbdialog.isshowing ())? true: (Settings.Global.getInt (CR, Settings.Global.ADB_ENABLED, 0)! = 0);- //added by Ouyang 2015-11-10 Set Menableadb=true if model is j5- if (android.os.SystemProperties.isJ5Version ()) {- ischecked=true;- } - //added by Ouyang 2015-11-10 end updateswitchpreference (menableadb, isChecked); M:update USB Preference Again mext.customusbpreference (MENABLEADB);
But in this case, the direct brush after the boot is still not directly connected to the USB debugging, but also to turn off the switch and then open the switch for USB debugging, so the program is discarded.
Because whether the "USB debugging" function is really turned on, is to see if the value of the Settings.Global.ADB_ENABLED property is 0 or 1. So the real way is to set the Settings.Global.ADB_ENABLED to 1 in a broadcast receiver that accepts a boot broadcast.
Modify it below with "unknown source" and resolve it in the 4th step.
3. Solve the "security"--"unknown source" switch by default open issue
First look at the Packages/apps/settings/src/com/android/settings/securitysettings.java file, and in the Createpreferencehierarchy () method, locate the Unknown source "control, near line 403
Mtoggleappinstallation = (switchpreference) findpreference ( key_toggle_install_applications); Mtoggleappinstallation.setchecked (isnonmarketappsallowed ());
where the Isnonmarketappsallowed () method code is as follows
Private Boolean isnonmarketappsallowed () { return Settings.Global.getInt (Getcontentresolver (), Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0; }
The Setnonmarketappsallowed (Boolean enabled) method code is as follows
private void Setnonmarketappsallowed (Boolean enabled) { final Usermanager um = (usermanager) getactivity (). Getsystemservice (context.user_service); if (Um.hasuserrestriction (usermanager.disallow_install_unknown_sources)) { return; } Change the system setting Settings.Global.putInt (Getcontentresolver (), Settings.Global.INSTALL_NON_MARKET_ APPS, enabled 1:0); }
At first I called the Setnonmarketappsallowed () method before judging the isnonmarketappsallowed () method, so that the "unknown source" option was checked when you entered the interface.
Mtoggleappinstallation = (switchpreference) findpreference ( key_toggle_install_applications);- - // Added by Ouyang 2015-11-10 setchecked (TRUE) if the model is j5- if (android.os.SystemProperties.isJ5Version ()) { - setnonmarketappsallowed (true);- } mtoggleappinstallation.setchecked (isnonmarketappsallowed ());- //added by Ouyang 2015-11-10 End
However, the machine directly installs a third-party apk, or it will pop-up window for me to set the "unknown source" option, as shown below, so the program is discarded.
Click the "Settings" button to enter the interface is the "unknown source" button is checked by default, this time to exit, continue to install the APK can be installed, as follows:
Because this added code is in the Securitysettings Createpreferencehierarchy () method, which means that the activity is entered into effect. This obviously did not achieve the purpose.
So, like setting up USB debugging, Settings.Global.INSTALL_NON_MARKET_APPS is set to 1 in a broadcast recipient receiving a start-up broadcast.
4, find settings inside the definition of a receiver to receive the broadcast receiver, found in the Androidmanifest.xml, of course, you can also define a broadcast receiver.
<!-- Restore Rotation Receiver--- <receiver android:name= " Com.mediatek.settings.RestoreRotationReceiver "> <intent-filter> <action android:name=" Android.intent.action.BOOT_COMPLETED "/> <action android:name=" Android.intent.action.ACTION_BOOT_IPO "/ > </intent-filter> </receiver>
So in Packages/apps/settings/src/com/mediatek/settings/restorerotationreceiver.java's onreceive (context context, Intent Intent) method, add the following code:
Added by Ouyang 2015-11-13 if (android.os.SystemProperties.isJ5Version ()) { //boot startup, default setting [unknown source] tick Settings.Global.putInt (Context.getcontentresolver (), settings.global.install_non_market_apps,1); When booting, the default setting [USB debug] Tick Settings.Global.putInt (Context.getcontentresolver (), Settings.Global.ADB_ENABLED, 1); } //added by Ouyang 2015-11-13 End
And the code that was added at the beginning can be commented out. By using Git diff, you can see that
Diff--git A/packages/apps/settings/src/com/android/settings/developmentsettings.java b/packages/apps/Settings/ Src/com/android/settings/develindex 0A987DF. 503270a 100755---a/packages/apps/settings/src/com/android/settings/developmentsettings.java+++ b/packages/apps/ settings/src/com/android/settings/developmentsettings.java@@ -508,15 +508,9 @@ public class Developmentsettings Extends Settingspreferencefragment Final Context context = getactivity (); Final Contentresolver cr = Context.getcontentresolver (); Mhavedebugsettings = false;-//M:CR ALPS00244115. Lock and Unlock screen, the "USB debugging" is unchecked. Boolean isChecked = (Madbdialog! = null && madbdialog.isshowing ())? true: (Settings.Global.getInt (CR, Settings.Global.ADB_ENABLED, 0)! = 0);-//added by Ouyang 20 15-11-10 set Menableadb=true if model is j5-if (Android.os.SystemProperties.isJ5Version ()) {-Ische cked=true;- }-//added by Ouyang 2015-11-10 end Updateswitchpreference (menableadb, isChecked); M:update USB Preference Again mext.customusbpreference (MENABLEADB);
Diff--git A/packages/apps/settings/src/com/android/settings/securitysettings.java b/packages/apps/Settings/src/ Com/android/settings/securityindex 4de173a. 392e6ee 100755---a/packages/apps/settings/src/com/android/settings/securitysettings.java+++ b/packages/apps/ settings/src/com/android/settings/securitysettings.java@@ -402,14 +402,7 @@ public class Securitysettings extends Settingspreferencefragment root.findpreference (key_device_admin_category); Mtoggleappinstallation = (switchpreference) findpreference (key_toggle_install_applications);-- Added by Ouyang 2015-11-10 setchecked (TRUE) if the model is j5-if (android.os.SystemProperties.isJ5Version ()) {-setnonmarketappsallowed (TRUE);-} mtoggleappinstallation.setchecked (Isnonmarketappsall Owed ());-//added by Ouyang 2015-11-10 end-//Side loading of apps. Disable for restricted profiles. For others, check IF Policy disallows it. Mtoggleappinstallation.setenabled (!um.getuserinfo (Userhandle.myuserid ()). isrestricted ());
In this case, after the compilation, after the brush, plug in the USB cable can start the ADB debugging, and can directly install the unknown source of the APK.
====================================================================================
Ouyangpeng welcome reprint, sharing with people is the source of progress!
Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng
====================================================================================
Copyright NOTICE: This article is Ouyangpeng original article, welcome reprint, reprint please indicate source! Http://blog.csdn.net/ouyang_peng
Android system porting and debugging-------> How to Modify the Android system by default show "developer Options" and turn on "USB debugging" and "unknown source" switch by default