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

Commit 236bbcb8 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi
Browse files

Propagate mute event to both ring volume slices

Fix a bug where introduction of a separate_ring_volume slice meant that
the original ring_volume slice would not get notified of ring stream
muting event.

Bug: b/266855922

Test: make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=VolumeSliceHelperTest RunSettingsRoboTests -j40
Change-Id: Ifb5ebe4e7d9bde3d14336891cce3fbee167a5911
parent 3773ae0d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -115,11 +115,13 @@ public class VolumeSliceHelper {
            for (Map.Entry<Uri, Integer> entry : sRegisteredUri.entrySet()) {
                if (entry.getValue() == inputType) {
                    context.getContentResolver().notifyChange(entry.getKey(), null /* observer */);
                    if (inputType != AudioManager.STREAM_RING) { // Two URIs are mapped to ring
                        break;
                    }
                }
            }
        }
    }

    private static void notifyAllStreamsChanged(Context context) {
        synchronized (sRegisteredUri) {
+40 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.net.Uri;

import com.android.settings.notification.MediaVolumePreferenceController;
import com.android.settings.notification.RingVolumePreferenceController;
import com.android.settings.notification.SeparateRingVolumePreferenceController;
import com.android.settings.notification.VolumeSeekBarPreferenceController;
import com.android.settingslib.SliceBroadcastRelay;

@@ -62,6 +63,7 @@ public class VolumeSliceHelperTest {
    private Intent mIntent;
    private VolumeSeekBarPreferenceController mMediaController;
    private VolumeSeekBarPreferenceController mRingController;
    private VolumeSeekBarPreferenceController mSeparateRingController;

    @Before
    public void setUp() {
@@ -70,6 +72,7 @@ public class VolumeSliceHelperTest {
        when(mContext.getContentResolver()).thenReturn(mResolver);

        mMediaController = new MediaVolumePreferenceController(mContext);
        mSeparateRingController = new SeparateRingVolumePreferenceController(mContext);
        mRingController = new RingVolumePreferenceController(mContext);

        mIntent = createIntent(AudioManager.VOLUME_CHANGED_ACTION)
@@ -186,6 +189,43 @@ public class VolumeSliceHelperTest {
        verify(mResolver, never()).notifyChange(mMediaController.getSliceUri(), null);
    }

    @Test
    public void onReceive_ringStreamVolumeMuted_shouldNotifySeparateRing() {
        final Intent intent = createIntent(AudioManager.STREAM_MUTE_CHANGED_ACTION)
                .putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mRingController.getAudioStream());
        registerIntentToUri(mRingController);
        registerIntentToUri(mSeparateRingController);

        VolumeSliceHelper.onReceive(mContext, intent);

        verify(mResolver).notifyChange(mSeparateRingController.getSliceUri(), null);
    }

    @Test
    public void onReceive_ringStreamVolumeMuted_shouldNotifyRing() {
        final Intent intent = createIntent(AudioManager.STREAM_MUTE_CHANGED_ACTION)
                .putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mRingController.getAudioStream());
        registerIntentToUri(mRingController);
        registerIntentToUri(mSeparateRingController);

        VolumeSliceHelper.onReceive(mContext, intent);

        verify(mResolver).notifyChange(mRingController.getSliceUri(), null);
    }

    @Test
    public void onReceive_ringStreamVolumeMuted_shouldNotifyBothRings() {
        final Intent intent = createIntent(AudioManager.STREAM_MUTE_CHANGED_ACTION)
                .putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mRingController.getAudioStream());
        registerIntentToUri(mRingController);
        registerIntentToUri(mSeparateRingController);

        VolumeSliceHelper.onReceive(mContext, intent);

        verify(mResolver).notifyChange(mSeparateRingController.getSliceUri(), null);
        verify(mResolver).notifyChange(mRingController.getSliceUri(), null);
    }

    @Test
    public void onReceive_streamVolumeMuted_shouldNotifyChange() {
        final Intent intent = createIntent(AudioManager.STREAM_MUTE_CHANGED_ACTION)