Merge "Clocks were switching too frequently" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-04 21:02:26 +00:00
committed by Android (Google) Code Review
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.dagger.qualifiers.Main
import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.NotificationLockscreenUserManager 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.ListEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
@@ -72,7 +74,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
private val lockscreenUserManager: NotificationLockscreenUserManager, private val lockscreenUserManager: NotificationLockscreenUserManager,
private val keyguardUpdateMonitor: KeyguardUpdateMonitor, private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
private val highPriorityProvider: HighPriorityProvider, private val highPriorityProvider: HighPriorityProvider,
private val statusBarStateController: StatusBarStateController, private val statusBarStateController: SysuiStatusBarStateController,
private val broadcastDispatcher: BroadcastDispatcher, private val broadcastDispatcher: BroadcastDispatcher,
private val secureSettings: SecureSettings, private val secureSettings: SecureSettings,
private val globalSettings: GlobalSettings private val globalSettings: GlobalSettings
@@ -105,7 +107,8 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
if (uri == showSilentNotifsUri) { if (uri == showSilentNotifsUri) {
readShowSilentNotificationSetting() readShowSilentNotificationSetting()
} }
if (keyguardStateController.isShowing) { if (statusBarStateController.getCurrentOrUpcomingState()
== StatusBarState.KEYGUARD) {
notifyStateChanged("Settings $uri changed") notifyStateChanged("Settings $uri changed")
} }
} }
@@ -131,13 +134,14 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
// register (maybe) public mode changed callbacks: // register (maybe) public mode changed callbacks:
statusBarStateController.addCallback(object : StatusBarStateController.StateListener { statusBarStateController.addCallback(object : StatusBarStateController.StateListener {
override fun onStateChanged(state: Int) { override fun onUpcomingStateChanged(state: Int) {
notifyStateChanged("onStatusBarStateChanged") notifyStateChanged("onStatusBarUpcomingStateChanged")
} }
}) })
broadcastDispatcher.registerReceiver(object : BroadcastReceiver() { broadcastDispatcher.registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (keyguardStateController.isShowing) { if (statusBarStateController.getCurrentOrUpcomingState()
== StatusBarState.KEYGUARD) {
// maybe public mode changed // maybe public mode changed
notifyStateChanged(intent.action!!) notifyStateChanged(intent.action!!)
} }
@@ -159,7 +163,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
override fun shouldHideNotification(entry: NotificationEntry): Boolean = when { override fun shouldHideNotification(entry: NotificationEntry): Boolean = when {
// Keyguard state doesn't matter if the keyguard is not showing. // 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. // Notifications not allowed on the lockscreen, always hide.
!lockscreenUserManager.shouldShowLockscreenNotifications() -> true !lockscreenUserManager.shouldShowLockscreenNotifications() -> true
// User settings do not allow this notification on the lockscreen, so hide it. // 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_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN; 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.statusbar.notification.collection.EntryUtilKt.modifyEntry;
import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat; import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat;
@@ -56,6 +58,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager; import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.RankingBuilder; 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.GroupEntry;
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder; import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder;
import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -91,7 +94,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Mock private NotificationLockscreenUserManager mLockscreenUserManager; @Mock private NotificationLockscreenUserManager mLockscreenUserManager;
@Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor; @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@Mock private HighPriorityProvider mHighPriorityProvider; @Mock private HighPriorityProvider mHighPriorityProvider;
@Mock private StatusBarStateController mStatusBarStateController; @Mock private SysuiStatusBarStateController mStatusBarStateController;
@Mock private BroadcastDispatcher mBroadcastDispatcher; @Mock private BroadcastDispatcher mBroadcastDispatcher;
private final FakeSettings mFakeSettings = new FakeSettings(); private final FakeSettings mFakeSettings = new FakeSettings();
@@ -179,7 +182,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
callback.onStateChanged(0); callback.onUpcomingStateChanged(0);
verify(listener).accept(anyString()); verify(listener).accept(anyString());
} }
@@ -200,7 +203,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
callback.onReceive(mContext, new Intent(Intent.ACTION_USER_SWITCHED)); callback.onReceive(mContext, new Intent(Intent.ACTION_USER_SWITCHED));
verify(listener).accept(anyString()); verify(listener).accept(anyString());
@@ -208,7 +211,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test @Test
public void notifyListeners_onSettingChange_lockScreenShowNotifs() { public void notifyListeners_onSettingChange_lockScreenShowNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -219,7 +222,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test @Test
public void notifyListeners_onSettingChange_lockScreenAllowPrivateNotifs() { public void notifyListeners_onSettingChange_lockScreenAllowPrivateNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -265,7 +268,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test @Test
public void notifyListeners_onSettingChange_zenMode() { public void notifyListeners_onSettingChange_zenMode() {
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -276,7 +279,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@Test @Test
public void notifyListeners_onSettingChange_lockScreenShowSilentNotifs() { public void notifyListeners_onSettingChange_lockScreenShowSilentNotifs() {
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
Consumer<String> listener = mock(Consumer.class); Consumer<String> listener = mock(Consumer.class);
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
@@ -298,7 +301,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
public void keyguardNotShowing() { public void keyguardNotShowing() {
// GIVEN the lockscreen isn't showing // GIVEN the lockscreen isn't showing
setupUnfilteredState(mEntry); setupUnfilteredState(mEntry);
when(mKeyguardStateController.isShowing()).thenReturn(false); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE);
// THEN don't filter out the entry // THEN don't filter out the entry
assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
@@ -440,7 +443,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
*/ */
private void setupUnfilteredState(NotificationEntry entry) { private void setupUnfilteredState(NotificationEntry entry) {
// keyguard is showing // keyguard is showing
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
// show notifications on the lockscreen // show notifications on the lockscreen
when(mLockscreenUserManager.shouldShowLockscreenNotifications()).thenReturn(true); when(mLockscreenUserManager.shouldShowLockscreenNotifications()).thenReturn(true);
@@ -488,7 +491,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
@BindsInstance NotificationLockscreenUserManager lockscreenUserManager, @BindsInstance NotificationLockscreenUserManager lockscreenUserManager,
@BindsInstance KeyguardUpdateMonitor keyguardUpdateMonitor, @BindsInstance KeyguardUpdateMonitor keyguardUpdateMonitor,
@BindsInstance HighPriorityProvider highPriorityProvider, @BindsInstance HighPriorityProvider highPriorityProvider,
@BindsInstance StatusBarStateController statusBarStateController, @BindsInstance SysuiStatusBarStateController statusBarStateController,
@BindsInstance BroadcastDispatcher broadcastDispatcher, @BindsInstance BroadcastDispatcher broadcastDispatcher,
@BindsInstance SecureSettings secureSettings, @BindsInstance SecureSettings secureSettings,
@BindsInstance GlobalSettings globalSettings @BindsInstance GlobalSettings globalSettings