Merge "Disable screen off animation in situations where it currently looks bad." into sc-dev am: f3dd83dbae

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14922150

Change-Id: I5a33da65d5c7ec77689348e123ff5c8f4838c763
This commit is contained in:
Josh Tsuji
2021-06-17 13:55:04 +00:00
committed by Automerger Merge Worker
17 changed files with 121 additions and 33 deletions

View File

@@ -249,6 +249,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
public void onStateChanged(int newState) {
mStatusBarState = newState;
}
@Override
public void onExpandedChanged(boolean isExpanded) {
for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) {
cb.onShadeExpandedChanged(isExpanded);
}
}
}
};
HashMap<Integer, SimData> mSimDatas = new HashMap<>();

View File

@@ -339,4 +339,8 @@ public class KeyguardUpdateMonitorCallback {
*/
public void onRequireUnlockForNfc() { }
/**
* Called when the notification shade is expanded or collapsed.
*/
public void onShadeExpandedChanged(boolean expanded) { }
}

View File

@@ -21,6 +21,7 @@ import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD_PAUSED;
import android.app.AlarmManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Handler;
import android.os.SystemClock;
import android.provider.Settings;
@@ -34,6 +35,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.doze.dagger.DozeScope;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.util.AlarmTimeout;
import com.android.systemui.util.wakelock.WakeLock;
@@ -48,7 +50,8 @@ import dagger.Lazy;
* The policy controlling doze.
*/
@DozeScope
public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
public class DozeUi implements DozeMachine.Part, TunerService.Tunable,
ConfigurationController.ConfigurationListener {
// if enabled, calls dozeTimeTick() whenever the time changes:
private static final boolean BURN_IN_TESTING_ENABLED = false;
private static final long TIME_TICK_DEADLINE_MILLIS = 90 * 1000; // 1.5min
@@ -63,6 +66,7 @@ public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
private final DozeLog mDozeLog;
private final Lazy<StatusBarStateController> mStatusBarStateController;
private final TunerService mTunerService;
private final ConfigurationController mConfigurationController;
private boolean mKeyguardShowing;
private final KeyguardUpdateMonitorCallback mKeyguardVisibilityCallback =
@@ -84,6 +88,11 @@ public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
mHandler.post(mWakeLock.wrap(() -> {}));
}
}
@Override
public void onShadeExpandedChanged(boolean expanded) {
updateAnimateScreenOff();
}
};
private long mLastTimeTickElapsed = 0;
@@ -93,7 +102,8 @@ public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
WakeLock wakeLock, DozeHost host, @Main Handler handler,
DozeParameters params, KeyguardUpdateMonitor keyguardUpdateMonitor,
DozeLog dozeLog, TunerService tunerService,
Lazy<StatusBarStateController> statusBarStateController) {
Lazy<StatusBarStateController> statusBarStateController,
ConfigurationController configurationController) {
mContext = context;
mWakeLock = wakeLock;
mHost = host;
@@ -107,11 +117,15 @@ public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
mStatusBarStateController = statusBarStateController;
mTunerService.addTunable(this, Settings.Secure.DOZE_ALWAYS_ON);
mConfigurationController = configurationController;
mConfigurationController.addCallback(this);
}
@Override
public void destroy() {
mTunerService.removeTunable(this);
mConfigurationController.removeCallback(this);
}
@Override
@@ -274,4 +288,9 @@ public class DozeUi implements DozeMachine.Part, TunerService.Tunable {
updateAnimateScreenOff();
}
}
@Override
public void onConfigChanged(Configuration newConfig) {
updateAnimateScreenOff();
}
}

View File

