Android6.0 ÁÁÆÁÃðÆÁÁ÷³Ì£¨DisplayPowerController¡¢WMS£©£¨Ò»£©
WMS»æÖÆ
ÁÁÆÁ¡¢ÃðÆÁÁ÷³ÌÕû¸öÁ÷³ÌÉæ¼°µÄÄ£¿é±È½Ï¶à£¬°üÀ¨PowerManagerService¡¢DisplayPowerControl¡¢WMS¡¢AMS¡£Òò´ËÔÚ·ÖÎöÍêWMSÖ®ºó£¬ÎÒÃÇ°ÑÕâ¿éÒ²·ÖÎöÏ¡£
DisplayPowerControl
ÎÒÃÇÖªµÀÃðÆÁÁ÷³ÌµÄ·¢ÆðÊÇÔÚPowerManagerServiceÖУ¬»áͨ¹ýupdatePowerStateº¯Êýµ÷ÓÃupdateDisplayPowerStateLockedº¯Êý£¬ÔÙµ÷ÓÃDisplayPowerControlµÄrequestPowerStateº¯Êý£¬µ½DisplayPowerControlÖС£DisplayPowerControlÖкóÃæ»áµ÷ÓÃupdatePowerStateº¯Êý£¬ÎÒÃÇÒ²Ö÷Òª´ÓÕâ¸öº¯Êý¿ªÊ¼·ÖÎö£º
updatePowerState»á¸ù¾ÝPowerManagerService´«¹ýÀ´µÄÏÔʾ״̬£¬È»ºóµ÷ÓÃanimateScreenStateChangeº¯Êý¡£ [cpp] view plain copy
animateScreenStateChange(state, performScreenOffTransition); ÏÂÃæÎÒÃÇÏÈÀ´¿´animateScreenStateChangeº¯Êý£º [cpp] view plain copy
private void animateScreenStateChange(int target, boolean performScreenOffTransition) { // If there is already an animation in progress, don't interfere with it. if (mColorFadeOnAnimator.isStarted()
|| mColorFadeOffAnimator.isStarted()) { return; }
// If we were in the process of turning off the screen but didn't quite // finish. Then finish up now to prevent a jarring transition back // to screen on if we skipped blocking screen on as usual. if (mPendingScreenOff && target != Display.STATE_OFF) { setScreenState(Display.STATE_OFF); mPendingScreenOff = false;
mPowerState.dismissColorFadeResources(); }
if (target == Display.STATE_ON) {//ÁÁÆÁ´¦Àí
// Want screen on. The contents of the screen may not yet // be visible if the color fade has not been dismissed because // its last frame of animation is solid black. if (!setScreenState(Display.STATE_ON)) { return; // screen on blocked }
if (USE_COLOR_FADE_ON_ANIMATION && mPowerRequest.isBrightOrDim()) {//
ÁÁÆÁ¶¯»
// Perform screen on animation.
if (mPowerState.getColorFadeLevel() == 1.0f) { mPowerState.dismissColorFade();
} else if (mPowerState.prepareColorFade(mContext, mColorFadeFadesConfig ?
ColorFade.MODE_FADE :
ColorFade.MODE_WARM_UP)) { mColorFadeOnAnimator.start(); } else {
mColorFadeOnAnimator.end(); }
} else {//Ìø¹ýÁÁÆÁ¶¯»
// Skip screen on animation.
mPowerState.setColorFadeLevel(1.0f); mPowerState.dismissColorFade(); }
} else if (target == Display.STATE_DOZE) { // Want screen dozing.
// Wait for brightness animation to complete beforehand when entering doze // from screen on to prevent a perceptible jump because brightness may operate // differently when the display is configured for dozing. ......
} else if (target == Display.STATE_DOZE_SUSPEND) { // Want screen dozing and suspended.
// Wait for brightness animation to complete beforehand unless already // suspended because we may not be able to change it after suspension. ......
} else {//ÃðÆÁ´¦Àí // Want screen off.
mPendingScreenOff = true;
if (mPowerState.getColorFadeLevel() == 0.0f) {//ÃðÆÁ¶¯»½áÊø // Turn the screen off.
// A black surface is already hiding the contents of the screen. setScreenState(Display.STATE_OFF); mPendingScreenOff = false;
mPowerState.dismissColorFadeResources(); } else if (performScreenOffTransition
&& mPowerState.prepareColorFade(mContext, mColorFadeFadesConfig ?
ColorFade.MODE_FADE ColorFade.MODE_COOL_DOWN)
&& mPowerState.getScreenState() != Display.STATE_OFF) { // Perform the screen off animation.
:
mColorFadeOffAnimator.start();//¿ªÆôÃðÆÁ¶¯» } else {
// Skip the screen off animation and add a black surface to hide the // contents of the screen.
mColorFadeOffAnimator.end();//¹Ø±ÕÃðÆÁ¶¯» } } }
animateScreenStateChangeÔÚÁÁÆÁµÄ´¦ÀíµÄʱºò£¬ÏÈ»áµ÷ÓÃsetScreenState(Display.STATE_ON£©£¬È»ºó¸ù¾ÝUSE_COLOR_FADE_ON_ANIMATION ÅжÏÊÇ·ñÒª¿ªÆôÁÁÆÁ¶¯»£¬ÕâÀïÎÒÃÇÊÇûÓÐÉèÖõġ£Òò´ËÖ±½ÓÌø¹ýÁÁÆÁ¶¯»¡£ÃðÆÁµÄ´¦ÀíµÄ»°£¬»áÓÐÒ»¸öÃðÆÁ¶¯»£¨Ò²ÊÇ×¢²áÒ»¸öVSyncÐźŻص÷º¯Êý´¦ÀíµÄ£¬ÕâÀïÎÒÃDz»·ÖÎöÁË£©£¬µ±¶¯»½áÊøºó£¬Ö±½Ó¾Íµ÷ÓÃsetScreenState(Display.STATE_OFF)½áÊø¡£ ÎÒÃÇÔÙÀ´¿´¿´setScreenStateº¯Êý [cpp] view plain copy
private boolean setScreenState(int state) {
if (mPowerState.getScreenState() != state) {
final boolean wasOn = (mPowerState.getScreenState() != Display.STATE_OFF); mPowerState.setScreenState(state); ...... }
// Tell the window manager policy when the screen is turned off or on unless it's due // to the proximity sensor. We temporarily block turning the screen on until the // window manager is ready by leaving a black surface covering the screen. // This surface is essentially the final state of the color fade animation and // it is only removed once the window manager tells us that the activity has // finished drawing underneath.
final boolean isOff = (state == Display.STATE_OFF);
if (isOff && mReportedScreenStateToPolicy != REPORTED_TO_POLICY_SCREEN_OFF && !mScreenOffBecauseOfProximity) {
mReportedScreenStateToPolicy = REPORTED_TO_POLICY_SCREEN_OFF; unblockScreenOn();
mWindowManagerPolicy.screenTurnedOff();//µ÷ÓÃPhoneWindowManagerµÄscreenTurnedOff } else if (!isOff && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_OFF) { mReportedScreenStateToPolicy = REPORTED_TO_POLICY_SCREEN_TURNING_ON; if (mPowerState.getColorFadeLevel() == 0.0f) { blockScreenOn(); } else {
unblockScreenOn(); }
mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker);//µ÷ÓÃPhoneWindowManagerµÄscreenTurningOnº¯Êý }
// Return true if the screen isn't blocked.
return mPendingScreenOnUnblocker == null; }
setScreenStateº¯Êý£¬ÏÈÊǵ÷ÓÃÁËDisplayPowerStateµÄsetScreenStateº¯Êý£¬È»ºó¸ù¾ÝÆÁÄ»ÊÇÃðÆÁ»¹ÊÇÁÁÆÁµ÷ÓÃPhoneWindowManagerµÄÏà¹Øº¯Êý¡£
PhoneWindowManagerµÄscreenTurnedOffºÍscreenTurningOnº¯Êý
PhoneWindowManagerµÄscreenTurnedOffº¯ÊýÖ÷ÒªÊÇ֪ͨkerguard£¬ÆÁÄ»ÃðÆÁÁË¡£ [cpp] view plain copy @Override
public void screenTurnedOff() {
if (DEBUG_WAKEUP) Slog.i(TAG, \
updateScreenOffSleepToken(true); synchronized (mLock) {
mScreenOnEarly = false; mScreenOnFully = false;
mKeyguardDrawComplete = false;
mWindowManagerDrawComplete = false; mScreenOnListener = null; updateOrientationListenerLp();
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onScreenTurnedOff(); } } }
ÎÒÃÇÔÙÀ´¿´PhoneWindowManagerµÄscreenTurningOnº¯Êý¡£µ±ÓÐkeyguardʱ£¬ÎÒÃÇ»áÏÈ·¢Ò»¸öÑÓʱµÄMSG_KEYGUARD_DRAWN_TIMEOUTÐźţ¬²¢ÇÒ»áµ÷ÓÃkeyguardµÄonScreenTurningOnº¯Êý£¬µ±Íê³É»áµ÷ÓÃmKeyguardDrawnCallback»Øµ÷º¯Êý¡£ÎÒÃÇÕâÀﻹҪעÒâÏÂÓÐÒ»¸öÆÁÄ»µãÁÁºóµÄ»Øµ÷¡£
[cpp] view plain copy ÔÚCODEÉϲ鿴´úÂëƬÅÉÉúµ½ÎҵĴúÂëƬ @Override
public void screenTurningOn(final ScreenOnListener screenOnListener) { if (DEBUG_WAKEUP) Slog.i(TAG, \
updateScreenOffSleepToken(false); synchronized (mLock) { mScreenOnEarly = true; mScreenOnFully = false;