Shutdown sequence of Android

To power off an Android phone, keep pressing power bottom then shutdown menu is appeard. Then choose ‘Power OFF’ to power off actually.
I looked for the source code to see how to do these sequence.
(Japanese version of this page)

Showing shutdown menu

Long press of power bottom is handled here.
frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
Runnable mPowerLongPress;

Here is the shutdown dialog.
frameworks/policies/base/phone/com/android/internal/policy/impl/GlobalActions.java
If you choose ‘Power OFF’, it calls ShutdownThread.shutdown.

Shutdown process

frameworks/base/core/java/com/android/internal/app/ShutdownThread.java
Through beginShutdownSequence(), actual shutdown process is done in run().

  1. Broadcasts ACTION_SHUTDOWN Intent
  2. Calls shutdown of ActivityManager service
  3. Calls disable of Bluetooth service
  4. Calls Radio(false) of Phone service
  5. Calls shutdown of Mount service
  6. Vibrate for a while
  7. Calls Power.shutdown();

frameworks/base/core/java/android/os/Power.java
Power#shutdown is a native method.
frameworks/base/core/jni/android_os_Power.cpp

static void android_os_Power_shutdown(JNIEnv *env, jobject clazz)
{
    sync();
#ifdef HAVE_ANDROID_OS
    reboot(RB_POWER_OFF);
#endif
}

sync, reboot are system calls. They are done in Linux kernel.

About tetsu_koba

Engineer.
This entry was posted in Android. Bookmark the permalink.

3 Responses to Shutdown sequence of Android

  1. AR_VR says:

    The first article I have ever come across which explains the process so cleanly. I really appreciate your blog. Thanks.

  2. AR_VR says:

    I am not able to see the files
    frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
    &
    frameworks/policies/base/phone/com/android/internal/policy/impl/GlobalActions.java

    Please let me know where I can find the respective source files. I am trying to see on what event does this dialog comes up. Can you please let me know what event should be posted by linux kernel so that the shutdown process handling begins.
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s