亮度設置,Dream,sleepToken,performSurfacePlacement刷新

kill -3 進程, 然後就可以在data/anr找到一個traces_00這麼一個文件

Android o 查看手機當前前臺的Activity命令:
adb shell dumpsys activity | findstr  "mResumedActivity"

手機解鎖

首先進入開發者模式,將"OEM unlocking"置爲開啓
adb reboot bootloader
//執行後手機重啓進入fastboot模式
fastboot flashing unlock
//執行後,手機會讓用戶選擇是否unlock,界面中會提示音量上鍵對應yes,按一下音量上鍵就可以了

vim複製多行

1. 將光標移動到要複製的文本開始的地方,按v進入可視模式。
2. 將光標移動到要複製的文本的結束的地方,按y複製。此時vim會自動將光標定位到選中文本的開始的地方,並退出可視模式。
3. 我移動光標到文本結束的地方,按p粘貼。

亮度設置 

--->DisplayPowerState.setScreenBrightness{
mScreenBrightness = brightness;
}
--->DisplayPowerState.setScreenState{
mScreenState = state;
}
...
-->DisplayPowerState.mScreenUpdateRunnable.run{

  int brightness = mScreenState != Display.STATE_OFF
                   && mColorFadeLevel > 0f ? mScreenBrightness : 0;
}

-->DisplayPowerState.mScreenUpdateRunnable.run{

  int brightness = mScreenState != Display.STATE_OFF
                   && mColorFadeLevel > 0f ? mScreenBrightness : 0;
}
...

-->DisplayPowerState.PhotonicModulator.run{

   mBlanker.requestDisplayState(state, backlight);
}
--->DisplayPowerState.mPhotonicModulator.setState-->

--->Interface DisplayBlacnker.requestDisplayState{
...
}
-->DisplayManagerService.LocalService.initPowerManagement.requestDisplayState{
      if (state == Display.STATE_OFF) {
             requestGlobalDisplayStateInternal(state, brightness);
       }

       callbacks.onDisplayStateChange(state);

       if (state != Display.STATE_OFF) {
           requestGlobalDisplayStateInternal(state, brightness);
       }
}
-->
DisplayManagerService.requestGlobalDisplayStateInternal{

             mGlobalDisplayState = state;
             mGlobalDisplayBrightness = brightness;
             applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);

}
---->
    private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
        final int count = mDisplayDevices.size();
        for (int i = 0; i < count; i++) {
            DisplayDevice device = mDisplayDevices.get(i);
            Runnable runnable = updateDisplayStateLocked(device);
            if (runnable != null) {
                workQueue.add(runnable);
            }
        }
    }
---->
DisplayManagerService.updateDisplayStateLocked(){
....
   if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
           return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
    }
}
--->
LocalDisplayAdapter.requestDisplayStateLocked{
....
      if (brightnessChanged || vrModeChange) {
          setDisplayBrightness(brightness);
      }
      // Enter the final desired state, possibly suspended.
      if (state != currentState) {
          setDisplayState(state);
       }
....
}

displayBecameReady  爲true時, 更新Dream狀態,之後screen on

PowerManagerService
UpdatePowerStateLocked{

 final boolean displayBecameReady = updateDisplayPowerStateLocked(dirtyPhase2);

             // Phase 4: Update dream state (depends on display ready signal).
              updateDreamLocked(dirtyPhase2, displayBecameReady);

              // Phase 5: Send notifications, if needed.
             finishWakefulnessChangeIfNeededLocked();
}
...
PowerManagerService.updateDreamLocked-->scheduleSandmanLocked-->H.MSG_SANDMAN--->handleSandman{
...
  mDreamManager.startDream(wakefulness == WAKEFULNESS_DOZING);
...
}
--->DreamManagerInternal.startDream-->DreamManagerService{

   private final class LocalService extends DreamManagerInternal {
         @Override
         public void startDream(boolean doze) {
1.             startDreamInternal(doze);
         }
 
         @Override
         public void stopDream(boolean immediate) {
2.             stopDreamInternal(immediate);
         }
 
         @Override
         public boolean isDreaming() {
3.             return isDreamingInternal();
         }
     }

}
///
1-->startDreamInternal-->startDreamLocked(dream, false /*isTest*/, doze, userId){
        PowerManager.WakeLock wakeLock = mPowerManager
                 .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "startDream");
