Skip to content

Instantly share code, notes, and snippets.

@mrk-han
Last active June 9, 2024 23:02
Show Gist options
  • Save mrk-han/67a98616e43f86f8482c5ee6dd3faabe to your computer and use it in GitHub Desktop.
Save mrk-han/67a98616e43f86f8482c5ee6dd3faabe to your computer and use it in GitHub Desktop.
Enable and Disable Android Accessibility Settings from the Command Line using ADB (Font scale, talkback, color blind)

Using ADB to control Accessbility settings for easier testing with Android Emulators + Real Devices

It's a lot easier to test accessibility on the fly using ADB. This gist attempts to make the days of navigating through the Android device settings UI to change Accessibility settings obsolete.

These ADB commands will hopefully encourage Android developers to test and use their apps with common Accessiblility settings enabled.

Credit to James Nitsch for inspiring this, and for figuring out the put commands to enable these settings.

Font Scale (Font Size -- Testing Dynamic Text)

adb shell settings put system font_scale 0.85 (small)

adb shell settings put system font_scale 1.0 (default)

adb shell settings put system font_scale 1.15 (large)

adb shell settings put system font_scale 1.30 (largest)

adb shell settings put system font_scale 2.0 (sizes like this can only be achieved with custom adb setting, not from ui)

Talkback

disable talkback

adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService

enable talkback

adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService

Color

Properties:

accessibility_display_daltonizer_enabled=1
accessibility_display_daltonizer=11
accessibility_display_daltonizer=12
accessibility_display_daltonizer=13

Examples:

adb shell settings put secure accessibility_display_daltonizer_enabled 1

adb shell settings put secure accessibility_display_daltonizer 0

adb shell settings put secure accessibility_display_daltonizer 11

adb shell settings put secure accessibility_display_daltonizer 12

adb shell settings put secure accessibility_display_daltonizer 13

0 == Monochromatic
11 is for Deuteranomaly (red-green)
12 is for Protanomaly (red-green)
13 is for Tritanomaly (blue-yellow)

Color Inversion

Property: accessibility_display_inversion_enabled=1

ADB Command: adb shell settings put secure accessibility_display_inversion_enabled 1

High Contrast Text

Property: high_text_contrast_enabled=1

ADB Command: adb shell settings put secure high_text_contrast_enabled 1

Magnification

Set: adb shell settings put secure accessibility_display_magnification_scale 5.0

Enable: adb shell settings put secure accessibility_display_magnification_enabled 1

Disable: adb shell settings put secure accessibility_display_magnification_enabled 0

List Existing Properties

adb shell settings list system
adb shell settings list global
adb shell settings list secure

Also, adb shell getprop is a great way to expose a lot of other properties you can change with the adb shell setprop functionality

Show Touches

adb shell settings put system show_touches 1

Pointer Location

adb shell settings put system pointer_location 1

https://developer.android.com/reference/android/provider/Settings

@AndroidDeveloperLB
Copy link

Are you sure enabling Accessbility is possible nowadays?
I've tried it, and it caused only issues. Tested on both Pixel 4 and emulator with Android R.
Also reported here about this:
https://issuetracker.google.com/issues/186875374

@bhy
Copy link

bhy commented Oct 31, 2021

To enable accessibility menu:

adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.accessibility.accessibilitymenu.AccessibilityMenuService

@AndroidDeveloperLB
Copy link

AndroidDeveloperLB commented Oct 31, 2021

To enable accessibility menu:

adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.accessibility.accessibilitymenu.AccessibilityMenuService

Have you checked the link? Google said they've reproduced the issue and fixed it. Have you tried on Android 12 now?

I don't understand what's going on...

@bhy
Copy link

bhy commented Oct 31, 2021

@AndroidDeveloperLB My phone don't have Android 12, so I have no idea about that.

@msenyer
Copy link

msenyer commented Dec 16, 2022

