How do I keep my screen unlocked during USB debugging?

前端 未结 19 1305
清酒与你
清酒与你 2020-12-13 07:55

Android OS2.2 used to have an option under Settings/Applications/Development to disable screen lock during USB debugging. After upgrading my Samsung Galaxy S to OS2.3.3 this

相关标签:
19条回答
  • 2020-12-13 08:40

    Use this in your Manifest:

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    

    and your screen won't turn off!

    0 讨论(0)
  • 2020-12-13 08:45

    You can just set the Screen Timeout to 30 minutes or turn it off. This option is under : Settings/Display/Screen Timeout

    Hope it helps.

    0 讨论(0)
  • 2020-12-13 08:46

    You can re-enable Developer options, which configurations are now hidden:

    1 - Go to Settings > About > Software information > More...

    2 - Then touch Build number 7 times, which will give you a count down, and then say “you’re now a developer”.

    And Developer Options are back!

    0 讨论(0)
  • 2020-12-13 08:47

    Completely automated solution with unlock and screen awake

    I solved this problem by combining two answers and then automating them. So basically when you run the app on a physical it might locked and it might keep going into sleep mode while you are actively developing.

    The solution is to write a script which unlocks the device if locked and then set the power mode to stay awake on usb power

    unlock_keep_device_awake.sh

    #!/bin/bash
    #Check if device locked
    if adb shell dumpsys window | grep  "mDreamingLockscreen=true"; then 
        echo "Locked"
        adb shell input keyevent KEYCODE_WAKEUP # activate 
        adb shell input touchscreen swipe 530 1420 530 1120 # swipe up
        adb shell input text 1234 # <Change to the device password> input password 
        #adb shell input keyevent 66 # press enter, if you keyguard requires it
    else 
        echo "UnLocked"  
    fi
    
    # 2 = Stay awake on USB, 0 = reset
    adb shell settings put global stay_on_while_plugged_in 2
    

    To automate this add it to the app run configuration to run before launch

    Step 1: Run -> Edit Configuration

    Step 2: create a Shell script configuration by clicking on '+' -> Shell Script

    Step 3: Add the configuration run before running the app

    That's it, no more unlocking device or waking it up while development.

    One small thing, i mostly charge the phone via AC power so I might not need to reset the stay_awake setting. But if you don't want the device screen to be awake while you charge via USB power the run the below command after you are done with development for the day.

    adb shell settings put global stay_on_while_plugged_in 0

    0 讨论(0)
  • 2020-12-13 08:49

    Tell PowerManager to keep the screen on (it will still dim):

    adb shell settings put global stay_on_while_plugged_in 3
    

    The value 3 is the following two types OR'd together:

    BatteryManager#BATTERY_PLUGGED_AC and BatteryManager#BATTERY_PLUGGED_USB.

    Use adb shell dumpsys power | grep mStayOnWhilePluggedInSetting to see the current value.

    To revert to normal behavior set the value to zero like so:

    adb shell settings put global stay_on_while_plugged_in 0
    

    Verified working on Android 4.4 through 9.0.

    0 讨论(0)
  • 2020-12-13 08:50

    I created simple shell script for my macOS

    File Name : cell-screen.sh

    #!/bin/sh
    
    echo '`cell-screen on` to keep the screen on during usb debugging'
    echo '`cell-screen off` to reset'
    
    echo ''
    echo 'your parameter - ' $1
    
    if [[ "$1" = "on" ]]; then
        ~/Library/Android/sdk/platform-tools/adb shell settings put global stay_on_while_plugged_in 2
    elif [[ "$1" = "off" ]]; then
        ~/Library/Android/sdk/platform-tools/adb shell settings put global stay_on_while_plugged_in 0
    else
        echo '\n[****]Bad Input.'
    fi
    
    echo '\nEnd'
    

    Steps:

    1. I saved the script to the default use location - /Users/[your username]
    2. Given executable access to the file - chmod +x ~/cell-screen.sh
    3. Whenever I start my development tasks, I just execute the shell script in terminal - ~/cell-screen.sh on
    4. After I complete my development work, I simply execute - ~/cell-screen.sh off

    For Windows Users:

    Change the shell script for the adb location - %LOCALAPPDATA%\Android\sdk\platform-tools\adb

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