Java Code Examples for android.bluetooth.BluetoothGattDescriptor#PERMISSION_READ_ENCRYPTED

The following examples show how to use android.bluetooth.BluetoothGattDescriptor#PERMISSION_READ_ENCRYPTED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CharacteristicNotificationDescriptor.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Will create a 0x2902 characteristic descriptor
 */
public CharacteristicNotificationDescriptor() {
    super(notificationDescriptorTwentyNineOhTwo, BluetoothGattDescriptor.PERMISSION_READ |
            BluetoothGattDescriptor.PERMISSION_WRITE |
            BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED |
            BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
}
 
Example 2
Source File: CharacteristicNamespaceDescriptor.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Will create a 0x2904 characteristic descriptor
 */
public CharacteristicNamespaceDescriptor() {
    super(notificationDescriptorTwentyNineOhFour, BluetoothGattDescriptor.PERMISSION_READ |
            BluetoothGattDescriptor.PERMISSION_WRITE |
            BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED |
            BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
}
 
Example 3
Source File: GattNotifyIndicateTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void subscribeToNotificationTest() {
    final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'};
    BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    SubscribeToCharacteristicNotificationsMockTransaction subscribeChar = new SubscribeToCharacteristicNotificationsMockTransaction(conn, GattState.ENABLE_CHARACTERISTIC_NOTIFICATION_SUCCESS, characteristic, fakeData, false);
    conn.runTx(subscribeChar, result -> {
        assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.SUCCESS) && result.resultState.equals(subscribeChar.getSuccessState()));
    });
}
 
Example 4
Source File: GattNotifyIndicateTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void unSubscribeToNotificationTest() {
    final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'};
    BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    UnSubscribeToGattCharacteristicNotificationsMockTransaction unSubscribeChar = new UnSubscribeToGattCharacteristicNotificationsMockTransaction(conn, GattState.ENABLE_CHARACTERISTIC_NOTIFICATION_SUCCESS, characteristic, fakeData, false);
    conn.runTx(unSubscribeChar, result -> {
        assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.SUCCESS) && result.resultState.equals(unSubscribeChar.getSuccessState()));
    });
}
 
Example 5
Source File: GattNotifyIndicateTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void failToSubscribeToNotificationTest() {
    final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'};
    BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    SubscribeToCharacteristicNotificationsMockTransaction subscribeChar = new SubscribeToCharacteristicNotificationsMockTransaction(conn, GattState.ENABLE_CHARACTERISTIC_NOTIFICATION_SUCCESS, characteristic, fakeData, true);
    conn.runTx(subscribeChar, result -> {
        assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.TIMEOUT));
    });
}
 
Example 6
Source File: GattNotifyIndicateTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void failToUnSubscribeToNotificationTest() {
    final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'};
    BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    UnSubscribeToGattCharacteristicNotificationsMockTransaction unSubscribeChar = new UnSubscribeToGattCharacteristicNotificationsMockTransaction(conn, GattState.ENABLE_CHARACTERISTIC_NOTIFICATION_SUCCESS, characteristic, fakeData, true);
    conn.runTx(unSubscribeChar, result -> {
        assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.TIMEOUT));
    });
}
 
Example 7
Source File: GattNotifyIndicateTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void NotifyServerCharacteristicTest() {
    final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'};
    BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    characteristic.setValue(fakeData);
    NotifyGattServerCharacteristicMockTransaction notifyChar = new NotifyGattServerCharacteristicMockTransaction(FitbitGatt.getInstance().getServer(), device, GattState.NOTIFY_CHARACTERISTIC_SUCCESS, characteristic, false, false);
    conn.runTx(notifyChar, result -> {
        assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.SUCCESS));
    });
}
 
Example 8
Source File: Helper.java    From react-native-ble-manager with Apache License 2.0 5 votes vote down vote up
public static WritableMap decodePermissions(BluetoothGattDescriptor descriptor) {

		// NOTE: props strings need to be consistent across iOS and Android
		WritableMap props = Arguments.createMap();
		int permissions = descriptor.getPermissions();

		if ((permissions & BluetoothGattDescriptor.PERMISSION_READ) != 0x0 ) {
			props.putString("Read", "Read");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE) != 0x0 ) {
			props.putString("Write", "Write");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED) != 0x0 ) {
			props.putString("ReadEncrypted", "ReadEncrypted");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED) != 0x0 ) {
			props.putString("WriteEncrypted", "WriteEncrypted");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM) != 0x0 ) {
			props.putString("ReadEncryptedMITM", "ReadEncryptedMITM");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM) != 0x0 ) {
			props.putString("WriteEncryptedMITM", "WriteEncryptedMITM");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED) != 0x0 ) {
			props.putString("WriteSigned", "WriteSigned");
		}

		if ((permissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM) != 0x0 ) {
			props.putString("WriteSignedMITM", "WriteSignedMITM");
		}

		return props;
	}
 
Example 9
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
String getStringRepresentationOfPermissionsForDescriptor(BluetoothGattDescriptor descriptor) {
    StringBuilder permissionBuilder = new StringBuilder();
    ArrayList<Integer> permissions = new ArrayList<>(8);
    int descriptorPermissions = descriptor.getPermissions();
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_READ) == BluetoothGattDescriptor.PERMISSION_READ) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_READ);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED) == BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM) == BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_WRITE) == BluetoothGattDescriptor.PERMISSION_WRITE) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_WRITE);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED) == BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM) == BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED) == BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED);
    }
    if ((descriptorPermissions & BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM) == BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM) {
        permissions.add(BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM);
    }
    for (int i = 0; i < permissions.size(); i++) {
        int permission = permissions.get(i);
        switch (permission) {
            case BluetoothGattDescriptor.PERMISSION_READ:
                permissionBuilder.append("read");
                break;
            case BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED:
                permissionBuilder.append("read-encrypted");
                break;
            case BluetoothGattDescriptor.PERMISSION_WRITE:
                permissionBuilder.append("write");
                break;
            case BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM:
                permissionBuilder.append("read-encrypted-mitm");
                break;
            case BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED:
                permissionBuilder.append("write-encrypted");
                break;
            case BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM:
                permissionBuilder.append("write-encrypted-mitm");
                break;
            case BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED:
                permissionBuilder.append("write-signed");
                break;
            case BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM:
                permissionBuilder.append("write-signed-mitm");
                break;
            default:
                permissionBuilder.append("unknown");
        }
        if (i < permissions.size() - 1) {
            permissionBuilder.append(", ");
        }
    }
    return permissionBuilder.toString();
}