16

I own a Samsung Galaxy S Relay 4G running Android 4.1.2. Also, I have adb installed on a PC.

When I long-press the Power button then tap "Restart", my phone takes about ten seconds to shut down. Then it reboots itself.

When I enter adb reboot instead, the phone shuts down much faster: the shutdown takes only a second or so. Then it reboots.

My questions:

  1. Why is adb reboot so much faster?

  2. Is it simply skipping the mobile network operator's shutdown animation, or is it skipping some more important procedures as well?

  3. Can I use adb reboot every single time I want to reboot the phone, or is there some disadvantage to doing so?

  4. (Optional) How do you know?


More information (you can skip this)

I did some research before posting this question. But I am still unenlightened. Let me show you what I did discover.

Tetsuyuki Kobayashi of Kyoto Microcomputer Co. explains in slide 8 of this PDF slideshow that adb consists of three parts: a client, a server, and a daemon. The client and the server run on a PC. The daemon runs on a phone. In slide 11, he explains that all three parts are built from one source directory. (It's this directory.)

I tried searching in that source directory for the word reboot and reading parts of services.cpp, but I still haven't been able to figure out what adb reboot actually does, or what bytes it sends over the wire, or what code the phone runs when it receives those bytes. I also haven't figured out the answer to any of my questions.


Related: "What's the best way to restart Android via command line (remotely)?"

1

2 Answers 2

8

Based on the platform/system/core repository you linked above, I think the key is in libcutils/android_reboot.c. And important definitions are in include/cutils/android_reboot.h; namely:

    /* Commands */
    #define ANDROID_RB_RESTART  0xDEAD0001
    #define ANDROID_RB_POWEROFF 0xDEAD0002
    #define ANDROID_RB_RESTART2 0xDEAD0003

Usually in normal reboot mode (using device button, etc.), the process is longer because (I assume) it umount partition, kill all applications, close all fopen nodes, as in shutdown process. The adb reboot can be compared with Linux reboot command (from where it comes): it just flushes the disk and enter reboot without first killing processes or unmounting filesystems. I see also a fast remount command issued to put disk (in our case device's storage part of system) in ro mode before reboot.

I also believe the command issued is kernel_restart() which is embedded in kernel. See for example http://www.phonesdevelopers.com/1730094/. Also check machine_restart calls.

4
  • 1
    +1. Thank you very much! Is it safe for me to do adb reboot every day even though it won't do a full shutdown procedure? Commented May 7, 2015 at 11:54
  • It doesn't hurt, but you may have a good reason to do so. If you actually want to clear some cached data, there are other solutions anyway.
    – ares777
    Commented May 7, 2015 at 14:01
  • Other solutions such as...?
    – JohnyTex
    Commented Dec 9, 2016 at 14:21
  • @JohnyTex if you still need it, see: android.stackexchange.com/a/138057/57668. My favourite is adb shell su -c "svc power shutdown".
    – Marc.2377
    Commented May 20, 2020 at 23:01
3

Other Stack Exchange users have already answered this question in posts elsewhere.

t0mm13b writes that, while displaying your carrier's shutdown animation:

  • 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.

[Commands such as adb reboot] are harsher. They actually bypass the safety mechanisms for a graceful shutdown.

Elsewhere, Yury offers another explanation of what Android does during a graceful shutdown:

  • It shuts down ActivityManager. I think shutting down ActivityManager means that all activities will pass necessary lifecycle and, thus, the states of activities will be stored. But I'm not sure. I did not check.
  • Then, Android turns off the cellular radio interface.
  • After that, it turns off Bluetooth.
  • Finally, it tries to shut MountService down.

adb reboot is faster because it skips some or all of the above.

You must log in to answer this question.

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