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

寵の児 提交于 2019-12-03 09:53:33

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23674668/android-bluetooth-low-energy-characteristic-getpermissions-returns-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!