4.         mHandler.post(wakeLock.wrap(
                 () -> mController.startDream(newToken, name, isTest, canDoze, userId, wakeLock)));


}
4-->DreamController.startDream{
...
   mCurrentDream = new DreamRecord(token, name, isTest, canDoze, userId, wakeLock);
...
   mIWindowManager.addWindowToken(token, TYPE_DREAM, DEFAULT_DISPLAY);
...
   if (!mContext.bindServiceAsUser(intent, mCurrentDream,
               Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
                         new UserHandle(userId))) {
           Slog.e(TAG, "Unable to bind dream service: " + intent);
           stopDream(true /*immediate*/);
           return;
    }
...
}
///
2-->stopDreamInternal-->stopDreamLocked{
....
           mHandler.post(new Runnable() {
                 @Override
                 public void run() {
                     Slog.i(TAG, "Performing gentle wake from dream.");
5                     mController.stopDream(immediate);
                 }
             });
}
5--->DreamController.stopDream{
....
   mIWindowManager.removeWindowToken(oldDream.mToken, DEFAULT_DISPLAY);
             mHandler.post(new Runnable() {
                 @Override
                 public void run() {
6.                     mListener.onDreamStopped(oldDream.mToken);
                  }
             });
...
}
6-->DreamManagerService. DreamController.Listener.onDreamStopped{
     cleanupDreamLocked();
}
....
////
finishWakefulnessChangeIfNeededLocked{
	logSleepTimeoutRecapturedLocked
	logScreenOn

}

 Power鍵sleep

PhoneWindowManager.powerPress-->PowerManagerService.goToSleep -->PMS.goToSleepInternal{
  1.if(goToSleepNoUpdateLocked){
  2.     updatePowerStateLocked()
  }
}
1.--->goToSleepNoUpdateLocked--->
2.--->updateWakefulnessLocked-->updateWakefulnessLocked{
....
                  if (shouldNapAtBedTimeLocked()) {
 1.                    changed = napNoUpdateLocked(time, Process.SYSTEM_UID);
                  } else {
 2.                    changed = goToSleepNoUpdateLocked(time,
                              PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, 0, Process.SYSTEM_UID);
                  }
....
}
1.napNoUpdateLocked--->setWakefulnessLocked(WAKEFULNESS_DREAMING, 0)-->Notifier.onWakefulnessChangeStarted

2.goToSleepNoUpdateLocked-->setWakefulnessLocked(WAKEFULNESS_ASLEEP, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT)-->Notifier.onWakefulnessChangeStarted-->

Notifier.handleEarlyInteractiveChange{
1.   mPolicy.startedWakingUp();
2.   mPolicy.startedGoingToSleep(why);   

}
2.----> KeyguardServiceDelegate.onStartedGoingToSleep

亮屏過程中waiting on Draw

DisplayPowerController.updatePowerState-->
DisplayPowerController.animateScreenStateChange-->
DisplayPowerController.setScreenState{
.....
         if (!isOff && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_OFF) {
              setReportedScreenState(REPORTED_TO_POLICY_SCREEN_TURNING_ON);
              if (mPowerState.getColorFadeLevel() == 0.0f) {
                 blockScreenOn();
              } else {
                  unblockScreenOn();
              }
              mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker);
          }
......
}

-->PhoneWindowManager{
1. H.MSG_KEYGUARD_DRAWN_COMPLETE
2. H.MSG_KEYGUARD_DRAWN_TIMEOUT
3. screenTurningOn

}
1,2,3-->PhoneWindowManager.finishKeyguardDrawn--->WindowManagerService.waitForAllWindowsDrawn{
....
  getDefaultDisplayContentLocked().waitForAllWindowsDrawn();
  mWindowPlacerLocked.requestTraversal();
....

}
----->DisplayContent.waitForAllWindowsDrawn{
...
         final WindowManagerPolicy policy = mService.mPolicy;
          forAllWindows(w -> {
              final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
              if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
                  w.mWinAnimator.mDrawState = DRAW_PENDING;
                  // Force add to mResizingWindows.
                  w.mLastContentInsets.set(-1, -1, -1, -1);
                  mService.mWaitingForDrawn.add(w);
              }
          }, true /* traverseTopToBottom */);
      }
