From d000396e2e9a260e7c78a896af10fc9245283886 Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Wed, 17 Feb 2021 16:03:58 -0500 Subject: [PATCH 1/2] Update animateScreenOff when AOD preferences change. Some parts of the Doze/AOD code were out of sync after a settings change, which caused issues during the first unlock after a settings change. Fixes: 179947580 Test: atest SystemUITests Test: turn AOD off and then on, then lock the phone, receive a call, note that the incoming call screen appears instead of a blank screen Change-Id: Ib998a99bc9ca0e810631ba4cba0c9bf6119aae72 --- .../src/com/android/systemui/doze/DozeUi.java | 15 +++++++++++++-- .../src/com/android/systemui/doze/DozeUiTest.java | 7 +++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java index 5c8c9f22d5852..8ab135ced97ed 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java @@ -23,6 +23,7 @@ import android.app.AlarmManager; import android.content.Context; import android.os.Handler; import android.os.SystemClock; +import android.provider.Settings; import android.text.format.Formatter; import android.util.Log; @@ -32,6 +33,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.doze.dagger.DozeScope; import com.android.systemui.statusbar.phone.DozeParameters; +import com.android.systemui.tuner.TunerService; import com.android.systemui.util.AlarmTimeout; import com.android.systemui.util.wakelock.WakeLock; @@ -43,7 +45,7 @@ import javax.inject.Inject; * The policy controlling doze. */ @DozeScope -public class DozeUi implements DozeMachine.Part { +public class DozeUi implements DozeMachine.Part, TunerService.Tunable { private static final long TIME_TICK_DEADLINE_MILLIS = 90 * 1000; // 1.5min private final Context mContext; @@ -73,7 +75,7 @@ public class DozeUi implements DozeMachine.Part { public DozeUi(Context context, AlarmManager alarmManager, WakeLock wakeLock, DozeHost host, @Main Handler handler, DozeParameters params, KeyguardUpdateMonitor keyguardUpdateMonitor, - DozeLog dozeLog) { + DozeLog dozeLog, TunerService tunerService) { mContext = context; mWakeLock = wakeLock; mHost = host; @@ -83,6 +85,8 @@ public class DozeUi implements DozeMachine.Part { mTimeTicker = new AlarmTimeout(alarmManager, this::onTimeTick, "doze_time_tick", handler); keyguardUpdateMonitor.registerCallback(mKeyguardVisibilityCallback); mDozeLog = dozeLog; + + tunerService.addTunable(this, Settings.Secure.DOZE_ALWAYS_ON); } @Override @@ -238,4 +242,11 @@ public class DozeUi implements DozeMachine.Part { KeyguardUpdateMonitorCallback getKeyguardCallback() { return mKeyguardVisibilityCallback; } + + @Override + public void onTuningChanged(String key, String newValue) { + if (key.equals(Settings.Secure.DOZE_ALWAYS_ON)) { + updateAnimateScreenOff(); + } + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java index 6d8c372a061bc..d60772730dff0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeUiTest.java @@ -42,6 +42,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.phone.DozeParameters; +import com.android.systemui.tuner.TunerService; import com.android.systemui.util.wakelock.WakeLockFake; import org.junit.After; @@ -67,6 +68,8 @@ public class DozeUiTest extends SysuiTestCase { private DozeHost mHost; @Mock private DozeLog mDozeLog; + @Mock + private TunerService mTunerService; private WakeLockFake mWakeLock; private Handler mHandler; private HandlerThread mHandlerThread; @@ -82,7 +85,7 @@ public class DozeUiTest extends SysuiTestCase { mHandler = mHandlerThread.getThreadHandler(); mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler, - mDozeParameters, mKeyguardUpdateMonitor, mDozeLog); + mDozeParameters, mKeyguardUpdateMonitor, mDozeLog, mTunerService); mDozeUi.setDozeMachine(mMachine); } @@ -138,7 +141,7 @@ public class DozeUiTest extends SysuiTestCase { reset(mHost); when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true); mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler, - mDozeParameters, mKeyguardUpdateMonitor, mDozeLog); + mDozeParameters, mKeyguardUpdateMonitor, mDozeLog, mTunerService); mDozeUi.setDozeMachine(mMachine); // Never animate if display doesn't support it. From f701d3ef0d56dcdd0b740dc5eae6e9fa3c274b96 Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Wed, 17 Feb 2021 20:56:25 -0500 Subject: [PATCH 2/2] Fix issues with interrupted screen off animations. Two problems here: - The activity lock screen was not being shown after the doze animation finished because forceCallbacks was false. We short-circuited if showing == showing and aodShowing == aodShowing, and both of those are true after the screen off animation. - Notifications would be gone until the next lock/unlock, sometimes longer. This is because we were overridding the doze amount in the NotificationWakeUpCoordinator, so that the notifications are not visible as the shade animates in during the screen off animation. If interrupted, the doze amount in the wake up coordinator remained overridden at 1f, which meant we were hiding them thinking we were on AOD. Fixes: 180100349 Test: Press the power button to trigger screen off, quickly auth via fingerprint before the animation finishes. notice that the notification shade has notifications wow! Change-Id: Iad608121adcc53c7d471607c438ba4542ea58143 --- .../keyguard/KeyguardViewMediator.java | 5 +++- .../NotificationWakeUpCoordinator.kt | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 91cf7108c7281..eef41e0459485 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -2395,6 +2395,9 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, return; } mDozing = dozing; + if (!dozing) { + mAnimatingScreenOff = false; + } setShowingLocked(mShowing); } @@ -2404,7 +2407,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, // is 1f), then show the activity lock screen. if (mAnimatingScreenOff && mDozing && linear == 1f) { mAnimatingScreenOff = false; - setShowingLocked(mShowing); + setShowingLocked(mShowing, true); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt index e391250dc8fd6..50cbbd5d48526 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt @@ -264,6 +264,20 @@ class NotificationWakeUpCoordinator @Inject constructor( } override fun onStateChanged(newState: Int) { + if (dozeParameters.shouldControlUnlockedScreenOff()) { + if (animatingScreenOff && + state == StatusBarState.KEYGUARD && + newState == StatusBarState.SHADE) { + // If we're animating the screen off and going from KEYGUARD back to SHADE, the + // animation was cancelled and we are unlocking. Override the doze amount to 0f (not + // dozing) so that the notifications are no longer hidden. + setDozeAmount(0f, 0f) + } + + animatingScreenOff = + state == StatusBarState.SHADE && newState == StatusBarState.KEYGUARD + } + overrideDozeAmountIfBypass() if (bypassController.bypassEnabled && newState == StatusBarState.KEYGUARD && state == StatusBarState.SHADE_LOCKED && @@ -273,13 +287,6 @@ class NotificationWakeUpCoordinator @Inject constructor( setNotificationsVisible(visible = false, increaseSpeed = false, animate = true) } - // If we want to control the screen off animation, check whether we are going from SHADE to - // KEYGUARD. - if (dozeParameters.shouldControlUnlockedScreenOff()) { - animatingScreenOff = - state == StatusBarState.SHADE && newState == StatusBarState.KEYGUARD - } - this.state = newState } @@ -386,8 +393,6 @@ class NotificationWakeUpCoordinator @Inject constructor( override fun onDozingChanged(isDozing: Boolean) { if (isDozing) { setNotificationsVisible(visible = false, animate = false, increaseSpeed = false) - } else { - animatingScreenOff = false } }