frameworks\base\services\core\java\com\android\server\display\LocalDisplayAdapter.java
public Runnable requestDisplayStateLocked(final int state, final int brightness) {
private void setDisplayState(int state) {}
private void setDisplayBrightness(int brightness) {}
}
requestDisplayStateLocked 会创建runnable ,并在runnable中调用setDisplayState与setDisplayBrightness,这里会打印
setDisplayState与setDisplayBrightness trace
亮屏会先调用 setDisplayState ->ON 在调用setDisplayBrightnesssetDisplayState 这个会时间较长 200ms~300mssetDisplayBrightness 3~5msframeworks\base\services\core\java\com\android\server\display\DisplayManagerService.javaprivate Runnable updateDisplayStateLocked(DisplayDevice device) { // Blank or unblank the display immediately to match the state requested // by the display power controller (if known). DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) { return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); } return null; }private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) { final int count = mDisplayDevices.size(); for (int i = 0; i < count; i++) { DisplayDevice device = mDisplayDevices.get(i); if (i == 0) { /// M: log for default display only Slog.d(TAG, "Update global display state (" + Display.stateToString(mGlobalDisplayState) + ", " + mGlobalDisplayBrightness + ") for " + device.getDisplayDeviceInfoLocked()); } Runnable runnable = updateDisplayStateLocked(device); if (runnable != null) { workQueue.add(runnable); } } }frameworks\base\services\core\java\com\android\server\display\DisplayManagerService.javaprivate void requestGlobalDisplayStateInternal(int state, int brightness) { if (state == Display.STATE_UNKNOWN) { state = Display.STATE_ON; } if (state == Display.STATE_OFF) { brightness = PowerManager.BRIGHTNESS_OFF; } else if (brightness < 0) { brightness = PowerManager.BRIGHTNESS_DEFAULT; } else if (brightness > PowerManager.BRIGHTNESS_ON) { brightness = PowerManager.BRIGHTNESS_ON; } synchronized (mTempDisplayStateWorkQueue) { try { // Update the display state within the lock. // Note that we do not need to schedule traversals here although it // may happen as a side-effect of displays changing state. synchronized (mSyncRoot) { if (mGlobalDisplayState == state && mGlobalDisplayBrightness == brightness) { return; // no change } Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" + Display.stateToString(state) + ", brightness=" + brightness + ")"); mGlobalDisplayState = state; mGlobalDisplayBrightness = brightness; applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); } // Setting the display power state can take hundreds of milliseconds // to complete so we defer the most expensive part of the work until // after we have exited the critical section to avoid blocking other // threads for a long time. for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { mTempDisplayStateWorkQueue.get(i).run(); } Trace.traceEnd(Trace.TRACE_TAG_POWER); } finally { mTempDisplayStateWorkQueue.clear(); } } }mTempDisplayStateWorkQueue 列表就是 applyGlobalDisplayStateLocked 获取的runnable 列表,并会循环调用runnable,
这里有 requestGlobalDisplayState traceprivate final class LocalService extends DisplayManagerInternal { @Override public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler, SensorManager sensorManager) { synchronized (mSyncRoot) { DisplayBlanker blanker = new DisplayBlanker() { @Override public void requestDisplayState(int state, int brightness) { // The order of operations is important for legacy reasons. if (state == Display.STATE_OFF) { requestGlobalDisplayStateInternal(state, brightness); } callbacks.onDisplayStateChange(state); if (state != Display.STATE_OFF) { requestGlobalDisplayStateInternal(state, brightness); } } }; mDisplayPowerController = new DisplayPowerController( mContext, callbacks, handler, sensorManager, blanker); } }这里将DisplayBlanker 传递给到mDisplayPowerControllerframeworks\base\services\core\java\com\android\server\power\PowerManagerService.javapublic void systemReady(IAppOpsService appOps) {
// Initialize display power management. mDisplayManagerInternal.initPowerManagement( mDisplayPowerCallbacks, mHandler, sensorManager);}/** * Asynchronous callbacks from the power controller to the power manager service. */ public interface DisplayPowerCallbacks { void onStateChanged(); void onProximityPositive(); void onProximityNegative(); void onDisplayStateChange(int state); // one of the Display state constants void acquireSuspendBlocker(); void releaseSuspendBlocker(); }
frameworks\base\services\java\com\android\server\SystemServer.javaTrace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady"); try { // TODO: use boot phase mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); } Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);各个服务的ready在这里调用
frameworks\base\services\core\java\com\android\server\display\DisplayPowerController.java
private void blockScreenOn() { if (mPendingScreenOnUnblocker == null) { Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, SCREEN_ON_BLOCKED_TRACE_NAME, 0); mPendingScreenOnUnblocker = new ScreenOnUnblocker(); mScreenOnBlockStartRealTime = SystemClock.elapsedRealtime(); Slog.i(TAG, "Blocking screen on until initial contents have been drawn."); } } private void unblockScreenOn() { if (mPendingScreenOnUnblocker != null) { mPendingScreenOnUnblocker = null; long delay = SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime; Slog.i(TAG, "Unblocked screen on after " + delay + " ms"); Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, SCREEN_ON_BLOCKED_TRACE_NAME, 0); } } private boolean setScreenState(int state) { if (mPowerState.getScreenState() != state) { final boolean wasOn = (mPowerState.getScreenState() != Display.STATE_OFF); mPowerState.setScreenState(state); // Tell battery stats about the transition. try { mBatteryStats.noteScreenState(state); } catch (RemoteException ex) { // same process } } // 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(); } 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); } // Return true if the screen isn't blocked. return mPendingScreenOnUnblocker == null; }
blockScreenOn 会阻止亮屏,等待winManager 准备好 。会打印 Screen on blocked traceblockScreenOn() 中winManager 准备好会发送 MSG_SCREEN_ON_UNBLOCKED 消息case MSG_SCREEN_ON_UNBLOCKED: if (mPendingScreenOnUnblocker == msg.obj) { unblockScreenOn(); updatePowerState(); } break;frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
private void wakeUpFromPowerKey(long eventTime) { wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); } private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { final boolean theaterModeEnabled = isTheaterModeEnabled(); if (!wakeInTheaterMode && theaterModeEnabled) { return false; } if (theaterModeEnabled) { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0); } mPowerManager.wakeUp(wakeTime, reason); return true; }frameworks\base\services\core\java\com\android\server\power\PowerManagerService.java@Override // Binder call public void wakeUp(long eventTime, String reason, String opPackageName) { if (eventTime > SystemClock.uptimeMillis()) { throw new IllegalArgumentException("event time must not be in the future"); } mContext.enforceCallingOrSelfPermission( android.Manifest.permission.DEVICE_POWER, null); final int uid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { wakeUpInternal(eventTime, reason, uid, opPackageName, uid); } finally { Binder.restoreCallingIdentity(ident); } }
private void wakeUpInternal(long eventTime, String reason, int uid, String opPackageName, int opUid) { synchronized (mLock) { if (mIPOShutdown && reason != PowerManager.WAKE_UP_REASON_SHUTDOWN) return; if (wakeUpNoUpdateLocked(eventTime, reason, uid, opPackageName, opUid)) { updatePowerStateLocked(); } } }wakeUpNoUpdateLocked 设置 mWakefulness == WAKEFULNESS_AWAKE 返回falsehttp://blog.csdn.net/kc58236582/article/details/51582950
http://blog.csdn.net/qnnming/article/details/51858788