diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d4cfb47c13d64..655daf89dda49 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -5697,19 +5697,17 @@ public class NotificationManagerService extends SystemService { } int indexBefore = findNotificationRecordIndexLocked(record); boolean interceptBefore = record.isIntercepted(); - float contactAffinityBefore = record.getContactAffinity(); int visibilityBefore = record.getPackageVisibilityOverride(); recon.applyChangesLocked(record); applyZenModeLocked(record); mRankingHelper.sort(mNotificationList); int indexAfter = findNotificationRecordIndexLocked(record); boolean interceptAfter = record.isIntercepted(); - float contactAffinityAfter = record.getContactAffinity(); int visibilityAfter = record.getPackageVisibilityOverride(); changed = indexBefore != indexAfter || interceptBefore != interceptAfter || visibilityBefore != visibilityAfter; if (interceptBefore && !interceptAfter - && Float.compare(contactAffinityBefore, contactAffinityAfter) != 0) { + && record.isNewEnoughForAlerting(System.currentTimeMillis())) { buzzBeepBlinkLocked(record); } } diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index d19fbfaad3329..9942f5920c9e8 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -92,6 +92,8 @@ public final class NotificationRecord { static final String TAG = "NotificationRecord"; static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); private static final int MAX_LOGTAG_LENGTH = 35; + // the period after which a notification is updated where it can make sound + private static final int MAX_SOUND_DELAY_MS = 2000; final StatusBarNotification sbn; IActivityManager mAm; UriGrantsManagerInternal mUgmInternal; @@ -125,7 +127,8 @@ public final class NotificationRecord { private long mVisibleSinceMs; // The most recent update time, or the creation time if no updates. - private long mUpdateTimeMs; + @VisibleForTesting + final long mUpdateTimeMs; // The most recent interruption time, or the creation time if no updates. Differs from the // above value because updates are filtered based on whether they actually interrupted the @@ -826,6 +829,10 @@ public final class NotificationRecord { return mIntercept; } + public boolean isNewEnoughForAlerting(long now) { + return getFreshnessMs(now) <= MAX_SOUND_DELAY_MS; + } + public void setHidden(boolean hidden) { mHidden = hidden; } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java index 65e640f5f73c8..1458266089c5b 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java @@ -825,4 +825,24 @@ public class NotificationRecordTest extends UiServiceTestCase { assertNotEquals(-1, record.getLastAudiblyAlertedMs()); } + + @Test + public void testIsNewEnoughForAlerting_new() { + StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, + true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, + false /* lights */, false /* defaultLights */, groupId /* group */); + NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); + + assertTrue(record.isNewEnoughForAlerting(record.mUpdateTimeMs)); + } + + @Test + public void testIsNewEnoughForAlerting_old() { + StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, + true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, + false /* lights */, false /* defaultLights */, groupId /* group */); + NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); + + assertFalse(record.isNewEnoughForAlerting(record.mUpdateTimeMs + (1000 * 60 * 60))); + } }