Merge "[Output Switcher] Disable volume control if route is volume_fixed" into tm-dev
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user