Android P开发者选项中的USB调试关闭

news/2024/12/22 0:50:48/

根据字符查找到开发者选项的字符是:reset_dashboard_title
packages/apps/Settings/res/xml/system_dashboard_fragment.xml
找到对应system_dashboard_fragment.xml调用的Java文件是:
packages/apps/Settings/src/com/android/settings/system/SystemDashboardFragment.java
进而找到:
packages/apps/Settings/src/com/android/settings/system/DashboardFragmentRegistry.java

     static {PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();PARENT_TO_CATEGORY_KEY_MAP.put(NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),CategoryKey.CATEGORY_CONNECT);PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),CategoryKey.CATEGORY_DEVICE);PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),CategoryKey.CATEGORY_APPS);PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),CategoryKey.CATEGORY_BATTERY);PARENT_TO_CATEGORY_KEY_MAP.put(DefaultAppSettings.class.getName(),CategoryKey.CATEGORY_APPS_DEFAULT);PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),CategoryKey.CATEGORY_DISPLAY);PARENT_TO_CATEGORY_KEY_MAP.put(SoundSettings.class.getName(),CategoryKey.CATEGORY_SOUND);PARENT_TO_CATEGORY_KEY_MAP.put(StorageDashboardFragment.class.getName(),CategoryKey.CATEGORY_STORAGE);PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),CategoryKey.CATEGORY_SECURITY);PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),CategoryKey.CATEGORY_ACCOUNT_DETAIL);PARENT_TO_CATEGORY_KEY_MAP.put(AccountDashboardFragment.class.getName(),CategoryKey.CATEGORY_ACCOUNT);PARENT_TO_CATEGORY_KEY_MAP.put(SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndInputSettings.class.getName(),CategoryKey.CATEGORY_SYSTEM_LANGUAGE);PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettingsDashboardFragment.class.getName(),CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),CategoryKey.CATEGORY_NOTIFICATIONS);PARENT_TO_CATEGORY_KEY_MAP.put(LockscreenDashboardFragment.class.getName(),CategoryKey.CATEGORY_SECURITY_LOCKSCREEN);PARENT_TO_CATEGORY_KEY_MAP.put(ZenModeSettings.class.getName(),CategoryKey.CATEGORY_DO_NOT_DISTURB);PARENT_TO_CATEGORY_KEY_MAP.put(GestureSettings.class.getName(),CategoryKey.CATEGORY_GESTURES);PARENT_TO_CATEGORY_KEY_MAP.put(NightDisplaySettings.class.getName(),CategoryKey.CATEGORY_NIGHT_DISPLAY);CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());for (Map.Entry<String, String> parentToKey : PARENT_TO_CATEGORY_KEY_MAP.entrySet()) {CATEGORY_KEY_TO_PARENT_MAP.put(parentToKey.getValue(), parentToKey.getKey());}}

以上见名知意,可以查看到DevelopmentSettingsDashboardFragment.java即为开发者选项的文件。
进入菜单时候初始化是否是开发者模式:

 @Overridepublic void onActivityCreated(Bundle icicle) {super.onActivityCreated(icicle);// Apply page-level restrictionssetIfOnlyAvailableForAdmins(true);if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {// Block access to developer options if the user is not the owner, if user policy// restricts it, or if the device has not been provisionedmIsAvailable = false;// Show error messageif (!isUiRestrictedByOnlyAdmin()) {getEmptyTextView().setText(R.string.development_settings_not_available);}getPreferenceScreen().removeAll();return;}// Set up master switchmSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();mSwitchBarController = new DevelopmentSwitchBarController(this /* DevelopmentSettings */, mSwitchBar, mIsAvailable, getLifecycle());mSwitchBar.show();// Restore UI state based on whether developer options is enabledif (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {enableDeveloperOptions();} else {disableDeveloperOptions();}}private void enableDeveloperOptions() {if (Utils.isMonkeyRunning()) {return;}DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);for (AbstractPreferenceController controller : mPreferenceControllers) {if (controller instanceof DeveloperOptionsPreferenceController) {((DeveloperOptionsPreferenceController) controller).onDeveloperOptionsEnabled();}}}private void disableDeveloperOptions() {if (Utils.isMonkeyRunning()) {return;}DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);final SystemPropPoker poker = SystemPropPoker.getInstance();poker.blockPokes();for (AbstractPreferenceController controller : mPreferenceControllers) {if (controller instanceof DeveloperOptionsPreferenceController) {((DeveloperOptionsPreferenceController) controller).onDeveloperOptionsDisabled();}}poker.unblockPokes();poker.poke();}

DevelopmentSettingsEnabler.java文件中:
判断开发者模式是否开启:

      public static final String DEVELOPMENT_SETTINGS_CHANGED_ACTION ="com.android.settingslib.development.DevelopmentSettingsEnabler.SETTINGS_CHANGED";private DevelopmentSettingsEnabler() {}public static void setDevelopmentSettingsEnabled(Context context, boolean enable) {Settings.Global.putInt(context.getContentResolver(),Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, enable ? 1 : 0);LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(DEVELOPMENT_SETTINGS_CHANGED_ACTION));}public static boolean isDevelopmentSettingsEnabled(Context context) {final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);final boolean settingEnabled = Settings.Global.getInt(context.getContentResolver(),Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,Build.TYPE.equals("eng") ? 1 : 0) != 0;final boolean hasRestriction = um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);final boolean isAdminOrDemo = um.isAdminUser() || um.isDemoUser();return isAdminOrDemo && !hasRestriction && settingEnabled;}

