Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bluetooth Low Energy: characteristic.getPermissions() returns 0?

I am writing an Android BLE application, and I am trying to get the permissions of a certain characteristic. I have already managed to get the characteristic properties with characteristic.getProperties(), and it returns a non-zero value, however, when I use the getPermission() method it returns 0 even though I am sure that the characteristic has PERMISSION_WRITE_ENCRYPTED_MITM (0x00000040).

Here is a code snippet

    // properties
    int properties = ch.getProperties();
    DebugWrapper.infoMsg("properties: " + properties, TAG); //returns non-zero value

    // permissions      
    int permissions = ch.getPermissions();  
    DebugWrapper.infoMsg("permissions: " + permissions, TAG); //returns zero value

Am I doing something wrong? Is there a specific way to get the permissions of the characteristic or is this a problem with the android api?

I am using API 19 and testing my program on a Samsung Galaxy Note 3.

I appreciate any help.

like image 283
KikiTheMonk Avatar asked May 15 '14 09:05

KikiTheMonk


1 Answers

This looks like an issue with the underlying framework. This link shows the block of code that the framework executes when discovering services/characteristics on the remote device. You can see when the new BluetoothGattCharacteristic is created, the permissions parameter is always passed in as 0.

Additionally, even when the characteristic is later read, only the characteristic's value is updated, no other parameters are reset on the object.

Instead, it seems Android attempts to handle authentication/permission issues on a trial and error basis. In other words, the framework always attempts a basic read/write, and if it fails for authentication reasons, it automatically tries again with MITM authentication requested.

like image 195
devunwired Avatar answered Oct 07 '22 07:10

devunwired