Hi, maybe this is not exactly related with what you posted but I thought you might be able to help me.
How would you disable the "TalkBack shortcut", on the TalkBack accessibility menu?
Thank you in advance
@mrk-han

@mrk-han
Copy link
Author

mrk-han commented Dec 16, 2022

@msenyer Try launching the Settings app and then selecting Accessibility. Then tap selectTalkBack, and then toggle the talkback shortcut. It may depend on your OS level and what flavor of Android you're running.

@msenyer
Copy link

msenyer commented Dec 19, 2022

@mrk-han I meant using adb! I don't know if that is possible, though

@mrk-han
Copy link
Author

mrk-han commented Dec 20, 2022

@msenyer There's a huge list of settings you can check out with a device attached

adb shell settings list secure
adb shell settings list system
adb shell settings list global
adb shell getprop

It might be in that list somewhere, but I haven't tried the specific thing you're talking about

@mrk-han
Copy link
Author

mrk-han commented Dec 20, 2022

adb shell settings put secure enabled_accessibility_services PACKAGE_NAME/PROVIDER_NAME might work if you get the provider name

@qbalsdon
Copy link

qbalsdon commented Jan 20, 2023

This is a great list! However I have noticed issues when turning TalkBack off with

adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService

On some devices, like a Samsung S21, it really breaks my on screen keyboard experience. I have found that

adb shell settings put secure enabled_accessibility_services \"\"

Works great on all devices, including Pixel phones. I imagine it was some sort of "find and replace" magic they had in earlier versions of Android.

Also, it might be helpful to note that enabled_accessibility_services is a colon (:) separated list of services, so you can enable a few at the same time if you like. Voice Access, Switch Access, Accessibility Scanner, and your own A11yServices

@mrk-han
Copy link
Author

mrk-han commented Jan 21, 2023

This is a great list! However I have noticed issues when turning TalkBack off with

adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService

On some devices, like a Samsung S21, it really breaks my on screen keyboard experience. I have found that

adb shell settings put secure enabled_accessibility_services \"\"

Works great on all devices, including Pixel phones. I imagine it was some sort of "find and replace" magic they had in earlier versions of Android.

Also, it might be helpful to note that enabled_accessibility_services is a colon (:) separated list of services, so you can enable a few at the same time if you like. Voice Access, Switch Access, Accessibility Scanner, and your own A11yServices

@qbalsdon Thank you so much for your contribution! This is great info. 🥳

@arendon1
Copy link

arendon1 commented May 16, 2023

I'm sorry to asking such a dumb question.
I do not develop for android, but I do have an annoyance where a specific app I enjoy uses an accesibility service to be able to be able to server its purpose.

Android keeps disabling it constantly and idk how to tell it to stop doing that.

I do have locally enable it on the phone, and then extracted the enabled_accessibility_services string I need to fullfill my need. But I need to know how pass an adb shell command with multiple devices/emulators simultaneosly connected, I know there's a -s <serial> flag, but I do seem to find how to structure the string for the command.

adb shell *-s <serial>* settings... did not work. Should it be after de settings key?

I'd appreaciate some light on this, as I cannot find something that specific online.

Edit:
I found my issue. I was structuring the thing all wrong. But I'd appreaciate in some process to avoid having to this each time. I want that specific service be always on.

@qbalsdon
Copy link

qbalsdon commented May 22, 2023

Hey @arendon1 - this annoys me too - I wrote something that isn't pretty, but will work:

function ADB_ALL {
    COMMAND="$1"
    COMMAND_RESULT=""
    adb devices | awk '{print $1}' | tail -n +2 | grep . | while read serial; do COMMAND_RESULT="${COMMAND_RESULT}adb -s $serial $COMMAND;"; done
    eval $COMMAND_RESULT
    unset COMMAND_RESULT
}

You can add this to your ~./zshenv or ~/.bash_profile file. Usage would be:

# talkback on
ADB_ALL "shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/.TalkBackService"

# talkback off
ADB_ALL "shell settings put secure enabled_accessibility_services \\\"\\\""

Note: I couldn't execute the commands inside the loop because it would exit after the first one. Happy for this to be improved

@arendon1
Copy link

@qbalsdon you are so kind to give such an intricate solution!
I see the script you've made it's to use inside bash! Unfortunately as I'm on a Windows based workstation, I won't be able to reproduce that verbatim. But maybe I could try to port it to PowerShell core. It seems a pretty good base to start.

Thank you so much again for the time you've spent creating that!
<3 from Colombia!

@qbalsdon
Copy link

qbalsdon commented May 24, 2023

Ah shucks! Windows! My one weakness!

So if you install cygwin you can run bash and sh commands on Windows, but you do need to learn a bit there. I do have a Windows box I mess around on. I'll try come up with an equivalent. I'm really keen on scripting for Android!

Hello from the UK! 🇬🇧

@msenyer
Copy link

msenyer commented Jul 11, 2023

Hi everyone! I just wanted to pass by to let you know I found what I was looking for, hope this may help someone in the future.
This was my problem:

Hi, maybe this is not exactly related with what you posted but I thought you might be able to help me. How would you disable the "TalkBack shortcut", on the TalkBack accessibility menu? Thank you in advance @mrk-han

And I wanted it to be solved with and adb command.

Screenshot_2023-07-11-16-35-46-072

I needed this "talkback shortcut" to be programmatically turned off.

The command adb shell settings put secure accessibility_shortcut_target_service null does the job :)

Thank you all for your help in this process, I finally found it.

@mrk-han
Copy link
Author

mrk-han commented Jul 12, 2023

@msenyer Thank you for the update! This is great info. Maybe when I find time I'll revise this document. Much appreciated.

@artmrch
Copy link

artmrch commented Aug 23, 2023

adb shell settings list secure

give me nothing

@qbalsdon
Copy link

@artmrch does the device appear when you use adb devices?

List of devices attached
[DEVICE_SERIAL_NUMBER]	device

Note it must have 'device' next to it, if it says anything else (for example, 'unauthorized') then there are other steps you need to take

I'm not sure of your experience level, so I apologize if you have done these, but it's good to check:

  1. Have you installed adb
  2. Put adb on the path
  3. Turned on developer mode on the phone and after plugging it in with a cable, opt in to trust the computer

@artmrch
Copy link

artmrch commented Aug 23, 2023

yes it shows

i did daltonizer color already
and its great
couldnt find any app to do it

but i cant check if there are more settings with

settings list

@qbalsdon
Copy link

Another thing you can try is:

  1. adb shell [press enter to enter the phone shell]
  2. settings list secure [while in the shell]
    2.1 settings list global [to see if you can get the global settings]
  3. exit [when you're done]

If there is an error getting the secure settings, try getting the global settings. Also if there is another profile (for work or whatever) that may be preventing you from getting access

@artmrch
Copy link

artmrch commented Aug 24, 2023

no error, just nothing

how do i check that something preventing it
daltonizer, zoom, contrast work like a charm
i just got interested what else i can do

like remove all the shadows from layers and pop-up massages

@mrk-han
Copy link
Author

mrk-han commented Aug 25, 2023

@artmrch Some of the settings are dependent on which device/emulator you are using.

@artmrch
Copy link

artmrch commented Sep 17, 2023

@artmrch Some of the settings are dependent on which device/emulator you are using.

flymeos 5.1.5.3G

it seems that settings command have no
'list' option :/

anyway, i have found some other great accessabillity commands

-- accelerometer_rotation --

adb shell settings put system accelerometer_rotation 0

adb shell settings put system user_rotation 0,1,2,3

0 - portaite
1 - 90' (landscape)
2 - 180' (reverse portait)
3 - 270' (reverse landscape)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment