@@ -0,0 +1,51 @@
1+#!/bin/bash
2+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 4 -*-
3+
4+# Our goal here is to get an Ubuntu Touch device into a testable unlocked state.
5+# This will include reboots.
6+
7+boot_delay=20
8+max_retries=5
9+
10+ANDROID_SERIAL=$1
11+if [ -z "$ANDROID_SERIAL" ]; then
12+ echo "E: Please provide an adb device number as an argument"
13+ exit 1
14+fi
15+
16+UNLOCK_SCRIPT="
17+import dbus, logging;
18+from unity8 import process_helpers as helpers;
19+logging.basicConfig(level=logging.INFO);
20+bus = dbus.SystemBus().get_object(\"com.canonical.powerd\", \"/com/canonical/powerd\");
21+cookie = bus.requestSysState(\"unlock-device-hold\", 1, dbus_interface=\"com.canonical.powerd\");
22+helpers.restart_unity_with_testability();
23+bus.clearSysState(cookie, dbus_interface=\"com.canonical.powerd\");
24+helpers.unlock_unity()
25+"
26+
27+RETURN_CODE=0
28+
29+retries=0
30+while [ $retries -lt $max_retries ]; do
31+ ((retries += 1))
32+ adb -s $ANDROID_SERIAL reboot
33+ sleep 5
34+ adb -s $ANDROID_SERIAL "wait-for-device"
35+ sleep $boot_delay
36+ UNLOCK_OUTPUT=$(adb -s $ANDROID_SERIAL shell "sudo -u phablet -i python3 -c '$UNLOCK_SCRIPT'" 2>&1)
37+ if echo "$UNLOCK_OUTPUT" | grep 'Greeter unlocked' >/dev/null; then
38+ echo "I: Unlock passed"
39+ retries=$max_retries
40+ else
41+ echo "I: Unlock script output: '$UNLOCK_OUTPUT'"
42+ if [ $retries -lt $max_retries ]; then
43+ echo "W: Unlock failed, trying again"
44+ else
45+ echo "E: Unlock failed, no more retries"
46+ RETURN_CODE=1
47+ fi
48+ fi
49+done
50+
51+exit $RETURN_CODE