Grant permissions to a service launched with ADB? I'm trying to get a simple accessibility service, like Google's Voice Access or Button Mapper to work on an LG Exalt LTE, running a stripped down version of Marshmellow.
The stock is missing many UI components, including system Accessibility Settings, which are normally used for turning accessibility services on or off.
I would like to know if it is possible to compensate for lack of UI with ADB.
I've tried the following:
Install the app (Take Button Mapper for example),
Its manifest declares a few permissions, that i've granted, say:
&lt;uses-permission name=&quot;android.permission.WRITE_SECURE_SETTINGS&quot; /&gt;
was granted
adb shell pm grant package.name.here android.permission.WRITE_SECURE_SETTINGS
I even gave it
android.permission.WRITE_SECURE_SETTINGS
even though its not declared in the permissions list in the top of the manifest.
I get this error:
Operation not allowed: java.lang.SecurityException: Package package.name.here has not requested permission android.permission.BIND_ACCESSIBILITY_SERVICE
However, It is declared in the manifest here though:
&lt;service name=&quot;a.i&quot; permission=&quot;android.permission.BIND_ACCESSIBILITY_SERVICE&quot; stopWithTask=&quot;true&quot;&gt;
  &lt;meta-data name=&quot;android.accessibilityservice&quot; resource=&quot;res/xml/accessibility.xml&quot; /&gt;
  &lt;intent-filter&gt;
    &lt;action name=&quot;android.accessibilityservice.AccessibilityService&quot; /&gt;
  &lt;/intent-filter&gt;
&lt;/service&gt;

and thats where the problem is.
this is the service itself, and it requires a non-package-wide permission, BIND_ACCESSIBILITY_SERVICE.
if I start it with ADB like this
adb shell am startservice -n package.name.here/a.i
I get and error
Error: Requires permission android.permission.BIND_ACCESSIBILITY_SERVICE
even though I already granted the permission to the package.
I've even tried adb shell settings put secure enabled_accessibility_services package.name.here/.a.i, but still get the same error.
Bottom line:
How do I start a service and grant permissions to that service with ADB? To be clear. I already know that I can use adb shell pm grant to grant a permission to the whole package, but in this case it is a permission not required by the whole package it is declared in a specific component and I am at loss as to how to launch the component with the permissions it requires through ADB.
I believe I figured it out.
I'll use Voice Access as the example app.
adb shell am startservice com.android.cts.apps.accessibility.voiceaccess/com.google.android.apps.accessibility.voiceaccess.JustSpeakService

Next
adb shell settings put secure enabled_accessibility_services com.android.cts.apps.accessibility.voiceaccess/com.google.android.apps.accessibility.voiceaccess.JustSpeakService

Then
adb shell settings put secure accessibility_enabled 1

Then finally delete the the readout app, to avoid the accessibility features from being overwritten
adb shell pm uninstall -k --user 0 com.lge.voicecommand

I don't think there should be any errors after that, leave a comment if there are though.