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

Commit e0bd8459 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Stop previous notification vibration on new buzzy notification" into main

parents e3d7697a c86c0150
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -489,6 +489,7 @@ public final class NotificationAttentionHelper {

                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
                    hasValidSound = false;
                    hasValidVibrate = false;
                }
            }
        }
@@ -753,6 +754,13 @@ public final class NotificationAttentionHelper {
        // notifying app does not have the VIBRATE permission.
        final long identity = Binder.clearCallingIdentity();
        try {
            // Need to explicitly cancel a previously playing vibration
            // Otherwise a looping vibration will not be stopped when starting a new one.
            if (mVibrateNotificationKey != null
                    && !mVibrateNotificationKey.equals(record.getKey())) {
                mVibrateNotificationKey = null;
                mVibratorHelper.cancelVibration();
            }
            final float scale = getVibrationIntensity(record);
            final VibrationEffect scaledEffect = Float.compare(scale, DEFAULT_VOLUME) != 0
                    ? mVibratorHelper.scale(effect, scale) : effect;
+19 −0
Original line number Diff line number Diff line
@@ -2006,6 +2006,25 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase {
        assertTrue(interrupter.isInterruptive());
    }

    @Test
    public void testCanInterruptNonRingtoneInsistentBuzzWithOtherBuzzyNotification() {
        NotificationRecord r = getInsistentBuzzyNotification();
        mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS);
        verifyVibrateLooped();
        assertTrue(r.isInterruptive());
        assertNotEquals(-1, r.getLastAudiblyAlertedMs());
        Mockito.reset(mVibrator);

        // New buzzy notification stops previous looping vibration
        NotificationRecord interrupter = getBuzzyOtherNotification();
        mAttentionHelper.buzzBeepBlinkLocked(interrupter, DEFAULT_SIGNALS);
        verifyStopVibrate();
        // And then vibrates itself
        verifyVibrate(1);
        assertTrue(interrupter.isInterruptive());
        assertNotEquals(-1, interrupter.getLastAudiblyAlertedMs());
    }

    @Test
    public void testRingtoneInsistentBeep_doesNotBlockFutureSoundsOnceStopped() throws Exception {
        NotificationChannel ringtoneChannel =