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

Commit c66c74f1 authored by David Duarte's avatar David Duarte Committed by Automerger Merge Worker
Browse files

Merge "Revert "AudioService: BT dual mode support"" into udc-dev am: deb8dc9a am: 7ae76617

parents cd76e543 7ae76617
Loading
Loading
Loading
Loading
+0 −63
Original line number Diff line number Diff line
@@ -1237,9 +1237,6 @@ public class AudioSystem
    public static final Set<Integer> DEVICE_IN_ALL_SCO_SET;
    /** @hide */
    public static final Set<Integer> DEVICE_IN_ALL_USB_SET;
    /** @hide */
    public static final Set<Integer> DEVICE_IN_ALL_BLE_SET;

    static {
        DEVICE_IN_ALL_SET = new HashSet<>();
        DEVICE_IN_ALL_SET.add(DEVICE_IN_COMMUNICATION);
@@ -1279,66 +1276,6 @@ public class AudioSystem
        DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_ACCESSORY);
        DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_DEVICE);
        DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_HEADSET);

        DEVICE_IN_ALL_BLE_SET = new HashSet<>();
        DEVICE_IN_ALL_BLE_SET.add(DEVICE_IN_BLE_HEADSET);
    }

    /** @hide */
    public static boolean isBluetoothDevice(int deviceType) {
        return isBluetoothA2dpOutDevice(deviceType)
                || isBluetoothScoDevice(deviceType)
                || isBluetoothLeDevice(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothOutDevice(int deviceType) {
        return isBluetoothA2dpOutDevice(deviceType)
                || isBluetoothScoOutDevice(deviceType)
                || isBluetoothLeOutDevice(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothInDevice(int deviceType) {
        return isBluetoothScoInDevice(deviceType)
                || isBluetoothLeInDevice(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothA2dpOutDevice(int deviceType) {
        return DEVICE_OUT_ALL_A2DP_SET.contains(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothScoOutDevice(int deviceType) {
        return DEVICE_OUT_ALL_SCO_SET.contains(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothScoInDevice(int deviceType) {
        return DEVICE_IN_ALL_SCO_SET.contains(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothScoDevice(int deviceType) {
        return isBluetoothScoOutDevice(deviceType)
                || isBluetoothScoInDevice(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothLeOutDevice(int deviceType) {
        return DEVICE_OUT_ALL_BLE_SET.contains(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothLeInDevice(int deviceType) {
        return DEVICE_IN_ALL_BLE_SET.contains(deviceType);
    }

    /** @hide */
    public static boolean isBluetoothLeDevice(int deviceType) {
        return isBluetoothLeOutDevice(deviceType)
                || isBluetoothLeInDevice(deviceType);
    }

    /** @hide */
+25 −49
Original line number Diff line number Diff line
@@ -87,14 +87,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
    private final @NonNull Context mContext;

    /** ID for Communication strategy retrieved form audio policy manager */
    /*package*/  int mCommunicationStrategyId = -1;
    private int mCommunicationStrategyId = -1;

    /** ID for Accessibility strategy retrieved form audio policy manager */
    private int mAccessibilityStrategyId = -1;


    /** Active communication device reported by audio policy manager */
    /*package*/ AudioDeviceInfo mActiveCommunicationDevice;
    private AudioDeviceInfo mActiveCommunicationDevice;
    /** Last preferred device set for communication strategy */
    private AudioDeviceAttributes mPreferredCommunicationDevice;

@@ -750,19 +750,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
            mIsLeOutput = false;
        }

        BtDeviceInfo(@NonNull BtDeviceInfo src, int state) {
            mDevice = src.mDevice;
            mState = state;
            mProfile = src.mProfile;
            mSupprNoisy = src.mSupprNoisy;
            mVolume = src.mVolume;
            mIsLeOutput = src.mIsLeOutput;
            mEventSource = src.mEventSource;
            mAudioSystemDevice = src.mAudioSystemDevice;
            mMusicDevice = src.mMusicDevice;
            mCodec = src.mCodec;
        }

        // redefine equality op so we can match messages intended for this device
        @Override
        public boolean equals(Object o) {
@@ -829,7 +816,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
     * @param info struct with the (dis)connection information
     */
    /*package*/ void queueOnBluetoothActiveDeviceChanged(@NonNull BtDeviceChangedData data) {
        if (data.mPreviousDevice != null
        if (data.mInfo.getProfile() == BluetoothProfile.A2DP && data.mPreviousDevice != null
                && data.mPreviousDevice.equals(data.mNewDevice)) {
            final String name = TextUtils.emptyIfNull(data.mNewDevice.getName());
            new MediaMetrics.Item(MediaMetrics.Name.AUDIO_DEVICE + MediaMetrics.SEPARATOR
@@ -838,8 +825,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
                    .set(MediaMetrics.Property.STATUS, data.mInfo.getProfile())
                    .record();
            synchronized (mDeviceStateLock) {
                postBluetoothDeviceConfigChange(createBtDeviceInfo(data, data.mNewDevice,
                        BluetoothProfile.STATE_CONNECTED));
                postBluetoothA2dpDeviceConfigChange(data.mNewDevice);
            }
        } else {
            synchronized (mDeviceStateLock) {
@@ -1064,8 +1050,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
                new AudioModeInfo(mode, pid, uid));
    }

    /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) {
        sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, info);
    /*package*/ void postBluetoothA2dpDeviceConfigChange(@NonNull BluetoothDevice device) {
        sendLMsgNoDelay(MSG_L_A2DP_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, device);
    }

    /*package*/ void startBluetoothScoForClient(IBinder cb, int pid, int scoAudioMode,
@@ -1322,10 +1308,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
        sendIMsgNoDelay(MSG_I_SCO_AUDIO_STATE_CHANGED, SENDMSG_QUEUE, state);
    }

    /*package*/ void postNotifyPreferredAudioProfileApplied(BluetoothDevice btDevice) {
        sendLMsgNoDelay(MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED, SENDMSG_QUEUE, btDevice);
    }

    /*package*/ static final class CommunicationDeviceInfo {
        final @NonNull IBinder mCb; // Identifies the requesting client for death handler
        final int mPid; // Requester process ID
@@ -1401,11 +1383,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
        }
    }

    /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes,
                                boolean connect, @Nullable BluetoothDevice btDevice) {
    /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes, boolean connect) {
        synchronized (mDeviceStateLock) {
            return mDeviceInventory.handleDeviceConnection(
                    attributes, connect, false /*for test*/, btDevice);
            return mDeviceInventory.handleDeviceConnection(attributes, connect, false /*for test*/);
        }
    }

@@ -1646,10 +1626,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
                                (String) msg.obj, msg.arg1);
                    }
                    break;
                case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE:
                case MSG_L_A2DP_DEVICE_CONFIG_CHANGE:
                    final BluetoothDevice btDevice = (BluetoothDevice) msg.obj;
                    synchronized (mDeviceStateLock) {
                        mDeviceInventory.onBluetoothDeviceConfigChange(
                                (BtDeviceInfo) msg.obj, BtHelper.EVENT_DEVICE_CONFIG_CHANGE);
                        final int a2dpCodec = mBtHelper.getA2dpCodec(btDevice);
                        mDeviceInventory.onBluetoothA2dpDeviceConfigChange(
                                new BtHelper.BluetoothA2dpDeviceInfo(btDevice, -1, a2dpCodec),
                                        BtHelper.EVENT_DEVICE_CONFIG_CHANGE);
                    }
                    break;
                case MSG_BROADCAST_AUDIO_BECOMING_NOISY:
@@ -1807,10 +1790,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
                    final int capturePreset = msg.arg1;
                    mDeviceInventory.onSaveClearPreferredDevicesForCapturePreset(capturePreset);
                } break;
                case MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED: {
                    final BluetoothDevice btDevice = (BluetoothDevice) msg.obj;
                    BtHelper.onNotifyPreferredAudioProfileApplied(btDevice);
                } break;
                default:
                    Log.wtf(TAG, "Invalid message " + msg.what);
            }
@@ -1846,7 +1825,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
    private static final int MSG_IL_BTA2DP_TIMEOUT = 10;

    // process change of A2DP device configuration, obj is BluetoothDevice
    private static final int MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE = 11;
    private static final int MSG_L_A2DP_DEVICE_CONFIG_CHANGE = 11;

    private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 12;
    private static final int MSG_REPORT_NEW_ROUTES = 13;
@@ -1886,15 +1865,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
    private static final int MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY = 48;
    private static final int MSG_IL_BTLEAUDIO_TIMEOUT = 49;

    private static final int MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED = 50;

    private static boolean isMessageHandledUnderWakelock(int msgId) {
        switch(msgId) {
            case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE:
            case MSG_L_SET_BT_ACTIVE_DEVICE:
            case MSG_IL_BTA2DP_TIMEOUT:
            case MSG_IL_BTLEAUDIO_TIMEOUT:
            case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE:
            case MSG_L_A2DP_DEVICE_CONFIG_CHANGE:
            case MSG_TOGGLE_HDMI:
            case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT:
            case MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT:
@@ -1986,7 +1963,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
                case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE:
                case MSG_IL_BTA2DP_TIMEOUT:
                case MSG_IL_BTLEAUDIO_TIMEOUT:
                case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE:
                case MSG_L_A2DP_DEVICE_CONFIG_CHANGE:
                    if (sLastDeviceConnectMsgTime >= time) {
                        // add a little delay to make sure messages are ordered as expected
                        time = sLastDeviceConnectMsgTime + 30;
@@ -2006,7 +1983,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
    static {
        MESSAGES_MUTE_MUSIC = new HashSet<>();
        MESSAGES_MUTE_MUSIC.add(MSG_L_SET_BT_ACTIVE_DEVICE);
        MESSAGES_MUTE_MUSIC.add(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE);
        MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONFIG_CHANGE);
        MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT);
        MESSAGES_MUTE_MUSIC.add(MSG_IIL_SET_FORCE_BT_A2DP_USE);
    }
@@ -2027,7 +2004,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
        // Do not mute on bluetooth event if music is playing on a wired headset.
        if ((message == MSG_L_SET_BT_ACTIVE_DEVICE
                || message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT
                || message == MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE)
                || message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE)
                && AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)
                && hasIntersection(mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET,
                        mAudioService.getDeviceSetForStream(AudioSystem.STREAM_MUSIC))) {
@@ -2166,19 +2143,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
        if (preferredCommunicationDevice == null) {
            AudioDeviceAttributes defaultDevice = getDefaultCommunicationDevice();
            if (defaultDevice != null) {
                mDeviceInventory.setPreferredDevicesForStrategy(
                setPreferredDevicesForStrategySync(
                        mCommunicationStrategyId, Arrays.asList(defaultDevice));
                mDeviceInventory.setPreferredDevicesForStrategy(
                setPreferredDevicesForStrategySync(
                        mAccessibilityStrategyId, Arrays.asList(defaultDevice));
            } else {
                mDeviceInventory.removePreferredDevicesForStrategy(mCommunicationStrategyId);
                mDeviceInventory.removePreferredDevicesForStrategy(mAccessibilityStrategyId);
                removePreferredDevicesForStrategySync(mCommunicationStrategyId);
                removePreferredDevicesForStrategySync(mAccessibilityStrategyId);
            }
            mDeviceInventory.applyConnectedDevicesRoles();
        } else {
            mDeviceInventory.setPreferredDevicesForStrategy(
            setPreferredDevicesForStrategySync(
                    mCommunicationStrategyId, Arrays.asList(preferredCommunicationDevice));
            mDeviceInventory.setPreferredDevicesForStrategy(
            setPreferredDevicesForStrategySync(
                    mAccessibilityStrategyId, Arrays.asList(preferredCommunicationDevice));
        }
        onUpdatePhoneStrategyDevice(preferredCommunicationDevice);