1、刷机完成或者OTA升级完成使设备USB调试口默认为关闭状态
packages/apps/Provision/src/com/android/provision/DefaultActivity.java
@@ -34,7 +34,7 @@ public class DefaultActivity extends Activity {// Add a persistent setting to allow other apps to know the device has been provisioned.Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);//Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);+ Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);// remove this activity from the package manager.PackageManager pm = getPackageManager();
2、重启设备使设备USB调试开关保持原有状态
frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
protected long mScreenUnlockedFunctions;protected boolean mAdbEnabled;+ protected boolean mBootAdbEnabled;protected boolean mBootCompleted;protected boolean mCurrentFunctionsApplied;protected boolean mUseUsbNotification;mAdbEnabled = UsbHandlerLegacy.containsFunction(getSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, ""), UsbManager.USB_FUNCTION_ADB);+ mBootAdbEnabled = (Settings.Global.getInt(mContentResolver,Settings.Global.ADB_ENABLED, 1) > 0);mSettings = getPinnedSharedPrefs(mContext);if (mSettings == null) {Slog.e(TAG, "Couldn't load shared preferences");updateUsbNotification(false);updateAdbNotification(false);updateUsbFunctions();+if (!mBootAdbEnabled){+ putGlobalSettings(mContentResolver, Settings.Global.ADB_ENABLED, 0);+}}}
3、通过setting->开发者选项 开启USB调试PC端无法找到设备com口
(1)添加vendor_usb_prop操作权限
device/qcom/sepolicy/vendor/msm8953/system_server.te
@@ -28,3 +28,4 @@r_dir_file(system_server, vendor_carrier_file);allow system_server resourcecache_data_file:dir create_dir_perms;allow system_server resourcecache_data_file:file create_file_perms;+ allow system_server vendor_usb_prop:file {read open getattr};
(2)重新开启USB调试口后需要对"persist.sys.usb.config"赋权限"diag,serial_cdev,rmnet,adb"
frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
* May also contain vendor-specific default functions for testing purposes.*/protected static final String USB_PERSISTENT_CONFIG_PROPERTY = "persist.sys.usb.config";+ protected static final String VENDOR_USB_PERSISTENT_CONFIG_PROPERTY = "persist.vendor.usb.config";UsbHandler(Looper looper, Context context, UsbDeviceManager deviceManager,UsbDebuggingManager debuggingManager, UsbAlsaManager alsaManager,if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable);if (enable != mAdbEnabled) {mAdbEnabled = enable;+String functions = getSystemProperty(VENDOR_USB_PERSISTENT_CONFIG_PROPERTY, "");if (enable) {- setSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_ADB);+ setSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, functions);+ //setSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_ADB);} else {setSystemProperty(USB_PERSISTENT_CONFIG_PROPERTY, "");}
注意:
diag立即生效: adb shell setprop sys.usb.config diag,serial_cdev,rmnet,adb
diag重启生效: adb shell setprop persist.sys.usb.config diag,serial_cdev,rmnet,adb