Merge changes I04291231,Ia224f6e3,I6daa22a7 into rvc-dev
* changes: Add null check when build MediaDevice Base on MediaDeviceType to ranking devices list Add new route type for support 3.5 mm headset and usb headset
This commit is contained in:
@@ -88,6 +88,13 @@ public class BluetoothMediaDevice extends MediaDevice {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFastPairDevice() {
|
||||
return mCachedDevice != null
|
||||
&& BluetoothUtils.getBooleanMetaData(
|
||||
mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
|
||||
@@ -17,11 +17,16 @@ 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_DOCK;
|
||||
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
||||
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_USB_ACCESSORY;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
|
||||
@@ -339,7 +344,7 @@ public class InfoMediaManager extends MediaManager {
|
||||
for (MediaRoute2Info route : mRouterManager.getAllRoutes()) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "buildAllRoutes() route : " + route.getName() + ", volume : "
|
||||
+ route.getVolume());
|
||||
+ route.getVolume() + ", type : " + route.getType());
|
||||
}
|
||||
if (route.isSystemRoute()) {
|
||||
addMediaDevice(route);
|
||||
@@ -350,13 +355,15 @@ public class InfoMediaManager extends MediaManager {
|
||||
private void buildAvailableRoutes() {
|
||||
for (MediaRoute2Info route : mRouterManager.getAvailableRoutes(mPackageName)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "buildAvailableRoutes() route : " + route.getName());
|
||||
Log.d(TAG, "buildAvailableRoutes() route : " + route.getName()
|
||||
+ ", type : " + route.getType());
|
||||
}
|
||||
addMediaDevice(route);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMediaDevice(MediaRoute2Info route) {
|
||||
@VisibleForTesting
|
||||
void addMediaDevice(MediaRoute2Info route) {
|
||||
final int deviceType = route.getType();
|
||||
MediaDevice mediaDevice = null;
|
||||
switch (deviceType) {
|
||||
@@ -374,6 +381,11 @@ public class InfoMediaManager extends MediaManager {
|
||||
}
|
||||
break;
|
||||
case TYPE_BUILTIN_SPEAKER:
|
||||
case TYPE_USB_DEVICE:
|
||||
case TYPE_USB_HEADSET:
|
||||
case TYPE_USB_ACCESSORY:
|
||||
case TYPE_DOCK:
|
||||
case TYPE_HDMI:
|
||||
case TYPE_WIRED_HEADSET:
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
mediaDevice =
|
||||
@@ -385,8 +397,10 @@ public class InfoMediaManager extends MediaManager {
|
||||
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(route.getOriginalId());
|
||||
final CachedBluetoothDevice cachedDevice =
|
||||
mBluetoothManager.getCachedDeviceManager().findDevice(device);
|
||||
mediaDevice = new BluetoothMediaDevice(mContext, cachedDevice, mRouterManager,
|
||||
route, mPackageName);
|
||||
if (cachedDevice != null) {
|
||||
mediaDevice = new BluetoothMediaDevice(mContext, cachedDevice, mRouterManager,
|
||||
route, mPackageName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Log.w(TAG, "addMediaDevice() unknown device type : " + deviceType);
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -185,7 +186,7 @@ public class LocalMediaManager implements BluetoothCallback {
|
||||
}
|
||||
|
||||
void dispatchDeviceListUpdate() {
|
||||
//TODO(b/149260820): Use new rule to rank device once device type api is ready.
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
for (DeviceCallback callback : getCallbacks()) {
|
||||
callback.onDeviceListUpdate(new ArrayList<>(mMediaDevices));
|
||||
}
|
||||
|
||||
@@ -17,11 +17,16 @@ 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_DOCK;
|
||||
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
||||
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_USB_ACCESSORY;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
@@ -102,6 +107,13 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
mType = MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE;
|
||||
break;
|
||||
case TYPE_USB_DEVICE:
|
||||
case TYPE_USB_HEADSET:
|
||||
case TYPE_USB_ACCESSORY:
|
||||
case TYPE_DOCK:
|
||||
case TYPE_HDMI:
|
||||
mType = MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE;
|
||||
break;
|
||||
case TYPE_HEARING_AID:
|
||||
case TYPE_BLUETOOTH_A2DP:
|
||||
mType = MediaDeviceType.TYPE_BLUETOOTH_DEVICE;
|
||||
@@ -266,16 +278,22 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
|
||||
/**
|
||||
* Rules:
|
||||
* 1. If there is one of the connected devices identified as a carkit, this carkit will
|
||||
* be always on the top of the device list. Rule 2 and Rule 3 can’t overrule this rule.
|
||||
* 1. If there is one of the connected devices identified as a carkit or fast pair device,
|
||||
* the fast pair device will be always on the first of the device list and carkit will be
|
||||
* second. Rule 2 and Rule 3 can’t overrule this rule.
|
||||
* 2. For devices without any usage data yet
|
||||
* WiFi device group sorted by alphabetical order + BT device group sorted by alphabetical
|
||||
* order + phone speaker
|
||||
* 3. For devices with usage record.
|
||||
* The most recent used one + device group with usage info sorted by how many times the
|
||||
* device has been used.
|
||||
* 4. Phone device always in the top and the connected Bluetooth devices, cast devices and
|
||||
* phone device will be always above on the disconnect Bluetooth devices.
|
||||
* 4. The order is followed below rule:
|
||||
* 1. USB-C audio device
|
||||
* 2. 3.5 mm audio device
|
||||
* 3. Bluetooth device
|
||||
* 4. Cast device
|
||||
* 5. Cast group device
|
||||
* 6. Phone
|
||||
*
|
||||
* So the device list will look like 5 slots ranked as below.
|
||||
* Rule 4 + Rule 1 + the most recently used device + Rule 3 + Rule 2
|
||||
@@ -295,39 +313,50 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
// Phone device always in the top.
|
||||
if (mType == MediaDeviceType.TYPE_PHONE_DEVICE) {
|
||||
return -1;
|
||||
} else if (another.mType == MediaDeviceType.TYPE_PHONE_DEVICE) {
|
||||
return 1;
|
||||
}
|
||||
// Check carkit
|
||||
if (isCarKitDevice()) {
|
||||
return -1;
|
||||
} else if (another.isCarKitDevice()) {
|
||||
return 1;
|
||||
}
|
||||
// Set last used device at the first item
|
||||
String lastSelectedDevice = ConnectionRecordManager.getInstance().getLastSelectedDevice();
|
||||
if (TextUtils.equals(lastSelectedDevice, getId())) {
|
||||
return -1;
|
||||
} else if (TextUtils.equals(lastSelectedDevice, another.getId())) {
|
||||
return 1;
|
||||
}
|
||||
// Sort by how many times the device has been used if there is usage record
|
||||
if ((mConnectedRecord != another.mConnectedRecord)
|
||||
&& (another.mConnectedRecord > 0 || mConnectedRecord > 0)) {
|
||||
return (another.mConnectedRecord - mConnectedRecord);
|
||||
}
|
||||
// Both devices have never been used
|
||||
// To devices with the same type, sort by alphabetical order
|
||||
if (mType == another.mType) {
|
||||
// Check fast pair device
|
||||
if (isFastPairDevice()) {
|
||||
return -1;
|
||||
} else if (another.isFastPairDevice()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check carkit
|
||||
if (isCarKitDevice()) {
|
||||
return -1;
|
||||
} else if (another.isCarKitDevice()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set last used device at the first item
|
||||
final String lastSelectedDevice = ConnectionRecordManager.getInstance()
|
||||
.getLastSelectedDevice();
|
||||
if (TextUtils.equals(lastSelectedDevice, getId())) {
|
||||
return -1;
|
||||
} else if (TextUtils.equals(lastSelectedDevice, another.getId())) {
|
||||
return 1;
|
||||
}
|
||||
// Sort by how many times the device has been used if there is usage record
|
||||
if ((mConnectedRecord != another.mConnectedRecord)
|
||||
&& (another.mConnectedRecord > 0 || mConnectedRecord > 0)) {
|
||||
return (another.mConnectedRecord - mConnectedRecord);
|
||||
}
|
||||
|
||||
// Both devices have never been used
|
||||
// To devices with the same type, sort by alphabetical order
|
||||
final String s1 = getName();
|
||||
final String s2 = another.getName();
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
} else {
|
||||
// Both devices have never been used, the priority is:
|
||||
// 1. USB-C audio device
|
||||
// 2. 3.5 mm audio device
|
||||
// 3. Bluetooth device
|
||||
// 4. Cast device
|
||||
// 5. Cast group device
|
||||
// 6. Phone
|
||||
return mType < another.mType ? -1 : 1;
|
||||
}
|
||||
// Both devices have never been used, the priority is Phone > Cast > Bluetooth
|
||||
return mType - another.mType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,6 +367,14 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is FastPair device
|
||||
* @return {@code true} if it is FastPair device, otherwise return {@code false}
|
||||
*/
|
||||
protected boolean isFastPairDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof MediaDevice)) {
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_DOCK;
|
||||
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_ACCESSORY;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
@@ -53,6 +58,13 @@ public class PhoneMediaDevice extends MediaDevice {
|
||||
switch (mRouteInfo.getType()) {
|
||||
case TYPE_WIRED_HEADSET:
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
name = mContext.getString(R.string.media_transfer_wired_device_name);
|
||||
break;
|
||||
case TYPE_USB_DEVICE:
|
||||
case TYPE_USB_HEADSET:
|
||||
case TYPE_USB_ACCESSORY:
|
||||
case TYPE_DOCK:
|
||||
case TYPE_HDMI:
|
||||
name = mRouteInfo.getName();
|
||||
break;
|
||||
case TYPE_BUILTIN_SPEAKER:
|
||||
@@ -78,6 +90,11 @@ public class PhoneMediaDevice extends MediaDevice {
|
||||
int getDrawableResId() {
|
||||
int resId;
|
||||
switch (mRouteInfo.getType()) {
|
||||
case TYPE_USB_DEVICE:
|
||||
case TYPE_USB_HEADSET:
|
||||
case TYPE_USB_ACCESSORY:
|
||||
case TYPE_DOCK:
|
||||
case TYPE_HDMI:
|
||||
case TYPE_WIRED_HEADSET:
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
resId = com.android.internal.R.drawable.ic_bt_headphones_a2dp;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.settingslib.media;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
@@ -69,4 +70,30 @@ public class BluetoothMediaDeviceTest {
|
||||
|
||||
assertThat(mBluetoothMediaDevice.isConnected()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFastPairDevice_isUntetheredHeadset_returnTrue() {
|
||||
final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
|
||||
when(mDevice.getDevice()).thenReturn(bluetoothDevice);
|
||||
|
||||
final String value = "True";
|
||||
final byte[] bytes = value.getBytes();
|
||||
when(bluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
||||
.thenReturn(bytes);
|
||||
|
||||
assertThat(mBluetoothMediaDevice.isFastPairDevice()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFastPairDevice_isNotUntetheredHeadset_returnFalse() {
|
||||
final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
|
||||
when(mDevice.getDevice()).thenReturn(bluetoothDevice);
|
||||
|
||||
final String value = "asjdaioshfaio";
|
||||
final byte[] bytes = value.getBytes();
|
||||
when(bluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
||||
.thenReturn(bytes);
|
||||
|
||||
assertThat(mBluetoothMediaDevice.isFastPairDevice()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,29 @@
|
||||
|
||||
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 android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_NETWORK_ERROR;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.media.MediaRoute2Info;
|
||||
import android.media.MediaRouter2Manager;
|
||||
import android.media.RoutingSessionInfo;
|
||||
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.testutils.shadow.ShadowRouter2Manager;
|
||||
|
||||
@@ -601,4 +610,60 @@ public class InfoMediaManagerTest {
|
||||
assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size());
|
||||
verify(mCallback).onConnectedDeviceChanged(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMediaDevice_verifyDeviceTypeCanCorrespondToMediaDevice() {
|
||||
final MediaRoute2Info route2Info = mock(MediaRoute2Info.class);
|
||||
final CachedBluetoothDeviceManager cachedBluetoothDeviceManager =
|
||||
mock(CachedBluetoothDeviceManager.class);
|
||||
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_REMOTE_SPEAKER);
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof InfoMediaDevice).isTrue();
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_USB_DEVICE);
|
||||
mInfoMediaManager.mMediaDevices.clear();
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue();
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_WIRED_HEADSET);
|
||||
mInfoMediaManager.mMediaDevices.clear();
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue();
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
|
||||
when(route2Info.getOriginalId()).thenReturn("00:00:00:00:00:00");
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager())
|
||||
.thenReturn(cachedBluetoothDeviceManager);
|
||||
when(cachedBluetoothDeviceManager.findDevice(any(BluetoothDevice.class)))
|
||||
.thenReturn(cachedDevice);
|
||||
mInfoMediaManager.mMediaDevices.clear();
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof BluetoothMediaDevice).isTrue();
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
|
||||
mInfoMediaManager.mMediaDevices.clear();
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMediaDevice_cachedBluetoothDeviceIsNull_shouldNotAdded() {
|
||||
final MediaRoute2Info route2Info = mock(MediaRoute2Info.class);
|
||||
final CachedBluetoothDeviceManager cachedBluetoothDeviceManager =
|
||||
mock(CachedBluetoothDeviceManager.class);
|
||||
|
||||
when(route2Info.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
|
||||
when(route2Info.getOriginalId()).thenReturn("00:00:00:00:00:00");
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager())
|
||||
.thenReturn(cachedBluetoothDeviceManager);
|
||||
when(cachedBluetoothDeviceManager.findDevice(any(BluetoothDevice.class)))
|
||||
.thenReturn(null);
|
||||
|
||||
mInfoMediaManager.mMediaDevices.clear();
|
||||
mInfoMediaManager.addMediaDevice(route2Info);
|
||||
|
||||
assertThat(mInfoMediaManager.mMediaDevices.size()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.bluetooth.BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.media.MediaRoute2Info;
|
||||
@@ -659,6 +661,7 @@ public class LocalMediaManagerTest {
|
||||
final BluetoothDevice bluetoothDevice4 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice5 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice6 = mock(BluetoothDevice.class);
|
||||
final BluetoothClass bluetoothClass = mock(BluetoothClass.class);
|
||||
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
final CachedBluetoothDeviceManager cachedManager = mock(CachedBluetoothDeviceManager.class);
|
||||
bluetoothDevices.add(bluetoothDevice);
|
||||
@@ -678,6 +681,9 @@ public class LocalMediaManagerTest {
|
||||
when(cachedManager.findDevice(bluetoothDevice6)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(cachedDevice.isConnected()).thenReturn(false);
|
||||
when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
|
||||
when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass);
|
||||
when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES);
|
||||
|
||||
when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
|
||||
|
||||
@@ -18,9 +18,11 @@ 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 android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -210,14 +212,14 @@ public class MediaDeviceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_carKit_phone_phoneFirst() {
|
||||
public void compareTo_carKit_phone_carKitFirst() {
|
||||
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
mMediaDevices.add(mPhoneMediaDevice);
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,7 +283,7 @@ public class MediaDeviceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_info_bluetooth_infoFirst() {
|
||||
public void compareTo_info_bluetooth_bluetoothFirst() {
|
||||
mMediaDevices.add(mInfoMediaDevice1);
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
|
||||
@@ -291,13 +293,45 @@ public class MediaDeviceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_bluetooth_phone_phoneFirst() {
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
public void compareTo_bluetooth_phone_bluetoothFirst() {
|
||||
mMediaDevices.add(mPhoneMediaDevice);
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_bluetooth_wiredHeadset_wiredHeadsetFirst() {
|
||||
final MediaRoute2Info phoneRouteInfo = mock(MediaRoute2Info.class);
|
||||
when(phoneRouteInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);
|
||||
|
||||
final PhoneMediaDevice phoneMediaDevice = new PhoneMediaDevice(mContext,
|
||||
mMediaRouter2Manager, phoneRouteInfo, TEST_PACKAGE_NAME);
|
||||
|
||||
mMediaDevices.add(mBluetoothMediaDevice1);
|
||||
mMediaDevices.add(phoneMediaDevice);
|
||||
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(phoneMediaDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_info_wiredHeadset_wiredHeadsetFirst() {
|
||||
final MediaRoute2Info phoneRouteInfo = mock(MediaRoute2Info.class);
|
||||
when(phoneRouteInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);
|
||||
|
||||
final PhoneMediaDevice phoneMediaDevice = new PhoneMediaDevice(mContext,
|
||||
mMediaRouter2Manager, phoneRouteInfo, TEST_PACKAGE_NAME);
|
||||
|
||||
mMediaDevices.add(mInfoMediaDevice1);
|
||||
mMediaDevices.add(phoneMediaDevice);
|
||||
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mInfoMediaDevice1);
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(phoneMediaDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -338,7 +372,7 @@ public class MediaDeviceTest {
|
||||
// 5.mBluetoothMediaDevice2: * 2 times usage
|
||||
// 6.mBluetoothMediaDevice3: * 1 time usage
|
||||
// 7.mPhoneMediaDevice: * 0 time usage
|
||||
// Order: 7 -> 2 -> 1 -> 5 -> 3 -> 6 -> 4
|
||||
// Order: 2 -> 5 -> 6 -> 1 -> 3 -> 4 -> 7
|
||||
@Test
|
||||
public void compareTo_mixedDevices_carKitFirst() {
|
||||
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
||||
@@ -360,13 +394,13 @@ public class MediaDeviceTest {
|
||||
mInfoMediaDevice1.connect();
|
||||
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||
assertThat(mMediaDevices.get(1)).isEqualTo(mBluetoothMediaDevice1);
|
||||
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice1);
|
||||
assertThat(mMediaDevices.get(3)).isEqualTo(mBluetoothMediaDevice2);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice1);
|
||||
assertThat(mMediaDevices.get(1)).isEqualTo(mBluetoothMediaDevice2);
|
||||
assertThat(mMediaDevices.get(2)).isEqualTo(mBluetoothMediaDevice3);
|
||||
assertThat(mMediaDevices.get(3)).isEqualTo(mInfoMediaDevice1);
|
||||
assertThat(mMediaDevices.get(4)).isEqualTo(mInfoMediaDevice2);
|
||||
assertThat(mMediaDevices.get(5)).isEqualTo(mBluetoothMediaDevice3);
|
||||
assertThat(mMediaDevices.get(6)).isEqualTo(mInfoMediaDevice3);
|
||||
assertThat(mMediaDevices.get(5)).isEqualTo(mInfoMediaDevice3);
|
||||
assertThat(mMediaDevices.get(6)).isEqualTo(mPhoneMediaDevice);
|
||||
}
|
||||
|
||||
// 1.mInfoMediaDevice1: Last Selected device
|
||||
@@ -376,7 +410,7 @@ public class MediaDeviceTest {
|
||||
// 5.mBluetoothMediaDevice2: * 4 times usage not connected
|
||||
// 6.mBluetoothMediaDevice3: * 1 time usage
|
||||
// 7.mPhoneMediaDevice: * 0 time usage
|
||||
// Order: 7 -> 1 -> 3 -> 6 -> 4 -> 2 -> 5
|
||||
// Order: 6 -> 1 -> 3 -> 4 -> 7 -> 2 -> 5
|
||||
@Test
|
||||
public void compareTo_mixedDevices_connectDeviceFirst() {
|
||||
when(mDevice1.getBluetoothClass()).thenReturn(mCarkitClass);
|
||||
@@ -402,11 +436,11 @@ public class MediaDeviceTest {
|
||||
mInfoMediaDevice1.connect();
|
||||
|
||||
Collections.sort(mMediaDevices, COMPARATOR);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mPhoneMediaDevice);
|
||||
assertThat(mMediaDevices.get(0)).isEqualTo(mBluetoothMediaDevice3);
|
||||
assertThat(mMediaDevices.get(1)).isEqualTo(mInfoMediaDevice1);
|
||||
assertThat(mMediaDevices.get(2)).isEqualTo(mInfoMediaDevice2);
|
||||
assertThat(mMediaDevices.get(3)).isEqualTo(mBluetoothMediaDevice3);
|
||||
assertThat(mMediaDevices.get(4)).isEqualTo(mInfoMediaDevice3);
|
||||
assertThat(mMediaDevices.get(3)).isEqualTo(mInfoMediaDevice3);
|
||||
assertThat(mMediaDevices.get(4)).isEqualTo(mPhoneMediaDevice);
|
||||
assertThat(mMediaDevices.get(5)).isEqualTo(mBluetoothMediaDevice1);
|
||||
assertThat(mMediaDevices.get(6)).isEqualTo(mBluetoothMediaDevice2);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
@@ -95,9 +96,9 @@ public class PhoneMediaDeviceTest {
|
||||
when(mInfo.getName()).thenReturn(deviceName);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getName())
|
||||
.isEqualTo(deviceName);
|
||||
.isEqualTo(mContext.getString(R.string.media_transfer_wired_device_name));
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADSET);
|
||||
when(mInfo.getType()).thenReturn(TYPE_USB_DEVICE);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getName())
|
||||
.isEqualTo(deviceName);
|
||||
|
||||
Reference in New Issue
Block a user