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

Commit c86c0150 authored by Valentin Iftime's avatar Valentin Iftime Committed by Iavor-Valentin Iftime
Browse files

Stop previous notification vibration on new buzzy notification

 VibratorHelper needs to explicitly cancel a previously playing
non-insistent notification vibration,
 otherwise a looping vibration will not be stopped when a new notification with vibration is posted.

Flag: EXEMPT bugfix
Test: atest NotificationAttentionHelper
Bug: 340653186
Change-Id: I4a6730faa89ea7f2c176512c6decb03a44d858a4
parent 2962f79d
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -489,6 +489,7 @@ public final class NotificationAttentionHelper {


                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
                    hasValidSound = false;
                    hasValidSound = false;
                    hasValidVibrate = false;
                }
                }
            }
            }
        }
        }
@@ -753,6 +754,13 @@ public final class NotificationAttentionHelper {
        // notifying app does not have the VIBRATE permission.
        // notifying app does not have the VIBRATE permission.
        final long identity = Binder.clearCallingIdentity();
        final long identity = Binder.clearCallingIdentity();
        try {
        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 float scale = getVibrationIntensity(record);
            final VibrationEffect scaledEffect = Float.compare(scale, DEFAULT_VOLUME) != 0
            final VibrationEffect scaledEffect = Float.compare(scale, DEFAULT_VOLUME) != 0
                    ? mVibratorHelper.scale(effect, scale) : effect;
                    ? mVibratorHelper.scale(effect, scale) : effect;
+19 −0
Original line number Original line Diff line number Diff line
@@ -2006,6 +2006,25 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase {
        assertTrue(interrupter.isInterruptive());
        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
    @Test
    public void testRingtoneInsistentBeep_doesNotBlockFutureSoundsOnceStopped() throws Exception {
    public void testRingtoneInsistentBeep_doesNotBlockFutureSoundsOnceStopped() throws Exception {
        NotificationChannel ringtoneChannel =
        NotificationChannel ringtoneChannel =