List of usage examples for android.bluetooth BluetoothGattDescriptor getPermissions
public int getPermissions()
From source file:Main.java
public static JSONArray decodePermissions(BluetoothGattDescriptor descriptor) { // NOTE: props strings need to be consistent across iOS and Android JSONArray props = new JSONArray(); int permissions = descriptor.getPermissions(); if ((permissions & BluetoothGattDescriptor.PERMISSION_READ) != 0x0) { props.put("Read"); }/*from w w w . ja v a 2s . co m*/ if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE) != 0x0) { props.put("Write"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED) != 0x0) { props.put("ReadEncrypted"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED) != 0x0) { props.put("WriteEncrypted"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM) != 0x0) { props.put("ReadEncryptedMITM"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM) != 0x0) { props.put("WriteEncryptedMITM"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED) != 0x0) { props.put("WriteSigned"); } if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM) != 0x0) { props.put("WriteSignedMITM"); } return props; }
From source file:com.megster.cordova.ble.central.Peripheral.java
public JSONObject asJSONObject(BluetoothGatt gatt) { JSONObject json = asJSONObject();/* ww w. jav a 2s.com*/ try { JSONArray servicesArray = new JSONArray(); JSONArray characteristicsArray = new JSONArray(); json.put("services", servicesArray); json.put("characteristics", characteristicsArray); if (connected && gatt != null) { for (BluetoothGattService service : gatt.getServices()) { servicesArray.put(UUIDHelper.uuidToString(service.getUuid())); for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) { JSONObject characteristicsJSON = new JSONObject(); characteristicsArray.put(characteristicsJSON); characteristicsJSON.put("service", UUIDHelper.uuidToString(service.getUuid())); characteristicsJSON.put("characteristic", UUIDHelper.uuidToString(characteristic.getUuid())); //characteristicsJSON.put("instanceId", characteristic.getInstanceId()); characteristicsJSON.put("properties", Helper.decodeProperties(characteristic)); // characteristicsJSON.put("propertiesValue", characteristic.getProperties()); if (characteristic.getPermissions() > 0) { characteristicsJSON.put("permissions", Helper.decodePermissions(characteristic)); // characteristicsJSON.put("permissionsValue", characteristic.getPermissions()); } JSONArray descriptorsArray = new JSONArray(); for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) { JSONObject descriptorJSON = new JSONObject(); descriptorJSON.put("uuid", UUIDHelper.uuidToString(descriptor.getUuid())); descriptorJSON.put("value", descriptor.getValue()); // always blank if (descriptor.getPermissions() > 0) { descriptorJSON.put("permissions", Helper.decodePermissions(descriptor)); // descriptorJSON.put("permissionsValue", descriptor.getPermissions()); } descriptorsArray.put(descriptorJSON); } if (descriptorsArray.length() > 0) { characteristicsJSON.put("descriptors", descriptorsArray); } } } } } catch (JSONException e) { // TODO better error handling e.printStackTrace(); } return json; }
From source file:com.evothings.BLE.java
private void descriptors(final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { final GattHandler gh = mGatt.get(args.getInt(0)); JSONArray a = new JSONArray(); for (BluetoothGattDescriptor d : gh.mCharacteristics.get(args.getInt(1)).getDescriptors()) { if (gh.mDescriptors == null) gh.mDescriptors = new HashMap<Integer, BluetoothGattDescriptor>(); Object res = gh.mDescriptors.put(gh.mNextHandle, d); assert (res == null); JSONObject o = new JSONObject(); o.put("handle", gh.mNextHandle); o.put("uuid", d.getUuid().toString()); o.put("permissions", d.getPermissions()); gh.mNextHandle++;//from w w w.j a v a 2s . co m a.put(o); } callbackContext.success(a); }
From source file:ti.android.ble.devicemonitor.ServiceView.java
void setItem(int pos) { boolean fHasRead; boolean fHasNotification; boolean fHasWrite; BluetoothGattDescriptor clientConfig; mChar = mCharList.get(pos);//from w ww .j a va2 s .c o m mProperty = mChar.getProperties(); fHasRead = (mProperty & BluetoothGattCharacteristic.PROPERTY_READ) > 0; fHasNotification = (mProperty & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0; fHasWrite = (mProperty & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0; // Activate input widgets according to char. property mBtnRead.setEnabled(fHasRead); mBtnWrite.setEnabled(fHasWrite); mData.setEnabled(fHasWrite); mBtnNotify.setEnabled(fHasNotification); if (fHasNotification) { mBtnNotify.setTextAppearance(mContext, R.style.checkboxStyle); mBtnNotify.setChecked(mGattService.isNotificationEnabled(mChar)); } else mBtnNotify.setTextAppearance(mContext, R.style.checkboxStyle_Disabled); if (fHasWrite) { mData.setHint(R.string.write_hint); } else { mData.setHint(""); } clientConfig = mChar.getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG); if (clientConfig != null) { int perm = clientConfig.getPermissions(); Log.d(TAG, "perm= " + perm); } setStatus(GattInfo.uuidToName(mChar.getUuid())); // Read the characteristic (if applicable) if (fHasRead) { mBtGatt.readCharacteristic(mChar); } // Make sure selection is highlighted mCharAdapter.setSelectedPosition(pos); mActivity.onSelectionUpdate(mChar); }