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

Commit 423650b6 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Synchronize on BT routes map to avoid ConcurrentModificationException

Bug: 394613143
Change-Id: I2cc0b612967b3ec346d3791c8619c6b3c192db7b
Flag: EXEMPT bugfix
Test: Manual
parent 4c314cd6
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -248,15 +248,18 @@ public class BluetoothDeviceManager {
                .getBluetoothRoutes();
        List<Pair<AudioRoute, BluetoothDevice>> btRoutesToRemove =
                new ArrayList<>();
        // Prevent concurrent modification exception by just iterating
        //through keys instead of simultaneously removing them. Ensure that
        // we synchronize on the map while we traverse via an Iterator.
        synchronized (btRoutes) {
            for (AudioRoute route: btRoutes.keySet()) {
                if (route.getType() != PROFILE_TO_AUDIO_ROUTE_MAP.get(profile)) {
                    continue;
                }
                BluetoothDevice device = btRoutes.get(route);
            // Prevent concurrent modification exception by just iterating through keys instead of
            // simultaneously removing them.
                btRoutesToRemove.add(new Pair<>(route, device));
            }
        }

        for (Pair<AudioRoute, BluetoothDevice> routeToRemove:
                btRoutesToRemove) {