31

I'm looking for the best / friendliest way to reboot my rooted android 4.1.1 device. I found these solutions so far:

  • su -c "reboot" - Causes problems with wifi after restart on my device... I read that this can cause a currupt file system in some cases... Doesn't work via ssh for me.
  • toolbox reboot - Same concerns here, but works via ssh.
  • reboot -d 8 -f - causes problems after restart e.g. some apps wont start
  • busybox killall system_server - "Hot Reboot" (not really a system restart)
  • start|stop - Starts/stops Android Runtime (not really a system restart)

What is the device doing exactly when I'm pushing the (hardware) power button? I guess that's the most friendly way.

acy
  • 459
  • 1
  • 5
  • 10

3 Answers3

17

What is the device doing exactly when I'm pushing the (hardware) power button? I guess that's the most friendly way.

You get to see a dialog with an option to power off the device (stock Android doesn't offer reboot). It appears that ShutdownActivity is called upon when you long press Power button.

Anyhow, this is what you can try, remotely or locally, but only with root access:

su -c 'am start -a android.intent.action.REBOOT'

It will do a graceful shutdown followed by the reboot. I was looking for an intent when I noticed it here.

Method is tested on Android 4.2.1, 5.0.2 and 6.0.1 and should work for Android 4.1.1 as well

Update

Tested on stock Android 5.0 and 6.0.1:

su -c 'svc power reboot'

Per the source code here, KitKat builds should also support the command.

Firelord
  • 25,528
  • 21
  • 129
  • 295
14

Simple, really:

  • Android is safely shutting down vital parts of the runtime.
  • The OS is also broadcasting intents to tell apps and services to gracefully close. These, in turn, flush their caches of all data and shared preferences, save what-nots to the sqlite database, et cetera.

In other words, apps and services are given a chance to do their cleanup systematically.

The commands that you have tried are harsher. They actually bypass the safety mechanisms for a graceful shutdown.

Android is not Linux per se, in the sense of an ordinary desktop version of Linux where those commands could be issued to shutdown the Linux environment.

It might be possible to create a wrapper script such as this:

#!/system/bin/sh
am broadcast android.intent.action.ACTION_SHUTDOWN
sleep 5
reboot

You could save this as safe_shutdown.sh, with permissions of 0755. Your mileage may vary, depending on handsets and ROMs — so no guarantees there.

Manu
  • 3,063
  • 7
  • 23
  • 43
t0mm13b
  • 13,476
  • 1
  • 50
  • 59
11
killall zygote

This will kill the root zygote process and cause a Android system refresh.

This does not restart your phone's hardware, only the Android processes.

By default (in Linux), the kill/killall commands do give the processes a graceful way to shut down, though it depends on the zygote implementation whether this in turn gracefully shuts down your running Android apps.

Note: you must run this as root, whether you use su -c, connect via SSH or ADB, or another method.

Other names for this action:

  • soft reboot
  • hot reboot
palswim
  • 303
  • 1
  • 3
  • 10