Wake up Android with use adb or Eclipse (just before debug)?

后端 未结 9 619
温柔的废话
温柔的废话 2021-01-31 04:45

How to wake up Android with use adb - I want to wake up (if asleep) Android terminal before debugging every new version of application.

Typical flow is: 1. I do some cha

相关标签:
9条回答
  • 2021-01-31 04:50

    I used the following to wake up remote devices for automated tests. If the screen isn't on, then it will press the power button followed by the menu button.

    (
      cd ${platform-tools};
      ./adb shell dumpsys power | grep -i 'SCREEN_ON' >/dev/null;
      if [ $? -eq 0 ]; then
        echo "Screen is on...";
      else
        echo "Pressing buttons to wake-up...";
        # http://developer.android.com/reference/android/view/KeyEvent.html
        ./adb shell input keyevent 26; # Power
        ./adb shell input keyevent 82; # Menu
        echo "Pausing for state to settle...";
        sleep 1;
        ./adb shell dumpsys power | grep -i 'SCREEN_ON';
      fi;
      echo '---';
      ./adb shell dumpsys power | grep -i 'SCREEN'
    )
    
    0 讨论(0)
  • 2021-01-31 04:57

    if you execute adb shell input keyevent KEYCODE_POWER and got Killed, you should use root user by execute su before.

    sleep:(adb shell) input keyevent KEYCODE_SLEEP

    wakeup:(adb shell) input keyevent KEYCODE_WAKEUP

    toggle:(adb shell) input keyevent KEYCODE_POWER

    0 讨论(0)
  • 2021-01-31 04:57

    For Windows and Eclipse you can use .bat file:

    @ECHO OFF
    setlocal
    for /f "delims= tokens=1*" %%a in ('adb shell dumpsys power ^| findstr.exe "mScreenOn="') DO (
    for /f "delims== tokens=2*" %%S in ("%%a") do (
    if "%%S" == "false" (goto move1) else (goto move2)
    )
    )
    
    :move1
    adb shell input keyevent 26
    goto end
    
    :move2
    goto end
    
    :end
    exit
    

    It will check, if screen is off it will switch the power state. To use it with Eclipse this .bat file should be used as "External tool" (just fill the path to the .bat) and linked to the project in it's properties (Builders - Import - ).

    0 讨论(0)
  • 2021-01-31 05:03

    I know that this is the opposite of what the OP requested, but I wanted to point out the definition of "truly asleep" for other readers: If adb is active, then the device is not truly asleep, since USB is on and the command prompt is running (how else is adb shell going to work?). When fully asleep, only the physical power button will wake it (unless other buttons are selected as a wake source in the BSP). My project draws about 120ma with screen off, but only 23ma in sleep mode (disconnect USB cable). "adb shell input keyevent 26" does not work in this mode. Neither does the serial console. My test fixture does have access to the battery and external power line separately. I can toggle the power line (with battery connected) to wake it up. I also have a switched USB hub that disconnects the USB specifically for the sleep portion of the test.

    I hope this can be some help to someone.

    0 讨论(0)
  • 2021-01-31 05:04
    adb shell input keyevent KEYCODE_WAKEUP
    

    As described here, this wakes up the device. Behaves somewhat like KEYCODE_POWER but it has no effect if the device is already awake.

    To toggle sleep/wake with one command you can issue

    adb shell input keyevent KEYCODE_POWER
    
    0 讨论(0)
  • 2021-01-31 05:11

    You can check device's current power state (including display) via adb with dumpsys power command and send the power key press event only if the display is off. The easier solution would be disabling the display timeout altogether "while connected to USB" in the Developer options.

    0 讨论(0)
提交回复
热议问题