Home » Android » android – Phone (as peripheral role) doesn't show Pairing dialog when in JustWorks pairing mode

android – Phone (as peripheral role) doesn't show Pairing dialog when in JustWorks pairing mode

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m writing an Android application that connects to a physical device via BLE. Android app will act as peripheral role while the device is central. Device I/O Capabilities is also set to NoInputNoOutput (ble_cmd_sm_set_parameters(0, 8, sm_io_capability_noinputnooutput))

The flow to set up connection is:

  • Open Android app, then open a Bluetooth Gatt Server connection via bluetoothManager.openGattServer()
  • Add BluetoothGattService into that BluetoothGattServer (herein that service contains some characteristics with property Indicate & Notify, permission Read & Write)
  • After adding all services, then start sending advertising
  • Touch on a button on the device to let it starts scanning for peripheral.
  • When detecting the phone, the device will send a Pairing signal to phone.
  • Receiving that signal, in theory, Android device will show a Pairing dialog with 2 buttons PAIR and CANCEL to confirm that pairing (this is mode JustWorks instead of Passkey because it doesn’t require us to use a keyboard to enter key).
  • However, after testing in several Android devices, some has that dialog such as Moto Z (Android 6), Moto G (Android 6) while others don’t have such as Galaxy S7, Galaxy Tab S2 (both Android 7). I use WireShark to capture and analyst Bluetooth package of these device and realize the former has Sent Pairing Request: AuthReq with Secure Connection Flag = 1 while the latter has Secure Connection Flag = 0 (For more information about Secure Connection flag, please refer to Bluetooth Pairing Part 4)

When reading output from Android Studio logcat (in case Samsung devices), I get these log:

01-31 15:21:53.322 D/BluetoothAdapter: isSecureModeEnabled
01-31 15:21:53.322 D/BtConfig.SecureMode: isSecureModeOn:false
01-31 15:21:53.325 D/BluetoothAdapter: STATE_ON
01-31 15:21:53.325 D/BluetoothLeAdvertiser: start advertising

Not sure if SecureMode same as SecureConnection that we’re mentioning.

As my understanding, that pairing is BLE Secure Connections, with JustWorks mode. But it seems not all Android devices support it (Could you please confirm my thought?). Or, how can we force latter devices to have Pairing dialog too?

One important thing is, I have an iOS app with the same connection flow and the same physical device, and it does show the Pairing dialog.

How to&Answers: