Loading framework/java/android/bluetooth/BluetoothAdapter.java +69 −39 Original line number Diff line number Diff line Loading @@ -893,6 +893,7 @@ public final class BluetoothAdapter { mListener = listener; } @GuardedBy("BluetoothAdapter.sProfileLock") void connect(BluetoothProfile proxy, IBinder binder) { Log.d(TAG, BluetoothProfile.getProfileName(mProfile) + " connected"); mConnected = true; Loading @@ -900,6 +901,7 @@ public final class BluetoothAdapter { mListener.onServiceConnected(mProfile, proxy); } @GuardedBy("BluetoothAdapter.sProfileLock") void disconnect(BluetoothProfile proxy) { Log.d(TAG, BluetoothProfile.getProfileName(mProfile) + " disconnected"); mConnected = false; Loading @@ -908,6 +910,9 @@ public final class BluetoothAdapter { } } private static final Object sProfileLock = new Object(); @GuardedBy("sProfileLock") private final Map<BluetoothProfile, ProfileConnection> mProfileConnections = new ConcurrentHashMap<>(); Loading Loading @@ -3651,16 +3656,25 @@ public final class BluetoothAdapter { BluetoothProfile profileProxy = constructor.apply(context, this); ProfileConnection connection = new ProfileConnection(profile, listener); mMainHandler.post( Runnable connectAction = () -> { synchronized (sProfileLock) { // Synchronize with the binder callback to prevent performing the // connection.connect // concurrently mProfileConnections.put(profileProxy, connection); IBinder binder = getProfile(profile); if (binder != null) { connection.connect(profileProxy, binder); } }); } }; if (Flags.getProfileUseLock()) { connectAction.run(); return true; } mMainHandler.post(connectAction); return true; } Loading Loading @@ -3697,6 +3711,7 @@ public final class BluetoothAdapter { return; } synchronized (sProfileLock) { ProfileConnection connection = mProfileConnections.remove(proxy); if (connection != null) { if (proxy instanceof BluetoothLeCallControl callControl) { Loading @@ -3706,6 +3721,7 @@ public final class BluetoothAdapter { connection.disconnect(proxy); } } } /** * Close the connection of the profile proxy to the Service. Loading Loading @@ -3876,8 +3892,9 @@ public final class BluetoothAdapter { @RequiresNoPermission public void onBluetoothOn() { mMainHandler.post( Runnable btOnAction = () -> { synchronized (sProfileLock) { mProfileConnections.forEach( (proxy, connection) -> { if (connection.mConnected) return; Loading @@ -3889,24 +3906,36 @@ public final class BluetoothAdapter { Log.e( TAG, "onBluetoothOn: Binder null for " + BluetoothProfile.getProfileName( connection.mProfile)); + BluetoothProfile.getProfileName(connection.mProfile)); } }); }); } }; if (Flags.getProfileUseLock()) { btOnAction.run(); return; } mMainHandler.post(btOnAction); } @RequiresNoPermission public void onBluetoothOff() { mMainHandler.post( Runnable btOffAction = () -> { synchronized (sProfileLock) { mProfileConnections.forEach( (proxy, connection) -> { if (connection.mConnected) { connection.disconnect(proxy); } }); }); } }; if (Flags.getProfileUseLock()) { btOffAction.run(); return; } mMainHandler.post(btOffAction); } }; Loading Loading @@ -4203,6 +4232,7 @@ public final class BluetoothAdapter { } /** Return a binder to a Profile service */ @GuardedBy("sProfileLock") private @Nullable IBinder getProfile(int profile) { mServiceLock.readLock().lock(); try { Loading Loading
framework/java/android/bluetooth/BluetoothAdapter.java +69 −39 Original line number Diff line number Diff line Loading @@ -893,6 +893,7 @@ public final class BluetoothAdapter { mListener = listener; } @GuardedBy("BluetoothAdapter.sProfileLock") void connect(BluetoothProfile proxy, IBinder binder) { Log.d(TAG, BluetoothProfile.getProfileName(mProfile) + " connected"); mConnected = true; Loading @@ -900,6 +901,7 @@ public final class BluetoothAdapter { mListener.onServiceConnected(mProfile, proxy); } @GuardedBy("BluetoothAdapter.sProfileLock") void disconnect(BluetoothProfile proxy) { Log.d(TAG, BluetoothProfile.getProfileName(mProfile) + " disconnected"); mConnected = false; Loading @@ -908,6 +910,9 @@ public final class BluetoothAdapter { } } private static final Object sProfileLock = new Object(); @GuardedBy("sProfileLock") private final Map<BluetoothProfile, ProfileConnection> mProfileConnections = new ConcurrentHashMap<>(); Loading Loading @@ -3651,16 +3656,25 @@ public final class BluetoothAdapter { BluetoothProfile profileProxy = constructor.apply(context, this); ProfileConnection connection = new ProfileConnection(profile, listener); mMainHandler.post( Runnable connectAction = () -> { synchronized (sProfileLock) { // Synchronize with the binder callback to prevent performing the // connection.connect // concurrently mProfileConnections.put(profileProxy, connection); IBinder binder = getProfile(profile); if (binder != null) { connection.connect(profileProxy, binder); } }); } }; if (Flags.getProfileUseLock()) { connectAction.run(); return true; } mMainHandler.post(connectAction); return true; } Loading Loading @@ -3697,6 +3711,7 @@ public final class BluetoothAdapter { return; } synchronized (sProfileLock) { ProfileConnection connection = mProfileConnections.remove(proxy); if (connection != null) { if (proxy instanceof BluetoothLeCallControl callControl) { Loading @@ -3706,6 +3721,7 @@ public final class BluetoothAdapter { connection.disconnect(proxy); } } } /** * Close the connection of the profile proxy to the Service. Loading Loading @@ -3876,8 +3892,9 @@ public final class BluetoothAdapter { @RequiresNoPermission public void onBluetoothOn() { mMainHandler.post( Runnable btOnAction = () -> { synchronized (sProfileLock) { mProfileConnections.forEach( (proxy, connection) -> { if (connection.mConnected) return; Loading @@ -3889,24 +3906,36 @@ public final class BluetoothAdapter { Log.e( TAG, "onBluetoothOn: Binder null for " + BluetoothProfile.getProfileName( connection.mProfile)); + BluetoothProfile.getProfileName(connection.mProfile)); } }); }); } }; if (Flags.getProfileUseLock()) { btOnAction.run(); return; } mMainHandler.post(btOnAction); } @RequiresNoPermission public void onBluetoothOff() { mMainHandler.post( Runnable btOffAction = () -> { synchronized (sProfileLock) { mProfileConnections.forEach( (proxy, connection) -> { if (connection.mConnected) { connection.disconnect(proxy); } }); }); } }; if (Flags.getProfileUseLock()) { btOffAction.run(); return; } mMainHandler.post(btOffAction); } }; Loading Loading @@ -4203,6 +4232,7 @@ public final class BluetoothAdapter { } /** Return a binder to a Profile service */ @GuardedBy("sProfileLock") private @Nullable IBinder getProfile(int profile) { mServiceLock.readLock().lock(); try { Loading