如果想让开发者选项默认显示,不需要点击7次版本号,可直接将showDev置为true即可:
final boolean showDev = true;
如果showDev为false,则在如下代码中隐藏“开发者选项”:
if (id == R.id.development_settings) {
if (!showDev) {
target.remove(i);
}
}
下面看一下点击版本号显示开发者选项的部分:
代码路径:packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java
首先是定义点击次数:
static final int TAPS_TO_BE_A_DEVELOPER = 7;
点击版本号的处理逻辑,若mDevHitCountdown小于0,则表示”开发者选项“已经显示,参考Resume函数的处理:
if (preference.getKey().equals(KEY_BUILD_NUMBER)) {
// Don’t enable developer options for secondary users.
if (UserHandle.myUserId() != UserHandle.USER_OWNER) return true;
if (mDevHitCountdown > 0) {
if (mDevHitCountdown == 1) {
if (super.ensurePinRestrictedPreference(preference)) {
return true;
}
}
mDevHitCountdown–;
if (mDevHitCountdown == 0) {
getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE).edit().putBoolean(
DevelopmentSettings.PREF_SHOW, true).apply();
if (mDevHitToast != null) {
mDevHitToast.cancel();
}
mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on,
Toast.LENGTH_LONG);
mDevHitToast.show();
} else if (mDevHitCountdown > 0
&& mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER-2)) {
if (mDevHitToast != null) {
mDevHitToast.cancel();
}
mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown),
Toast.LENGTH_SHORT);
mDevHitToast.show();
}
} else if (mDevHitCountdown < 0) {
if (mDevHitToast != null) {
mDevHitToast.cancel();
}
mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already,
Toast.LENGTH_LONG);
mDevHitToast.show();
}
}
Resume函数:
@Override
public void onResume() {
super.onResume();
PreferenceGroup parentPreference = getPreferenceScreen();
mDevHitCountdown = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW,
android.os.Build.TYPE.equals(“eng”)) ? -1 : TAPS_TO_BE_A_DEVELOPER;
mDevHitToast = null;
}
Setting的默认初始配置
frameworks/base/packages/SettingsProvider/res/values/default.xml
这里貌似可以修改很多东西,但要在
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
中初始化才会生效:
true
/mnt/sdcard
true
60000
false
cell,bluetooth,wifi,nfc,wimax
bluetooth,wifi,nfc
true
true
true
102
false
100%
10