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

Commit 6d3e697d authored by Aritra Sen's avatar Aritra Sen Committed by Gerrit Code Review
Browse files

Revert "Reduce the use of locks to avoid deadlock"

This reverts commit 891d48ae.

Reason for revert:  b/299687033 

Change-Id: I81268b4de932ed55bb5573c9012b9684a1b503f8
parent 891d48ae
Loading
Loading
Loading
Loading
+42 −49
Original line number Diff line number Diff line
@@ -373,7 +373,6 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                return;
            }
            mHearingAidConnectedDevices.add(device);
        }
            // New connected device: select it as active
            if (setHearingAidActiveDevice(device)) {
                setA2dpActiveDevice(null, true);
@@ -381,6 +380,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                setLeAudioActiveDevice(null, true);
            }
        }
    }

    private void handleLeAudioConnected(BluetoothDevice device) {
        synchronized (mLock) {
@@ -669,12 +669,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    private void handleHearingAidActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
            if (DBG) {
                Log.d(
                        TAG,
                        "handleHearingAidActiveDeviceChanged: "
                                + device
                                + ", mHearingAidActiveDevices="
                                + mHearingAidActiveDevices);
                Log.d(TAG, "handleHearingAidActiveDeviceChanged: " + device
                        + ", mHearingAidActiveDevices=" + mHearingAidActiveDevices);
            }
            // Just assign locally the new value
            final HearingAidService hearingAidService = mFactory.getHearingAidService();
@@ -688,13 +684,13 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                            hearingAidService.getConnectedPeerDevices(hiSyncId));
                }
            }
        }
            if (device != null) {
                setA2dpActiveDevice(null, true);
                setHfpActiveDevice(null);
                setLeAudioActiveDevice(null, true);
            }
        }
    }

    private void handleLeAudioActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
@@ -853,29 +849,26 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac

    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    private boolean setHfpActiveDevice(BluetoothDevice device) {
        synchronized (mLock) {
            if (DBG) {
                Log.d(TAG, "setHfpActiveDevice(" + device + ")");
            }
        synchronized (mLock) {
            if (mPendingActiveDevice != null) {
                mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                mPendingActiveDevice = null;
            }
        }
            final HeadsetService headsetService = mFactory.getHeadsetService();
            if (headsetService == null) {
                return false;
            }
            BluetoothSinkAudioPolicy audioPolicy = headsetService.getHfpCallAudioPolicy(device);
        if (audioPolicy != null
                && audioPolicy.getActiveDevicePolicyAfterConnection()
            if (audioPolicy != null && audioPolicy.getActiveDevicePolicyAfterConnection()
                    == BluetoothSinkAudioPolicy.POLICY_NOT_ALLOWED) {
                return false;
            }
            if (!headsetService.setActiveDevice(device)) {
                return false;
            }
        synchronized (mLock) {
            mHfpActiveDevice = device;
        }
        return true;
@@ -930,6 +923,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
            Log.d(TAG, "setLeAudioActiveDevice(" + device + ")"
                    + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
        }
        synchronized (mLock) {
            final LeAudioService leAudioService = mFactory.getLeAudioService();
            if (leAudioService == null) {
                return false;
@@ -945,7 +939,6 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                return false;
            }

        synchronized (mLock) {
            mLeAudioActiveDevice = device;
            if (device == null) {
                mLeHearingAidActiveDevice = null;
+1 −1
Original line number Diff line number Diff line
@@ -1339,12 +1339,12 @@ public class HeadsetService extends ProfileService {
     * Remove the active device
     */
    private void removeActiveDevice() {
        BluetoothDevice fallbackDevice = mActiveDeviceManager.getHfpFallbackDevice();
        synchronized (mStateMachines) {
            // As per b/202602952, if we remove the active device due to a disconnection,
            // we need to check if another device is connected and set it active instead.
            // Calling this before any other active related calls has the same effect as
            // a classic active device switch.
            BluetoothDevice fallbackDevice = mActiveDeviceManager.getHfpFallbackDevice();
            if (fallbackDevice != null && mActiveDevice != null
                    && getConnectionState(mActiveDevice) != BluetoothProfile.STATE_CONNECTED) {
                setActiveDevice(fallbackDevice);