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().
- Broadcasts ACTION_SHUTDOWN Intent
- Calls shutdown of ActivityManager service
- Calls disable of Bluetooth service
- Calls Radio(false) of Phone service
- Calls shutdown of Mount service
- Vibrate for a while
- 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.
Sep 06, 2011 @ 21:22:27
The first article I have ever come across which explains the process so cleanly. I really appreciate your blog. Thanks.
Sep 06, 2011 @ 21:42:59
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
Sep 06, 2011 @ 22:46:20
Android git repository is not available now. Be patient.