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

Commit 53661edb authored by Shaowei Shen's avatar Shaowei Shen Committed by Automerger Merge Worker
Browse files

Merge "[Output Switcher] Disable volume control if route is volume_fixed" into...

Merge "[Output Switcher] Disable volume control if route is volume_fixed" into tm-dev am: 25639f1b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18756771



Change-Id: Ic11bc62236f85cdb873c1dc25b10232251a5d3d8
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ccdf34d9 25639f1b
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;

import static com.android.settingslib.media.LocalMediaManager.MediaDeviceState.STATE_SELECTED;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.MediaRoute2Info;
@@ -267,6 +268,20 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
        return mType;
    }

    /**
     * Checks if route's volume is fixed, if true, we should disable volume control for the device.
     *
     * @return route for this device is fixed.
     */
    @SuppressLint("NewApi")
    public boolean isVolumeFixed() {
        if (mRouteInfo == null) {
            Log.w(TAG, "RouteInfo is empty, regarded as volume fixed.");
            return true;
        }
        return mRouteInfo.getVolumeHandling() == MediaRoute2Info.PLAYBACK_VOLUME_FIXED;
    }

    /**
     * Transfer MediaDevice for media
     *
+3 −2
Original line number Diff line number Diff line
@@ -932,8 +932,9 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
    }

    boolean isVolumeControlEnabled(@NonNull MediaDevice device) {
        return isPlayBackInfoLocal()
                || device.getDeviceType() != MediaDevice.MediaDeviceType.TYPE_CAST_GROUP_DEVICE;
        return (isPlayBackInfoLocal()
                || device.getDeviceType() != MediaDevice.MediaDeviceType.TYPE_CAST_GROUP_DEVICE)
                && !device.isVolumeFixed();
    }

    @Override
+20 −0
Original line number Diff line number Diff line
@@ -571,4 +571,24 @@ public class MediaOutputControllerTest extends SysuiTestCase {

        assertThat(mMediaOutputController.getNotificationIcon()).isNull();
    }

    @Test
    public void isVolumeControlEnabled_isCastWithVolumeFixed_returnsFalse() {
        when(mMediaDevice1.getDeviceType()).thenReturn(
                MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);

        when(mMediaDevice1.isVolumeFixed()).thenReturn(true);

        assertThat(mMediaOutputController.isVolumeControlEnabled(mMediaDevice1)).isFalse();
    }

    @Test
    public void isVolumeControlEnabled_isCastWithVolumeNotFixed_returnsTrue() {
        when(mMediaDevice1.getDeviceType()).thenReturn(
                MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);

        when(mMediaDevice1.isVolumeFixed()).thenReturn(false);

        assertThat(mMediaOutputController.isVolumeControlEnabled(mMediaDevice1)).isTrue();
    }
}