TLDR: You cannot use that command, and you cannot use another permission based command either.
Working solution to automate pressing this button
The only solution I could think of is it to use adb
to press the OK
button on the Connection request alert dialog generated by the OS:
adb shell uiautomator dump /sdcard/Download/view.xml
adb pull /sdcard/Download/view.xml
Observe the file, it contains the alert dialog. Specifically, OK is:
<node index="2" text="OK" resource-id="android:id/button1" class="android.widget.Button" package="com.android.vpndialogs" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[564,2040][1008,2148]" /></node>
Press it:
coords=$(perl -ne 'printf "%d %d\n", ($1+$3)/2, ($2+$4)/2 if /text="OK"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/' view.xml)
adb shell input tap $coords

Mostly inspired from Apricot's answer.
You might have tried: adb shell pm grant com.example.package_name android.permission.CONTROL_VPN
, but that won't work.
Exception occurred while executing 'grant':
java.lang.SecurityException: Package com.example.package_name has not requested permission android.permission.CONTROL_VPN
at com.android.server.pm.permission.BasePermission.enforceDeclaredUsedAndRuntimeOrDevelopment(BasePermission.java:453)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermissionInternal(PermissionManagerService.java:1549)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermissionInternal(PermissionManagerService.java:1503)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermission(PermissionManagerService.java:1495)
at com.android.server.pm.PackageManagerShellCommand.runGrantRevokePermission(PackageManagerShellCommand.java:2339)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:261)
at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
at android.os.ShellCommand.exec(ShellCommand.java:44)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:26885)
at android.os.Binder.shellCommand(Binder.java:965)
at android.os.Binder.onTransact(Binder.java:839)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:5206)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:5357)
at android.os.Binder.execTransactInternal(Binder.java:1195)
at android.os.Binder.execTransact(Binder.java:1159)
You have to request the permission using prepare(context)
.
Do you understand what settings
command is doing?
It's not for permissions.
enabled_accessibility_services
is used to change the Settings (in the Settings app) to enable a specific accessible service declared in an application. In this case, this accessibility service still needs the "android.permission.BIND_ACCESSIBILITY_SERVICE"
permission. It cannot add it through ADB.
There is no equivalent for VPN permissions within this, this command doesn't give permissions to applications, it configures the OS settings.