Skip to content

Run adb shell input keyevent KEYCODE_WAKEUP during deploy/run to wake sleeping devices #11064

@jonathanpeppers

Description

@jonathanpeppers

Summary

When deploying and launching an app on a sleeping Android device (screen off), the app starts but the screen stays off, so you can't see it. Running adb shell input keyevent KEYCODE_WAKEUP before (or after) launching the activity would wake the screen, making dotnet run and dotnet build -t:Run work seamlessly even when the device has gone to sleep.

Motivation

During development it's common for the device screen to turn off between builds. When you hit dotnet run or dotnet build -t:Run, the app installs and launches successfully but you're left staring at a black screen. You have to manually press the power button or tap the screen. This is a small but frequent annoyance — especially for inner-loop iteration where you want to build-deploy-see the result immediately.

Proposed change

Run adb shell input keyevent KEYCODE_WAKEUP at an appropriate point in the deploy/run pipeline. Likely candidates:

dotnet run path (Microsoft.Android.Run)

In src/Microsoft.Android.Run/Program.cs, the StartApp() method calls adb shell am start -S -W .... A wakeup command could be issued just before or just after that call.

dotnet build -t:Run path (MSBuild targets)

The Run target is defined in Microsoft.Android.Sdk.Application.targets and depends on Install then either StartAndroidActivity or _Run. A new target (e.g. _WakeDevice) could be inserted into the dependency chain just before the activity is started. It would use the existing AndroidAdb task:

<Target Name="_WakeDevice">
  <AndroidAdb Command="shell" Arguments="input keyevent KEYCODE_WAKEUP" />
</Target>

RunWithLogging target

This target in Microsoft.Android.Sdk.Application.targets already runs several adb shell commands (setprop, logcat -c, am start). The wakeup command could be added alongside those existing adb calls.

Notes

  • KEYCODE_WAKEUP (224) is a no-op if the screen is already on, so it's safe to always run.
  • This matches the behavior of Android Studio / Gradle, which wakes the device on deploy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssues that need to be assigned.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions