Skip to content

Commit 01b86fc

Browse files
authored
Fix Wear OS screenshot capture with granted location + Gibraltar scenarios (#15)
1 parent 20fd8d4 commit 01b86fc

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/wearos-emulator-screenshots.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ on:
4848
description: "Deep links separated by comma or newline"
4949
required: false
5050
type: string
51-
default: "eclipsetimer://wear/landing,eclipsetimer://wear/live,eclipsetimer://wear/preview,eclipsetimer://wear/diagnostics"
51+
default: "eclipsetimer://wear/live?scenario=gibraltar-between-c1-c3,eclipsetimer://wear/live?scenario=gibraltar-max"
5252

5353
concurrency:
5454
group: wearos-screenshots-${{ github.ref }}
@@ -430,6 +430,30 @@ jobs:
430430
431431
adb -s "$emulator_serial" install -r "$APP_PATH"
432432
433+
adb -s "$emulator_serial" shell pm grant "$BUNDLE_ID" android.permission.ACCESS_FINE_LOCATION || true
434+
adb -s "$emulator_serial" shell pm grant "$BUNDLE_ID" android.permission.ACCESS_COARSE_LOCATION || true
435+
436+
adb -s "$emulator_serial" shell settings put global auto_time 0 || true
437+
adb -s "$emulator_serial" shell settings put global auto_time_zone 0 || true
438+
439+
set_emulator_time_utc() {
440+
local iso_utc="$1"
441+
local compact_utc
442+
compact_utc="$(date -u -j -f "%Y-%m-%dT%H:%M:%SZ" "$iso_utc" "+%Y%m%d.%H%M%S" 2>/dev/null || true)"
443+
if [ -z "$compact_utc" ]; then
444+
compact_utc="$(printf '%s' "$iso_utc" | tr -d ':-' | sed -E 's/T/./; s/Z$//')"
445+
fi
446+
447+
adb -s "$emulator_serial" shell "date -u $compact_utc" >/dev/null 2>&1 || true
448+
adb -s "$emulator_serial" emu avd host-time-scale 1 >/dev/null 2>&1 || true
449+
}
450+
451+
set_emulator_geo_gibraltar() {
452+
local lat="36.1408"
453+
local lon="-5.3536"
454+
adb -s "$emulator_serial" emu geo fix "$lon" "$lat" >/dev/null 2>&1 || true
455+
}
456+
433457
wait_for_app_foreground() {
434458
local package_name="$1"
435459
for _ in {1..30}; do
@@ -450,8 +474,6 @@ jobs:
450474
echo "::warning::App did not enter the foreground after initial launch."
451475
fi
452476
sleep "$STARTUP_WAIT_SECONDS"
453-
adb -s "$emulator_serial" exec-out screencap -p > "$shots_dir/00-launch.png"
454-
printf "00,launch,00-launch.png\n" >> "$shots_dir/manifest.csv"
455477
456478
DEEP_LINKS_INPUT="$(cat <<'EOF'
457479
${{ github.event.inputs.deep_links }}
@@ -470,13 +492,25 @@ jobs:
470492
index=1
471493
while IFS= read -r url; do
472494
[ -z "$url" ] && continue
495+
496+
case "$url" in
497+
*gibraltar-between-c1-c3*)
498+
set_emulator_time_utc "2027-08-02T08:23:09Z"
499+
set_emulator_geo_gibraltar
500+
;;
501+
*gibraltar-max*)
502+
set_emulator_time_utc "2027-08-02T08:47:59Z"
503+
set_emulator_geo_gibraltar
504+
;;
505+
esac
506+
473507
slug="$(printf '%s' "$url" | sed -E 's#^[a-zA-Z][a-zA-Z0-9+.-]*://##; s#[^A-Za-z0-9._-]+#-#g; s#-+#-#g; s#^-##; s#-$##')"
474508
if [ -z "$slug" ]; then
475509
slug="screen-$index"
476510
fi
477511
filename="$(printf '%02d' "$index")-$slug.png"
478512
479-
if adb -s "$emulator_serial" shell am start -W -a android.intent.action.VIEW -d "$url" "$BUNDLE_ID" >/dev/null 2>&1 </dev/null; then
513+
if adb -s "$emulator_serial" shell am start -W -a android.intent.action.VIEW -d "$url" -n "$BUNDLE_ID/$MAIN_ACTIVITY" >/dev/null 2>&1 </dev/null; then
480514
if ! wait_for_app_foreground "$BUNDLE_ID"; then
481515
echo "::warning::Deep link opened but app is not foregrounded: $url"
482516
index=$((index + 1))

0 commit comments

Comments
 (0)