The shutdown operation is triggered by a key. the linux kernel layer returns a key event to the android framework layer to go to the framework layer, and then executes the shutdown task of the kernel layer from the framework layer to the kernel layer.
Handler code corresponding to long buttons:
Frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager. java
Runnable mPowerLongPress;
Private final Runnable mPowerLongPress = new Runnable (){
Public void run (){
If (! MPowerKeyHandled ){
MPowerKeyHandled = true;
PerformHapticFeedbackLw (null, HapticFeedbackConstants. LONG_PRESS, false );
SendCloseSystemWindows (SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS );
ShowGlobalActionsDialog ();
}
}
};
MPowerLongPress startup shutdown dialog box
(Frameworks/policies/base/phone/com/android/internal/policy/impl/GlobalActions. java)
If we select Power OFF, ShutdownThread. shutdown will be called to start the shutdown thread to execute the shutdown action.
Frameworks/base/core/java/com/android/internal/app/ShutdownThread. java
Real shutdown process:
(1) broadcast global events, ACTION_SHUTDOWN Intent
(2) shutdown ActivityManager Service
(3) Stop the Bluetooth service
(4) Stop the telephone service (radio phone service)
(5) Stop the mount service.
(6) Call Power. shutdown () to enter the native Layer
Frameworks/base/core/java/android/OS/Power. java
Native implementation code of power:
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 and reboot are called by the linux system to go To the linux kernel shutdown process.
Author: LuoXianXion