Merge "Fix behavior of updates to insistent notifs" into sc-qpr1-dev am: 5bda39799d am: bb01aa8d71
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15676601 Change-Id: Ib9e6ac55fb139c7c11b59e76881ba3f8c10d74eb
This commit is contained in:
@@ -7449,27 +7449,37 @@ public class NotificationManagerService extends SystemService {
|
|||||||
sentAccessibilityEvent = true;
|
sentAccessibilityEvent = true;
|
||||||
}
|
}
|
||||||
if (DBG) Slog.v(TAG, "Interrupting!");
|
if (DBG) Slog.v(TAG, "Interrupting!");
|
||||||
|
boolean isInsistentUpdate = isInsistentUpdate(record);
|
||||||
if (hasValidSound) {
|
if (hasValidSound) {
|
||||||
|
if (isInsistentUpdate) {
|
||||||
|
// don't reset insistent sound, it's jarring
|
||||||
|
beep = true;
|
||||||
|
} else {
|
||||||
if (isInCall()) {
|
if (isInCall()) {
|
||||||
playInCallNotification();
|
playInCallNotification();
|
||||||
beep = true;
|
beep = true;
|
||||||
} else {
|
} else {
|
||||||
beep = playSound(record, soundUri);
|
beep = playSound(record, soundUri);
|
||||||
}
|
}
|
||||||
if(beep) {
|
if (beep) {
|
||||||
mSoundNotificationKey = key;
|
mSoundNotificationKey = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final boolean ringerModeSilent =
|
final boolean ringerModeSilent =
|
||||||
mAudioManager.getRingerModeInternal()
|
mAudioManager.getRingerModeInternal()
|
||||||
== AudioManager.RINGER_MODE_SILENT;
|
== AudioManager.RINGER_MODE_SILENT;
|
||||||
if (!isInCall() && hasValidVibrate && !ringerModeSilent) {
|
if (!isInCall() && hasValidVibrate && !ringerModeSilent) {
|
||||||
|
if (isInsistentUpdate) {
|
||||||
|
buzz = true;
|
||||||
|
} else {
|
||||||
buzz = playVibration(record, vibration, hasValidSound);
|
buzz = playVibration(record, vibration, hasValidSound);
|
||||||
if(buzz) {
|
if (buzz) {
|
||||||
mVibrateNotificationKey = key;
|
mVibrateNotificationKey = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
|
} else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
|
||||||
hasValidSound = false;
|
hasValidSound = false;
|
||||||
}
|
}
|
||||||
@@ -7570,6 +7580,19 @@ public class NotificationManagerService extends SystemService {
|
|||||||
return true;
|
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")
|
@GuardedBy("mNotificationLock")
|
||||||
boolean shouldMuteNotificationLocked(final NotificationRecord record) {
|
boolean shouldMuteNotificationLocked(final NotificationRecord record) {
|
||||||
// Suppressed because it's a silent update
|
// Suppressed because it's a silent update
|
||||||
@@ -7609,10 +7632,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A looping ringtone, such as an incoming call is playing
|
// A different looping ringtone, such as an incoming call is playing
|
||||||
if (isLoopingRingtoneNotification(mNotificationsByKey.get(mSoundNotificationKey))
|
if (isCurrentlyInsistent() && !isInsistentUpdate(record)) {
|
||||||
|| isLoopingRingtoneNotification(
|
|
||||||
mNotificationsByKey.get(mVibrateNotificationKey))) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import static junit.framework.Assert.assertTrue;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
@@ -72,6 +73,7 @@ import android.provider.Settings;
|
|||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
import android.util.Slog;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.view.accessibility.IAccessibilityManager;
|
import android.view.accessibility.IAccessibilityManager;
|
||||||
@@ -1182,6 +1184,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
|
|||||||
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
|
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
|
||||||
|
|
||||||
mService.buzzBeepBlinkLocked(r);
|
mService.buzzBeepBlinkLocked(r);
|
||||||
|
verifyDelayedVibrate(mService.getVibratorHelper().createFallbackVibration(false));
|
||||||
|
|
||||||
// quiet update should stop making noise
|
// quiet update should stop making noise
|
||||||
mService.buzzBeepBlinkLocked(s);
|
mService.buzzBeepBlinkLocked(s);
|
||||||
@@ -1563,6 +1566,32 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
|
|||||||
assertEquals(-1, interrupter.getLastAudiblyAlertedMs());
|
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
|
@Test
|
||||||
public void testCannotInterruptRingtoneInsistentBuzz() {
|
public void testCannotInterruptRingtoneInsistentBuzz() {
|
||||||
NotificationChannel ringtoneChannel =
|
NotificationChannel ringtoneChannel =
|
||||||
|
|||||||
Reference in New Issue
Block a user