[Output Switcher] Disable volume control if route is volume_fixed

Bug: 233953128
Test: verified on device
Change-Id: Ibb73b62b24cb3070e15854c5bfa08987e7d226da
This commit is contained in:
shaoweishen
2022-06-08 09:58:26 +00:00
committed by Shaowei Shen
parent 1ad9256245
commit 675bc7bf5b
3 changed files with 38 additions and 2 deletions

View File

@@ -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
*

View File

@@ -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

View File

@@ -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();
}
}