对应的布局文件是:packages/apps/Settings/res/xml/development_settings.xml

<PreferenceCategoryandroid:key="debug_debugging_category"android:title="@string/debug_debugging_category"android:order="200"><SwitchPreferenceandroid:key="enable_adb"android:title="@string/enable_adb"android:summary="@string/enable_adb_summary" /><Preference android:key="clear_adb_keys"android:title="@string/clear_adb_keys" /><SwitchPreferenceandroid:key="enable_terminal"android:title="@string/enable_terminal_title"android:summary="@string/enable_terminal_summary" />
....省略较多代码

其对应的实现位于:
frameworks/base/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java
对应ADB的开关如下:

    private boolean isAdbEnabled() {final ContentResolver cr = mContext.getContentResolver();return Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, ADB_SETTING_OFF)!= ADB_SETTING_OFF;}

然后在设置中查找对应的默认参数即可。
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

  private void loadSecureSettings(SQLiteDatabase db) {SQLiteStatement stmt = null;try {stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"+ " VALUES(?,?);");loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,R.string.def_location_providers_allowed);// Don't do this.  The SystemServer will initialize ADB_ENABLED from a// persistent system property instead.//loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);// Allow mock locations default, based on buildloadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,"1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);....//省略较多代码

根据以上注释重新查找persistent 中属性的位置;
frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java

UsbHandler(Looper looper, Context context, UsbDeviceManager deviceManager,UsbDebuggingManager debuggingManager, UsbAlsaManager alsaManager,UsbSettingsManager settingsManager) {super(looper);mContext = context;mDebuggingManager = debuggingManager;mUsbDeviceManager = deviceManager;mUsbAlsaManager = alsaManager;mSettingsManager = settingsManager;mContentResolver = context.getContentResolver();mCurrentUser = ActivityManager.getCurrentUser();mScreenLocked = true;/** Use the normal bootmode persistent prop to maintain state of adb across* all boot modes.*/mAdbEnabled = UsbHandlerLegacy.containsFunction(getSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, ""), UsbManager.USB_FUNCTION_ADB);mSettings = getPinnedSharedPrefs(mContext);if (mSettings == null) {Slog.e(TAG, "Couldn't load shared preferences");} else {mScreenUnlockedFunctions = UsbManager.usbFunctionsFromString(mSettings.getString(String.format(Locale.ENGLISH, UNLOCKED_CONFIG_PREF, mCurrentUser),""));}// We do not show the USB notification if the primary volume supports mass storage.// The legacy mass storage UI will be used instead.final StorageManager storageManager = StorageManager.from(mContext);final StorageVolume primary = storageManager.getPrimaryVolume();boolean massStorageSupported = primary != null && primary.allowMassStorage();mUseUsbNotification = !massStorageSupported && mContext.getResources().getBoolean(com.android.internal.R.bool.config_usbChargingMessage);}

查看具体的:USB_PERSISTENT_CONFIG_PROPERTY的属性值:
protected static final String USB_PERSISTENT_CONFIG_PROPERTY = “persist.sys.usb.config”;

继续查看有文件:
build/make/tools/post_process_props.py


# Put the modifications that you need to make into the /system/etc/prop.default into this
# function. The prop object has get(name) and put(name,value) methods.
def mangle_default_prop(prop):# If ro.debuggable is 1, then enable adb on USB by default# (this is for userdebug builds)if prop.get("ro.debuggable") == "1":val = prop.get("persist.sys.usb.config")if "adb" not in val:if val == "":val = "diag,serial_cdev,rmnet,adb"else:val = val + ",adb"prop.put("persist.sys.usb.config", val)# UsbDeviceManager expects a value here.  If it doesn't get it, it will# default to "adb". That might not the right policy there, but it's better# to be explicit.if not prop.get("persist.sys.usb.config"):prop.put("persist.sys.usb.config", "none");

如果ro.debuggable 为1 则赋值,否则不操作;
对应ro.debuggable的赋值过程见 build/make/core/main.mk

user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
tags_to_install :=
ifneq (,$(user_variant))# Target is secure in user builds.ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1ifeq ($(user_variant),user)ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1endififeq ($(user_variant),userdebug)# Pick up some extra useful toolstags_to_install += debugelse# Disable debugging in plain user builds.enable_target_debugging :=endif# Disallow mock locations by default for user buildsADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0else # !user_variant# Turn on checkjni for non-user builds.ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=0# Set device insecure for non-user builds.ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0# Allow mock locations by default for non user buildsADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
endif # !user_variantifeq (true,$(strip $(enable_target_debugging)))# Target is more debuggable and adbd is on by defaultifeq ($(user_variant),user)ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0elseADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1endif# Enable Dalvik lock contention logging.ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500# Include the debugging/testing OTA keys in this build.INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging# Target is less debuggable and adbd is off by defaultADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
endif # !enable_target_debugging

此处应该就是默认是否debug的位置;
如果以上修改依然不能成功,则需要判断开关的控制是否被拦截;具体文件可能是:
device/qcom/common / rootdir/etc/init.qcom.usb.sh


#
# Override USB default composition
#
# If USB persist config not set, set default configuration
if [ "$(getprop persist.vendor.usb.config)" == "" -a \"$(getprop init.svc.vendor.usb-gadget-hal-1-0)" != "running" ]; thenif [ "$esoc_name" != "" ]; thensetprop persist.vendor.usb.config diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,rmnet,adbelsecase "$(getprop ro.baseband)" in"apq")setprop persist.vendor.usb.config diag,adb;;*)case "$soc_hwplatform" in"Dragon" | "SBC")setprop persist.vendor.usb.config diag,adb;;*)case "$soc_machine" in"SA")setprop persist.vendor.usb.config diag,adb;;*)case "$target" in"msm8909")setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb;;"msm8937")if [ -d /config/usb_gadget ]; thensetprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adbelsecase "$soc_id" in"313" | "320")setprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adb;;*)setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb;;esacfi;;"msm8953")if [ -d /config/usb_gadget ]; thensetprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adbelsesetprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adbfi;;"msm8996")if [ -d /config/usb_gadget ]; thensetprop persist.vendor.usb.config diag,serial_cdev,rmnet,adbelsesetprop persist.vendor.usb.config diag,serial_cdev,serial_tty,rmnet_ipa,mass_storage,adbfi;;"msm8998" | "sdm660" | "apq8098_latv")setprop persist.vendor.usb.config diag,serial_cdev,rmnet,adb;;"sdm845" | "sdm710")setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb;;"msmnile" | "sm6150" | "trinket")setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,qdss,adb;;*)setprop persist.vendor.usb.config diag,adb;;esac;;esac;;esac;;esacfi
fi

