Class ServiceHelper


  • public class ServiceHelper
    extends Object
    Provides utility methods related to GATT services.
    • Method Detail

      • getReadPermission

        public static int getReadPermission​(int securityLevel)
        Returns the read permission for the given security level.
        Parameters:
        securityLevel - the security level (see SecurityLevels).
        Returns:
        the read permission for the given security level (see BluetoothPermissions).
      • getWritePermission

        public static int getWritePermission​(int securityLevel)
        Returns the write permission for the given security level.
        Parameters:
        securityLevel - the security level (see SecurityLevels).
        Returns:
        the write permission for the given security level (see BluetoothPermissions).
      • getCharacteristic

        public static BluetoothCharacteristic getCharacteristic​(BluetoothService service,
                                                                BluetoothUuid characteristicUuid)
                                                         throws AttributeNotFoundException
        Returns the characteristic with the given UUID in the given service.

        If multiple characteristics have the same UUID, any of them may be returned.

        Parameters:
        service - the service to search in.
        characteristicUuid - the UUID of the characteristic to look for.
        Returns:
        the characteristic with the given UUID.
        Throws:
        AttributeNotFoundException - if this service does not provide a characteristic with the given UUID.
      • getDescriptor

        public static BluetoothDescriptor getDescriptor​(BluetoothCharacteristic characteristic,
                                                        BluetoothUuid descriptorUuid)
                                                 throws AttributeNotFoundException
        Returns the descriptor with the given UUID in the given characteristic.

        If multiple descriptors have the same UUID, any of them may be returned.

        Parameters:
        characteristic - the characteristic to search in.
        descriptorUuid - the UUID of the descriptor to look for.
        Returns:
        the descriptor with the given UUID.
        Throws:
        AttributeNotFoundException - if this characteristic does not provide a descriptor with the given UUID.
      • printService

        public static void printService​(BluetoothService service,
                                        PrintStream printStream)
        Prints information on the given service to the given print stream.
        Parameters:
        service - the service to inspect.
        printStream - the print stream to print to.