Loading services/core/java/com/android/server/notification/NotificationAttentionHelper.java +18 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.notification; import static android.app.Flags.sortSectionByTime; import static android.app.Notification.CATEGORY_MESSAGE; import static android.app.Notification.FLAG_INSISTENT; import static android.app.Notification.FLAG_ONLY_ALERT_ONCE; import static android.app.NotificationManager.IMPORTANCE_MIN; Loading @@ -42,6 +43,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.UserInfo; import android.content.res.Resources; import android.database.ContentObserver; Loading Loading @@ -1641,7 +1643,7 @@ public final class NotificationAttentionHelper { } // recent conversation if (record.isConversation() if ((record.isConversation() || isConversationMessage(record)) && record.getNotification().getWhen() > mLastAvalancheTriggerTimestamp) { return true; } Loading @@ -1656,6 +1658,21 @@ public final class NotificationAttentionHelper { return false; } // Relaxed signals for conversations messages private boolean isConversationMessage(final NotificationRecord record) { if (!CATEGORY_MESSAGE.equals(record.getSbn().getNotification().category)) { return false; } if (record.getChannel().isDemoted()) { return false; } final ShortcutInfo shortcut = record.getShortcutInfo(); if (shortcut == null) { return false; } return true; } } //====================== Observers ============================= Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +57 −0 Original line number Diff line number Diff line Loading @@ -2636,6 +2636,63 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mAccessibilityService, times(3)).sendAccessibilityEvent(any(), anyInt()); } @Test public void testBeepVolume_politeNotif_AvalancheStrategy_exempt_msgCategory() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_CROSS_APP_POLITE_NOTIFICATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS_ATTN_UPDATE); TestableFlagResolver flagResolver = new TestableFlagResolver(); flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME1, 50); 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); // Create a conversation group with GROUP_ALERT_SUMMARY behavior // Where the summary is not MessagingStyle final String groupKey = "grup_name"; final String shortcutId = "shortcut"; NotificationRecord summary = getBeepyNotificationRecord(groupKey, GROUP_ALERT_SUMMARY); summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; summary.getNotification().category = Notification.CATEGORY_MESSAGE; ShortcutInfo.Builder sb = new ShortcutInfo.Builder(getContext()); summary.setShortcutInfo(sb.setId(shortcutId).build()); // Should beep at 100% volume mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyBeepVolume(1.0f); assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // Post child notifications with GROUP_ALERT_SUMMARY NotificationRecord child = getConversationNotificationRecord(mId, false /* insistent */, false /* once */, true /* noisy */, false /* buzzy*/, false /* lights */, true, true, false, groupKey, Notification.GROUP_ALERT_SUMMARY, false, mUser, mPkg, shortcutId); // Should not beep mAttentionHelper.buzzBeepBlinkLocked(child, DEFAULT_SIGNALS); verifyNeverBeep(); assertFalse(child.isInterruptive()); assertEquals(-1, child.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // 2nd update for summary should beep at 50% volume mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyBeepVolume(0.5f); assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // 3rd update for summary should not beep mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyNeverBeep(); assertFalse(summary.isInterruptive()); assertEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test public void testBeepVolume_politeNotif_exemptEmergency() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); Loading Loading
services/core/java/com/android/server/notification/NotificationAttentionHelper.java +18 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.notification; import static android.app.Flags.sortSectionByTime; import static android.app.Notification.CATEGORY_MESSAGE; import static android.app.Notification.FLAG_INSISTENT; import static android.app.Notification.FLAG_ONLY_ALERT_ONCE; import static android.app.NotificationManager.IMPORTANCE_MIN; Loading @@ -42,6 +43,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.UserInfo; import android.content.res.Resources; import android.database.ContentObserver; Loading Loading @@ -1641,7 +1643,7 @@ public final class NotificationAttentionHelper { } // recent conversation if (record.isConversation() if ((record.isConversation() || isConversationMessage(record)) && record.getNotification().getWhen() > mLastAvalancheTriggerTimestamp) { return true; } Loading @@ -1656,6 +1658,21 @@ public final class NotificationAttentionHelper { return false; } // Relaxed signals for conversations messages private boolean isConversationMessage(final NotificationRecord record) { if (!CATEGORY_MESSAGE.equals(record.getSbn().getNotification().category)) { return false; } if (record.getChannel().isDemoted()) { return false; } final ShortcutInfo shortcut = record.getShortcutInfo(); if (shortcut == null) { return false; } return true; } } //====================== Observers ============================= Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +57 −0 Original line number Diff line number Diff line Loading @@ -2636,6 +2636,63 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mAccessibilityService, times(3)).sendAccessibilityEvent(any(), anyInt()); } @Test public void testBeepVolume_politeNotif_AvalancheStrategy_exempt_msgCategory() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_CROSS_APP_POLITE_NOTIFICATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS_ATTN_UPDATE); TestableFlagResolver flagResolver = new TestableFlagResolver(); flagResolver.setFlagOverride(NotificationFlags.NOTIF_VOLUME1, 50); 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); // Create a conversation group with GROUP_ALERT_SUMMARY behavior // Where the summary is not MessagingStyle final String groupKey = "grup_name"; final String shortcutId = "shortcut"; NotificationRecord summary = getBeepyNotificationRecord(groupKey, GROUP_ALERT_SUMMARY); summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; summary.getNotification().category = Notification.CATEGORY_MESSAGE; ShortcutInfo.Builder sb = new ShortcutInfo.Builder(getContext()); summary.setShortcutInfo(sb.setId(shortcutId).build()); // Should beep at 100% volume mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyBeepVolume(1.0f); assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // Post child notifications with GROUP_ALERT_SUMMARY NotificationRecord child = getConversationNotificationRecord(mId, false /* insistent */, false /* once */, true /* noisy */, false /* buzzy*/, false /* lights */, true, true, false, groupKey, Notification.GROUP_ALERT_SUMMARY, false, mUser, mPkg, shortcutId); // Should not beep mAttentionHelper.buzzBeepBlinkLocked(child, DEFAULT_SIGNALS); verifyNeverBeep(); assertFalse(child.isInterruptive()); assertEquals(-1, child.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // 2nd update for summary should beep at 50% volume mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyBeepVolume(0.5f); assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // 3rd update for summary should not beep mAttentionHelper.buzzBeepBlinkLocked(summary, DEFAULT_SIGNALS); verifyNeverBeep(); assertFalse(summary.isInterruptive()); assertEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test public void testBeepVolume_politeNotif_exemptEmergency() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); Loading