....

}

Keyguard 更新sleepToken

KeyguardController.updateKeyguardSleepToken--->ActivityManagerService.acquireSleepToken
//////

RootWindowContainer.performSurfacePlacement-->RootWindowContainer.applySurfaceChangesTransaction-->

-->DisplayContent.applySurfaceChangesTransaction{
...
    mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
   forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
1..pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();

...

}

PhoneWindowManager.applyPostLayoutPolicyLw--->DisplayContent{
....
      private final Consumer<WindowState> mApplyPostLayoutPolicy =
              w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
                      mService.mInputMethodTarget);
....
}

//
1-->PhoneWindowManager.finishPostLayoutPolicyLw{
....
         // lockscreen state.  We will use this to determine whether the dream
         // started while the lockscreen was showing and remember this state
         // while the dream is showing.
        if (!mShowingDream) {
2.             mDreamingLockscreen = isKeyguardShowingAndNotOccluded();
             if (mDreamingSleepTokenNeeded) {
                 mDreamingSleepTokenNeeded = false;
3.                 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
             }
         } else {
             if (!mDreamingSleepTokenNeeded) {
                 mDreamingSleepTokenNeeded = true;
4.                 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
             }
         }
...
...
}
//
2-->isKeyguardShowingAndNotOccluded {
         if (mKeyguardDelegate == null) return false;
         return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
     }
3.4.-->MSG_UPDATE_DREAMING_SLEEP_TOKEN(msg.arg1 != 0)-->updateDreamingSleepToken(boolean acquire){

        if (acquire) {
             if (mDreamingSleepToken == null) {
5.                 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken(
                         "Dream", DEFAULT_DISPLAY);
             }
         } else {
             if (mDreamingSleepToken != null) {
                 mDreamingSleepToken.release();
                 mDreamingSleepToken = null;
             }
         }



}
//
5-->ActivityManagerService.acquireSleepToken
       synchronized (this) {
6.           final SleepToken token = mStackSupervisor.createSleepTokenLocked(tag, displayId);
7.            updateSleepIfNeededLocked();
             return token;
         }

//
6-->ActivityStackSupervisor.createSleepTokenLocked{
        ActivityDisplay display = mActivityDisplays.get(displayId);
         if (display == null) {
             throw new IllegalArgumentException("Invalid display: " + displayId);
         }
 
         final SleepTokenImpl token = new SleepTokenImpl(tag, displayId);
         mSleepTokens.add(token);
         display.mAllSleepTokens.add(token);
         return token;
     }
..
}
7-->ActivityManagerService.updateSleepIfNeededLocked{
 final boolean shouldSleep = !mStackSupervisor.hasAwakeDisplay();
 final boolean wasSleeping = mSleeping;
  if (!shouldSleep) {
...
8.  mStackSupervisor.applySleepTokensLocked(true /* applyToStacks */);
...
  if (wasSleeping) {
      updateOomAdjLocked();
   }

  }else if (!mSleeping && shouldSleep) {
....
9.   mStackSupervisor.goingToSleepLocked();
...
  updateOomAdjLocked();
  }

}
//
8-->ActivityStackSupervisor.applySleepTokensLocked-{
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx){
....
final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx);
final boolean displayShouldSleep = display.shouldSleep();
          // Set the sleeping state of the stacks on the display.
 for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
....
  final ActivityStack stack = display.getChildAt(stackNdx);
  if (displayShouldSleep) {
    stack.goToSleepIfPossible(false /* shuttingDown */);
  }else{
...
      stack.awakeFromSleepingLocked();
      if (isFocusedStack(stack) && !getKeyguardController().isKeyguardOrAodShowing(
                            display.mDisplayId)) {
....
      // If the keyguard is unlocked - resume immediately.
      // It is possible that the display will not be awake at the time we
      // process the keyguard going away, which can happen before the sleep token
      // is released. As a result, it is important we resume the activity here.
 10.        resumeFocusedStackTopActivityLocked();
      }
...
  }
....
}

}
////
10-->resumeFocusedStackTopActivityLocked{
...
 if (targetStack != null && isFocusedStack(targetStack)) {
11.  return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions);
 }
