Loading packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 * Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +3 −2 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 * Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +3 −2 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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(); } }