From 5bb5365b03772dea0bdace08ff6a3c1d74b3e5f1 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 31 May 2023 17:10:04 +0800 Subject: [PATCH] Allow a drawn reported activity to keep screen brightness In case if the activity was requested to redraw for config change, then the draw state becomes DRAW_PENDING (isDrawn() will be false) but it is still visible on screen. The firstWindowDrawn is set when the main window of activity is drawn, and it cleared when the activity is stopped. So it can keep the state across redraw. Also simplify the conditions a bit because onScreen already means mHasSurface==true and isDisplayed()==onScreen&&isDrawn(). Bug: 284917190 Test: Launch an activity which sets screenBrightness and enter split screen. After resizing the divider, the screen brightness should not be changed. Change-Id: If31fc3ff492918e6486c0e16ef5ca3edb16b0bea --- .../server/wm/RootWindowContainer.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 129a48f6f193b..821046ae936bd 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -1046,31 +1046,28 @@ class RootWindowContainer extends WindowContainer * manager may choose to mirror or blank the display. */ boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) { - final WindowManager.LayoutParams attrs = w.mAttrs; - final int attrFlags = attrs.flags; final boolean onScreen = w.isOnScreen(); - final boolean canBeSeen = w.isDisplayed(); - final int privateflags = attrs.privateFlags; boolean displayHasContent = false; ProtoLog.d(WM_DEBUG_KEEP_SCREEN_ON, "handleNotObscuredLocked w: %s, w.mHasSurface: %b, w.isOnScreen(): %b, w" + ".isDisplayedLw(): %b, w.mAttrs.userActivityTimeout: %d", w, w.mHasSurface, onScreen, w.isDisplayed(), w.mAttrs.userActivityTimeout); - if (w.mHasSurface && onScreen) { - if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) { - mUserActivityTimeout = w.mAttrs.userActivityTimeout; - ProtoLog.d(WM_DEBUG_KEEP_SCREEN_ON, "mUserActivityTimeout set to %d", - mUserActivityTimeout); - } + if (!onScreen) { + return false; } - if (w.mHasSurface && canBeSeen) { + if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) { + mUserActivityTimeout = w.mAttrs.userActivityTimeout; + ProtoLog.d(WM_DEBUG_KEEP_SCREEN_ON, "mUserActivityTimeout set to %d", + mUserActivityTimeout); + } + if (w.isDrawn() || (w.mActivityRecord != null && w.mActivityRecord.firstWindowDrawn + && w.mActivityRecord.isVisibleRequested())) { if (!syswin && w.mAttrs.screenBrightness >= 0 && Float.isNaN(mScreenBrightnessOverride)) { mScreenBrightnessOverride = w.mAttrs.screenBrightness; } - final int type = attrs.type; // This function assumes that the contents of the default display are processed first // before secondary displays. final DisplayContent displayContent = w.getDisplayContent(); @@ -1084,11 +1081,11 @@ class RootWindowContainer extends WindowContainer displayHasContent = true; } else if (displayContent != null && (!mObscureApplicationContentOnSecondaryDisplays - || (obscured && type == TYPE_KEYGUARD_DIALOG))) { + || (obscured && w.mAttrs.type == TYPE_KEYGUARD_DIALOG))) { // Allow full screen keyguard presentation dialogs to be seen. displayHasContent = true; } - if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { + if ((w.mAttrs.privateFlags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { mSustainedPerformanceModeCurrent = true; } }