简体   繁体   English

Android蓝牙低功耗:characteristic.getPermissions()返回0?

[英]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. 我正在编写一个Android BLE应用程序,我正在尝试获得某个特性的权限。 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). 我已经设法使用characteristic.getProperties()获取特性属性,并返回非零值,但是,当我使用getPermission()方法时,它返回0,即使我确定该特性具有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? 有没有特定的方法来获得特性的权限或这是Android api的问题?

I am using API 19 and testing my program on a Samsung Galaxy Note 3. 我正在使用API​​ 19并在Samsung Galaxy Note 3上测试我的程序。

I appreciate any help. 我感谢任何帮助。

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 . 您可以看到创建新的BluetoothGattCharacteristic时,权限参数始终传递为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. 相反,似乎Android尝试在试错的基础上处理身份验证/权限问题。 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. 换句话说,框架总是尝试基本的读/写,如果由于验证原因而失败,它会自动再次尝试请求MITM身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM