Android6.0 亮屏灭屏流程(DisplayPowerController、WMS)(一)WMS绘制 - 百度文库 ر

mKeyguardDrawComplete = false;

mWindowManagerDrawComplete = false;

mScreenOnListener = screenOnListener;//ĻĻص

if (mKeyguardDelegate != null) {

if (DEBUG_WAKEUP) Slog.d(TAG,

\ mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);

mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);

mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); } else {

if (DEBUG_WAKEUP) Slog.d(TAG,

\ finishKeyguardDrawn(); } } }

ȿmKeyguardDrawnCallback صǷMSG_KEYGUARD_DRAWN_COMPLETEkeyguardϢ [cpp] view plain copy CODEϲ鿴ƬҵĴƬ

final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { @Override

public void onDrawn() {

if (DEBUG_WAKEUP) Slog.d(TAG, \ mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); } }; MSG_KEYGUARD_DRAWN_COMPLETEԼMSG_KEYGUARD_DRAWN_TIMEOUTźŵĴfinishKeyguardDrawn [cpp] view plain copy CODEϲ鿴ƬҵĴƬ case MSG_KEYGUARD_DRAWN_COMPLETE:

if (DEBUG_WAKEUP) Slog.w(TAG, \ finishKeyguardDrawn(); break;

case MSG_KEYGUARD_DRAWN_TIMEOUT:

Slog.w(TAG, \ finishKeyguardDrawn(); break;

finishKeyguardDrawnȥеMSG_KEYGUARD_DRAWN_TIMEOUTϢΪ֮ǰMSG_KEYGUARD_DRAWN_TIMEOUTϢkeyguardMSG_KEYGUARD_DRAWN_COMPLETEϢõfinishKeyguardDrawnҪMSG_KEYGUARD_DRAWN_TIMEOUTȥˣȻ

[cpp] view plain copy CODEϲ鿴ƬҵĴƬ private void finishKeyguardDrawn() { synchronized (mLock) {

if (!mScreenOnEarly || mKeyguardDrawComplete) {

return; // We are not awake yet or we have already informed of this event. }

mKeyguardDrawComplete = true; if (mKeyguardDelegate != null) {

mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); }

mWindowManagerDrawComplete = false; }

// ... eventually calls finishWindowsDrawn which will finalize our screen turn on // as well as enabling the orientation change logic/sensor.

mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, WAITING_FOR_DRAWN_TIMEOUT); }

ٿWMSwaitForAllWindowsDrawnԼmWindowManagerDrawCallbackһWAITING_FOR_DRAWN_TIMEOUT1룩

WMSwaitForAllWindowsDrawn

WMSwaitForAllWindowsDrawnѴĻصmWaitingForDrawnCallback ȻеwindowsҪʾѾʾĴȫ뵽mWaitingForDrawnȻrequestTraversalLocked֮ǰǷһϢˢUI֡ȻǼmWaitingForDrawnΪգûɶʾֱӵûصmWaitingForDrawnҪʾĴڣҪȷһWAITING_FOR_DRAWN_TIMEOUTtimeout֮ǰ1롣ȻcheckDrawnWindowsLocked

[cpp] view plain copy CODEϲ鿴ƬҵĴƬ @Override

public void waitForAllWindowsDrawn(Runnable callback, long timeout) { synchronized (mWindowMap) {

mWaitingForDrawnCallback = callback;//صmWaitingForDrawnCallback final WindowList windows = getDefaultWindowListLocked(); for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { final WindowState win = windows.get(winNdx);

final boolean isForceHiding = mPolicy.isForceHiding(win.mAttrs); Slog.i(TAG,\ if (win.isVisibleLw()

&& (win.mAppToken != null || isForceHiding)) { Slog.i(TAG,\ win.mWinAnimator.mDrawState =

WindowStateAnimator.DRAW_PENDING;

// Force add to mResizingWindows.

win.mLastContentInsets.set(-1, -1, -1, -1); mWaitingForDrawn.add(win);

// No need to wait for the windows below Keyguard. if (isForceHiding) { break; } } }

requestTraversalLocked(); }

mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT); if (mWaitingForDrawn.isEmpty()) { callback.run();

Slog.i(TAG,\ } else {

mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, timeout); checkDrawnWindowsLocked();

Slog.i(TAG,\ } }

checkDrawnWindowsLocked֮ǰmWaitingForDrawnҪʾĴڣʱǰѾȥģҪʾģûsurfaceĴڴmWaitingForDrawnȥѾƺõҲȥȻٵmWaitingForDrawnΪʱͷALL_WINDOWS_DRAWNϢ

[cpp] view plain copy CODEϲ鿴ƬҵĴƬ void checkDrawnWindowsLocked() {

if (mWaitingForDrawn.isEmpty() || mWaitingForDrawnCallback == null) { return; }

for (int j = mWaitingForDrawn.size() - 1; j >= 0; j--) { WindowState win = mWaitingForDrawn.get(j);

if (win.mRemoved || !win.mHasSurface || !win.mPolicyVisibility) {

// Window has been removed or hidden; no draw will now happen, so stop waiting. if (DEBUG_SCREEN_ON) Slog.w(TAG, \ mWaitingForDrawn.remove(win); } else if (win.hasDrawnLw()) {

// Window is nowww.sm136.comw drawn (and shown).

if (DEBUG_SCREEN_ON) Slog.d(TAG, \ mWaitingForDrawn.remove(win); } }

if (mWaitingForDrawn.isEmpty()) {

if (DEBUG_SCREEN_ON) Slog.d(TAG, \ mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT); mH.sendEmptyMessage(H.ALL_WINDOWS_DRAWN); } }

ALL_WINDOWS_DRAWNϢĴmWaitingForDrawnCallback Ȼûص

[cpp] view plain copy CODEϲ鿴ƬҵĴƬ case ALL_WINDOWS_DRAWN: { Runnable callback;

synchronized (mWindowMap) {

callback = mWaitingForDrawnCallback; mWaitingForDrawnCallback = null; }

if (callback != null) { callback.run(); } }

еǵwaitForAllWindowsDrawnһ㶼ҪʾĴڣֱӵcheckDrawnWindowsLockedеĴڻûɡôǾҪȣˢµĺĺperformLayoutAndPlaceSurfacesLockedInner´룬ʱ֮ǰûɵĴڣƺˡٵcheckDrawnWindowsLockedmWaitingForDrawnеĴڻƺˣmWaitingForDrawnȥڡȻmWaitingForDrawnΪˣ֮ᷢALL_WINDOWS_DRAWNϢmWaitingForDrawnCallbackص

[cpp] view plain copy CODEϲ鿴ƬҵĴƬ if (mWaitingForDrawnCallback != null ||

(mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded && !mInnerFields.mUpdateRotation)) { checkDrawnWindowsLocked(); }

Ȼ֮ǰûаmWaitingForDrawnеĴգWAITING_FOR_DRAWN_TIMEOUT1룩ʱ䵽Ҳûصġ [cpp] view plain copy CODEϲ鿴ƬҵĴƬ case WAITING_FOR_DRAWN_TIMEOUT: { Runnable callback = null;

synchronized (mWindowMap) {

Slog.w(TAG, \ mWaitingForDrawn.clear();

callback = mWaitingForDrawnCallback; mWaitingForDrawnCallback = null; }

if (callback != null) {