Merge "Extend the MediaDeviceType to support more media device" into rvc-dev am: 08348dead8
Change-Id: I6f153e103b3fe8130014f375e1169e5150239bfb
This commit is contained in:
@@ -38,7 +38,7 @@ public class BluetoothMediaDevice extends MediaDevice {
|
|||||||
|
|
||||||
BluetoothMediaDevice(Context context, CachedBluetoothDevice device,
|
BluetoothMediaDevice(Context context, CachedBluetoothDevice device,
|
||||||
MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName) {
|
MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName) {
|
||||||
super(context, MediaDeviceType.TYPE_BLUETOOTH_DEVICE, routerManager, info, packageName);
|
super(context, routerManager, info, packageName);
|
||||||
mCachedDevice = device;
|
mCachedDevice = device;
|
||||||
initDeviceRecord();
|
initDeviceRecord();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class InfoMediaDevice extends MediaDevice {
|
|||||||
|
|
||||||
InfoMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info,
|
InfoMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info,
|
||||||
String packageName) {
|
String packageName) {
|
||||||
super(context, MediaDeviceType.TYPE_CAST_DEVICE, routerManager, info, packageName);
|
super(context, routerManager, info, packageName);
|
||||||
initDeviceRecord();
|
initDeviceRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settingslib.media;
|
package com.android.settingslib.media;
|
||||||
|
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BLUETOOTH_A2DP;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_HEARING_AID;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_UNKNOWN;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -38,13 +48,21 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
|||||||
private static final String TAG = "MediaDevice";
|
private static final String TAG = "MediaDevice";
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({MediaDeviceType.TYPE_CAST_DEVICE,
|
@IntDef({MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE,
|
||||||
|
MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE,
|
||||||
|
MediaDeviceType.TYPE_FAST_PAIR_BLUETOOTH_DEVICE,
|
||||||
MediaDeviceType.TYPE_BLUETOOTH_DEVICE,
|
MediaDeviceType.TYPE_BLUETOOTH_DEVICE,
|
||||||
|
MediaDeviceType.TYPE_CAST_DEVICE,
|
||||||
|
MediaDeviceType.TYPE_CAST_GROUP_DEVICE,
|
||||||
MediaDeviceType.TYPE_PHONE_DEVICE})
|
MediaDeviceType.TYPE_PHONE_DEVICE})
|
||||||
public @interface MediaDeviceType {
|
public @interface MediaDeviceType {
|
||||||
int TYPE_PHONE_DEVICE = 1;
|
int TYPE_USB_C_AUDIO_DEVICE = 1;
|
||||||
int TYPE_CAST_DEVICE = 2;
|
int TYPE_3POINT5_MM_AUDIO_DEVICE = 2;
|
||||||
int TYPE_BLUETOOTH_DEVICE = 3;
|
int TYPE_FAST_PAIR_BLUETOOTH_DEVICE = 3;
|
||||||
|
int TYPE_BLUETOOTH_DEVICE = 4;
|
||||||
|
int TYPE_CAST_DEVICE = 5;
|
||||||
|
int TYPE_CAST_GROUP_DEVICE = 6;
|
||||||
|
int TYPE_PHONE_DEVICE = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -58,13 +76,43 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
|||||||
protected final MediaRouter2Manager mRouterManager;
|
protected final MediaRouter2Manager mRouterManager;
|
||||||
protected final String mPackageName;
|
protected final String mPackageName;
|
||||||
|
|
||||||
MediaDevice(Context context, @MediaDeviceType int type, MediaRouter2Manager routerManager,
|
MediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info,
|
||||||
MediaRoute2Info info, String packageName) {
|
String packageName) {
|
||||||
mType = type;
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mRouteInfo = info;
|
mRouteInfo = info;
|
||||||
mRouterManager = routerManager;
|
mRouterManager = routerManager;
|
||||||
mPackageName = packageName;
|
mPackageName = packageName;
|
||||||
|
setType(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setType(MediaRoute2Info info) {
|
||||||
|
if (info == null) {
|
||||||
|
mType = MediaDeviceType.TYPE_BLUETOOTH_DEVICE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (info.getType()) {
|
||||||
|
case TYPE_GROUP:
|
||||||
|
mType = MediaDeviceType.TYPE_CAST_GROUP_DEVICE;
|
||||||
|
break;
|
||||||
|
case TYPE_BUILTIN_SPEAKER:
|
||||||
|
mType = MediaDeviceType.TYPE_PHONE_DEVICE;
|
||||||
|
break;
|
||||||
|
case TYPE_WIRED_HEADSET:
|
||||||
|
case TYPE_WIRED_HEADPHONES:
|
||||||
|
mType = MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE;
|
||||||
|
break;
|
||||||
|
case TYPE_HEARING_AID:
|
||||||
|
case TYPE_BLUETOOTH_A2DP:
|
||||||
|
mType = MediaDeviceType.TYPE_BLUETOOTH_DEVICE;
|
||||||
|
break;
|
||||||
|
case TYPE_UNKNOWN:
|
||||||
|
case TYPE_REMOTE_TV:
|
||||||
|
case TYPE_REMOTE_SPEAKER:
|
||||||
|
default:
|
||||||
|
mType = MediaDeviceType.TYPE_CAST_DEVICE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initDeviceRecord() {
|
void initDeviceRecord() {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class PhoneMediaDevice extends MediaDevice {
|
|||||||
|
|
||||||
PhoneMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info,
|
PhoneMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info,
|
||||||
String packageName) {
|
String packageName) {
|
||||||
super(context, MediaDeviceType.TYPE_PHONE_DEVICE, routerManager, info, packageName);
|
super(context, routerManager, info, packageName);
|
||||||
|
|
||||||
initDeviceRecord();
|
initDeviceRecord();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settingslib.media;
|
package com.android.settingslib.media;
|
||||||
|
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BLUETOOTH_A2DP;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -144,12 +148,19 @@ public class MediaDeviceTest {
|
|||||||
when(mCachedDevice2.isConnected()).thenReturn(true);
|
when(mCachedDevice2.isConnected()).thenReturn(true);
|
||||||
when(mCachedDevice3.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
when(mCachedDevice3.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
when(mCachedDevice3.isConnected()).thenReturn(true);
|
when(mCachedDevice3.isConnected()).thenReturn(true);
|
||||||
|
when(mBluetoothRouteInfo1.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
|
||||||
|
when(mBluetoothRouteInfo2.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
|
||||||
|
when(mBluetoothRouteInfo3.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
|
||||||
when(mRouteInfo1.getId()).thenReturn(ROUTER_ID_1);
|
when(mRouteInfo1.getId()).thenReturn(ROUTER_ID_1);
|
||||||
when(mRouteInfo2.getId()).thenReturn(ROUTER_ID_2);
|
when(mRouteInfo2.getId()).thenReturn(ROUTER_ID_2);
|
||||||
when(mRouteInfo3.getId()).thenReturn(ROUTER_ID_3);
|
when(mRouteInfo3.getId()).thenReturn(ROUTER_ID_3);
|
||||||
when(mRouteInfo1.getName()).thenReturn(DEVICE_NAME_1);
|
when(mRouteInfo1.getName()).thenReturn(DEVICE_NAME_1);
|
||||||
when(mRouteInfo2.getName()).thenReturn(DEVICE_NAME_2);
|
when(mRouteInfo2.getName()).thenReturn(DEVICE_NAME_2);
|
||||||
when(mRouteInfo3.getName()).thenReturn(DEVICE_NAME_3);
|
when(mRouteInfo3.getName()).thenReturn(DEVICE_NAME_3);
|
||||||
|
when(mRouteInfo1.getType()).thenReturn(TYPE_REMOTE_SPEAKER);
|
||||||
|
when(mRouteInfo2.getType()).thenReturn(TYPE_REMOTE_SPEAKER);
|
||||||
|
when(mRouteInfo3.getType()).thenReturn(TYPE_REMOTE_SPEAKER);
|
||||||
|
when(mPhoneRouteInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
|
||||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager);
|
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager);
|
||||||
when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
||||||
when(mProfileManager.getHearingAidProfile()).thenReturn(mHapProfile);
|
when(mProfileManager.getHearingAidProfile()).thenReturn(mHapProfile);
|
||||||
@@ -271,12 +282,12 @@ public class MediaDeviceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo_info_bluetooth_infoFirst() {
|
public void compareTo_info_bluetooth_infoFirst() {
|
||||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
|
||||||
mMediaDevices.add(mInfoMediaDevice1);
|
mMediaDevices.add(mInfoMediaDevice1);
|
||||||
|
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||||
|
|
||||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
|
||||||
Collections.sort(mMediaDevices, COMPARATOR);
|
|
||||||
assertThat(mMediaDevices.get(0)).isEqualTo(mInfoMediaDevice1);
|
assertThat(mMediaDevices.get(0)).isEqualTo(mInfoMediaDevice1);
|
||||||
|
Collections.sort(mMediaDevices, COMPARATOR);
|
||||||
|
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -327,7 +338,7 @@ public class MediaDeviceTest {
|
|||||||
// 5.mBluetoothMediaDevice2: * 2 times usage
|
// 5.mBluetoothMediaDevice2: * 2 times usage
|
||||||
// 6.mBluetoothMediaDevice3: * 1 time usage
|
// 6.mBluetoothMediaDevice3: * 1 time usage
|
||||||
// 7.mPhoneMediaDevice: * 0 time usage
|
// 7.mPhoneMediaDevice: * 0 time usage
|
||||||
// Order: 7 -> 2 -> 1 -> 3 -> 5 -> 4 -> 6
|
// Order: 7 -> 2 -> 1 -> 5 -> 3 -> 6 -> 4
|
||||||
@Test
|
@Test
|
||||||
public void compareTo_mixedDevices_carKitFirst() {
|
public void compareTo_mixedDevices_carKitFirst() {
|
||||||
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
||||||
@@ -352,10 +363,10 @@ public class MediaDeviceTest {
|
|||||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||||
assertThat(mMediaDevices.get(1)).isEqualTo(mBluetoothMediaDevice1);
|
assertThat(mMediaDevices.get(1)).isEqualTo(mBluetoothMediaDevice1);
|
||||||
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice1);
|
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice1);
|
||||||
assertThat(mMediaDevices.get(3)).isEqualTo(mInfoMediaDevice2);
|
assertThat(mMediaDevices.get(3)).isEqualTo(mBluetoothMediaDevice2);
|
||||||
assertThat(mMediaDevices.get(4)).isEqualTo(mBluetoothMediaDevice2);
|
assertThat(mMediaDevices.get(4)).isEqualTo(mInfoMediaDevice2);
|
||||||
assertThat(mMediaDevices.get(5)).isEqualTo(mInfoMediaDevice3);
|
assertThat(mMediaDevices.get(5)).isEqualTo(mBluetoothMediaDevice3);
|
||||||
assertThat(mMediaDevices.get(6)).isEqualTo(mBluetoothMediaDevice3);
|
assertThat(mMediaDevices.get(6)).isEqualTo(mInfoMediaDevice3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.mInfoMediaDevice1: Last Selected device
|
// 1.mInfoMediaDevice1: Last Selected device
|
||||||
@@ -365,7 +376,7 @@ public class MediaDeviceTest {
|
|||||||
// 5.mBluetoothMediaDevice2: * 4 times usage not connected
|
// 5.mBluetoothMediaDevice2: * 4 times usage not connected
|
||||||
// 6.mBluetoothMediaDevice3: * 1 time usage
|
// 6.mBluetoothMediaDevice3: * 1 time usage
|
||||||
// 7.mPhoneMediaDevice: * 0 time usage
|
// 7.mPhoneMediaDevice: * 0 time usage
|
||||||
// Order: 7 -> 1 -> 3 -> 4 -> 6 -> 2 -> 5
|
// Order: 7 -> 1 -> 3 -> 6 -> 4 -> 2 -> 5
|
||||||
@Test
|
@Test
|
||||||
public void compareTo_mixedDevices_connectDeviceFirst() {
|
public void compareTo_mixedDevices_connectDeviceFirst() {
|
||||||
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
||||||
@@ -394,8 +405,8 @@ public class MediaDeviceTest {
|
|||||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||||
assertThat(mMediaDevices.get(1)).isEqualTo(mInfoMediaDevice1);
|
assertThat(mMediaDevices.get(1)).isEqualTo(mInfoMediaDevice1);
|
||||||
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice2);
|
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice2);
|
||||||
assertThat(mMediaDevices.get(3)).isEqualTo(mInfoMediaDevice3);
|
assertThat(mMediaDevices.get(3)).isEqualTo(mBluetoothMediaDevice3);
|
||||||
assertThat(mMediaDevices.get(4)).isEqualTo(mBluetoothMediaDevice3);
|
assertThat(mMediaDevices.get(4)).isEqualTo(mInfoMediaDevice3);
|
||||||
assertThat(mMediaDevices.get(5)).isEqualTo(mBluetoothMediaDevice1);
|
assertThat(mMediaDevices.get(5)).isEqualTo(mBluetoothMediaDevice1);
|
||||||
assertThat(mMediaDevices.get(6)).isEqualTo(mBluetoothMediaDevice2);
|
assertThat(mMediaDevices.get(6)).isEqualTo(mBluetoothMediaDevice2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user