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

Commit 68f81372 authored by Ats Jenk's avatar Ats Jenk
Browse files

Stop sound when bubble notification is suppressed

In BubbleMetadata for a notification there is a flag whether the
notification should be suppressed from the shade. When we expand a
bubble, we update this flag to suppress the notification as it has been
seen by the user.
Adding an additional check to see if the suppressed notification has
audio playing. If it has, stop audio playback.

Bug: 230691147
Test: atest NotificationManagerServiceTest
Change-Id: I8df12158c09496175ebf1c818706e440b2bea101
parent 518b492a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1444,6 +1444,11 @@ public class NotificationManagerService extends SystemService {
                    }
                    if (flags != data.getFlags()) {
                        int changedFlags = data.getFlags() ^ flags;
                        if ((changedFlags & FLAG_SUPPRESS_NOTIFICATION) != 0) {
                            // Suppress notification flag changed, clear any effects
                            clearEffectsLocked(key);
                        }
                        data.setFlags(flags);
                        // Shouldn't alert again just because of a flag change.
                        r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE;
@@ -1595,6 +1600,20 @@ public class NotificationManagerService extends SystemService {
        updateLightsLocked();
    }
    @GuardedBy("mNotificationLock")
    private void clearEffectsLocked(String key) {
        if (key.equals(mSoundNotificationKey)) {
            clearSoundLocked();
        }
        if (key.equals(mVibrateNotificationKey)) {
            clearVibrateLocked();
        }
        boolean removed = mLights.remove(key);
        if (removed) {
            updateLightsLocked();
        }
    }
    protected final BroadcastReceiver mLocaleChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+29 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.media.AudioManager;
import android.media.IRingtonePlayer;
import android.media.session.MediaSession;
import android.net.Uri;
import android.os.Binder;
@@ -7737,6 +7738,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertEquals(0, n.getBubbleMetadata().getFlags());
    }

    @Test
    public void testOnBubbleMetadataChangedToSuppressNotification_soundStopped()
            throws RemoteException {
        IRingtonePlayer mockPlayer = mock(IRingtonePlayer.class);
        when(mAudioManager.getRingtonePlayer()).thenReturn(mockPlayer);
        // Set up volume to be above 0 for the sound to actually play
        when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10);

        setUpPrefsForBubbles(PKG, mUid,
                true /* global */,
                BUBBLE_PREFERENCE_ALL /* app */,
                true /* channel */);

        // Post a bubble notification
        NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag");
        mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
                nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
        waitForIdle();

        // Test: suppress notification via bubble metadata update
        mService.mNotificationDelegate.onBubbleMetadataFlagChanged(nr.getKey(),
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION);
        waitForIdle();

        // Check audio is stopped
        verify(mockPlayer).stopAsync();
    }

    @Test
    public void testGrantInlineReplyUriPermission_recordExists() throws Exception {
        int userId = UserManager.isHeadlessSystemUserMode()