Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 997244fd authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Fix behavior of updates to insistent notifs" into sc-qpr1-dev am:...

Merge "Fix behavior of updates to insistent notifs" into sc-qpr1-dev am: 5bda3979 am: bb01aa8d am: 9f3b2daf

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15676601

Change-Id: I73ba32a056729afc180dd46ae89b0f6619449fcf
parents 66549fb9 9f3b2daf
Loading
Loading
Loading
Loading
+34 −13
Original line number Diff line number Diff line
@@ -7451,7 +7451,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;
@@ -7462,16 +7467,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;
                }
@@ -7572,6 +7582,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
@@ -7611,10 +7634,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;
        }

+29 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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);
@@ -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 =