From 250a970001a9efa9510fa4224bc1d760411a4e01 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 10 Feb 2022 17:28:45 +0800 Subject: [PATCH] Reduce unnecessary invocation of pokeDrawLock Now it only acquires wake lock (poke draw) for focused activity window. Because the original purpose (commit c2932a1) is to make sure that ambiactive activity can draw without being suspended for wearable devices. Check focus instead of visibility because pokeDrawLockIfNeeded can be called from DisplayListener which happens before the visibility change. On a regular phone device with AOD enabled, this can reduce the number of invocation: 30+ times when turning screen off. 4 times per minute (the clock on AOD). i.e. pokeDrawLock will never be called on a device with keyguard. Bug: 218406154 Test: Enable AOD, turn off screen to enter AOD. Check the section "Wake Lock Log" of "adb shell dumpsys power". There is no more "ACQ Window:xxx (draw)". And after several minutes, the clock on AOD still shows the latest time (because com.android.systemui.doze.DozeUi#onTimeTick also acquires WakeLock). Change-Id: I6fc7f6afec68c63124d76c4734285188ab62fc41 --- core/java/android/view/ViewRootImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 777e89d145b2d..c7d05f856c2b2 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -1788,10 +1788,16 @@ public final class ViewRootImpl implements ViewParent, } void pokeDrawLockIfNeeded() { - final int displayState = mAttachInfo.mDisplayState; - if (mView != null && mAdded && mTraversalScheduled - && (displayState == Display.STATE_DOZE - || displayState == Display.STATE_DOZE_SUSPEND)) { + if (!Display.isDozeState(mAttachInfo.mDisplayState)) { + // Only need to acquire wake lock for DOZE state. + return; + } + if (mWindowAttributes.type != WindowManager.LayoutParams.TYPE_BASE_APPLICATION) { + // Non-activity windows should be responsible to hold wake lock by themself, because + // usually they are system windows. + return; + } + if (mAdded && mTraversalScheduled && mAttachInfo.mHasWindowFocus) { try { mWindowSession.pokeDrawLock(mWindow); } catch (RemoteException ex) {