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 these ads