How to set On/Off Timers on Android 9 using ADB?

405 Views Asked by At

I am trying to set an automatic on/off timer for a device that is running Android 9 (For examples sake let's say I want it to turn on at 9 AM and turn off at 5PM) This must happen daily.

I want this to be done using adb commands so that it can be automated down the line.

If I go into settings I can navigate as so: Settings > Accessibility > Scheduled Power on and off once in here I can set the Power off time, Power on time and the 2 relative Repeats

Any changes I make (physically or via adb) are then required to be confirmed by pressing the Save Settings button at the bottom of the screen.

Pressing the Save Settings button triggers the introduction of multiple variables: close_machine_time_hour
close_machine_time_mins open_machine_time_hour
open_machine_time_mins
power_off_cycle_mode

power_on_cycle_mode
power_off_date

power_on_date power_way
machine_time_secs

Of which the 2 I am most concerned about are the last 2 as these seem like odd variables to only introduce when activating a niche setting (I feel as though they should either be there always)

Question 1: would be is this a standard Android feature? Or is this something that has been done for custom ROM?

I have tried setting all the settings as they appear in settings grabbed using command adb shell settings list system

They are set individually using the commands below:

adb shell settings put system timer_power_switch_settings 1
adb shell settings put system close_machine_time_hour 09
adb shell settings put system close_machine_time_mins 00
adb shell settings put system open_machine_time_hour 17
adb shell settings put system open_machine_time_mins 00
adb shell settings put system power_off_time 9:00:16
adb shell settings put system power_on_time 17:00:16
adb shell settings put system power_off_cycle_mode 0-1-2-3-4-5-6-
adb shell settings put system power_on_cycle_mode 0-1-2-3-4-5-6-

You'll note that in essence I am setting the time twice, which is quite odd.

The key thing is that none of this works unless I physically press the save button (despite showing visual feedback on the device screen that values change as I alter them via adb). Which is fine for 1 device but will become quite laborious if it needs to be done for 30+ devices at a time.

Question 2: Is there to simulate this Save Settings button click without simulating a tap on screen? Or to bypass this setting entirely?

Question 2.A: Is there a way to continuously monitor activity using an adb command? so I can run it, then click the button, and it will show me what's going on in the background?

0

There are 0 best solutions below