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

Commit f676e7d7 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Stop sound when bubble notification is suppressed" into tm-qpr-dev

parents bfe6b276 68f81372
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()