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

Commit 122f9da1 authored by William Escande's avatar William Escande Committed by Cherrypicker Worker
Browse files

Prevent concurrentModification of profilesServices

Since BluetoothProfileConnector is used for all profiles, the
BluetoothManagerService is calling the serviceDisconnected of the
BluetoothProfileConnector, that will call it's unbind, that will be
performed back in the BluetoothManagerService...
We are using an async but it does not prevent against re-entrant call

Fix: 263757880
Test: manual test of turn on off the bluetooth
Change-Id: I673244b2110b09135d82d2985a33c6f4c3739d03
(cherry picked from commit 66ec07e6)
Merged-In: I673244b2110b09135d82d2985a33c6f4c3739d03
parent 463ea77b
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -302,6 +302,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    // Save a ProfileServiceConnections object for each of the bound
    // bluetooth profile services
    private final Map<Integer, ProfileServiceConnections> mProfileServices = new HashMap<>();
    @GuardedBy("mProfileServices")
    private boolean mUnbindingAll = false;

    private final IBluetoothCallback mBluetoothCallback = new IBluetoothCallback.Stub() {
        @Override
@@ -1598,13 +1600,16 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Unable to unbind service with intent: " + psc.mIntent, e);
                }
                if (!mUnbindingAll) {
                    mProfileServices.remove(profile);
                }
            }
        }
    }

    private void unbindAllBluetoothProfileServices() {
        synchronized (mProfileServices) {
            mUnbindingAll = true;
            for (Integer i : mProfileServices.keySet()) {
                ProfileServiceConnections psc = mProfileServices.get(i);
                try {
@@ -1614,6 +1619,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                }
                psc.removeAllProxies();
            }
            mUnbindingAll = false;
            mProfileServices.clear();
        }
    }