本文基于Android5.1
packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
@Override
public void onResume() {
super.onResume();
if (mUnavailable) {
// Show error message
TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(emptyView);
if (emptyView != null) {
emptyView.setText(R.string.development_settings_not_available);
}
return;
}
if (mDpm.getMaximumTimeToLock(null) > 0) {
// A DeviceAdmin has specified a maximum time until the device
// will lock... in this case we can't allow the user to turn
// on "stay awake when plugged in" because that would defeat the
// restriction.
mDisabledPrefs.add(mKeepScreenOn);
} else {
mDisabledPrefs.remove(mKeepScreenOn);
}
final ContentResolver cr = getActivity().getContentResolver();
mLastEnabledState = Settings.Global.getInt(cr,
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
/// M: CR ALPS00327180. Lock and unlock screen, the switch is unchecked.
boolean isChecked = (mEnableDialog != null && mEnableDialog.isShowing()) ? true : mLastEnabledState;
mSwitchBar.setChecked(isChecked);
setPrefsEnabledState(mLastEnabledState);
//eng版本默认打开开发者模式
if (mHaveDebugSettings && !mLastEnabledState && "eng".equals(android.os.Build.TYPE)) {
// Overall debugging is disabled, but there are some debug
// settings that are enabled. This is an invalid state. Switch
// to debug settings being enabled, so the user knows there is
// stuff enabled and can turn it all off if they want.
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mLastEnabledState = true;
mSwitchBar.setChecked(mLastEnabledState);
setPrefsEnabledState(mLastEnabledState);
}
mSwitchBar.show();
mExt.customUSBPreference(mEnableAdb);
}