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

Commit 80564fe2 authored by Zhou Song's avatar Zhou Song Committed by Bruno Martins
Browse files

Check for a2dp profile when removing stale connection events

During disconnecting both a2dp output and input device, same
device is passed to handler but with different profile, to
avoid removing existing event in the handler, check the a2dp
profile as well.

CRs-Fixed: 2943846
Change-Id: I9d0eced33d57c46d6e49a74e958c488f3a07249c
parent 6c19a2e5
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -538,7 +538,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
                return true;
            }
            if (o instanceof BtDeviceConnectionInfo) {
                return mDevice.equals(((BtDeviceConnectionInfo) o).mDevice);
                return mDevice.equals(((BtDeviceConnectionInfo) o).mDevice) &&
                       mProfile == (((BtDeviceConnectionInfo) o).mProfile);
            }
            return false;
        }
@@ -571,7 +572,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
            // when receiving a request to change the connection state of a device, this last
            // request is the source of truth, so cancel all previous requests that are already in
            // the handler
            removeScheduledA2dpEvents(info.mDevice);
            removeScheduledA2dpEvents(info.mDevice, info.mProfile);

            sendLMsgNoDelay(
                    info.mState == BluetoothProfile.STATE_CONNECTED
@@ -583,14 +584,14 @@ import java.util.concurrent.atomic.AtomicBoolean;

    /** remove all previously scheduled connection and state change events for the given device */
    @GuardedBy("mDeviceStateLock")
    private void removeScheduledA2dpEvents(@NonNull BluetoothDevice device) {
    private void removeScheduledA2dpEvents(@NonNull BluetoothDevice device, int profile) {
        mBrokerHandler.removeEqualMessages(MSG_L_A2DP_DEVICE_CONFIG_CHANGE, device);

        final BtDeviceConnectionInfo connectionInfoToRemove = new BtDeviceConnectionInfo(device,
                // the next parameters of the constructor will be ignored when finding the message
                // to remove as the equality of the message's object is tested on the device itself
                // (see BtDeviceConnectionInfo.equals() method override)
                BluetoothProfile.STATE_CONNECTED, 0, false, -1);
                BluetoothProfile.STATE_CONNECTED, profile, false, -1);
        mBrokerHandler.removeEqualMessages(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_DISCONNECTION,
                connectionInfoToRemove);
        mBrokerHandler.removeEqualMessages(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_CONNECTION,