Android 11.0 默认开启USB调试功能

Android 11.0 默认开启USB调试功能

近来收到项目反馈需求想要默认开启USB调试功能,默认开启USB调试功能主要是在UsbDebuggingActivity.java文件中实现,具体修改参照如下:

/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java

        public void onReceive(Context content, Intent intent) {
            String action = intent.getAction();
            if (!UsbManager.ACTION_USB_STATE.equals(action)) {
                return;
            }
-            boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
+            boolean connected = false;
+            if (!connected) {
+                mActivity.finish();
+            }
+   	   try {
+		 IBinder b = ServiceManager.getService(ADB_SERVICE);
+		 IAdbManager service = IAdbManager.Stub.asInterface(b);
+		 service.allowDebugging(true, mKey);
+		 } catch (Exception e) {
+		 	Log.e(TAG, "Unable to notify Usb service", e);
+			 }
        }

默认开启USB调试功能的话,USB调试的权限申请弹窗自然也要去掉,去掉弹窗并默认赋予权限是在UsbPermissionActivity.java文件中修改,具体修改参照如下:

/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java
 

            mAlwaysUse.setOnCheckedChangeListener(this);

            mClearDefaultHint = (TextView)ap.mView.findViewById(
                    com.android.internal.R.id.clearDefaultHint);
            mClearDefaultHint.setVisibility(View.GONE);
        }

-        setupAlert();
+        mPermissionGranted = true;
+        finish();
    }

重新编译验证,修改生效,已默认开启USB调试功能

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