1
adb devices

ADB授权脚本自动开启无障碍权限

获取包名

1
toastLog(context.getPackageName());

开启无障碍权限

$packageName$替换成实际的AutoJS包名;

1
adb shell pm grant '$packageName$' android.permission.WRITE_SECURE_SETTINGS

例如:

1
adb shell pm grant org.autojs.autojs6 android.permission.WRITE_SECURE_SETTINGS

撤销无障碍权限

1
adb shell pm revoke '$packageName$' android.permission.WRITE_SECURE_SETTINGS

投影媒体权限

1
adb shell appops set org.autojs.autojs6 PROJECT_MEDIA allow

检验ADB权限

1
2
importClass(android.content.pm.PackageManager)
toastLog('是否有ADB权限' + (PackageManager.PERMISSION_GRANTED === context.getPackageManager().checkPermission('android.permission.WRITE_SECURE_SETTINGS', context.getPackageName())))

报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Exception occurred while executing 'set':
java.lang.SecurityException: uid 2000 does not have android.permission.MANAGE_APP_OPS_MODES.
at android.app.ContextImpl.enforce(ContextImpl.java:2189)
at android.app.ContextImpl.enforcePermission(ContextImpl.java:2198)
at com.android.server.appop.AppOpsService.enforceManageAppOpsModes(AppOpsService.java:2575)
at com.android.server.appop.AppOpsService.setMode(AppOpsService.java:2905)
at com.android.server.appop.AppOpsService.setMode(AppOpsService.java:2900)
at com.android.server.appop.AppOpsService.onShellCommand(AppOpsService.java:5680)
at com.android.server.appop.AppOpsService$Shell.onCommand(AppOpsService.java:5449)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.appop.AppOpsService.onShellCommand(AppOpsService.java:5621)
at android.os.Binder.shellCommand(Binder.java:971)
at android.os.Binder.onTransact(Binder.java:855)
at com.android.internal.app.IAppOpsService$Stub.onTransact(IAppOpsService.java:1198)
at com.android.server.appop.OplusAppOpsService.onTransact(OplusAppOpsService.java:38)
at android.os.Binder.execTransactInternal(Binder.java:1227)
at android.os.Binder.execTransact(Binder.java:1164)

解决办法

设置 –> 开发者选项 –> 禁用监控权限

参考链接