Repository navigation
Expand file tree
/
Copy pathresetOnboarding.sh
More file actions
executable file
·108 lines (94 loc) · 3.88 KB
/
Copy pathresetOnboarding.sh
File metadata and controls
executable file
·108 lines (94 loc) · 3.88 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
#!/usr/bin/env bash
#
# resetOnboarding.sh — reset Faceclaw on an attached phone back to its
# pre-onboarding state, for testing the onboarding flow repeatedly.
#
# By default this only clears the onboarding-related preference keys
# (onboarding.complete, onboarding.previewOnly, ...) and leaves everything
# else — notably the saved glasses/ring MAC addresses — intact, so you don't
# have to re-scan devices on every test pass. Pass --all to wipe ALL app data
# (a true fresh-install state, addresses included).
#
# Usage:
# scripts/resetOnboarding.sh # reset onboarding flags only
# scripts/resetOnboarding.sh --all # full `pm clear` (wipes everything)
# scripts/resetOnboarding.sh -s <device-id> # target a specific adb device
#
# The device id defaults to $FACECLAW_DEVICE_ID, then to the id used by
# build_and_run.sh. adb is located the same way build.sh finds its tools.
set -euo pipefail
PACKAGE="com.faceclaw.app"
PREF_KEY_PREFIX="onboarding."
DEVICE_ID="${FACECLAW_DEVICE_ID:-3A101JEHN12330}"
WIPE_ALL=0
# Match build.sh's tool locations so adb is on PATH even from a bare shell.
export ANDROID_HOME="${ANDROID_HOME:-/Users/jbabcock/Library/Android/sdk}"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
while [ $# -gt 0 ]; do
case "$1" in
--all) WIPE_ALL=1; shift ;;
-s|--device) DEVICE_ID="$2"; shift 2 ;;
-h|--help)
sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
exit 0 ;;
*)
echo "unknown option: $1 (try --help)" >&2
exit 2 ;;
esac
done
command -v adb >/dev/null 2>&1 || { echo "error: adb not found on PATH" >&2; exit 1; }
ADB="adb -s $DEVICE_ID"
# Confirm the device is actually there before doing anything.
if ! $ADB get-state >/dev/null 2>&1; then
echo "error: adb device '$DEVICE_ID' not connected." >&2
echo " Connected devices:" >&2
adb devices -l | sed '1d' >&2
exit 1
fi
if [ "$WIPE_ALL" -eq 1 ]; then
echo "Wiping ALL app data for $PACKAGE (fresh-install state)..."
$ADB shell pm clear "$PACKAGE"
echo "Done. The next launch starts from a clean onboarding."
exit 0
fi
# Surgical reset: strip only the onboarding.* keys from the app's
# SharedPreferences XML, preserving saved device addresses and other settings.
# This needs run-as, which works for debuggable (sideloaded/dev) builds.
if ! $ADB shell run-as "$PACKAGE" true >/dev/null 2>&1; then
echo "run-as is unavailable for $PACKAGE (release build?)." >&2
echo "Falling back to a full data wipe; re-run with --all to silence this." >&2
$ADB shell pm clear "$PACKAGE"
echo "Done (full wipe)."
exit 0
fi
echo "Clearing onboarding preference keys ($PREF_KEY_PREFIX*) for $PACKAGE..."
# Force-stop first so the running app can't flush its in-memory preferences
# back over the files after we edit them.
$ADB shell am force-stop "$PACKAGE"
# List the shared_prefs XML files, then strip matching <... name="onboarding...">
# entries from each. toybox sed (present on modern Android) supports -i.
# Note: each remote command is passed to `adb shell` as ONE quoted string --
# adb joins multiple args with spaces without re-quoting, so inner quoting
# (e.g. sh -c '...') gets flattened and re-tokenized by the device shell.
FILES="$($ADB shell "run-as $PACKAGE ls shared_prefs 2>/dev/null" | tr -d '\r' || true)"
if [ -z "$FILES" ]; then
echo "No shared_prefs found; the app may not have run yet. Nothing to do."
exit 0
fi
CHANGED=0
for f in $FILES; do
case "$f" in
*.xml) ;;
*) continue ;;
esac
if $ADB shell "run-as $PACKAGE grep -q 'name=\"$PREF_KEY_PREFIX' shared_prefs/$f" >/dev/null 2>&1; then
$ADB shell "run-as $PACKAGE sed -i '/name=\"$PREF_KEY_PREFIX/d' shared_prefs/$f"
echo " cleared onboarding keys in shared_prefs/$f"
CHANGED=1
fi
done
if [ "$CHANGED" -eq 1 ]; then
echo "Done. Relaunch Faceclaw to go through onboarding again."
else
echo "No onboarding keys were set. App is already in pre-onboarding state."
fi