2

I have a rooted Lenovo Vibe K5 Plus (A6020a46) running TWRP + Arrow OS. It doesn't provide an automatically scheduled reboot out of the box. None of the apps worked. Also the apps that claim to provide this functionality are suspiciously ad-filled and I'm not comfortable giving root permission to them.

So, here is what I've tried till now:

  • SMManager. Didn't work. Also, suspicious app.

  • Wrote an infinite loop shell script, but I'm afraid it'll make my system too busy:

    while true; do
      if [[ "$(date +"%H")" -eq "3" ]] ; then
        reboot
      fi
    done
    

    But I don't know how to autorun it on boot and I'm afraid it'll break my Android

  • Tried Termux (elevated) with cronie

    I'd put 0 3 * * * /system/bin/sh reboot in /data/crontab/root like mentioned in this link, but crond isn't recognised as a valid command in root shell.

Further, the init.d directory doesn't even exist, but an init directory does with a bunch of .rc files.

I've ran sudo crontab /data/crontab and then crontab -l lists the proper crontab, but it doesn't show up anywhere else. I'm not sure it will work. Further, I'll have to always manually run this (as far as I understand it) and seriously manually rebooting is infinitely easier.

I'm out of ideas. Any suggestions appreciated. I'd prefer shell scripts over shady apps.

11
  • 2
    I have a feeling that this might be an XY-problem since this is quite an uncommon request: why do you need to restart the device every 3 AM? (That said, googling a6020a446 doesn't return anything).
    – Andrew T.
    Commented Jun 20, 2021 at 9:44
  • sorry it was dumb of me to not notice the spelling error. It is a6020a46. Also, I just want to restart my device everyday at 3 am with possibly a shell script. I have shared what I've tried and the outcomes but my original problem still remains, I want to restart my device automatically at 3 AM. This is to have optimal performance and avoid network issues which for some reason appear when my phone has been running for abt 2+ days. Commented Jun 20, 2021 at 10:14
  • 4
    automation is an option. Using MacroDroid, create a macro with trigger of day /time and action - reboot. If you are OK with apps. You can test it by adding empty trigger as another trigger and testing the macro from 3 dots menu
    – beeshyams
    Commented Jun 20, 2021 at 10:20
  • 1
    Why not just write a normal alarm clock app that will run system("su -c reboot"); (or maybe even call the Android API function for this, if it exists) when the alarm is triggered? Alarm clocks made correctly don't usually suffer from energy saving modes.
    – Ruslan
    Commented Jun 20, 2021 at 19:09
  • @beeshyams, thank you that app seems good enough and is what I'll probably use for now since I am not technically advanced enough (yet) to implement the other solutions. Nonetheless it is an app, one that perhaps isn't gpl and hence I'm still suspicious of it.especially since it now has root access. Commented Jun 21, 2021 at 2:37

1 Answer 1

3

Run the following shell script from init.d (or /data/adb/*.d/ in case of Magisk). Or run directly from init's .rc file. See How to run an executable on boot and keep it running?

#!/system/bin/sh -e

# ignore signals
for i in $(seq 64); do trap '' "$i"; done

# seconds until today 3AM
SECS=$(( $(date -d '03:00' +%s) - $(date +%s) ))

# if today's 3AM has passed, set it to tomorrow's
[ SECS -gt 0 ] || SECS=$((SECS + 86400))

# wait until 3AM
echo "${0##*/}: sleeping for $SECS seconds"
sleep $SECS

# Reboot device
echo "${0##*/}: restarting"
/system/bin/reboot scheduled-reboot ||
/system/bin/setprop sys.powerctl reboot,scheduled-reboot
3
  • doubt it will work, guesswork sleep is stretched in idle mode (power saving)
    – alecxs
    Commented Jun 20, 2021 at 15:47
  • This answer is interesting, one that I think I'll eventually use. However, I haven't understood completely and shall use it only when I do so. Also could you clarify what @alecxs has said in his comment above? Commented Jun 21, 2021 at 2:49
  • 2
    @alecxs that's correct. But the process can be added to foreground cgroup so that it's not affected by idle mode. That's how services work. Or sleep for smaller intervals like 1min and check intermittently if 3AM has passed. Else the only way to wake up the device from idle mode to perform a task at exactly 3AM is to use AlarmManager API from an app. It's not possible with a shell script. Commented Jun 21, 2021 at 6:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .