jeudi 29 décembre 2016

Enable Bluetooth HCI log programatically

For some logging purposes I need to enable Bluetooth HCI log on my device. Of course this can be easily done from the Developers Settings menu, but most of my users won't be familiar with that and I would like to do it programatically. These devices won't be rooted, so I can't manually edit bt_stack.conf file.

While searching through the internet, I found a hidden API method BluetoothAdapter.configHciSnoopLog(). I don't really want to mess with SDK jars, so I wanted to use reflection in order to access this method, like this:

Method configHciSnoopLogMethod = BluetoothAdapter.class.getDeclaredMethod("configHciSnoopLog", boolean.class);
Object r = configHciSnoopLogMethod.invoke(BluetoothAdapter.getDefaultAdapter(), true);

This works well on about ~20% of devices I tested (returns true) but returns false for the rest (out of ~20 different devices). I am giving the app correct BLUETOOTH_ADMIN permission, so I don't know why it's not working. As I looked at the AOSP source code for main Settings application, this is exactly what it it doing internally (just without reflection of course). Is there something I am missing? Some permission that should be added?

Thanks for help!





Aucun commentaire:

Enregistrer un commentaire