@@ -264,7 +264,7 @@ class NotificationWakeUpCoordinator @Inject constructor(
}
override fun onStateChanged(newState: Int) {
if (unlockedScreenOffAnimationController.shouldPlayScreenOffAnimation()) {
if (dozeParameters.shouldControlUnlockedScreenOff()) {
if (unlockedScreenOffAnimationController.isScreenOffAnimationPlaying() &&
state == StatusBarState.KEYGUARD &&
newState == StatusBarState.SHADE) {

View File

@@ -63,6 +63,7 @@ public class DozeParameters implements TunerService.Tunable,
private final Resources mResources;
private final BatteryController mBatteryController;
private final FeatureFlags mFeatureFlags;
private final UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;
private final Set<Callback> mCallbacks = new HashSet<>();
@@ -78,7 +79,8 @@ public class DozeParameters implements TunerService.Tunable,
BatteryController batteryController,
TunerService tunerService,
DumpManager dumpManager,
FeatureFlags featureFlags) {
FeatureFlags featureFlags,
UnlockedScreenOffAnimationController unlockedScreenOffAnimationController) {
mResources = resources;
mAmbientDisplayConfiguration = ambientDisplayConfiguration;
mAlwaysOnPolicy = alwaysOnDisplayPolicy;
@@ -89,6 +91,7 @@ public class DozeParameters implements TunerService.Tunable,
mPowerManager = powerManager;
mPowerManager.setDozeAfterScreenOff(!mControlScreenOffAnimation);
mFeatureFlags = featureFlags;
mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController;
tunerService.addTunable(
this,
@@ -220,7 +223,8 @@ public class DozeParameters implements TunerService.Tunable,
* then abruptly showing AOD.
*/
public boolean shouldControlUnlockedScreenOff() {
return getAlwaysOn() && mFeatureFlags.useNewLockscreenAnimations();
return getAlwaysOn() && mFeatureFlags.useNewLockscreenAnimations()
&& mUnlockedScreenOffAnimationController.shouldPlayUnlockedScreenOffAnimation();
}
private boolean getBoolean(String propName, int resId) {

View File

@@ -4249,7 +4249,7 @@ public class NotificationPanelViewController extends PanelViewController {
int oldState = mBarState;
boolean keyguardShowing = statusBarState == KEYGUARD;
if (mUnlockedScreenOffAnimationController.shouldPlayScreenOffAnimation()
if (mDozeParameters.shouldControlUnlockedScreenOff()
&& oldState == StatusBarState.SHADE
&& statusBarState == KEYGUARD) {
// This means we're doing the screen off animation - position the keyguard status

View File

@@ -26,11 +26,9 @@ import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENAB
import android.app.IActivityManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.Binder;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.Trace;
import android.util.Log;
import android.view.Display;
@@ -53,6 +51,7 @@ import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.google.android.collect.Lists;
@@ -108,12 +107,14 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
StatusBarStateController statusBarStateController,
ConfigurationController configurationController,
KeyguardViewMediator keyguardViewMediator,
KeyguardBypassController keyguardBypassController, SysuiColorExtractor colorExtractor,
DumpManager dumpManager) {
KeyguardBypassController keyguardBypassController,
SysuiColorExtractor colorExtractor,
DumpManager dumpManager,
KeyguardStateController keyguardStateController) {
mContext = context;
mWindowManager = windowManager;
mActivityManager = activityManager;
mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
mKeyguardScreenRotation = keyguardStateController.isKeyguardScreenRotationAllowed();
mDozeParameters = dozeParameters;
mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
mLpChanged = new LayoutParams();
@@ -173,12 +174,6 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
}
}
private boolean shouldEnableKeyguardScreenRotation() {
Resources res = mContext.getResources();
return SystemProperties.getBoolean("lockscreen.rot_override", false)
|| res.getBoolean(R.bool.config_enableLockScreenRotation);
}
/**
* Adds the notification shade view to the window manager.
*/

View File

@@ -4054,7 +4054,7 @@ public class StatusBar extends SystemUI implements DemoMode,
// The screen off animation uses our LightRevealScrim - we need to be expanded for it to
// be visible.
if (mUnlockedScreenOffAnimationController.shouldPlayScreenOffAnimation()) {
if (mDozeParameters.shouldControlUnlockedScreenOff()) {
makeExpandedVisible(true);
}

View File

@@ -3,6 +3,8 @@ package com.android.systemui.statusbar.phone
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.content.Context
import android.content.res.Configuration
import android.os.Handler
import android.view.View
import com.android.systemui.animation.Interpolators
@@ -16,6 +18,7 @@ import com.android.systemui.statusbar.notification.AnimatableProperty
import com.android.systemui.statusbar.notification.PropertyAnimator
import com.android.systemui.statusbar.notification.stack.AnimationProperties
import com.android.systemui.statusbar.notification.stack.StackStateAnimator
import com.android.systemui.statusbar.policy.KeyguardStateController
import javax.inject.Inject
/**
@@ -38,10 +41,11 @@ private const val LIGHT_REVEAL_ANIMATION_DURATION = 750L
*/
@SysUISingleton
class UnlockedScreenOffAnimationController @Inject constructor(
private val context: Context,
private val wakefulnessLifecycle: WakefulnessLifecycle,
private val statusBarStateControllerImpl: StatusBarStateControllerImpl,
private val keyguardViewMediatorLazy: dagger.Lazy<KeyguardViewMediator>,
private val dozeParameters: DozeParameters
private val keyguardStateController: KeyguardStateController
) : WakefulnessLifecycle.Observer {
private val handler = Handler()
@@ -142,7 +146,7 @@ class UnlockedScreenOffAnimationController @Inject constructor(
}
override fun onStartedGoingToSleep() {
if (shouldPlayScreenOffAnimation()) {
if (shouldPlayUnlockedScreenOffAnimation()) {
lightRevealAnimationPlaying = true
lightRevealAnimator.start()
@@ -156,13 +160,31 @@ class UnlockedScreenOffAnimationController @Inject constructor(
}
/**
* Whether we should play the screen off animation when the phone starts going to sleep. We can
* do that if dozeParameters says we can control the unlocked screen off animation and we are in
* the SHADE state. If we're in KEYGUARD or SHADE_LOCKED, the regular
* Whether we want to play the screen off animation when the phone starts going to sleep, based
* on the current state of the device.
*/
fun shouldPlayScreenOffAnimation(): Boolean {
return dozeParameters.shouldControlUnlockedScreenOff() &&
statusBarStateControllerImpl.state == StatusBarState.SHADE
fun shouldPlayUnlockedScreenOffAnimation(): Boolean {
// We only play the unlocked screen off animation if we are... unlocked.
if (statusBarStateControllerImpl.state != StatusBarState.SHADE) {
return false
}
// We currently draw both the light reveal scrim, and the AOD UI, in the shade. If it's
// already expanded and showing notifications/QS, the animation looks really messy. For now,
// disable it if the notification panel is expanded.
if (statusBar.notificationPanelViewController.isFullyExpanded) {
return false
}
// If we're not allowed to rotate the keyguard, then only do the screen off animation if
// we're in portrait. Otherwise, AOD will animate in sideways, which looks weird.
if (!keyguardStateController.isKeyguardScreenRotationAllowed &&
context.resources.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
return false
}
// Otherwise, good to go.
return true
}
/**

View File

@@ -56,6 +56,11 @@ public interface KeyguardStateController extends CallbackController<Callback> {
*/
boolean canPerformSmartSpaceTransition();
/**
* Whether the keyguard is allowed to rotate, or needs to be locked to the default orientation.
*/
boolean isKeyguardScreenRotationAllowed();
/**
* If the device has PIN/pattern/password or a lock screen at all.
*/

View File

@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.biometrics.BiometricSourceType;
import android.os.Build;
import android.os.SystemProperties;
import android.os.Trace;
import androidx.annotation.VisibleForTesting;
@@ -31,6 +32,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.shared.system.smartspace.SmartspaceTransitionController;
@@ -50,6 +52,7 @@ public class KeyguardStateControllerImpl implements KeyguardStateController, Dum
private static final String AUTH_BROADCAST_KEY = "debug_trigger_auth";
private final ArrayList<Callback> mCallbacks = new ArrayList<>();
private final Context mContext;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final LockPatternUtils mLockPatternUtils;
private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
@@ -100,6 +103,7 @@ public class KeyguardStateControllerImpl implements KeyguardStateController, Dum
public KeyguardStateControllerImpl(Context context,
KeyguardUpdateMonitor keyguardUpdateMonitor, LockPatternUtils lockPatternUtils,
SmartspaceTransitionController smartspaceTransitionController) {
mContext = context;
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mLockPatternUtils = lockPatternUtils;
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
@@ -242,6 +246,12 @@ public class KeyguardStateControllerImpl implements KeyguardStateController, Dum
&& mSmartspaceTransitionController.isSmartspaceTransitionPossible();
}
@Override
public boolean isKeyguardScreenRotationAllowed() {
return SystemProperties.getBoolean("lockscreen.rot_override", false)
|| mContext.getResources().getBoolean(R.bool.config_enableLockScreenRotation);
}
@Override
public boolean isFaceAuthEnabled() {
return mFaceAuthEnabled;

View File

@@ -43,6 +43,7 @@ import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.util.wakelock.WakeLockFake;
@@ -77,6 +78,8 @@ public class DozeUiTest extends SysuiTestCase {
private DozeUi mDozeUi;
@Mock
private StatusBarStateController mStatusBarStateController;
@Mock
private ConfigurationController mConfigurationController;
@Before
public void setUp() throws Exception {
@@ -89,7 +92,7 @@ public class DozeUiTest extends SysuiTestCase {
mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler,
mDozeParameters, mKeyguardUpdateMonitor, mDozeLog, mTunerService,
() -> mStatusBarStateController);
() -> mStatusBarStateController, mConfigurationController);
mDozeUi.setDozeMachine(mMachine);
}
@@ -146,7 +149,7 @@ public class DozeUiTest extends SysuiTestCase {
when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true);
mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler,
mDozeParameters, mKeyguardUpdateMonitor, mDozeLog, mTunerService,
() -> mStatusBarStateController);
() -> mStatusBarStateController, mConfigurationController);
mDozeUi.setDozeMachine(mMachine);
// Never animate if display doesn't support it.

View File

@@ -63,6 +63,7 @@ public class DozeParametersTest extends SysuiTestCase {
@Mock private BatteryController mBatteryController;
@Mock private FeatureFlags mFeatureFlags;
@Mock private DumpManager mDumpManager;
@Mock private UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;
@Before
public void setup() {
@@ -75,7 +76,8 @@ public class DozeParametersTest extends SysuiTestCase {
mBatteryController,
mTunerService,
mDumpManager,
mFeatureFlags
mFeatureFlags,
mUnlockedScreenOffAnimationController
);
}
@Test
@@ -125,7 +127,8 @@ public class DozeParametersTest extends SysuiTestCase {
when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
mDozeParameters.onTuningChanged(Settings.Secure.DOZE_ALWAYS_ON, "1");
when(mFeatureFlags.useNewLockscreenAnimations()).thenReturn(true);
when(mUnlockedScreenOffAnimationController.shouldPlayUnlockedScreenOffAnimation())
.thenReturn(true);
assertTrue(mDozeParameters.shouldControlUnlockedScreenOff());
// Trigger the setter for the current value.

View File

@@ -45,6 +45,7 @@ import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import org.junit.Before;
import org.junit.Test;
@@ -70,6 +71,7 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase {
@Mock private SysuiColorExtractor mColorExtractor;
@Mock ColorExtractor.GradientColors mGradientColors;
@Mock private DumpManager mDumpManager;
@Mock private KeyguardStateController mKeyguardStateController;
@Captor private ArgumentCaptor<WindowManager.LayoutParams> mLayoutParameters;
private NotificationShadeWindowControllerImpl mNotificationShadeWindowController;
@@ -83,7 +85,7 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase {
mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext,
mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
mConfigurationController, mKeyguardViewMediator, mKeyguardBypassController,
mColorExtractor, mDumpManager);
mColorExtractor, mDumpManager, mKeyguardStateController);
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
mNotificationShadeWindowController.attach();

View File

@@ -132,4 +132,9 @@ public class FakeKeyguardStateController implements KeyguardStateController {
public boolean canPerformSmartSpaceTransition() {
return false;
}
@Override
public boolean isKeyguardScreenRotationAllowed() {
return false;
}
}

View File

@@ -98,6 +98,7 @@ import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.wm.shell.R;
import com.android.wm.shell.ShellTaskOrganizer;
@@ -228,6 +229,8 @@ public class BubblesTest extends SysuiTestCase {
private TaskStackListenerImpl mTaskStackListener;
@Mock
private ShellTaskOrganizer mShellTaskOrganizer;
@Mock
private KeyguardStateController mKeyguardStateController;
private TestableBubblePositioner mPositioner;
@@ -250,7 +253,7 @@ public class BubblesTest extends SysuiTestCase {
mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext,
mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
mConfigurationController, mKeyguardViewMediator, mKeyguardBypassController,
mColorExtractor, mDumpManager);
mColorExtractor, mDumpManager, mKeyguardStateController);
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
mNotificationShadeWindowController.attach();

View File

@@ -82,6 +82,7 @@ import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.WindowManagerShellWrapper;
@@ -193,6 +194,8 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase {
private TaskStackListenerImpl mTaskStackListener;
@Mock
private ShellTaskOrganizer mShellTaskOrganizer;
@Mock
private KeyguardStateController mKeyguardStateController;
private TestableBubblePositioner mPositioner;
@@ -214,7 +217,7 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase {
mNotificationShadeWindowController = new NotificationShadeWindowControllerImpl(mContext,
mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
mConfigurationController, mKeyguardViewMediator, mKeyguardBypassController,
mColorExtractor, mDumpManager);
mColorExtractor, mDumpManager, mKeyguardStateController);
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
mNotificationShadeWindowController.attach();