....
  final ActivityRecord r = mFocusedStack.topRunningActivityLocked();
  if (r == null || !r.isState(RESUMED)) {
     mFocusedStack.resumeTopActivityUncheckedLocked(null, null);
  }else if (r.isState(RESUMED)) {
   // Kick off any lingering app transitions form the MoveTaskToFront operation.
12.   mFocusedStack.executeAppTransition(targetOptions);
  }
....
}
///
Ensure that the top activity in the stack is resumed.
11-->ActivityStack.resumeTopActivityUncheckedLocked{
....
   result = resumeTopActivityInnerLocked(prev, options);
....
  // When resuming the top activity, it may be necessary to pause the top activity (for
 // example, returning to the lock screen. We suppress the normal pause logic in
 // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the
 // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here
 // to ensure any necessary pause logic occurs. In the case where the Activity will be
 // shown regardless of the lock screen, the call to
 // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped.
   final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */);
  if (next == null || !next.canTurnScreenOn()) {
     checkReadyForSleep();
  }
....
}
12-->ActivityStack.executeAppTransition{
13.     mWindowManager.executeAppTransition();
}
//
13--->WindowManagerService.executeAppTransition{
...
  synchronized(mWindowMap) {
       if (mAppTransition.isTransitionSet()) {
             mAppTransition.setReady();
             mWindowPlacerLocked.requestTraversal();
       }
  }
....
}

 Keyguard setOccluded 設置爲false後進行Keyguard顯示繪製

KeyguardViewMediator.setOccluded-->H.SET_OCCLUDED--->handleSetOccluded{
...
if (mHiding && isOccluded) {
1.startKeyguardExitAnimation(0, 0);
}
...
 if (mOccluded != isOccluded) {
          mOccluded = isOccluded;
2.        mUpdateMonitor.setKeyguardOccluded(isOccluded);
3.        mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
                          && mDeviceInteractive);
          adjustStatusBarLocked();
 }
...
}

1.-->H.START_KEYGUARD_EXIT_ANIM--->
KeyguardViewMediator.handleStartKeyguardExitAnimation{
....
        setShowingLocked(false, mAodShowing);
        mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
        adjustStatusBarLocked();
        sendUserPresentBroadcast();
        mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
....
}
2.KeyguardUpdateMonitor.setKeyguardOccluded{

}

 Keyguard show

1.KeyguardServiceDelegate.mKeyguardConnection {
ActivityManager.getService().setLockScreenShown(true /* keyguardShowing */,false /* aodShowing */, INVALID_DISPLAY);

}
2.KeyguardViewMediator.setShowingLocked--->
KeyguardViewMediator.updateActivityLockScreenState{
        mUiOffloadThread.submit(() -> {
           try {
                  ActivityManager.getService().setLockScreenShown(showing, aodShowing,
                          secondaryDisplayShowing);
              } catch (RemoteException e) {
              }
          });
}
------>

2.AMS.setLockScreenShown-->KeyguardController.setKeyguardShown---> 
ActivityStackSupervisor.ensureActivitiesVisibleLocked--->
ActivityStack.ensureActivitiesVisibleLocked{

                      // Now check whether it's really visible depending on Keyguard state.
                      final boolean reallyVisible = checkKeyguardVisibility(r,
                             visibleIgnoringKeyguard, isTop && isTopNotPinnedStack);

}

-->ActivityStack.checkKeyguardVisibility{
          final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController()
                 .isKeyguardOrAodShowing(displayId);
          final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked();
....
        if (keyguardOrAodShowing) {
            // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard
            // right away and AOD isn't visible.
            return shouldBeVisible && mStackSupervisor.getKeyguardController()
                    .canShowActivityWhileKeyguardShowing(r, dismissKeyguard);
        } else if (keyguardLocked) {
            return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded(
                    dismissKeyguard, showWhenLocked);
        } else {
            return shouldBeVisible;
        }
....

}

--->KeyguardController.isKeyguardOrAodShowing{
         return (mKeyguardShowing || mAodShowing) && !mKeyguardGoingAway &&
                  (displayId == DEFAULT_DISPLAY ? !mOccluded : displayId == mSecondaryDisplayShowing);
}
---->



