Merge "[Output Switcher] Add new check for BT device and apply the ranking"
This commit is contained in:
@@ -19,6 +19,7 @@ import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaRoute2Info;
|
||||
import android.media.MediaRouter2Manager;
|
||||
|
||||
@@ -34,11 +35,13 @@ public class BluetoothMediaDevice extends MediaDevice {
|
||||
private static final String TAG = "BluetoothMediaDevice";
|
||||
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
private final AudioManager mAudioManager;
|
||||
|
||||
BluetoothMediaDevice(Context context, CachedBluetoothDevice device,
|
||||
MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName) {
|
||||
super(context, routerManager, info, packageName);
|
||||
mCachedDevice = device;
|
||||
mAudioManager = context.getSystemService(AudioManager.class);
|
||||
initDeviceRecord();
|
||||
}
|
||||
|
||||
@@ -97,6 +100,12 @@ public class BluetoothMediaDevice extends MediaDevice {
|
||||
mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutingExpectedDevice() {
|
||||
return mAudioManager.getMutingExpectedDevice() != null && mCachedDevice.getAddress().equals(
|
||||
mAudioManager.getMutingExpectedDevice().getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
|
||||
@@ -320,6 +320,13 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
}
|
||||
|
||||
if (mType == another.mType) {
|
||||
// Check device is muting expected device
|
||||
if (isMutingExpectedDevice()) {
|
||||
return -1;
|
||||
} else if (another.isMutingExpectedDevice()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check fast pair device
|
||||
if (isFastPairDevice()) {
|
||||
return -1;
|
||||
@@ -392,6 +399,14 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is muting expected device
|
||||
* @return {@code true} if it is muting expected device, otherwise return {@code false}
|
||||
*/
|
||||
protected boolean isMutingExpectedDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof MediaDevice)) {
|
||||
|
||||
Reference in New Issue
Block a user