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

Commit c7a37521 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Fix locking for BluetoothDeviceManager

am: c46c161f

Change-Id: Ie535f8a980f035b3f281c0c3b2baf4c90ceef904
parents e6e6336d c46c161f
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -30,7 +30,9 @@ import com.android.server.telecom.BluetoothAdapterProxy;
import com.android.server.telecom.BluetoothHeadsetProxy;
import com.android.server.telecom.BluetoothHeadsetProxy;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.TelecomSystem;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
@@ -103,11 +105,16 @@ public class BluetoothDeviceManager {
    }
    }


    public int getNumConnectedDevices() {
    public int getNumConnectedDevices() {
        synchronized (mLock) {
            return mConnectedDevicesByAddress.size();
            return mConnectedDevicesByAddress.size();
        }
        }
    }


    public Collection<BluetoothDevice> getConnectedDevices() {
    public Collection<BluetoothDevice> getConnectedDevices() {
        return mConnectedDevicesByAddress.values();
        synchronized (mLock) {
            return Collections.unmodifiableCollection(
                    new ArrayList<>(mConnectedDevicesByAddress.values()));
        }
    }
    }


    public String getMostRecentlyConnectedDevice(String excludeAddress) {
    public String getMostRecentlyConnectedDevice(String excludeAddress) {
@@ -131,8 +138,10 @@ public class BluetoothDeviceManager {
    }
    }


    public BluetoothDevice getDeviceFromAddress(String address) {
    public BluetoothDevice getDeviceFromAddress(String address) {
        synchronized (mLock) {
            return mConnectedDevicesByAddress.get(address);
            return mConnectedDevicesByAddress.get(address);
        }
        }
    }


    void onDeviceConnected(BluetoothDevice device) {
    void onDeviceConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
+1 −4
Original line number Original line Diff line number Diff line
@@ -33,9 +33,7 @@ import com.android.server.telecom.BluetoothHeadsetProxy;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;
import com.android.server.telecom.Timeouts;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedHashSet;
@@ -572,8 +570,7 @@ public class BluetoothRouteManager extends StateMachine {
    }
    }


    public Collection<BluetoothDevice> getConnectedDevices() {
    public Collection<BluetoothDevice> getConnectedDevices() {
        return Collections.unmodifiableCollection(
        return mDeviceManager.getConnectedDevices();
                new ArrayList<>(mDeviceManager.getConnectedDevices()));
    }
    }


    private String connectHfpAudio(String address) {
    private String connectHfpAudio(String address) {