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

Commit 83a70949 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Prevent ConcurrentModificationException on HandleMap

Bug: 216289682
Tag: #stability
Test: atest com.android.bluetooth.gatt.GattServiceTest
Change-Id: I275e0f7b2d4e1a4c48d38f85f99ca16e2cedc9fc
parent 9d718b1d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3444,7 +3444,7 @@ public class GattService extends ProfileService {
            return new ArrayList<>(0);
        }
        List<ParcelUuid> serviceUuids = new ArrayList<ParcelUuid>();
        for (HandleMap.Entry entry : mHandleMap.mEntries) {
        for (HandleMap.Entry entry : mHandleMap.getEntries()) {
            serviceUuids.add(new ParcelUuid(entry.uuid));
        }
        return serviceUuids;
+6 −15
Original line number Diff line number Diff line
@@ -17,12 +17,11 @@ package com.android.bluetooth.gatt;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

class HandleMap {
    private static final boolean DBG = GattServiceConfig.DBG;
@@ -88,8 +87,8 @@ class HandleMap {
    int mLastCharacteristic = 0;

    HandleMap() {
        mEntries = new ArrayList<Entry>();
        mRequestMap = new HashMap<Integer, Integer>();
        mEntries = new CopyOnWriteArrayList<Entry>();
        mRequestMap = new ConcurrentHashMap<Integer, Integer>();
    }

    void clear() {
@@ -144,16 +143,8 @@ class HandleMap {
    }

    void deleteService(int serverIf, int serviceHandle) {
        for (Iterator<Entry> it = mEntries.iterator(); it.hasNext(); ) {
            Entry entry = it.next();
            if (entry.serverIf != serverIf) {
                continue;
            }

            if (entry.handle == serviceHandle || entry.serviceHandle == serviceHandle) {
                it.remove();
            }
        }
        mEntries.removeIf(entry -> ((entry.serverIf == serverIf)
                && (entry.handle == serviceHandle || entry.serviceHandle == serviceHandle)));
    }

    List<Entry> getEntries() {