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

Commit 9baaf445 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Prevent concurrentModification of profilesServices"

parents 20044dc0 66ec07e6
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -302,6 +302,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    // Save a ProfileServiceConnections object for each of the bound
    // Save a ProfileServiceConnections object for each of the bound
    // bluetooth profile services
    // bluetooth profile services
    private final Map<Integer, ProfileServiceConnections> mProfileServices = new HashMap<>();
    private final Map<Integer, ProfileServiceConnections> mProfileServices = new HashMap<>();
    @GuardedBy("mProfileServices")
    private boolean mUnbindingAll = false;


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


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