Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ static jmethodID method_switchCodecCallback; static jmethodID method_acquireWakeLock; static jmethodID method_releaseWakeLock; static jmethodID method_energyInfo; static jmethodID method_keyMissingCallback; static struct { jclass clazz; Loading Loading @@ -752,6 +753,29 @@ static void le_rand_callback(uint64_t /* random */) { // Android doesn't support the LeRand API. } static void key_missing_callback(RawAddress bd_addr) { std::shared_lock<std::shared_timed_mutex> lock(jniObjMutex); if (!sJniCallbacksObj) { ALOGE("%s, JNI obj is null. Failed to call JNI callback", __func__); return; } CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; ScopedLocalRef<jbyteArray> addr( sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress))); if (!addr.get()) { ALOGE("Address allocation failed in %s", __func__); return; } sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr); sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_keyMissingCallback, addr.get()); } static void callback_thread_event(bt_cb_thread_evt event) { if (event == ASSOCIATE_JVM) { JavaVMAttachArgs args; Loading Loading @@ -838,7 +862,8 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks), generate_local_oob_data_callback, switch_buffer_size_callback, switch_codec_callback, le_rand_callback}; le_rand_callback, key_missing_callback}; class JNIThreadAttacher { public: Loading Loading @@ -2207,6 +2232,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) { {"releaseWakeLock", "(Ljava/lang/String;)Z", &method_releaseWakeLock}, {"energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V", &method_energyInfo}, {"keyMissingCallback", "([B)V", &method_keyMissingCallback}, }; GET_JAVA_METHODS(env, "com/android/bluetooth/btservice/JniCallbacks", javaMethods); Loading android/app/src/com/android/bluetooth/btservice/JniCallbacks.java +4 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ class JniCallbacks { transportLinkType, hciReason, handle); } void keyMissingCallback(byte[] address) { mRemoteDevices.keyMissingCallback(address); } void stateChangeCallback(int status) { mAdapterService.stateChangeCallback(status); } Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +31 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.bluetooth.btservice; import static android.Manifest.permission.BLUETOOTH_CONNECT; import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.Manifest.permission.BLUETOOTH_SCAN; import android.annotation.RequiresPermission; Loading Loading @@ -46,6 +47,7 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.bas.BatteryService; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetHalConstants; import com.android.internal.annotations.VisibleForTesting; Loading @@ -68,6 +70,7 @@ public class RemoteDevices { private BluetoothAdapter mAdapter; private AdapterService mAdapterService; private FeatureFlagsImpl mFeatureFlags; private ArrayList<BluetoothDevice> mSdpTracker; private final Object mObject = new Object(); Loading Loading @@ -152,6 +155,7 @@ public class RemoteDevices { RemoteDevices(AdapterService service, Looper looper) { mAdapter = ((Context) service).getSystemService(BluetoothManager.class).getAdapter(); mAdapterService = service; mFeatureFlags = new FeatureFlagsImpl(); mSdpTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<String, DeviceProperties>(); mDualDevicesMap = new HashMap<String, String>(); Loading Loading @@ -1238,6 +1242,33 @@ public class RemoteDevices { } } void keyMissingCallback(byte[] address) { BluetoothDevice bluetoothDevice = getDevice(address); if (bluetoothDevice == null) { errorLog( "keyMissingCallback: device is NULL, address=" + Utils.getRedactedAddressStringFromByte(address)); return; } Log.d(TAG, "keyMissingCallback device: " + bluetoothDevice); if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) { if (!mFeatureFlags.keyMissingBroadcast()) { Log.d(TAG, "flag not set - don't send key missing broadcast"); return; } Intent intent = new Intent(BluetoothDevice.ACTION_KEY_MISSING) .putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice) .addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mAdapterService.sendBroadcastMultiplePermissions( intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}, Utils.getTempBroadcastOptions()); } } void fetchUuids(BluetoothDevice device, int transport) { if (mSdpTracker.contains(device)) { Loading system/bta/dm/bta_dm_sec.cc +8 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,14 @@ void bta_dm_sec_enable(tBTA_DM_SEC_CBACK* p_sec_cback) { btm_local_io_caps = btif_storage_get_local_io_caps(); } void bta_dm_remote_key_missing(RawAddress bd_addr) { if (bta_dm_sec_cb.p_sec_cback) { tBTA_DM_SEC sec_event; sec_event.key_missing.bd_addr = bd_addr; bta_dm_sec_cb.p_sec_cback(BTA_DM_KEY_MISSING_EVT, &sec_event); } } /******************************************************************************* * * Function bta_dm_add_device Loading system/bta/include/bta_api_data_types.h +3 −0 Original line number Diff line number Diff line Loading @@ -58,3 +58,6 @@ typedef struct { RawAddress id_addr; } tBTA_DM_PROC_ID_ADDR; typedef struct { RawAddress bd_addr; } tBTA_DM_KEY_MISSING; Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ static jmethodID method_switchCodecCallback; static jmethodID method_acquireWakeLock; static jmethodID method_releaseWakeLock; static jmethodID method_energyInfo; static jmethodID method_keyMissingCallback; static struct { jclass clazz; Loading Loading @@ -752,6 +753,29 @@ static void le_rand_callback(uint64_t /* random */) { // Android doesn't support the LeRand API. } static void key_missing_callback(RawAddress bd_addr) { std::shared_lock<std::shared_timed_mutex> lock(jniObjMutex); if (!sJniCallbacksObj) { ALOGE("%s, JNI obj is null. Failed to call JNI callback", __func__); return; } CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; ScopedLocalRef<jbyteArray> addr( sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress))); if (!addr.get()) { ALOGE("Address allocation failed in %s", __func__); return; } sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr); sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_keyMissingCallback, addr.get()); } static void callback_thread_event(bt_cb_thread_evt event) { if (event == ASSOCIATE_JVM) { JavaVMAttachArgs args; Loading Loading @@ -838,7 +862,8 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks), generate_local_oob_data_callback, switch_buffer_size_callback, switch_codec_callback, le_rand_callback}; le_rand_callback, key_missing_callback}; class JNIThreadAttacher { public: Loading Loading @@ -2207,6 +2232,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) { {"releaseWakeLock", "(Ljava/lang/String;)Z", &method_releaseWakeLock}, {"energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V", &method_energyInfo}, {"keyMissingCallback", "([B)V", &method_keyMissingCallback}, }; GET_JAVA_METHODS(env, "com/android/bluetooth/btservice/JniCallbacks", javaMethods); Loading
android/app/src/com/android/bluetooth/btservice/JniCallbacks.java +4 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ class JniCallbacks { transportLinkType, hciReason, handle); } void keyMissingCallback(byte[] address) { mRemoteDevices.keyMissingCallback(address); } void stateChangeCallback(int status) { mAdapterService.stateChangeCallback(status); } Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +31 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.bluetooth.btservice; import static android.Manifest.permission.BLUETOOTH_CONNECT; import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.Manifest.permission.BLUETOOTH_SCAN; import android.annotation.RequiresPermission; Loading Loading @@ -46,6 +47,7 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.bas.BatteryService; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetHalConstants; import com.android.internal.annotations.VisibleForTesting; Loading @@ -68,6 +70,7 @@ public class RemoteDevices { private BluetoothAdapter mAdapter; private AdapterService mAdapterService; private FeatureFlagsImpl mFeatureFlags; private ArrayList<BluetoothDevice> mSdpTracker; private final Object mObject = new Object(); Loading Loading @@ -152,6 +155,7 @@ public class RemoteDevices { RemoteDevices(AdapterService service, Looper looper) { mAdapter = ((Context) service).getSystemService(BluetoothManager.class).getAdapter(); mAdapterService = service; mFeatureFlags = new FeatureFlagsImpl(); mSdpTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<String, DeviceProperties>(); mDualDevicesMap = new HashMap<String, String>(); Loading Loading @@ -1238,6 +1242,33 @@ public class RemoteDevices { } } void keyMissingCallback(byte[] address) { BluetoothDevice bluetoothDevice = getDevice(address); if (bluetoothDevice == null) { errorLog( "keyMissingCallback: device is NULL, address=" + Utils.getRedactedAddressStringFromByte(address)); return; } Log.d(TAG, "keyMissingCallback device: " + bluetoothDevice); if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) { if (!mFeatureFlags.keyMissingBroadcast()) { Log.d(TAG, "flag not set - don't send key missing broadcast"); return; } Intent intent = new Intent(BluetoothDevice.ACTION_KEY_MISSING) .putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice) .addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); mAdapterService.sendBroadcastMultiplePermissions( intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}, Utils.getTempBroadcastOptions()); } } void fetchUuids(BluetoothDevice device, int transport) { if (mSdpTracker.contains(device)) { Loading
system/bta/dm/bta_dm_sec.cc +8 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,14 @@ void bta_dm_sec_enable(tBTA_DM_SEC_CBACK* p_sec_cback) { btm_local_io_caps = btif_storage_get_local_io_caps(); } void bta_dm_remote_key_missing(RawAddress bd_addr) { if (bta_dm_sec_cb.p_sec_cback) { tBTA_DM_SEC sec_event; sec_event.key_missing.bd_addr = bd_addr; bta_dm_sec_cb.p_sec_cback(BTA_DM_KEY_MISSING_EVT, &sec_event); } } /******************************************************************************* * * Function bta_dm_add_device Loading
system/bta/include/bta_api_data_types.h +3 −0 Original line number Diff line number Diff line Loading @@ -58,3 +58,6 @@ typedef struct { RawAddress id_addr; } tBTA_DM_PROC_ID_ADDR; typedef struct { RawAddress bd_addr; } tBTA_DM_KEY_MISSING;