Repository navigation
Expand file tree
/
Copy pathscreen-reader-setting.sh
More file actions
executable file
·121 lines (114 loc) · 6.27 KB
/
Copy pathscreen-reader-setting.sh
File metadata and controls
executable file
·121 lines (114 loc) · 6.27 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
#!/bin/sh
# The screen reader as a setting: `mobium accessibility screen_reader on`.
#
# docs/checks/screen-reader-setting.sh <android-serial | iphone-udid | simulator-udid>
#
# TalkBack on Android and VoiceOver on an iPhone, turned on for a session and
# put back when it ends, like every other accessibility setting. It checks:
#
# - it starts off, and `on` is confirmed by the platform itself — on
# Android TalkBack bound with touch exploration on, read here from
# dumpsys, not from Mobium; on an iPhone WebDriverAgent's VoiceOver
# state;
# - with it on, a tap still lands: MobiumApp's Form Demo selects Pro;
# - ending the session puts it back: on Android both keys exactly as found,
# still so three seconds later (the system rewrites accessibility_enabled
# while TalkBack unbinds, CHALLENGES 348), and on an iPhone VoiceOver off;
# - a simulator refuses, naming the Settings switch instead.
#
# TalkBack and VoiceOver take over touch for whoever holds the device: a
# phone only with ALLOW_PHONE=1, and the restore is registered before
# anything is turned on.
set -e
DEV="$1"
if [ -z "$DEV" ]; then echo "usage: $0 <serial|udid>" >&2; exit 2; fi
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
. "$ROOT/docs/checks/lib.sh"
check_lock "$DEV"
fail() { echo "FAIL: $*" >&2; exit 1; }
row() { printf ' %-10s %-60s ok\n' "$1" "$2"; }
APP=dev.mobium.mobiumapp
export MOBIUM_SESSION="${MOBIUM_SESSION:-srsetting}"
M="$ROOT/bin/mobium --device $DEV"
a() { adb -s "$DEV" shell "$@" | tr -d '\r'; }
case "$DEV" in
????????-????????????????) KIND=phone ;;
*-*-*-*-*) KIND=simulator ;;
emulator-*) KIND=emulator ;;
*) KIND=android-phone ;;
esac
echo "--- $DEV ($KIND)"
if [ "$KIND" = simulator ]; then
out=$($M accessibility screen_reader on 2>&1) && fail "a simulator turned VoiceOver on: $out"
echo "$out" | grep -q "Settings > Accessibility > VoiceOver" || fail "the refusal did not name the Settings switch: $out"
row "refused" "a simulator, naming its Settings switch"
echo PASS; exit 0
fi
case "$KIND" in
phone | android-phone) [ -n "$ALLOW_PHONE" ] || { echo "$DEV is a phone: a screen reader takes over its owner's touch. ALLOW_PHONE=1 to go ahead" >&2; exit 2; } ;;
esac
# The keys as found, read before any session: while a UiAutomator2 session is
# open Android sets accessibility_enabled to 1 — measured on the Pixel 8 Pro,
# where it is 0 — and a check that read it after its first call expected
# the 1 back and failed on the phone's own 0 (CHALLENGES 353).
if [ "$KIND" != phone ]; then
was_svc=$(a settings get secure enabled_accessibility_services)
was_on=$(a settings get secure accessibility_enabled)
fi
state=$($M accessibility screen_reader 2>/dev/null) || fail "the screen reader could not be read: $($M accessibility screen_reader 2>&1)"
[ "$state" = "screen_reader off" ] || { echo "the screen reader is already on ($state): left alone" >&2; exit 2; }
if [ "$KIND" = phone ]; then
# The backstop, if the session's own restore never runs: VoiceOver off.
at_exit "$M daemon stop >/dev/null 2>&1; MOBIUM_SESSION=srsetting-restore $M accessibility screen_reader off >/dev/null 2>&1; MOBIUM_SESSION=srsetting-restore $M daemon stop >/dev/null 2>&1"
else
explore() { a dumpsys accessibility | grep -o -m1 'touchExplorationEnabled=[a-z]*' | cut -d= -f2; }
talkback() { a dumpsys accessibility | sed -n '/Bound services:{/,/Enabled services/p' | grep -c 'label=TalkBack' || true; }
backstop() {
$M daemon stop >/dev/null 2>&1 || true
if [ "$(a settings get secure enabled_accessibility_services)" != "$was_svc" ]; then
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
sleep 3
fi
if [ "$(a settings get secure accessibility_enabled)" != "$was_on" ]; then
if [ "$was_on" = null ]; then a settings delete secure accessibility_enabled >/dev/null
else a "settings put secure accessibility_enabled '$was_on'"; fi
fi
}
at_exit backstop
fi
out=$($M accessibility screen_reader on 2>/dev/null) || fail "turning the screen reader on failed: $($M accessibility screen_reader on 2>&1)"
echo "$out" | grep -q "^screen_reader on (was off)" || fail "the answer was not on, from off: $out"
if [ "$KIND" = phone ]; then
# The session's own read says it changed the setting: "screen_reader on
# (changed by this session; …)".
case "$($M accessibility screen_reader)" in "screen_reader on"*) ;; *) fail "VoiceOver does not read back on" ;; esac
row "on" "VoiceOver, as WebDriverAgent reports it"
else
[ "$(talkback)" -ge 1 ] && [ "$(explore)" = true ] || fail "Mobium said on, and TalkBack is not bound with touch exploration"
row "on" "TalkBack bound, touch exploration on, read from dumpsys"
fi
# A tap with it on. TalkBack's own prompt may come up over the app first.
$M terminate $APP >/dev/null 2>&1 || true
$M launch $APP >/dev/null
$M scroll-to 'label="Form Demo"' --direction down >/dev/null 2>&1 || true
$M tap 'label="Form Demo"' >/dev/null
$M wait 'label=Pro' >/dev/null
$M tap 'label=Pro' >/dev/null || fail "the tap on Pro was refused with the screen reader on"
$M map 2>&1 | grep -q 'Pro (radio, checked)' || fail "the tap on Pro did not select it"
$M tap 'label=Free' >/dev/null
row "tap" "lands with it on: Pro selected, Free put back"
$M daemon stop >/dev/null
if [ "$KIND" = phone ]; then
got=$(MOBIUM_SESSION=srsetting-read $M accessibility screen_reader 2>/dev/null); MOBIUM_SESSION=srsetting-read $M daemon stop >/dev/null 2>&1 || true
[ "$got" = "screen_reader off" ] || fail "after the session VoiceOver reads '$got'"
row "restored" "VoiceOver off when the session ended"
else
i=0; until [ "$(explore)" != true ]; do i=$((i + 1)); [ $i -lt 15 ] || fail "touch exploration still on after the session"; sleep 1; done
sleep 3
[ "$(a settings get secure enabled_accessibility_services)" = "$was_svc" ] || fail "enabled services not as found: $(a settings get secure enabled_accessibility_services)"
[ "$(a settings get secure accessibility_enabled)" = "$was_on" ] || fail "accessibility_enabled is $(a settings get secure accessibility_enabled), found $was_on"
[ "$(talkback)" = 0 ] || fail "TalkBack still bound after the session"
row "restored" "both keys as found, TalkBack unbound, three seconds on"
fi
echo PASS