KeyguardViewMediator.setOccluded-->KeyguardViewMediator. handleSetOccluded--->

/////
KeyguardViewMediator.setShowingLocked-->
KeyguardViewMediator.updateActivityLockScreenState-->
{
...
   ActivityManager.getService().setLockScreenShown(showing, aodShowing,
                      secondaryDisplayShowing);
...
}
--->ActivityManagerService. setLockScreenShown{
...
  mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing,
                         secondaryDisplayShowing);
...
}
--->KeyguardController.setKeyguardShown{
....
1.    mWindowManager.setAodShowing(aodShowing);
    if (showingChanged) {
...
2.	setKeyguardGoingAway(false);
...
3.        mWindowManager.setKeyguardOrAodShowingOnDefaultDisplay(
                     isKeyguardOrAodShowing(DEFAULT_DISPLAY));
    }
4.    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
5.    updateKeyguardSleepToken();
....
}
///
1.WMS.setAodShowing{
        synchronized (mWindowMap) {
             if (mPolicy.setAodShowing(aodShowing)) {
                 mWindowPlacerLocked.performSurfacePlacement();
             }
         }
}
2.
3.KeyguardController.setKeyguardGoingAway{

     mWindowManager.setKeyguardGoingAway(keyguardGoingAway);
}
--->WMS.setKeyguardGoingAway{
...
       synchronized (mWindowMap) {
             mKeyguardGoingAway = keyguardGoingAway;
         }
...
}
-->DisplayContent-->mService.mKeyguardGoingAway

 performSurfacePlacement繪製刷新

WindowSurfacePlacer.requestTraversal{
   if (!mTraversalScheduled) {
              mTraversalScheduled = true;
              mService.mAnimationHandler.post(mPerformSurfacePlacement);
          }
    }
}

-->WindowSurfacePlacer{
         mPerformSurfacePlacement = () -> {
             synchronized (mService.mWindowMap) {
                  performSurfacePlacement();
             }
          };
}

--->performSurfacePlacement-->
{

         int loopCount = 6;
          do {
              mTraversalScheduled = false;
              performSurfacePlacementLoop();
              mService.mAnimationHandler.removeCallbacks(mPerformSurfacePlacement);
              loopCount--;
          } while (mTraversalScheduled && loopCount > 0);

}
--->performSurfacePlacementLoop-->
{
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
1.             mService.mRoot.performSurfacePlacement(recoveringMemory);
2.           if (mService.mRoot.isLayoutNeeded()) {
                  if (++mLayoutRepeatCount < 6) {
                      requestTraversal();
                  } else {
                      Slog.e(TAG, "Performed 6 layouts in a row. Skipping");
                      mLayoutRepeatCount = 0;
                  }
              } else {
                  mLayoutRepeatCount = 0;
              }

 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
}
1.RootWindowContainer.performSurfacePlacement--{
    applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
...
        // If we are ready to perform an app transition, check through all of the app tokens to be
        // shown and see if they are ready to go.
        if (mService.mAppTransition.isReady()) {
            // This needs to be split into two expressions, as handleAppTransitionReadyLocked may
            // modify dc.pendingLayoutChanges, which would get lost when writing
            // defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked()
            final int layoutChanges = surfacePlacer.handleAppTransitionReadyLocked();
.....
       }
    if (!isAppAnimating() && mService.mAppTransition.isRunning()) {
            // We have finished the animation of an app transition. To do this, we have delayed a
            // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
            // token list reflects the correct Z-order, but the window list may now be out of sync
            // with it. So here we will just rebuild the entire app window list. Fun!
            defaultDisplay.pendingLayoutChanges |=
                    mService.handleAnimatingStoppedAndTransitionLocked();

    }

}

2.--->RootWindowContainer-->isLayoutNeeded{
         final int numDisplays = mChildren.size();
          for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
              final DisplayContent displayContent = mChildren.get(displayNdx);
3.              if (displayContent.isLayoutNeeded()) {
                  return true;
              }
          }
          return false;
      }
}
3.--->DisplayContent.isLayoutNeeded.mLayoutNeeded

DisplayContent.setLayoutNeeded{
 mLayoutNeeded = true;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章