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

Commit 478fac74 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge changes Ia21f45c1,I208797f3

* changes:
  Check if notification is valid before it finally vibrates because it can be canceled as soon as enqeued
  Update sound/vibrate notification key only when it actually buzz/beep.
parents f15c4816 de933884
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -5258,22 +5258,25 @@ public class NotificationManagerService extends SystemService {
                    }
                    if (DBG) Slog.v(TAG, "Interrupting!");
                    if (hasValidSound) {
                        mSoundNotificationKey = key;
                        if (mInCall) {
                            playInCallNotification();
                            beep = true;
                        } else {
                            beep = playSound(record, soundUri);
                        }
                        if(beep) {
                            mSoundNotificationKey = key;
                        }
                    }

                    final boolean ringerModeSilent =
                            mAudioManager.getRingerModeInternal()
                                    == AudioManager.RINGER_MODE_SILENT;
                    if (!mInCall && hasValidVibrate && !ringerModeSilent) {
                        mVibrateNotificationKey = key;

                        buzz = playVibration(record, vibration, hasValidSound);
                        if(buzz) {
                            mVibrateNotificationKey = key;
                        }
                    }
                } else if ((record.getFlags() & Notification.FLAG_INSISTENT) != 0) {
                    hasValidSound = false;
@@ -5454,8 +5457,17 @@ public class NotificationManagerService extends SystemService {
                    try {
                        Thread.sleep(waitMs);
                    } catch (InterruptedException e) { }
                    mVibrator.vibrate(record.sbn.getUid(), record.sbn.getPackageName(),

                    // Notifications might be canceled before it actually vibrates due to waitMs,
                    // so need to check the notification still valide for vibrate.
                    synchronized (mNotificationLock) {
                        if (mNotificationsByKey.get(record.getKey()) != null) {
                            mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(),
                                    effect, "Notification (delayed)", record.getAudioAttributes());
                        } else {
                            Slog.e(TAG, "No vibration for canceled notification : " + record.getKey());
                        }
                    }
                }).start();
            } else {
                mVibrator.vibrate(record.sbn.getUid(), record.sbn.getPackageName(),
+16 −0
Original line number Diff line number Diff line
@@ -1014,6 +1014,22 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
        assertEquals(-1, s.getLastAudiblyAlertedMs());
    }

    @Test
    public void testCanceledNoisyNeverVibrate() throws Exception {
        NotificationRecord r = getBuzzyBeepyNotification();

        final int waitMs = mAudioManager.getFocusRampTimeMs(
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
                r.getAudioAttributes());

        mService.buzzBeepBlinkLocked(r);
        mService.clearNotifications();

        verifyNeverVibrate();
        Thread.sleep(waitMs);
        verifyNeverVibrate();
    }
    
    @Test
    public void testEmptyUriSoundTreatedAsNoSound() throws Exception {
        NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH);