Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +12 −5 Original line number Diff line number Diff line Loading @@ -186,6 +186,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; Loading Loading @@ -257,6 +258,8 @@ public class AdapterService extends Service { mBluetoothQualityReportReadyCallbacks = new RemoteCallbackList<>(); private final RemoteCallbackList<IBluetoothCallback> mRemoteCallbacks = new RemoteCallbackList<>(); private final RemoteCallbackList<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new RemoteCallbackList<>(); private final EvictingQueue<String> mScanModeChanges = EvictingQueue.create(10); Loading @@ -283,7 +286,6 @@ public class AdapterService extends Service { private boolean mNativeAvailable; private boolean mCleaningUp; private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>(); private boolean mQuietmode = false; private Map<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>(); Loading Loading @@ -3452,7 +3454,7 @@ public class AdapterService extends Service { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.mBluetoothConnectionCallbacks.add(callback); service.mBluetoothConnectionCallbacks.register(callback); } @Override Loading @@ -3466,7 +3468,7 @@ public class AdapterService extends Service { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.mBluetoothConnectionCallbacks.remove(callback); service.mBluetoothConnectionCallbacks.unregister(callback); } @Override Loading Loading @@ -5517,8 +5519,13 @@ public class AdapterService extends Service { return mRemoteDevices.getUuids(device); } public Set<IBluetoothConnectionCallback> getBluetoothConnectionCallbacks() { return mBluetoothConnectionCallbacks; void aclStateChangeBroadcastCallback(Consumer<IBluetoothConnectionCallback> cb) { int n = mBluetoothConnectionCallbacks.beginBroadcast(); Log.d(TAG, "aclStateChangeBroadcastCallback() - Broadcasting to " + n + " receivers."); for (int i = 0; i < n; i++) { cb.accept(mBluetoothConnectionCallbacks.getBroadcastItem(i)); } mRemoteCallbacks.finishBroadcast(); } /** Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +24 −27 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; import android.os.SystemProperties; import android.util.Log; Loading Loading @@ -1174,17 +1173,19 @@ public class RemoteDevices { return; } BluetoothDevice device = getDevice(address); if (device == null) { warnLog( "aclStateChangeCallback: device is NULL, address=" + Utils.getRedactedAddressStringFromByte(address) + ", newState=" + newState); addDeviceProperties(address); device = Objects.requireNonNull(getDevice(address)); } final BluetoothDevice device = Objects.requireNonNullElseGet( getDevice(address), () -> { Log.w( TAG, "aclStateChangeCallback: device is NULL" + ("address=" + Utils.getRedactedAddressStringFromByte( address)) + (" newState=" + newState)); return addDeviceProperties(address).getDevice(); }); DeviceProperties deviceProperties = getDeviceProperties(device); Loading Loading @@ -1294,22 +1295,18 @@ public class RemoteDevices { mAdapterService.sendBroadcast( intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle()); synchronized (mAdapterService.getBluetoothConnectionCallbacks()) { Set<IBluetoothConnectionCallback> bluetoothConnectionCallbacks = mAdapterService.getBluetoothConnectionCallbacks(); for (IBluetoothConnectionCallback callback : bluetoothConnectionCallbacks) { try { Utils.RemoteExceptionIgnoringConsumer<IBluetoothConnectionCallback> connectionChangeConsumer; if (connectionState == BluetoothAdapter.STATE_CONNECTED) { callback.onDeviceConnected(device); connectionChangeConsumer = cb -> cb.onDeviceConnected(device); } else { callback.onDeviceDisconnected( connectionChangeConsumer = cb -> cb.onDeviceDisconnected( device, AdapterService.hciToAndroidDisconnectReason(hciReason)); } } catch (RemoteException ex) { Log.e(TAG, "RemoteException in calling IBluetoothConnectionCallback"); } } } mAdapterService.aclStateChangeBroadcastCallback(connectionChangeConsumer); } @NonNull Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +12 −5 Original line number Diff line number Diff line Loading @@ -186,6 +186,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; Loading Loading @@ -257,6 +258,8 @@ public class AdapterService extends Service { mBluetoothQualityReportReadyCallbacks = new RemoteCallbackList<>(); private final RemoteCallbackList<IBluetoothCallback> mRemoteCallbacks = new RemoteCallbackList<>(); private final RemoteCallbackList<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new RemoteCallbackList<>(); private final EvictingQueue<String> mScanModeChanges = EvictingQueue.create(10); Loading @@ -283,7 +286,6 @@ public class AdapterService extends Service { private boolean mNativeAvailable; private boolean mCleaningUp; private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>(); private boolean mQuietmode = false; private Map<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>(); Loading Loading @@ -3452,7 +3454,7 @@ public class AdapterService extends Service { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.mBluetoothConnectionCallbacks.add(callback); service.mBluetoothConnectionCallbacks.register(callback); } @Override Loading @@ -3466,7 +3468,7 @@ public class AdapterService extends Service { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.mBluetoothConnectionCallbacks.remove(callback); service.mBluetoothConnectionCallbacks.unregister(callback); } @Override Loading Loading @@ -5517,8 +5519,13 @@ public class AdapterService extends Service { return mRemoteDevices.getUuids(device); } public Set<IBluetoothConnectionCallback> getBluetoothConnectionCallbacks() { return mBluetoothConnectionCallbacks; void aclStateChangeBroadcastCallback(Consumer<IBluetoothConnectionCallback> cb) { int n = mBluetoothConnectionCallbacks.beginBroadcast(); Log.d(TAG, "aclStateChangeBroadcastCallback() - Broadcasting to " + n + " receivers."); for (int i = 0; i < n; i++) { cb.accept(mBluetoothConnectionCallbacks.getBroadcastItem(i)); } mRemoteCallbacks.finishBroadcast(); } /** Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +24 −27 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; import android.os.SystemProperties; import android.util.Log; Loading Loading @@ -1174,17 +1173,19 @@ public class RemoteDevices { return; } BluetoothDevice device = getDevice(address); if (device == null) { warnLog( "aclStateChangeCallback: device is NULL, address=" + Utils.getRedactedAddressStringFromByte(address) + ", newState=" + newState); addDeviceProperties(address); device = Objects.requireNonNull(getDevice(address)); } final BluetoothDevice device = Objects.requireNonNullElseGet( getDevice(address), () -> { Log.w( TAG, "aclStateChangeCallback: device is NULL" + ("address=" + Utils.getRedactedAddressStringFromByte( address)) + (" newState=" + newState)); return addDeviceProperties(address).getDevice(); }); DeviceProperties deviceProperties = getDeviceProperties(device); Loading Loading @@ -1294,22 +1295,18 @@ public class RemoteDevices { mAdapterService.sendBroadcast( intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle()); synchronized (mAdapterService.getBluetoothConnectionCallbacks()) { Set<IBluetoothConnectionCallback> bluetoothConnectionCallbacks = mAdapterService.getBluetoothConnectionCallbacks(); for (IBluetoothConnectionCallback callback : bluetoothConnectionCallbacks) { try { Utils.RemoteExceptionIgnoringConsumer<IBluetoothConnectionCallback> connectionChangeConsumer; if (connectionState == BluetoothAdapter.STATE_CONNECTED) { callback.onDeviceConnected(device); connectionChangeConsumer = cb -> cb.onDeviceConnected(device); } else { callback.onDeviceDisconnected( connectionChangeConsumer = cb -> cb.onDeviceDisconnected( device, AdapterService.hciToAndroidDisconnectReason(hciReason)); } } catch (RemoteException ex) { Log.e(TAG, "RemoteException in calling IBluetoothConnectionCallback"); } } } mAdapterService.aclStateChangeBroadcastCallback(connectionChangeConsumer); } @NonNull Loading