1

I'm preparing a bunch of tablets using a minimal android OS (https://slimroms.org/). And was wondering if there's a way to always have the display on (i.e. disable Sleep and Auto Screen lock) without needing to use third party apps. I've got full root access via SSH and ADB etc - hoping there's some setting in /proc or as a kernel boot argument that I can make.

These are intended to be "We would like your feedback" tablets which are out on public display - so the display should never dim or lock etc. They're always going to be plugged in so power saving etc isn't going to be an issue.

migrated from serverfault.com Aug 17 at 5:38

This question came from our site for system and network administrators.

1

Set the 'keep awake while plugged in' setting
(Screen will never sleep while charging)

Settings - Developer options - Stay awake: on

or from terminal

svc power stayon true

if the user can press the power button, set the screen lock to "none" (not even swipe) and
use Tasker/MacroDroid/Automate to watch the power button. or run a watchdog from shell

the following example depends on three android binaries
/system/bin/toolbox
/system/bin/toybox
/system/bin/input

# (replace first line with while 1)
until [ $(($(toybox cat /sys/class/power_supply/ac/online)+$(toybox cat /sys/class/power_supply/*usb/online))) -eq 0 ]
  do
    case "$(toolbox getevent -lc4 /dev/input/event2 | toybox head -n1)" in
      *KEY_POWER*)
        input keyevent KEYCODE_WAKEUP
      ;;
    esac
done  

the above code checks for charger is connected as entry point for the loop. the loop exit when charger is disconnected. /dev/input/event2 may vary for your device. you can check which input event has only 3x buttons [Vol+|Vol-|Pwr] from getevent -il (for more generic code look here)

  • Ugh - maybe spoke too soon. After a certain amount of time (even with "Settings -> Developer Options -> Stay Awake On") the screen will dim, and dims almost to the point where you can't see anything. A "tap" will bring the screen back to full brightness - but is there a way to maintain 100% brightness ? – Patrick Rynhart Aug 17 at 23:34
  • not sure if there is a keycode for unlock. the only other harmless input event i can imagine is a mouse cursor moving (not touch/swipe) but the cursor might be visible – alecxs Aug 18 at 1:59
  • 1
    Actually another thought I just had - is there somewhere where you can set the "dim" percentage for the display. E.g. If dim is going to 30% of the total screen brightness, can I set "dim" to 100%. This way - even if the screen is going into "dim" mode it won't matter (i.e. no need to send 'tap'/'mouse'/'key' events to the display) – Patrick Rynhart Aug 18 at 2:05
  • Hmmm - wonder if I can use some of the commands from github.com/Genymobile/scrcpy/issues/101 to achieve what I want (via the "adb shell settings put system screen_*" commands). After looking at developer.android.com/reference/android/provider/… there seems to be quite a few settings that have been deprecated though..... – Patrick Rynhart Aug 18 at 2:49
  • @PatrickRynhart if you use it in kiosk mode with very limited gui, just send a tap to corner every 15 seconds i don't think this harms much (will drop notifications). for more safety you can increase the display timeout up to 30 min and decrease the tap frequency (even tap outside of display will work) while [ 1 ]; do input tap 720 1260; sleep 15; done – alecxs Aug 19 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.