按照以上配置屏蔽即可。


http://www.ppmy.cn/news/815618.html

相关文章

USB驱动调试

1、USB驱动在64位操作系统上的使用 Driver can support 64bit OS too. Please try&#xff1a; 1.open a command window as administrator. 2.bcdedit/set testsigning on 3.restart computer. 2、USB没有diag口 【问题】 手机有adb、mtp&#xff0c;但是没有Diagnostics…

安卓USB调试adb安装和使用

在Windows下安装adb工具 环境&#xff1a;Windows 10 1、下载和解压缩 下载地址&#xff1a; https://developer.android.google.cn/studio/releases/platform-tools 2、配置环境变量 我的电脑&#xff0c;右键选择属性-->高级系统设置-->设置pathadb的路径 3、cmd验证…

USB调试分析

最近在设计Jetson Xavier NX模块的底板&#xff0c;进行USB接口调试。由于USB HUB芯片设计错误&#xff0c;就直接调试了USB接口和NX模块直连的情况。 首先先了解USB2.0 和3.0 引脚上区别&#xff1a;从引脚上可以看出USB3.0为什么向下兼容。因为USB3.0引脚包含D,D- USB HOST…

解决Android调试不显示 “允许USB调试” 认证窗口

问题 真机调试&#xff0c;连接USB后&#xff0c;通常会显示如下认证。 未认证的设备显示如下 有些机器在某些情况下&#xff0c;可能没有弹出认证窗口&#xff0c;可以通过下面的方式尝试解决。 解决 执行 adb reconnect在开发者选项中撤销USB调试授权 重新插拔USB调试线…

USB debugging 菜单在哪里

大家都知道要调试真的时候要把USB debugging菜单打开&#xff0c;但今天拿到一个机子却怎么也找不到&#xff0c;原来被隐藏掉了 大多数机器&#xff08;Android 3.2 或更老&#xff09;, 都可以在设置->应用程序->开发下找到USB调试&#xff08;Settings > Applicat…

usb调试与adb调试

之前没有太注意二者的区别&#xff0c;这里简单记录一下。 usb调试&#xff0c;android应用开发或许经常会用到&#xff0c;之前我也是用这个方式来调试程序的&#xff0c;android设备如果是手机的话就很方便&#xff0c;设备打开usb调试&#xff0c;并用数据线连接电脑与andr…

开机默认usb debug 调试,且不弹窗自动确认选择。默认开启开发者模式(不是仅仅开启开发者菜单)。

总结下这个默认开启开发者模式问题就是&#xff0c; Settings.Global.putInt(getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); Settings.Global.putInt(context.getContentResolver(), Settings.Global.ADB_ENABLED, 1); 这两句…

ADB调试USB设备指南

Android设备的USB功能&#xff0c;是现有产品中一个必要组成部分&#xff0c;但常用的ADB调试&#xff0c;需要运行在USB模式下&#xff0c;导致USB被占用&#xff0c;无法挂载USB外设&#xff0c;所以采用WIFI模式来进行ADB调试可以更加方便和直观。 环境准备 Android Studi…