Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkService.java +46 −25 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import java.util.concurrent.ConcurrentHashMap; public class A2dpSinkService extends ProfileService { private static final String TAG = A2dpSinkService.class.getSimpleName(); // This is also used as a lock for shared data in {@link A2dpSinkService} @GuardedBy("mDeviceStateMap") private final Map<BluetoothDevice, A2dpSinkStateMachine> mDeviceStateMap = new ConcurrentHashMap<>(1); Loading Loading @@ -116,10 +118,12 @@ public class A2dpSinkService extends ProfileService { public void stop() { setA2dpSinkService(null); mNativeInterface.cleanup(); synchronized (mDeviceStateMap) { for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) { stateMachine.quitNow(); } mDeviceStateMap.clear(); } synchronized (mStreamHandlerLock) { if (mA2dpSinkStreamHandler != null) { mA2dpSinkStreamHandler.cleanup(); Loading Loading @@ -362,7 +366,10 @@ public class A2dpSinkService extends ProfileService { throw new IllegalArgumentException("Null device"); } A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } // a state machine instance doesn't exist. maybe it is already gone? if (stateMachine == null) { return false; Loading @@ -389,7 +396,9 @@ public class A2dpSinkService extends ProfileService { if (stateMachine == null) { return; } synchronized (mDeviceStateMap) { mDeviceStateMap.remove(stateMachine.getDevice()); } stateMachine.quitNow(); } Loading @@ -400,6 +409,7 @@ public class A2dpSinkService extends ProfileService { protected A2dpSinkStateMachine getOrCreateStateMachine(BluetoothDevice device) { A2dpSinkStateMachine newStateMachine = new A2dpSinkStateMachine(mLooper, device, this, mNativeInterface); synchronized (mDeviceStateMap) { A2dpSinkStateMachine existingStateMachine = mDeviceStateMap.putIfAbsent(device, newStateMachine); // Given null is not a valid value in our map, ConcurrentHashMap will return null if the Loading @@ -411,11 +421,14 @@ public class A2dpSinkService extends ProfileService { } return existingStateMachine; } } @VisibleForTesting protected A2dpSinkStateMachine getStateMachineForDevice(BluetoothDevice device) { synchronized (mDeviceStateMap) { return mDeviceStateMap.get(device); } } List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Log.d(TAG, "getDevicesMatchingConnectionStates(states=" + Arrays.toString(states) + ")"); Loading Loading @@ -451,7 +464,10 @@ public class A2dpSinkService extends ProfileService { */ public int getConnectionState(BluetoothDevice device) { if (device == null) return BluetoothProfile.STATE_DISCONNECTED; A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } return (stateMachine == null) ? BluetoothProfile.STATE_DISCONNECTED : stateMachine.getState(); Loading Loading @@ -501,6 +517,7 @@ public class A2dpSinkService extends ProfileService { super.dump(sb); ProfileService.println(sb, "Active Device = " + getActiveDevice()); ProfileService.println(sb, "Max Connected Devices = " + mMaxConnectedAudioDevices); synchronized (mDeviceStateMap) { ProfileService.println(sb, "Devices Tracked = " + mDeviceStateMap.size()); for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) { ProfileService.println( Loading @@ -508,10 +525,14 @@ public class A2dpSinkService extends ProfileService { stateMachine.dump(sb); } } } BluetoothAudioConfig getAudioConfig(BluetoothDevice device) { if (device == null) return null; A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } // a state machine instance doesn't exist. maybe it is already gone? if (stateMachine == null) { return null; Loading Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkService.java +46 −25 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import java.util.concurrent.ConcurrentHashMap; public class A2dpSinkService extends ProfileService { private static final String TAG = A2dpSinkService.class.getSimpleName(); // This is also used as a lock for shared data in {@link A2dpSinkService} @GuardedBy("mDeviceStateMap") private final Map<BluetoothDevice, A2dpSinkStateMachine> mDeviceStateMap = new ConcurrentHashMap<>(1); Loading Loading @@ -116,10 +118,12 @@ public class A2dpSinkService extends ProfileService { public void stop() { setA2dpSinkService(null); mNativeInterface.cleanup(); synchronized (mDeviceStateMap) { for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) { stateMachine.quitNow(); } mDeviceStateMap.clear(); } synchronized (mStreamHandlerLock) { if (mA2dpSinkStreamHandler != null) { mA2dpSinkStreamHandler.cleanup(); Loading Loading @@ -362,7 +366,10 @@ public class A2dpSinkService extends ProfileService { throw new IllegalArgumentException("Null device"); } A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } // a state machine instance doesn't exist. maybe it is already gone? if (stateMachine == null) { return false; Loading @@ -389,7 +396,9 @@ public class A2dpSinkService extends ProfileService { if (stateMachine == null) { return; } synchronized (mDeviceStateMap) { mDeviceStateMap.remove(stateMachine.getDevice()); } stateMachine.quitNow(); } Loading @@ -400,6 +409,7 @@ public class A2dpSinkService extends ProfileService { protected A2dpSinkStateMachine getOrCreateStateMachine(BluetoothDevice device) { A2dpSinkStateMachine newStateMachine = new A2dpSinkStateMachine(mLooper, device, this, mNativeInterface); synchronized (mDeviceStateMap) { A2dpSinkStateMachine existingStateMachine = mDeviceStateMap.putIfAbsent(device, newStateMachine); // Given null is not a valid value in our map, ConcurrentHashMap will return null if the Loading @@ -411,11 +421,14 @@ public class A2dpSinkService extends ProfileService { } return existingStateMachine; } } @VisibleForTesting protected A2dpSinkStateMachine getStateMachineForDevice(BluetoothDevice device) { synchronized (mDeviceStateMap) { return mDeviceStateMap.get(device); } } List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Log.d(TAG, "getDevicesMatchingConnectionStates(states=" + Arrays.toString(states) + ")"); Loading Loading @@ -451,7 +464,10 @@ public class A2dpSinkService extends ProfileService { */ public int getConnectionState(BluetoothDevice device) { if (device == null) return BluetoothProfile.STATE_DISCONNECTED; A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } return (stateMachine == null) ? BluetoothProfile.STATE_DISCONNECTED : stateMachine.getState(); Loading Loading @@ -501,6 +517,7 @@ public class A2dpSinkService extends ProfileService { super.dump(sb); ProfileService.println(sb, "Active Device = " + getActiveDevice()); ProfileService.println(sb, "Max Connected Devices = " + mMaxConnectedAudioDevices); synchronized (mDeviceStateMap) { ProfileService.println(sb, "Devices Tracked = " + mDeviceStateMap.size()); for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) { ProfileService.println( Loading @@ -508,10 +525,14 @@ public class A2dpSinkService extends ProfileService { stateMachine.dump(sb); } } } BluetoothAudioConfig getAudioConfig(BluetoothDevice device) { if (device == null) return null; A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device); A2dpSinkStateMachine stateMachine; synchronized (mDeviceStateMap) { stateMachine = mDeviceStateMap.get(device); } // a state machine instance doesn't exist. maybe it is already gone? if (stateMachine == null) { return null; Loading