Skip to content

Commit 3a7e526

Browse files
committed
Slightly more gracefully handle ADB failures with locked devices
It still fails, but the screen now turns on and shows as locked, which makes that a little clearer, and avoids a complete no-op.
1 parent 3b709ab commit 3a7e526

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,22 @@ export async function injectSystemCertificate(
243243
await run(adbClient, deviceId, rootCmd.concat('sh', injectionScriptPath));
244244
}
245245

246-
export function bringToFront(
246+
export async function bringToFront(
247247
adbClient: adb.AdbClient,
248248
deviceId: string,
249249
activityName: string // Of the form: com.package/com.package.YourActivity
250250
) {
251-
return adbClient.shell(deviceId, [
251+
// Wake the device up, so it's at least obviously locked if locked.
252+
// It's not possible to unlock the device over ADB. Does nothing if already awake.
253+
await adbClient.shell(deviceId, [
254+
"input", "keyevent", "KEYCODE_WAKEUP"
255+
]);
256+
257+
await delay(10);
258+
259+
// Bring the activity to the front, so we can interact with it (this will
260+
// silently fail if the device is locked, but we're ok with that).
261+
await adbClient.shell(deviceId, [
252262
"am", "start", "--activity-single-top", activityName
253263
]);
254264
}

0 commit comments

Comments
 (0)