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
Use this in your Manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
and your screen won't turn off!
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.
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!
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
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.
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:
/Users/[your username]
chmod +x ~/cell-screen.sh
~/cell-screen.sh on
~/cell-screen.sh off
For Windows Users:
Change the shell script for the adb location - %LOCALAPPDATA%\Android\sdk\platform-tools\adb