Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -1467,6 +1467,14 @@ static jboolean cancelBondNative(JNIEnv* env, jobject /* obj */, return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; } static jboolean pairingIsBusyNative(JNIEnv* /*env*/, jobject /* obj */) { ALOGV("%s", __func__); if (!sBluetoothInterface) return JNI_FALSE; return sBluetoothInterface->pairing_is_busy(); } static int getConnectionStateNative(JNIEnv* env, jobject /* obj */, jbyteArray address) { ALOGV("%s", __func__); Loading Loading @@ -2116,6 +2124,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) { (void*)createBondOutOfBandNative}, {"removeBondNative", "([B)Z", (void*)removeBondNative}, {"cancelBondNative", "([B)Z", (void*)cancelBondNative}, {"pairingIsBusyNative", "()Z", (void*)pairingIsBusyNative}, {"generateLocalOobDataNative", "(I)V", (void*)generateLocalOobDataNative}, {"getConnectionStateNative", "([B)I", (void*)getConnectionStateNative}, {"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative}, Loading android/app/src/com/android/bluetooth/btservice/AdapterNativeInterface.java +6 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ public class AdapterNativeInterface { return cancelBondNative(address); } boolean pairingIsBusy() { return pairingIsBusyNative(); } void generateLocalOobData(int transport) { generateLocalOobDataNative(transport); } Loading Loading @@ -285,6 +289,8 @@ public class AdapterNativeInterface { private native boolean cancelBondNative(byte[] address); private native boolean pairingIsBusyNative(); private native void generateLocalOobDataNative(int transport); private native boolean sdpSearchNative(byte[] address, byte[] uuid); Loading android/app/src/com/android/bluetooth/btservice/BondStateMachine.java +42 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ import com.android.bluetooth.Utils; import com.android.bluetooth.a2dp.A2dpService; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidHostService; Loading Loading @@ -89,9 +91,14 @@ final class BondStateMachine extends StateMachine { public static final String OOBDATAP192 = "oobdatap192"; public static final String OOBDATAP256 = "oobdatap256"; public static final String DISPLAY_PASSKEY = "display_passkey"; public static final String DELAY_RETRY_COUNT = "delay_retry_count"; public static final short DELAY_MAX_RETRIES = 30; public static final int BOND_RETRY_DELAY_MS = 500; @VisibleForTesting Set<BluetoothDevice> mPendingBondedDevices = new HashSet<>(); private final FeatureFlags mFeatureFlags = new FeatureFlagsImpl(); private BondStateMachine(AdapterService service, AdapterProperties prop, RemoteDevices remoteDevices) { super("BondStateMachine:"); Loading Loading @@ -141,6 +148,41 @@ final class BondStateMachine extends StateMachine { switch (msg.what) { case CREATE_BOND: /* BOND_BONDED event is send after keys are exchanged, but BTIF layer would still use bonding control blocks until service discovery is finished. If next pairing is started while previous still makes service discovery, it would fail. Check the busy status of BTIF instead, and wait with starting the bond. */ if (mFeatureFlags.delayBondingWhenBusy() && mAdapterService.getNative().pairingIsBusy()) { short retry_no = (msg.getData() != null) ? msg.getData().getShort(DELAY_RETRY_COUNT) : 0; Log.d( TAG, "Delay CREATE_BOND because native is busy - attempt no " + retry_no); if (retry_no < DELAY_MAX_RETRIES) { retry_no++; Message new_msg = obtainMessage(); new_msg.copyFrom(msg); if (new_msg.getData() == null) { Bundle bundle = new Bundle(); new_msg.setData(bundle); } new_msg.getData().putShort(DELAY_RETRY_COUNT, retry_no); sendMessageDelayed(new_msg, BOND_RETRY_DELAY_MS); return true; } else { Log.w(TAG, "Native was busy - the bond will most likely fail!"); } } OobData p192Data = (msg.getData() != null) ? msg.getData().getParcelable(OOBDATAP192) : null; OobData p256Data = (msg.getData() != null) Loading system/btif/src/bluetooth.cc +7 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,12 @@ static int remove_bond(const RawAddress* bd_addr) { return BT_STATUS_SUCCESS; } static bool pairing_is_busy() { if (btif_dm_pairing_is_busy()) return true; return false; } static int get_connection_state(const RawAddress* bd_addr) { if (!interface_ready()) return 0; Loading Loading @@ -1146,6 +1152,7 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = { .create_bond_out_of_band = create_bond_out_of_band, .remove_bond = remove_bond, .cancel_bond = cancel_bond, .pairing_is_busy = pairing_is_busy, .get_connection_state = get_connection_state, .pin_reply = pin_reply, .ssp_reply = ssp_reply, Loading system/include/hardware/bluetooth.h +2 −0 Original line number Diff line number Diff line Loading @@ -739,6 +739,8 @@ typedef struct { /** Cancel Bond */ int (*cancel_bond)(const RawAddress* bd_addr); bool (*pairing_is_busy)(); /** * Get the connection status for a given remote device. * return value of 0 means the device is not connected, Loading Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -1467,6 +1467,14 @@ static jboolean cancelBondNative(JNIEnv* env, jobject /* obj */, return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; } static jboolean pairingIsBusyNative(JNIEnv* /*env*/, jobject /* obj */) { ALOGV("%s", __func__); if (!sBluetoothInterface) return JNI_FALSE; return sBluetoothInterface->pairing_is_busy(); } static int getConnectionStateNative(JNIEnv* env, jobject /* obj */, jbyteArray address) { ALOGV("%s", __func__); Loading Loading @@ -2116,6 +2124,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) { (void*)createBondOutOfBandNative}, {"removeBondNative", "([B)Z", (void*)removeBondNative}, {"cancelBondNative", "([B)Z", (void*)cancelBondNative}, {"pairingIsBusyNative", "()Z", (void*)pairingIsBusyNative}, {"generateLocalOobDataNative", "(I)V", (void*)generateLocalOobDataNative}, {"getConnectionStateNative", "([B)I", (void*)getConnectionStateNative}, {"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative}, Loading
android/app/src/com/android/bluetooth/btservice/AdapterNativeInterface.java +6 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,10 @@ public class AdapterNativeInterface { return cancelBondNative(address); } boolean pairingIsBusy() { return pairingIsBusyNative(); } void generateLocalOobData(int transport) { generateLocalOobDataNative(transport); } Loading Loading @@ -285,6 +289,8 @@ public class AdapterNativeInterface { private native boolean cancelBondNative(byte[] address); private native boolean pairingIsBusyNative(); private native void generateLocalOobDataNative(int transport); private native boolean sdpSearchNative(byte[] address, byte[] uuid); Loading
android/app/src/com/android/bluetooth/btservice/BondStateMachine.java +42 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ import com.android.bluetooth.Utils; import com.android.bluetooth.a2dp.A2dpService; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidHostService; Loading Loading @@ -89,9 +91,14 @@ final class BondStateMachine extends StateMachine { public static final String OOBDATAP192 = "oobdatap192"; public static final String OOBDATAP256 = "oobdatap256"; public static final String DISPLAY_PASSKEY = "display_passkey"; public static final String DELAY_RETRY_COUNT = "delay_retry_count"; public static final short DELAY_MAX_RETRIES = 30; public static final int BOND_RETRY_DELAY_MS = 500; @VisibleForTesting Set<BluetoothDevice> mPendingBondedDevices = new HashSet<>(); private final FeatureFlags mFeatureFlags = new FeatureFlagsImpl(); private BondStateMachine(AdapterService service, AdapterProperties prop, RemoteDevices remoteDevices) { super("BondStateMachine:"); Loading Loading @@ -141,6 +148,41 @@ final class BondStateMachine extends StateMachine { switch (msg.what) { case CREATE_BOND: /* BOND_BONDED event is send after keys are exchanged, but BTIF layer would still use bonding control blocks until service discovery is finished. If next pairing is started while previous still makes service discovery, it would fail. Check the busy status of BTIF instead, and wait with starting the bond. */ if (mFeatureFlags.delayBondingWhenBusy() && mAdapterService.getNative().pairingIsBusy()) { short retry_no = (msg.getData() != null) ? msg.getData().getShort(DELAY_RETRY_COUNT) : 0; Log.d( TAG, "Delay CREATE_BOND because native is busy - attempt no " + retry_no); if (retry_no < DELAY_MAX_RETRIES) { retry_no++; Message new_msg = obtainMessage(); new_msg.copyFrom(msg); if (new_msg.getData() == null) { Bundle bundle = new Bundle(); new_msg.setData(bundle); } new_msg.getData().putShort(DELAY_RETRY_COUNT, retry_no); sendMessageDelayed(new_msg, BOND_RETRY_DELAY_MS); return true; } else { Log.w(TAG, "Native was busy - the bond will most likely fail!"); } } OobData p192Data = (msg.getData() != null) ? msg.getData().getParcelable(OOBDATAP192) : null; OobData p256Data = (msg.getData() != null) Loading
system/btif/src/bluetooth.cc +7 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,12 @@ static int remove_bond(const RawAddress* bd_addr) { return BT_STATUS_SUCCESS; } static bool pairing_is_busy() { if (btif_dm_pairing_is_busy()) return true; return false; } static int get_connection_state(const RawAddress* bd_addr) { if (!interface_ready()) return 0; Loading Loading @@ -1146,6 +1152,7 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = { .create_bond_out_of_band = create_bond_out_of_band, .remove_bond = remove_bond, .cancel_bond = cancel_bond, .pairing_is_busy = pairing_is_busy, .get_connection_state = get_connection_state, .pin_reply = pin_reply, .ssp_reply = ssp_reply, Loading
system/include/hardware/bluetooth.h +2 −0 Original line number Diff line number Diff line Loading @@ -739,6 +739,8 @@ typedef struct { /** Cancel Bond */ int (*cancel_bond)(const RawAddress* bd_addr); bool (*pairing_is_busy)(); /** * Get the connection status for a given remote device. * return value of 0 means the device is not connected, Loading