From b20addbdfb6e09f1721798db531aeec73d45a374 Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Tue, 9 Aug 2016 18:52:01 -0700 Subject: [PATCH] Allow to keep screen on only if window can be seen If user has static wallpaper on lock screen and live wallpaper on home screen, when screen is locked, wallpaper will not be an obscuring window. In this case, if there is a non-obscured app window behind the lock screen which has FLAG_KEEP_SCREEN_ON set, it will not allow to turn screen off automatically, although it is not really visible behind lock screen. This CL restricts holding screen windows to only ones that can be seen. Same applies for screen and button brightness and user activity timeout settings. Bug: 30359386 Change-Id: I46de831211c943d8077282e3274b2df180739239 --- .../server/wm/WindowSurfacePlacer.java | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java index ee4a9a4173796..70a400eb7e9fc 100644 --- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java +++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java @@ -1468,7 +1468,7 @@ class WindowSurfacePlacer { mObscured = true; } - if (w.mHasSurface) { + if (w.mHasSurface && canBeSeen) { if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { mHoldScreen = w.mSession; mHoldScreenWindow = w; @@ -1491,43 +1491,39 @@ class WindowSurfacePlacer { } final int type = attrs.type; - if (canBeSeen - && (type == TYPE_SYSTEM_DIALOG - || type == TYPE_SYSTEM_ERROR - || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0)) { + if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR + || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { mSyswin = true; } - if (canBeSeen) { - // This function assumes that the contents of the default display are - // processed first before secondary displays. - final DisplayContent displayContent = w.getDisplayContent(); - if (displayContent != null && displayContent.isDefaultDisplay) { - // While a dream or keyguard is showing, obscure ordinary application - // content on secondary displays (by forcibly enabling mirroring unless - // there is other content we want to show) but still allow opaque - // keyguard dialogs to be shown. - if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { - mObscureApplicationContentOnSecondaryDisplays = true; - } - mDisplayHasContent = true; - } else if (displayContent != null && - (!mObscureApplicationContentOnSecondaryDisplays - || (mObscured && type == TYPE_KEYGUARD_DIALOG))) { - // Allow full screen keyguard presentation dialogs to be seen. - mDisplayHasContent = true; - } - if (mPreferredRefreshRate == 0 - && w.mAttrs.preferredRefreshRate != 0) { - mPreferredRefreshRate = w.mAttrs.preferredRefreshRate; - } - if (mPreferredModeId == 0 - && w.mAttrs.preferredDisplayModeId != 0) { - mPreferredModeId = w.mAttrs.preferredDisplayModeId; - } - if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { - mSustainedPerformanceModeCurrent = true; + // This function assumes that the contents of the default display are + // processed first before secondary displays. + final DisplayContent displayContent = w.getDisplayContent(); + if (displayContent != null && displayContent.isDefaultDisplay) { + // While a dream or keyguard is showing, obscure ordinary application + // content on secondary displays (by forcibly enabling mirroring unless + // there is other content we want to show) but still allow opaque + // keyguard dialogs to be shown. + if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { + mObscureApplicationContentOnSecondaryDisplays = true; } + mDisplayHasContent = true; + } else if (displayContent != null && + (!mObscureApplicationContentOnSecondaryDisplays + || (mObscured && type == TYPE_KEYGUARD_DIALOG))) { + // Allow full screen keyguard presentation dialogs to be seen. + mDisplayHasContent = true; + } + if (mPreferredRefreshRate == 0 + && w.mAttrs.preferredRefreshRate != 0) { + mPreferredRefreshRate = w.mAttrs.preferredRefreshRate; + } + if (mPreferredModeId == 0 + && w.mAttrs.preferredDisplayModeId != 0) { + mPreferredModeId = w.mAttrs.preferredDisplayModeId; + } + if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { + mSustainedPerformanceModeCurrent = true; } } }