Android porting and debugging -------) how to modify the default display of the Android System
1. First, solve the problem of displaying the "Developer options" by default on the "Settings" interface.
View Source Code: packages/apps/Settings/src/com/android/settings/SettingsActivity. java
In updateTilesList (List 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; } }
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));
Therefore, to directly display the [developer options] for a specific customer, change the value of showDev. The Code is as follows:
//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, before the showDev variable is initialized, set the value of DevelopmentSettings. PREF_SHOW to true, so that showDev is also true. In this way, the [developer options] will be enabled by default. The J5 customer's method 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 the [developer options] --> [USB debugging] switch.
First, check packages/apps/Settings/src/com/android/settings/DevelopmentSettings. java
In the updateAllOptions () method, the logic of USB debugging is described.
/// 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; }
Among them, mEnableAdb is the USB debug switch control. At first, I set the isChecked variable to true directly, 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);
In this case, you still cannot directly connect to USB debugging after the flash is directly turned on. You have to re-turn the switch and then enable the switch to debug the USB. Therefore, this solution is abandoned.
Whether to enable the USB debugging function depends on whether the value of Settings. Global. ADB_ENABLED is 0 or 1. Therefore, the real method is to set Settings. Global. ADB_ENABLED to 1 in a broadcast receiver that receives the boot broadcast.
Modify it with [unknown source] below and resolve it in step 4th.
3. solve the problem that the [Security] --> [unknown source] switch is enabled by default.
First, check the packages/apps/Settings/src/com/android/settings/SecuritySettings. java file, and find the control of [unknown source] In the createPreferenceHierarchy () method, near line 1
mToggleAppInstallation = (SwitchPreference) findPreference( KEY_TOGGLE_INSTALL_APPLICATIONS); mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
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); }
Before determining the isNonMarketAppsAllowed () method, I first call the setNonMarketAppsAllowed () method. When entering this interface, the unknown source option is selected.
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, if a third-party apk is directly installed after the machine is refreshed, the "Unknown Source" option should be set in the pop-up window, as shown below, so the solution is abandoned.
Click the "Settings" button to go to the interface. The "Unknown Source" button is selected by default. Exit at this time. You can continue to install the apk, as shown below:
Because the added code is in the createPreferenceHierarchy () method of SecuritySettings, that is, it takes effect only when the Activity is entered. This obviously fails to achieve the goal.
Therefore, like setting USB debugging, set Settings. Global. INSTALL_NON_MARKET_APPS to 1 in a broadcast receiver that receives the boot broadcast.
4. Find a broadcast receiver defined in Settings that receives the boot broadcast, and find one in AndroidManifest. xml. Of course, you can also define such a broadcast receiver by yourself.
Therefore, add the following code to the packages/apps/Settings/src/com/mediatek/settings/restorerotationconfigurer. java onReceive (Context context, Intent intent) method:
// Added by ouyang 2015-11-13 if (android. OS. systemProperties. isJ5Version () {// when starting the instance, [unknown source] is selected by default. global. putInt (context. getContentResolver (), Settings. global. INSTALL_NON_MARKET_APPS, 1); // when starting the instance, [USB debugging] is selected by default. global. putInt (context. getContentResolver (), Settings. global. ADB_ENABLED, 1);} // added by ouyang 2015-11-13 end
The code added at the beginning can be commented out. It can be seen through git diff
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 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);
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(isNonMarketAppsAllowed());- //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());
After this change, compile the SDK and install the apk from an unknown source, and then plug in the USB data cable to start adb debugging.