Clocks were switching too frequently

This regressed since S. The statusbar state is only changed after the
keyguard is fully visible, which produces a noticeable shift from
small to large clock over and over when there are silent
notifications. This change should happen at the start of the
transition to keyguard.

Fixes: 229828779
Test: atest KeyguardNotificationVisibilityProviderTest
Change-Id: I2ced8747a32ac22246018171262b2ea8b32bdf22
This commit is contained in:
Matt Pietal
2022-05-02 11:23:18 -04:00
parent 1999fa1097
commit ea154b06db
2 changed files with 24 additions and 17 deletions

View File

@@ -18,6 +18,8 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
@@ -72,7 +74,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
private val lockscreenUserManager: NotificationLockscreenUserManager,
private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
private val highPriorityProvider: HighPriorityProvider,
private val statusBarStateController: StatusBarStateController,
private val statusBarStateController: SysuiStatusBarStateController,
private val broadcastDispatcher: BroadcastDispatcher,
private val secureSettings: SecureSettings,
private val globalSettings: GlobalSettings
@@ -105,7 +107,8 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
if (uri == showSilentNotifsUri) {
readShowSilentNotificationSetting()
}
if (keyguardStateController.isShowing) {
if (statusBarStateController.getCurrentOrUpcomingState()
== StatusBarState.KEYGUARD) {
notifyStateChanged("Settings $uri changed")
}
}
@@ -131,13 +134,14 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
// register (maybe) public mode changed callbacks:
statusBarStateController.addCallback(object : StatusBarStateController.StateListener {
override fun onStateChanged(state: Int) {
notifyStateChanged("onStatusBarStateChanged")
override fun onUpcomingStateChanged(state: Int) {
notifyStateChanged("onStatusBarUpcomingStateChanged")
}
})
broadcastDispatcher.registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (keyguardStateController.isShowing) {
if (statusBarStateController.getCurrentOrUpcomingState()
== StatusBarState.KEYGUARD) {
// maybe public mode changed
notifyStateChanged(intent.action!!)
}
@@ -159,7 +163,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
override fun shouldHideNotification(entry: NotificationEntry): Boolean = when {
// Keyguard state doesn't matter if the keyguard is not showing.
!keyguardStateController.isShowing -> false
statusBarStateController.getCurrentOrUpcomingState() != StatusBarState.KEYGUARD -> false
// Notifications not allowed on the lockscreen, always hide.
!lockscreenUserManager.shouldShowLockscreenNotifications() -> true
// User settings do not allow this notification on the lockscreen, so hide it.

View File

@@ -22,6 +22,8 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
import static com.android.systemui.statusbar.notification.collection.EntryUtilKt.modifyEntry;
import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat;
@@ -55,6 +57,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.RankingBuilder;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.notification.collection.GroupEntry;
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -90,7 +93,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Mock private NotificationLockscreenUserManager mLockscreenUserManager;
@Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@Mock private HighPriorityProvider mHighPriorityProvider;
@Mock private StatusBarStateController mStatusBarStateController;
@Mock private SysuiStatusBarStateController mStatusBarStateController;
@Mock private BroadcastDispatcher mBroadcastDispatcher;
private final FakeSettings mFakeSettings = new FakeSettings();
@@ -178,7 +181,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
callback.onStateChanged(0);
callback.onUpcomingStateChanged(0);
verify(listener).accept(anyString());
}
@@ -199,7 +202,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
callback.onReceive(mContext, new Intent(Intent.ACTION_USER_SWITCHED));
verify(listener).accept(anyString());
@@ -207,7 +210,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test
public void notifyListeners_onSettingChange_lockScreenShowNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -218,7 +221,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test
public void notifyListeners_onSettingChange_lockScreenAllowPrivateNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -229,7 +232,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test
public void notifyListeners_onSettingChange_zenMode() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -240,7 +243,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test
public void notifyListeners_onSettingChange_lockScreenShowSilentNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -262,7 +265,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
public void keyguardNotShowing() {
// GIVEN the lockscreen isn't showing
setupUnfilteredState(mEntry);
when(mKeyguardStateController.isShowing()).thenReturn(false);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE);
// THEN don't filter out the entry
assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
@@ -404,7 +407,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
*/
private void setupUnfilteredState(NotificationEntry entry) {
// keyguard is showing
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
// show notifications on the lockscreen
when(mLockscreenUserManager.shouldShowLockscreenNotifications()).thenReturn(true);
@@ -452,11 +455,11 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@BindsInstance NotificationLockscreenUserManager lockscreenUserManager,
@BindsInstance KeyguardUpdateMonitor keyguardUpdateMonitor,
@BindsInstance HighPriorityProvider highPriorityProvider,
@BindsInstance StatusBarStateController statusBarStateController,
@BindsInstance SysuiStatusBarStateController statusBarStateController,
@BindsInstance BroadcastDispatcher broadcastDispatcher,
@BindsInstance SecureSettings secureSettings,
@BindsInstance GlobalSettings globalSettings
);
}
}
}
}