From b945ea53673eb927c71e97779cd2f0ac28464464 Mon Sep 17 00:00:00 2001 From: Adam Bookatz Date: Tue, 14 Dec 2021 13:10:14 -0800 Subject: [PATCH] WMS screen-unfreezing trace tags Adds perfetto trace tag for WMS (un)freezing screen. This is important for user-switches, where we need to determine when the user-switch is complete. Test: manual - user-switch and observe Test: systemui-multiuser-suite Bug: 210527498 Change-Id: Ieff68eb7175efbac9e23684564d9bd4c0e189312 --- .../com/android/server/am/UserController.java | 5 +++++ .../server/wm/WindowManagerService.java | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index e4c0846d090f7..481b6dddc31ba 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -2034,6 +2034,11 @@ class UserController implements Handler.Callback { } } + /** + * Tell WindowManager we're ready to unfreeze the screen, at its leisure. Note that there is + * likely a lot going on, and WM won't unfreeze until the drawing is all done, so + * the actual unfreeze may still not happen for a long time; this is expected. + */ @VisibleForTesting void unfreezeScreen() { TimingsTraceAndSlog t = new TimingsTraceAndSlog(); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index eb1274c18147d..e70bb1e093e6f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -695,6 +695,7 @@ public class WindowManagerService extends IWindowManager.Stub final static int WINDOWS_FREEZING_SCREENS_TIMEOUT = 2; int mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE; + /** Indicates that the system server is actively demanding the screen be frozen. */ boolean mClientFreezingScreen = false; int mAppsFreezingScreen = 0; @@ -3091,6 +3092,7 @@ public class WindowManagerService extends IWindowManager.Stub // Misc IWindowSession methods // ------------------------------------------------------------- + /** Freeze the screen during a user-switch event. Called by UserController. */ @Override public void startFreezingScreen(int exitAnim, int enterAnim) { if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, @@ -3113,6 +3115,11 @@ public class WindowManagerService extends IWindowManager.Stub } } + /** + * No longer actively demand that the screen remain frozen. + * Called by UserController after a user-switch. + * This doesn't necessarily immediately unlock the screen; it just allows it if we're ready. + */ @Override public void stopFreezingScreen() { if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, @@ -5859,6 +5866,13 @@ public class WindowManagerService extends IWindowManager.Stub return; } + Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "WMS.doStartFreezingDisplay"); + doStartFreezingDisplay(exitAnim, enterAnim, displayContent, overrideOriginalRotation); + Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); + } + + private void doStartFreezingDisplay(int exitAnim, int enterAnim, DisplayContent displayContent, + int overrideOriginalRotation) { ProtoLog.d(WM_DEBUG_ORIENTATION, "startFreezingDisplayLocked: exitAnim=%d enterAnim=%d called by %s", exitAnim, enterAnim, Debug.getCallers(8)); @@ -5929,10 +5943,16 @@ public class WindowManagerService extends IWindowManager.Stub return; } + Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "WMS.doStopFreezingDisplayLocked-" + + mLastFinishedFreezeSource); + doStopFreezingDisplayLocked(displayContent); + Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); + } + + private void doStopFreezingDisplayLocked(DisplayContent displayContent) { ProtoLog.d(WM_DEBUG_ORIENTATION, "stopFreezingDisplayLocked: Unfreezing now"); - // We must make a local copy of the displayId as it can be potentially overwritten later on // in this method. For example, {@link startFreezingDisplayLocked} may be called as a result // of update rotation, but we reference the frozen display after that call in this method.