diff options
| author | 2024-10-07 15:20:40 +0200 | |
|---|---|---|
| committer | 2024-10-07 15:20:40 +0200 | |
| commit | 27b818eaf87e31463d489ce9ca339b8dc3604acb (patch) | |
| tree | 35ac1728b89133d525a4b76a1aa7474881b2f49e | |
| parent | 41e5ff4f176be65ddeba9ed35b049ad6fbdda14b (diff) | |
De-flake notification avalanche tests
Ensure that the notifications posted after an avalanche event will
have a more recent 'when' timestamp.
Flag: com.android.server.notification.polite_notifications
Test: atest NotificationAttentionHelperTest
Bug: 371547369
Change-Id: I46ec71b69bc524b7d3d7fafb99615fd7bfbe5789
| -rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java index 03cad24a738a..592eec539ae6 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java @@ -2291,10 +2291,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); NotificationRecord r = getBeepyNotification(); @@ -2338,10 +2335,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); NotificationRecord r = getBeepyNotification(); @@ -2379,10 +2373,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); NotificationRecord r = getBeepyNotification(); @@ -2428,10 +2419,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); NotificationRecord r = getBeepyNotification(); r.getNotification().category = Notification.CATEGORY_EVENT; @@ -2504,10 +2492,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); // Regular notification: should beep at 0% volume NotificationRecord r = getBeepyNotification(); @@ -2574,10 +2559,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); NotificationRecord r = getBeepyNotification(); @@ -2602,10 +2584,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); // CATEGORY_ALARM is exempted NotificationRecord r = getBeepyNotification(); @@ -2646,10 +2625,7 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME2, 0); initAttentionHelper(flagResolver); - // Trigger avalanche trigger intent - final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", false); - mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + triggerAvalancheEvent(); // Create a conversation group with GROUP_ALERT_SUMMARY behavior // Where the summary is not MessagingStyle @@ -2693,6 +2669,16 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { assertEquals(-1, summary.getLastAudiblyAlertedMs()); } + private void triggerAvalancheEvent() throws Exception { + // Trigger avalanche trigger intent + final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); + intent.putExtra("state", false); + mAvalancheBroadcastReceiver.onReceive(getContext(), intent); + // Wait after avalanche trigger before posting notifications + // so that notification#getWhen() is not the same value + Thread.sleep(100); + } + @Test public void testBeepVolume_politeNotif_exemptEmergency() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); |