androidandroid-debug

stay awake over wifi debuging


I use WiFi ADB Active or ADB Wireless application to debug my build app in eclipse over Wifi instead USB debuging.

how I can keep turn on my device during debug? no options in this application to stay awake.


Solution

  • When BuildConfig.DEBUG == true, spawn a thread, that calls Debug.WatiForDebugger then get a full wake lock. Periodically poll Debug.isDebuggerConnected(), releasing the wake lock if not.

    WaitForDebugger will lock the thread until a debugger is attached (over wifi or not) - if that happens the wakelock will keep the device from sleeping. Once the debugger is disconnected, the next time the background thread checks the status of the debugger, it will release the wake lock and allow the device to sleep again.