Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b309d99 authored by Shaowei Shen's avatar Shaowei Shen Committed by Android (Google) Code Review
Browse files

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

parents 489f6d9d f7e1ea04
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.MediaRoute2Info;
import android.media.MediaRoute2Info;
import android.media.MediaRouter2Manager;
import android.media.MediaRouter2Manager;


@@ -34,11 +35,13 @@ public class BluetoothMediaDevice extends MediaDevice {
    private static final String TAG = "BluetoothMediaDevice";
    private static final String TAG = "BluetoothMediaDevice";


    private CachedBluetoothDevice mCachedDevice;
    private CachedBluetoothDevice mCachedDevice;
    private final AudioManager mAudioManager;


    BluetoothMediaDevice(Context context, CachedBluetoothDevice device,
    BluetoothMediaDevice(Context context, CachedBluetoothDevice device,
            MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName) {
            MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName) {
        super(context, routerManager, info, packageName);
        super(context, routerManager, info, packageName);
        mCachedDevice = device;
        mCachedDevice = device;
        mAudioManager = context.getSystemService(AudioManager.class);
        initDeviceRecord();
        initDeviceRecord();
    }
    }


@@ -97,6 +100,12 @@ public class BluetoothMediaDevice extends MediaDevice {
                mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
                mCachedDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
    }
    }


    @Override
    public boolean isMutingExpectedDevice() {
        return mAudioManager.getMutingExpectedDevice() != null && mCachedDevice.getAddress().equals(
                mAudioManager.getMutingExpectedDevice().getAddress());
    }

    @Override
    @Override
    public boolean isConnected() {
    public boolean isConnected() {
        return mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
        return mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
+15 −0
Original line number Original line Diff line number Diff line
@@ -320,6 +320,13 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
        }
        }


        if (mType == another.mType) {
        if (mType == another.mType) {
            // Check device is muting expected device
            if (isMutingExpectedDevice()) {
                return -1;
            } else if (another.isMutingExpectedDevice()) {
                return 1;
            }

            // Check fast pair device
            // Check fast pair device
            if (isFastPairDevice()) {
            if (isFastPairDevice()) {
                return -1;
                return -1;
@@ -392,6 +399,14 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
        return false;
        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
    @Override
    public boolean equals(Object obj) {
    public boolean equals(Object obj) {
        if (!(obj instanceof MediaDevice)) {
        if (!(obj instanceof MediaDevice)) {