前言
在机顶盒领域,经常会碰到客户定制产品时,希望屏蔽开发者选项,所以记录一下新的设计思路,供大家参考,本文实例是Rockchip平台 Android12 AOSP系统
一、屏蔽开发者选项
1.如果你不想完全删除代码或者注释代码,可以这样做;
设置一个始终为真的条件:
如果你不想完全删除代码,但想让它始终为假,你可以添加一个始终为真的条件来阻止相关代码的执行。例如,在if (mDevHitCountdown > 0)
之前添加一个if (false)
:
代码路径:
/packages/apps/TvSettings/Settings/src/com/android/tv/settings/about/AboutFragment.java
代码如下(示例):
+ if (false) { //增加一个false,阻止相关代码
--现有代码--
+ }
case KEY_BUILD_NUMBER:
logEntrySelected(TvSettingsEnums.SYSTEM_ABOUT_BUILD);
// Don't enable developer options for secondary users.
if (!mUm.isAdminUser()) {
return true;
}
if (mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtilsInternal
.checkIfRestrictionEnforced(getContext(),
UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.myUserId());
if (admin != null) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), admin);
}
return true;
}
if (false){ //add false, preventing the following code from executing
if (mDevHitCountdown > 0) {
mDevHitCountdown--;
if (mDevHitCountdown == 0) {
DevelopmentSettingsEnabler
.setDevelopmentSettingsEnabled(getContext(), true);
if (mDevHitToast != null) {
mDevHitToast.cancel();
}
mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on,
Toast.LENGTH_LONG);
mDevHitToast.show();
// This is good time to index the Developer Options
// Index.getInstance(
// getActivity().getApplicationContext()).updateFromClassNameResource(
// DevelopmentSettings.class.getName(), true, true);
} 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();
}
}
break;
2.如果编译的版本是userdebug版本,可以默认去将关闭usb debug,版本编译出来后,debug没是关闭的,开发者选项又调不出来,自然就无法使用adb调试了:
代码文件路径:build/make/core/main.mk b/build/make/core/main.mk
修改点:
user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
- enable_target_debugging := true
+ enable_target_debugging := false
代码修改如下(示例):
/build/make/core/main.mk b/build/make/core/main.mk
index c5a0baeef63..3480a7fb7f9 100644
--- a/build/make/core/main.mk
+++ b/build/make/core/main.mk
@@ -385,7 +385,7 @@ endif
## user/userdebug ##
user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
-enable_target_debugging := true
+enable_target_debugging := false
tags_to_install :=
ifneq (,$(user_variant))
# Target is secure in user builds.
总结
提示:这里对文章进行总结:
1、默认关闭usb debug
2、屏蔽开发者选项连点操作