Is Bluetooth OOB Compatibility Really Supported in Android?

I am a complete newbie in the Android world. Please forgive me if my question is too naive.

I am working on an example application for implementing Bluetooth pairing between the Linux Box (FC-21 with Bluez-5.42) and Android tablets. I use NFC to transfer the Bluetooth name, address and OOB data from an Android PC. I can send the above data from a PC to Android via NFC (beam for sure), and I can parse and decode all the data on the Android side. With the Bluetooth address in the Linux box available on Android, I can call CreateBond () to connect the Android tablet to the Linux Box. I tested this part and it works as expected.

Now the problem with this method is that during Bluetooth pairing, digital matching or key association is used, which in my opinion is an aberration for the user when he uses NFC for pairing. Since I already have OOB data on my PC, I would like to use the OOB association for pairing so that the user interface is not compromised.

For this, when I replace CreateBond () with CreateBondOutOfBand () [using reflection], the connection request is not sent from Android to the Linux PC.

try { showLog("Pairing started"); Method m = bDev.getClass().getMethod("createBondOutOfBand", byte[].class, byte[].class); showLog("Found method"); Boolean flag = (Boolean) m.invoke(bDev, Hash, Rand,(Object[]) null); //Method m = bDev.getClass().getMethod("createBond", (Class[]) null); //Boolean flag = (Boolean) m.invoke(bDev, (Object[]) null); if(flag) showLog("Pairing successfully finished."); else showLog("Pairing failed"); } catch (Exception e) { showLog("Pairing failed."); } 

I searched the Internet, but did not find any concrete evidence that the OOB connection could be implemented in Android.

In addition, to test the behavior of my own Android, I created an NFC tag with the Bluetooth name, address and OOB data in the Linux box. When I held the tag against an Android tablet, pairing of Bluettoth was started, but it still did not use the OOB association model.

My questions are as follows:

  • Is the OOB association model supported on Android?
  • If the OOB association model is supported, is the CreateBondOutOfBand () API created to use, or is there any other API I need to use?

Any input is welcome.

Thanks,

Sai

+5
source share
1 answer

I do not use NFC, but I use reflection to use createBondOutOfBand. In addition, this code really works on Motorola lineage rom 7.1 (on Moto G4 play and Moto E 2015) and on the official Samsung 7.0 (Galaxy S6), but does not work on the official language of LG G5 or G6 7.0 (authentication does not always work).

Here is my code (not exactly different from your @ saai63).

 private boolean createBondOutOfBand(final byte[] oobKey) { try { if (DEBUG) { Log.d(LOG_TAG, "createBondOutOfBand entry"); } Class c = Class.forName("android.bluetooth.OobData"); Constructor constr = c.getConstructor(); Object oobData = constr.newInstance(); Method method = c.getMethod("setSecurityManagerTk", byte[].class); method.invoke(oobData, oobKey); Method m = mBluetoothDevice.getClass().getMethod("createBondOutOfBand", int.class, c); boolean res = (boolean)m.invoke(mBluetoothDevice, BluetoothDevice.TRANSPORT_AUTO, oobData); if (DEBUG) { Log.d(LOG_TAG, "createBondOutOfBand result => " + res); } return res; } catch (Exception e) { Log.e(LOG_TAG, "Error when calling createBondOutOfBand", e); return false; } } 
0
source

Source: https://habr.com/ru/post/1262666/


All Articles