Loading services/core/java/com/android/server/notification/NotificationManagerService.java +34 −13 Original line number Diff line number Diff line Loading @@ -7449,7 +7449,12 @@ public class NotificationManagerService extends SystemService { sentAccessibilityEvent = true; } if (DBG) Slog.v(TAG, "Interrupting!"); boolean isInsistentUpdate = isInsistentUpdate(record); if (hasValidSound) { if (isInsistentUpdate) { // don't reset insistent sound, it's jarring beep = true; } else { if (isInCall()) { playInCallNotification(); beep = true; Loading @@ -7460,16 +7465,21 @@ public class NotificationManagerService extends SystemService { mSoundNotificationKey = key; } } } final boolean ringerModeSilent = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; if (!isInCall() && hasValidVibrate && !ringerModeSilent) { if (isInsistentUpdate) { buzz = true; } else { buzz = playVibration(record, vibration, hasValidSound); if (buzz) { mVibrateNotificationKey = key; } } } } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) { hasValidSound = false; } Loading Loading @@ -7570,6 +7580,19 @@ public class NotificationManagerService extends SystemService { return true; } @GuardedBy("mNotificationLock") boolean isInsistentUpdate(final NotificationRecord record) { return (Objects.equals(record.getKey(), mSoundNotificationKey) || Objects.equals(record.getKey(), mVibrateNotificationKey)) && isCurrentlyInsistent(); } @GuardedBy("mNotificationLock") boolean isCurrentlyInsistent() { return isLoopingRingtoneNotification(mNotificationsByKey.get(mSoundNotificationKey)) || isLoopingRingtoneNotification(mNotificationsByKey.get(mVibrateNotificationKey)); } @GuardedBy("mNotificationLock") boolean shouldMuteNotificationLocked(final NotificationRecord record) { // Suppressed because it's a silent update Loading Loading @@ -7609,10 +7632,8 @@ public class NotificationManagerService extends SystemService { return true; } // A looping ringtone, such as an incoming call is playing if (isLoopingRingtoneNotification(mNotificationsByKey.get(mSoundNotificationKey)) || isLoopingRingtoneNotification( mNotificationsByKey.get(mVibrateNotificationKey))) { // A different looping ringtone, such as an incoming call is playing if (isCurrentlyInsistent() && !isInsistentUpdate(record)) { return true; } Loading services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; Loading Loading @@ -72,6 +73,7 @@ import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.test.suitebuilder.annotation.SmallTest; import android.util.Slog; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IAccessibilityManager; Loading Loading @@ -1182,6 +1184,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mService.buzzBeepBlinkLocked(r); verifyDelayedVibrate(mService.getVibratorHelper().createFallbackVibration(false)); // quiet update should stop making noise mService.buzzBeepBlinkLocked(s); Loading Loading @@ -1563,6 +1566,32 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { assertEquals(-1, interrupter.getLastAudiblyAlertedMs()); } @Test public void testRingtoneInsistentBeep_canUpdate() throws Exception { NotificationChannel ringtoneChannel = new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); ringtoneChannel.setSound(Uri.fromParts("a", "b", "c"), new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); ringtoneChannel.enableVibration(true); NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); mService.addNotification(ringtoneNotification); assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification)); mService.buzzBeepBlinkLocked(ringtoneNotification); verifyBeepLooped(); verifyDelayedVibrateLooped(); Mockito.reset(mVibrator); Mockito.reset(mRingtonePlayer); assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification)); mService.buzzBeepBlinkLocked(ringtoneNotification); // beep wasn't reset verifyNeverBeep(); verifyNeverVibrate(); verify(mRingtonePlayer, never()).stopAsync(); verify(mVibrator, never()).cancel(); } @Test public void testCannotInterruptRingtoneInsistentBuzz() { NotificationChannel ringtoneChannel = Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +34 −13 Original line number Diff line number Diff line Loading @@ -7449,7 +7449,12 @@ public class NotificationManagerService extends SystemService { sentAccessibilityEvent = true; } if (DBG) Slog.v(TAG, "Interrupting!"); boolean isInsistentUpdate = isInsistentUpdate(record); if (hasValidSound) { if (isInsistentUpdate) { // don't reset insistent sound, it's jarring beep = true; } else { if (isInCall()) { playInCallNotification(); beep = true; Loading @@ -7460,16 +7465,21 @@ public class NotificationManagerService extends SystemService { mSoundNotificationKey = key; } } } final boolean ringerModeSilent = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; if (!isInCall() && hasValidVibrate && !ringerModeSilent) { if (isInsistentUpdate) { buzz = true; } else { buzz = playVibration(record, vibration, hasValidSound); if (buzz) { mVibrateNotificationKey = key; } } } } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) { hasValidSound = false; } Loading Loading @@ -7570,6 +7580,19 @@ public class NotificationManagerService extends SystemService { return true; } @GuardedBy("mNotificationLock") boolean isInsistentUpdate(final NotificationRecord record) { return (Objects.equals(record.getKey(), mSoundNotificationKey) || Objects.equals(record.getKey(), mVibrateNotificationKey)) && isCurrentlyInsistent(); } @GuardedBy("mNotificationLock") boolean isCurrentlyInsistent() { return isLoopingRingtoneNotification(mNotificationsByKey.get(mSoundNotificationKey)) || isLoopingRingtoneNotification(mNotificationsByKey.get(mVibrateNotificationKey)); } @GuardedBy("mNotificationLock") boolean shouldMuteNotificationLocked(final NotificationRecord record) { // Suppressed because it's a silent update Loading Loading @@ -7609,10 +7632,8 @@ public class NotificationManagerService extends SystemService { return true; } // A looping ringtone, such as an incoming call is playing if (isLoopingRingtoneNotification(mNotificationsByKey.get(mSoundNotificationKey)) || isLoopingRingtoneNotification( mNotificationsByKey.get(mVibrateNotificationKey))) { // A different looping ringtone, such as an incoming call is playing if (isCurrentlyInsistent() && !isInsistentUpdate(record)) { return true; } Loading
services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; Loading Loading @@ -72,6 +73,7 @@ import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.test.suitebuilder.annotation.SmallTest; import android.util.Slog; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IAccessibilityManager; Loading Loading @@ -1182,6 +1184,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mService.buzzBeepBlinkLocked(r); verifyDelayedVibrate(mService.getVibratorHelper().createFallbackVibration(false)); // quiet update should stop making noise mService.buzzBeepBlinkLocked(s); Loading Loading @@ -1563,6 +1566,32 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { assertEquals(-1, interrupter.getLastAudiblyAlertedMs()); } @Test public void testRingtoneInsistentBeep_canUpdate() throws Exception { NotificationChannel ringtoneChannel = new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); ringtoneChannel.setSound(Uri.fromParts("a", "b", "c"), new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); ringtoneChannel.enableVibration(true); NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); mService.addNotification(ringtoneNotification); assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification)); mService.buzzBeepBlinkLocked(ringtoneNotification); verifyBeepLooped(); verifyDelayedVibrateLooped(); Mockito.reset(mVibrator); Mockito.reset(mRingtonePlayer); assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification)); mService.buzzBeepBlinkLocked(ringtoneNotification); // beep wasn't reset verifyNeverBeep(); verifyNeverVibrate(); verify(mRingtonePlayer, never()).stopAsync(); verify(mVibrator, never()).cancel(); } @Test public void testCannotInterruptRingtoneInsistentBuzz() { NotificationChannel ringtoneChannel = Loading