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

Commit 12129525 authored by hughchen's avatar hughchen
Browse files

Fix ConcurrentModificationException on LocalBluetoothProfileManager

This CL use CopyOnWriteArrayList to avoid
ConcurrentModificationException.

Bug: 148176840
Test: manually
Change-Id: If6107892bbdebf2bb10f8add63e96ccbae3b4cd5
parent 32d078ac
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;


/**
@@ -232,7 +233,7 @@ public class LocalBluetoothProfileManager {
    }

    private final Collection<ServiceListener> mServiceListeners =
            new ArrayList<ServiceListener>();
            new CopyOnWriteArrayList<ServiceListener>();

    private void addProfile(LocalBluetoothProfile profile,
            String profileName, String stateChangedAction) {
@@ -361,14 +362,18 @@ public class LocalBluetoothProfileManager {

    // not synchronized: use only from UI thread! (TODO: verify)
    void callServiceConnectedListeners() {
        for (ServiceListener l : mServiceListeners) {
        final Collection<ServiceListener> listeners = new ArrayList<>(mServiceListeners);

        for (ServiceListener l : listeners) {
            l.onServiceConnected();
        }
    }

    // not synchronized: use only from UI thread! (TODO: verify)
    void callServiceDisconnectedListeners() {
        for (ServiceListener listener : mServiceListeners) {
        final Collection<ServiceListener> listeners = new ArrayList<>(mServiceListeners);

        for (ServiceListener listener : listeners) {
            listener.onServiceDisconnected();
        }
    }