Android Framework layer Power key Shutdown Process (1. Power long button operation), androidframework

Source: Internet
Author: User

Android Framework layer Power key Shutdown Process (1. Power long button operation), androidframework

I. Android powers long-pressed buttons

In the Framework layer, Android4.x analyzes the operation on the Power key (KeyEvent. KEYCODE_POWER) from PhoneWindowManager. Before the analysis, I printed the stack call information of this method. For more information, see.

Public long interceptKeyBeforeDispatching (WindowState win, KeyEvent event, int policyFlags ){

......

Android. util. Log. d ("BILL", android. util. Log. getStackTraceString (new Throwable ()));

......

}

1-13 19:35:32. 458 D/BILL (718): java. lang. Throwable

01-13 19:35:32. 458 D/BILL (718): at com. android. internal. policy. impl. PhoneWindowManager. interceptKeyBeforeDispatching (PhoneWindowManager. java: 2224)

01-13 19:35:32. 458 D/BILL (718): at com. android. server. wm. InputMonitor. interceptKeyBeforeDispatching (InputMonitor. java: 501)

01-13 19:35:32. 458 D/BILL (718): at com. android. server. input. InputManagerService. interceptKeyBeforeDispatching (InputManagerService. java: 1383)

01-13 19:35:32. 458 D/BILL (718): at dalvik. system. NativeStart. run (Native Method)

The call process is as follows (only key code is attached ):


InterceptKeyBeforeDispatching () -->InterceptPowerKeyDown () --> mPowerLongPress. run ()


1>

Public long interceptKeyBeforeDispatching (WindowState win, KeyEvent event, int policyFlags ){

......

Case KeyEvent. KEYCODE_POWER :{
Result & = ~ ACTION_PASS_TO_USER;
If (down ){
MImmersiveModeConfirmation. onPowerKeyDown (isScreenOn, event. getDownTime (),
IsImmersiveMode (mLastSystemUiFlags ));
If (isScreenOn &&! MPowerKeyTriggered
& (Event. getFlags () & KeyEvent. FLAG_FALLBACK) = 0 ){
MPowerKeyTriggered = true;
MPowerKeyTime = event. getDownTime ();
InterceptScreenshotChord ();
}


ITelephony telephonyService = getTelephonyService ();
Boolean hungUp = false;
If (telephonyService! = Null ){
Try {
If (telephonyService. isRinging ()){
// Pressing Power while there's a ringing incoming
// Call shoshould silence the ringer.
TelephonyService. silenceRinger ();
/// M: [ALPS00093981] @ {
} Else if (isScreenOn
| MScreenOffReason = OFF_BECAUSE_OF_PROX_SENSOR)
///@}
& (MIncallPowerBehavior
& Settings. Secure. INCALL_POWER_BUTTON_BEHAVIOR_HANGUP )! = 0
& TelephonyService. isOffhook ()){
// Otherwise, if "Power button ends call" is enabled,
// The Power button will hang up any current active call.
HungUp = telephonyService. endCall ();
}
} Catch (RemoteException ex ){
Log. w (TAG, "ITelephony threw RemoteException", ex );
}
}
InterceptPowerKeyDown (! IsScreenOn | hungUp
| MVolumeDownKeyTriggered | mVolumeUpKeyTriggered );

} Else {
MPowerKeyTriggered = false;
CancelPendingScreenshotChordAction ();
If (InterceptPowerKeyUp(Canceled | mPendingPowerKeyUpCanceled )){
Result = (result &~ ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
}
MPendingPowerKeyUpCanceled = false;
}
Break;
}

......

}

Note! Red indicates long-pressed (down), and blue indicates short-pressed (up ).

2>

Private void interceptPowerKeyDown (boolean handled ){
MPowerKeyHandled = handled;
If (! Handled ){
MHandler. postDelayed (MPowerLongPress, ViewConfiguration. getGlobalActionKeyTimeout ());
}
}

3>

Private final Runnable mPowerLongPress = new Runnable (){
......
Case LONG_PRESS_POWER_GLOBAL_ACTIONS:
MPowerKeyHandled = true;
If (! PerformHapticFeedbackLw (null, HapticFeedbackConstants. LONG_PRESS, false )){
Inclumauditoryfeedbackforaccessibilityifneed ();
}
SendCloseSystemWindows (SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS );
ShowGlobalActionsDialog ();
Break;
Case LONG_PRESS_POWER_SHUT_OFF:
Case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
MPowerKeyHandled = true;
PerformHapticFeedbackLw (null, HapticFeedbackConstants. LONG_PRESS, false );
SendCloseSystemWindows (SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS );
MWindowManagerFuncs. shutdown (resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF );
Break;
......
};

Note: The underline dialog box (shutdown, restart, flight mode, and other options) is displayed.








In android, how can I view the changed effect after the framework layer code is changed?

1. the following method applies to the real machine: Download the android source code, compile the modified framwork code, generate framework. jar, push it to the system/framework directory, and restart the machine! OK

2. The following method is suitable for simulators:
(1) decompress the package with unyaffs. In the sdk directory you downloaded, replace system. img with the framework. jar and compress it into a new system. img. Then, start the simulator and OK.

(2): You can also directly compile the source code and generate system. img to replace system. img in the simulator.

There is a POWER key on the keyboard on the computer, and it shuts down as soon as you press it.

On the Control Panel-power options, there is an option. When you press the power button: The option does not take any operation!
I will give you a picture. WINXP is similar to Windows 7.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.