Grant permissions to a service launched with ADB?


Question

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:


<uses-permission name="android.permission.WRITE_SECURE_SETTINGS" />


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:


<service name="a.i" permission="android.permission.BIND_ACCESSIBILITY_SERVICE" stopWithTask="true">
<meta-data name="android.accessibilityservice" resource="res/xml/accessibility.xml" />
<intent-filter>
<action name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>

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.


Answer

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.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes