Repository navigation
Expand file tree
/
Copy pathscreen-reader.sh
More file actions
executable file
·123 lines (114 loc) · 5.95 KB
/
Copy pathscreen-reader.sh
File metadata and controls
executable file
·123 lines (114 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
# A screen reader stays on while the default driver drives the device.
#
# docs/checks/screen-reader.sh <android-serial>
#
# Android's test-automation connection silences every other accessibility
# service unless it is opened not to (CHALLENGES 208). The UiAutomator2
# server opens it so only when its instrumentation is started with
# DISABLE_SUPPRESS_ACCESSIBILITY_SERVICES — not a setting or a capability —
# and Mobium starts it that way. This turns TalkBack on and checks, with a
# UiAutomator2 session open:
#
# - TalkBack, and any service already on, stay bound, and touch
# exploration stays on;
# - a tap, a scroll and typing still land, as MobiumApp says;
# - the device's accessibility settings are back exactly as found after.
#
# The suppression it guards against shows as TalkBack missing from the bound
# services, and touch exploration off, for as long as the session is open.
#
# It changes a setting a person relies on, and TalkBack takes over touch for
# whoever holds the device: an emulator only, unless ALLOW_PHONE=1. Needs
# TalkBack (com.google.android.marvin.talkback) and MobiumApp installed.
set -e
DEV="$1"
if [ -z "$DEV" ]; then echo "usage: $0 <android-serial>" >&2; exit 2; fi
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
. "$ROOT/docs/checks/lib.sh"
check_platform android "$DEV"
check_lock "$DEV"
fail() { echo "FAIL: $*" >&2; exit 1; }
row() { printf ' %-14s %-58s ok\n' "$1" "$2"; }
APP=dev.mobium.mobiumapp
TB=com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService
export MOBIUM_SESSION="${MOBIUM_SESSION:-srcheck}"
M="$ROOT/bin/mobium --device $DEV"
a() { adb -s "$DEV" shell "$@" | tr -d '\r'; }
case "$DEV" in
emulator-*) ;;
# Refused, not failed: exit 2, as audio.sh refuses a phone, so a sweep
# reads it as not run rather than as broken.
*) [ -n "$ALLOW_PHONE" ] || { echo "$DEV is not an emulator: TalkBack would take over a person's phone. ALLOW_PHONE=1 to go ahead" >&2; exit 2; } ;;
esac
a pm list packages com.google.android.marvin.talkback | grep -q talkback || fail "TalkBack is not installed on $DEV"
echo "--- $DEV"
bound() {
a dumpsys accessibility | python3 -c '
import re, sys
t = sys.stdin.read()
m = re.search(r"Bound services:\{(.*?)\}\s*\n\s*Enabled services", t, re.S)
print(",".join(re.findall(r"label=([^,]+)", m.group(1))) if m else "")'
}
exploring() { a dumpsys accessibility | grep -o -m1 'touchExplorationEnabled=[a-z]*' | cut -d= -f2; }
was_svc=$(a settings get secure enabled_accessibility_services)
was_on=$(a settings get secure accessibility_enabled)
# adb shell joins its arguments into one line for the device's shell, so an
# empty value vanishes and a phone's "" would be put back as nothing at all:
# every value goes over quoted.
restore() {
$M daemon stop >/dev/null 2>&1 || true
if [ "$was_svc" = null ]; then a settings delete secure enabled_accessibility_services >/dev/null
else a "settings put secure enabled_accessibility_services '$was_svc'"; fi
# While TalkBack unbinds the system writes accessibility_enabled itself: on
# the Pixel 8 Pro it was 1 again after the phone's 0 had been put back
# (CHALLENGES 348). So it is put back once touch exploration has ended,
# and read back after a pause.
_i=0; until [ "$(exploring)" != true ] || [ $_i -ge 15 ]; do _i=$((_i + 1)); sleep 1; done
for _k in 1 2 3; do
if [ "$was_on" = null ]; then a settings delete secure accessibility_enabled >/dev/null
else a "settings put secure accessibility_enabled '$was_on'"; fi
sleep 2
[ "$(a settings get secure accessibility_enabled)" = "$was_on" ] && break
done
}
at_exit restore
$M daemon stop >/dev/null 2>&1 || true
if [ "$was_svc" = null ] || [ -z "$was_svc" ]; then on="$TB"; else on="$was_svc:$TB"; fi
a settings put secure enabled_accessibility_services "$on"
a settings put secure accessibility_enabled 1
# Touch exploration comes on a moment after TalkBack is bound: wait for both.
i=0; until bound | grep -q TalkBack && [ "$(exploring)" = true ]; do
i=$((i + 1)); [ $i -lt 30 ] || fail "TalkBack did not come up with touch exploration after being enabled"; sleep 1
done
before=$(bound)
row "talkback" "on, bound: $before"
# A session: the server starts with the screen reader running.
$M terminate "$APP" >/dev/null 2>&1 || true
$M launch "$APP" >/dev/null
[ "$(bound)" = "$before" ] || fail "with a session open the bound services are '$(bound)', were '$before' — the screen reader was silenced"
[ "$(exploring)" = true ] || fail "touch exploration went off when the session opened"
row "session" "open, every service still bound, touch exploration on"
$M scroll-to "label=Motion Demo" >/dev/null 2>&1 || true
$M tap "label=Motion Demo" >/dev/null
$M tap "label=Replay Ignoring" >/dev/null
$M tap "label=Ignoring target" >/dev/null
$M text testid=ignoringResult | grep -q "tapped" || fail "a tap did not land with TalkBack on: $($M text testid=ignoringResult)"
row "tap" "landed, as the app says"
$M press back >/dev/null
$M scroll-to "label=Slider Demo" >/dev/null || fail "scrolling did not reach Slider Demo with TalkBack on"
$M scroll-to "label=Login Demo" --direction up >/dev/null
$M tap "label=Login Demo" >/dev/null
$M fill testid=username "screen-reader-on" >/dev/null
[ "$($M text testid=username)" = "screen-reader-on" ] || fail "typing did not land with TalkBack on: $($M text testid=username)"
row "scroll, type" "both landed"
[ "$(bound)" = "$before" ] || fail "after the actions the bound services are '$(bound)'"
[ "$(exploring)" = true ] || fail "touch exploration went off during the actions"
row "after" "every service still bound, touch exploration on"
$M terminate "$APP" >/dev/null 2>&1 || true
restore
at_exit_clear
[ "$(a settings get secure enabled_accessibility_services)" = "$was_svc" ] || fail "enabled services not put back: $(a settings get secure enabled_accessibility_services)"
[ "$(a settings get secure accessibility_enabled)" = "$was_on" ] || fail "accessibility_enabled not put back"
row "restored" "the device's accessibility settings as found"
echo PASS