[Output Switcher] Add new check for BT device and apply the ranking

Add new support for checking if BT device is MutingExpected device.
If yes, sort it as the first in the list as other Bt devices.

Bug: 190235178
Test: verified on devices
Change-Id: I6dd8190ec2bbca1a069e8106f6eb1b3566791309
This commit is contained in:
shaoweishen
2022-02-08 13:19:33 +00:00
parent e429730809
commit f7e1ea043f
2 changed files with 24 additions and 0 deletions

View File

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

View File

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