Skip to content Skip to sidebar Skip to footer

Is Bluetooth OOB Pairing Really Supported In Android?

I am a complete newbie to the world of Android.Please forgive me if my question is too naive. I have been working on a sample application to realize Bluetooth pairing between a Lin

Solution 1:

According to this,

Android 9 introduces new restrictions on the use of non-SDK interfaces, whether directly, via reflection, or via JNI. These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI.

Since createBondOutOfBand() and removeBond() are hidden from public documentation, these methods are restricted from Android 9. Calling these methods using reflection will cause exceptions.


Solution 2:

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

Here is my code (not really different from yours @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;
    }
}

Post a Comment for "Is Bluetooth OOB Pairing Really Supported In Android?"