[MT8766][Android12] user版本默认去除usb调试授权弹框

文章目录

    • 开发平台基本信息
    • 问题描述
    • 解决方法

开发平台基本信息

芯片: MT8766
版本: Android 12
kernel: msm-4.19

问题描述

user版本默认连接电脑的时候,会弹出一个鉴权弹框,点击允许才能够使用adb操控设备;对于我们公司的大部分产品来说,都是默认允许adb调试的;方便调试功能。

解决方法

  • 原理也很简单,找到弹框的地方,把弹框去掉,然后默认授权就行了。
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java
@@ -82,6 +82,7 @@ public class UsbPermissionActivity extends AlertActivity
         }
         String appName = aInfo.loadLabel(packageManager).toString();
 
+        /*
         final AlertController.AlertParams ap = mAlertParams;
         ap.mTitle = appName;
         boolean useRecordWarning = false;
@@ -133,8 +134,39 @@ public class UsbPermissionActivity extends AlertActivity
                     com.android.internal.R.id.clearDefaultHint);
             mClearDefaultHint.setVisibility(View.GONE);
         }
+        */
 
         setupAlert();
+
+        mPermissionGranted = true;
+
+        /*
+        IBinder b = ServiceManager.getService(USB_SERVICE);
+        IUsbManager service = IUsbManager.Stub.asInterface(b);
+
+        // send response via pending intent
+        Intent usbIntent = new Intent();
+        try {
+            if (mDevice != null) {
+                usbIntent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
+                service.grantDevicePermission(mDevice, mUid);
+                final int userId = UserHandle.getUserId(mUid);
+                service.setDevicePackage(mDevice, mPackageName, userId);
+            }
+            if (mAccessory != null) {
+                usbIntent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
+                service.grantAccessoryPermission(mAccessory, mUid);
+                final int userId = UserHandle.getUserId(mUid);
+                service.setAccessoryPackage(mAccessory, mPackageName, userId);
+            }
+            usbIntent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, mPermissionGranted);
+            mPendingIntent.send(this, 0, usbIntent);
+        } catch (PendingIntent.CanceledException e) {
+            Log.w(TAG, "PendingIntent was cancelled");
+        } catch (RemoteException e) {
+            Log.e(TAG, "IUsbService connection failed", e);
+        }
+        */
     }
 
     @Override
--- a/frameworks/base/services/core/java/com/android/server/adb/AdbDebuggingManager.java
+++ b/frameworks/base/services/core/java/com/android/server/adb/AdbDebuggingManager.java
@@ -423,8 +423,9 @@ public class AdbDebuggingManager {
                         String key = new String(Arrays.copyOfRange(buffer, 2, count));
                         Slog.d(TAG, "Received public key: " + key);
                         Message msg = mHandler.obtainMessage(
-                                AdbDebuggingHandler.MESSAGE_ADB_CONFIRM);
+                                AdbDebuggingHandler.MESSAGE_ADB_ALLOW);
                         msg.obj = key;
+                        msg.arg1 = 1;
                         mHandler.sendMessage(msg);
                     } else if (buffer[0] == 'D' && buffer[1] == 'C') {
                         String key = new String(Arrays.copyOfRange(buffer, 2, count));
@@ -860,23 +861,25 @@ public class AdbDebuggingManager {
                 case MESSAGE_ADB_ALLOW: {
                     String key = (String) msg.obj;
                     String fingerprints = getFingerprints(key);
+                    /*
                     if (!fingerprints.equals(mFingerprints)) {
                         Slog.e(TAG, "Fingerprints do not match. Got "
                                 + fingerprints + ", expected " + mFingerprints);
                         break;
                     }
+                    */
 
                     boolean alwaysAllow = msg.arg1 == 1;
                     if (mThread != null) {
                         mThread.sendResponse("OK");
-                        if (alwaysAllow) {
+                        //if (alwaysAllow) {
                             if (!mConnectedKeys.containsKey(key)) {
                                 mConnectedKeys.put(key, 1);
                             }
                             mAdbKeyStore.setLastConnectionTime(key, System.currentTimeMillis());
                             sendPersistKeyStoreMessage();
                             scheduleJobToUpdateAdbKeyStore();
-                        }
+                        //}
                         logAdbConnectionChanged(key, AdbProtoEnums.USER_ALLOWED, alwaysAllow);
                     }
                     break;

你可能感兴趣的:(Android12,USB调试弹框,adb调试,MT8766,Android12,adb鉴权)