在AndroidR user版本的设备上,如何默认打开USB调试,如何去掉USB调试确认弹窗

适用场景:例如自动化测试等场景,需要在开机后可以直接使用USB调试,无需手动打开。

修改方案:
修改1为默认打开usb调试,修改2为默认不弹框

修改1: build/core/main.mk

diff --git a/core/main.mk b/core/main.mk
index 6b34939..dbae91f 100755
--- a/core/main.mk
+++ b/core/main.mk
@@ -270,7 +270,8 @@
   # Target is secure in user builds.
   ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
   ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1
+  ADDITIONAL_DEFAULT_PROPERTIES += persist.sys.usb.config=adb
   ifeq ($(user_variant),user)
     ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
   endif

修改2:/frameworks/base/services/core/java/com/android/server/adb/AdbDebuggingManager.java

diff --git a/services/core/java/com/android/server/adb/AdbDebuggingManager.java b/services/core/java/com/android/server/adb/AdbDebuggingManager.java
index ed83a64..ae0d979 100644
--- a/services/core/java/com/android/server/adb/AdbDebuggingManager.java
+++ b/services/core/java/com/android/server/adb/AdbDebuggingManager.java
@@ -905,7 +905,8 @@
                     }
                     logAdbConnectionChanged(key, AdbProtoEnums.AWAITING_USER_APPROVAL, false);
                     mFingerprints = fingerprints;
-                    startConfirmationForKey(key, mFingerprints);
+                    //startConfirmationForKey(key, mFingerprints);
+                    allowDebugging(true,key);
                     break;
                 }

风险评估:默认打开USB调试可能存在系统安全风险,使用前需要根据具体场景做风险评估。

你可能感兴趣的:(Android系统,android)