How to enable Stay awake in the developer options using ADB?
Asked Answered
D

6

22

I'm trying to find a way to enable the Developer options -> Stay awake option via ADB. The solution that I found was to find a way to open developers option menu and then enable stay awake option using setevent command in ADB.

Now I'm trying to find the command that will open the developers options. I found the command that opens display options:

adb shell am start -n com.android.settings/.DisplaySettings

So I think that a similar command that opens developers options exists.

I will also be glad to hear about another way to enable stay awake option via ADB if there is any.

Decalcify answered 16/8, 2013 at 9:10 Comment(0)
E
43
adb shell am start -n com.android.settings/.DevelopmentSettings
Eusebiaeusebio answered 16/8, 2013 at 10:16 Comment(2)
your way is a little cleaner then mine :)Decalcify
The command does not work on my Android 9 device (Sony). Activity class {com.android.settings/com.android.settings.DevelopmentSettings} does not exist.Recidivate
G
24

You can enable Stay awake option without having to use UI with the following command:

adb shell settings put global stay_on_while_plugged_in 3
Gadmon answered 16/8, 2013 at 15:27 Comment(5)
Where is this settings database stored?Matherly
Its stored in /data/system/user/0/settings_global.xmlCrenelate
found it was missing an "s" on "user" - /data/system/users/0/settings_global.xmlPropaganda
Then how do disable it?Jaquelynjaquenetta
@Jaquelynjaquenetta Set value to 0 to disable it: stuff.mit.edu/afs/sipb/project/android/docs/reference/android/…Imperator
D
6

OK, I found a way:

adb shell am start -S com.android.settings/.Settings\$DevelopmentSettingsActivity

I used this : https://github.com/android/platform_packages_apps_settings/blob/master/AndroidManifest.xml

to find the name of the Activity I needed.

Now I have to figure out how to choose the stay awake option by createing a touch event or something...

Decalcify answered 16/8, 2013 at 10:4 Comment(0)
B
4

Set the 'keep awake while plugged in' setting.

adb shell svc power stayon true  
Bunnell answered 30/10, 2020 at 21:7 Comment(4)
This work on my RedMi Note 5 (Android 9) device, thanks.Counter
Works on Android 11 (Sony Xperia 10 iii). The 'Stay awake' slider in the 'Developer options' menu changes when this command is issued (from the PC).Fu
To check the state of the setting, use adb shell dumpsys power | grep 'mStayOn='Fu
When toggling mStayOn, also other settings under adb shell dumpsys power change. From my expierience they are mStayOnWhilePluggedInSetting, mUserActivitySummary and mLastSleepReasonFu
S
0

Okay I know it is not what MiSo was asking but I think it may be relevant, I have created an app that will enable/dissable this 'Stay awake' setting as you connect/disconnect ADB.

The code is available open-source here: ABD-Stay_Awake

Sabina answered 22/2, 2019 at 14:8 Comment(0)
P
-3

try this:

setprop persist.sys.usb.config mtp,adb
Padriac answered 14/3, 2016 at 2:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.