Class ServiceHelper


  • public class ServiceHelper
    extends java.lang.Object
    Provides utility methods related to GATT services.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ej.bluetooth.BluetoothCharacteristic getCharacteristic​(ej.bluetooth.BluetoothService service, ej.bluetooth.BluetoothUuid characteristicUuid)
      Returns the characteristic with the given UUID in the given service.
      static ej.bluetooth.BluetoothDescriptor getDescriptor​(ej.bluetooth.BluetoothCharacteristic characteristic, ej.bluetooth.BluetoothUuid descriptorUuid)
      Returns the descriptor with the given UUID in the given characteristic.
      static int getReadPermission​(int securityLevel)
      Returns the read permission for the given security level.
      static int getWritePermission​(int securityLevel)
      Returns the write permission for the given security level.
      static void printService​(ej.bluetooth.BluetoothService service, java.io.PrintStream printStream)
      Prints information on the given service to the given print stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 ej.bluetooth.BluetoothCharacteristic getCharacteristic​(ej.bluetooth.BluetoothService service,
                                                                             ej.bluetooth.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 ej.bluetooth.BluetoothDescriptor getDescriptor​(ej.bluetooth.BluetoothCharacteristic characteristic,
                                                                     ej.bluetooth.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​(ej.bluetooth.BluetoothService service,
                                        java.io.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.