Class BluetoothDevice

java.lang.Object
com.github.hypfvieh.bluetooth.wrapper.AbstractBluetoothObject
com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice

public class BluetoothDevice extends AbstractBluetoothObject
Wrapper class which represents a remote bluetooth device.
Author:
hypfvieh
  • Constructor Details

    • BluetoothDevice

      public BluetoothDevice(Device1 _device, BluetoothAdapter _adapter, String _dbusPath, org.freedesktop.dbus.connections.impl.DBusConnection _dbusConnection)
  • Method Details

    • getInterfaceClass

      protected Class<? extends org.freedesktop.dbus.interfaces.DBusInterface> getInterfaceClass()
      DBus-Interface class used in this wrapper object.
      Specified by:
      getInterfaceClass in class AbstractBluetoothObject
      Returns:
      class which implements the interface
    • getGattServices

      public List<BluetoothGattService> getGattServices()
      Return the list of available BluetoothGattServices.
      Will start a query if no list was gathered before.
      To re-scan for services use refreshGattServices().
      Returns:
      List, maybe empty but never null
    • refreshGattServices

      public void refreshGattServices()
      Re-queries the list of available BluetoothGattService's on this device.
    • getGattServiceByUuid

      public BluetoothGattService getGattServiceByUuid(String _uuid)
      Get the given BluetoothGattService instance by UUID.
      Parameters:
      _uuid - uuid
      Returns:
      BluetoothGattService, maybe null if not found
    • getAdapter

      public BluetoothAdapter getAdapter()
      Get BluetoothAdapter object where this BluetoothDevice object belongs to.
      Returns:
      adapter
    • getRawDevice

      public Device1 getRawDevice()
      Get the raw Device1 object wrapped by this BluetoothDevice object.
      Returns:
      device
    • isBlocked

      public Boolean isBlocked()
      True if incoming connections are rejected, false otherwise.
      Returns:
      maybe null if feature is not supported
    • setBlocked

      public void setBlocked(Boolean _blocked)
      From bluez Documentation:

      If set to true any incoming connections from the
      device will be immediately rejected. Any device
      drivers will also be removed and no new ones will
      be probed as long as the device is blocked

      Parameters:
      _blocked - set blocked status
    • isTrusted

      public Boolean isTrusted()
      True if the remote device is trusted, false otherwise.
      Returns:
      maybe null if feature is not supported
    • setTrusted

      public void setTrusted(boolean _trusted)
      Set to true to trust the connected device, or to false if you don't.
      Default is false.
      Parameters:
      _trusted - set trusted
    • getAlias

      public String getAlias()
      The current name alias for the remote device.
      Returns:
      alias name
    • setAlias

      public void setAlias(String _alias)
      From bluez Documentation:

      The name alias for the remote device. The alias can
      be used to have a different friendly name for the
      remote device.
      In case no alias is set, it will return the remote
      device name. Setting an empty string as alias will
      convert it back to the remote device name.

      Parameters:
      _alias - alias name to set
    • getAdvertisingFlags

      public byte[] getAdvertisingFlags()
      The Advertising Data Flags of the remote device.
      EXPERIMENTAL
      Returns:
      byte array maybe null
    • getUuids

      public String[] getUuids()
      From bluez Documentation:

      List of 128-bit UUIDs that represents the available remote services.

      Returns:
      string array of UUIDs, maybe null
    • isConnected

      public Boolean isConnected()
      True if device is connected, false otherwise.
      Returns:
      maybe null if feature is not supported
    • isLegacyPairing

      public Boolean isLegacyPairing()
      From bluez Documentation:

      Set to true if the device only supports the pre-2.1
      pairing mechanism. This property is useful during
      device discovery to anticipate whether legacy or
      simple pairing will occur if pairing is initiated.
      Note that this property can exhibit false-positives
      in the case of Bluetooth 2.1 (or newer) devices that
      have disabled Extended Inquiry Response support.

      Returns:
      maybe null if feature is not supported
    • isPaired

      public Boolean isPaired()
      True if the device is currently paired with another device. False otherwise.
      Returns:
      boolean, maybe null
    • isServicesResolved

      public Boolean isServicesResolved()
      From bluez Documentation:

      Indicate whether or not service discovery has been resolved.

      Returns:
      maybe null if feature is not supported
    • getServiceData

      public Map<String,byte[]> getServiceData()
      From bluez Documentation:

      Service advertisement data. Keys are the UUIDs in string format followed by its byte array value.

      Returns:
      map of string/bytearray, maybe null
    • getManufacturerData

      public Map<org.freedesktop.dbus.types.UInt16,byte[]> getManufacturerData()
      From bluez Documentation:

      Manufacturer specific advertisement data. Keys are 16 bits Manufacturer ID followed by its byte array value.

      Returns:
      map of uint16/bytearray, maybe null
    • getRssi

      public Short getRssi()
      From bluez Documentation:

      Received Signal Strength Indicator of the remote device (inquiry or advertising).

      Returns:
      short, maybe null
    • getTxPower

      public Short getTxPower()
      From bluez Documentation:

      Advertised transmitted power level (inquiry or advertising).

      Returns:
      short, maybe null
    • getAddress

      public String getAddress()
      Returns the remote devices bluetooth (MAC) address.
      Returns:
      mac address, maybe null
    • getIcon

      public String getIcon()
      From bluez Documentation:

      Proposed icon name according to the freedesktop.org icon naming specification.

      Returns:
      icon name, maybe null
    • getModAlias

      public String getModAlias()
      From bluez Documentation:

      Remote Device ID information in modalias format used by the kernel and udev.

      Returns:
      modalias string, maybe null
    • getName

      public String getName()
      Get the bluetooth device name.
      This may fail if you not connected to the device, or if the device does not support this operation.
      If no name could be retrieved, the alias will be used.

      From bluez Documentation:

      The Bluetooth remote name. This value can not be
      changed. Use the Alias property instead.
      This value is only present for completeness. It is
      better to always use the Alias property when
      displaying the devices name.
      If the Alias property is unset, it will reflect
      this value which makes it more convenient.

      Returns:
      name, maybe null
    • getAppearance

      public Integer getAppearance()
      From bluez Documentation:

      External appearance of device, as found on GAP service.

      Returns:
      integer, maybe null
    • getBluetoothClass

      public Integer getBluetoothClass()
      From bluez Documentation:

      The Bluetooth class of device of the remote device.

      Returns:
      integer, maybe null
    • connect

      public boolean connect()
      From bluez Documentation:

      This is a generic method to connect any profiles
      the remote device supports that can be connected
      to and have been flagged as auto-connectable on
      our side. If only subset of profiles is already
      connected it will try to connect currently disconnected ones.

      Returns:
      true if connected, false otherwise
    • disconnect

      public boolean disconnect()
      From bluez Documentation:

      This method gracefully disconnects all connected
      profiles and then terminates low-level ACL connection.
      ACL connection will be terminated even if some profiles
      were not disconnected properly e.g. due to misbehaving
      device.

      This method can be also used to cancel a preceding
      Connect call before a reply to it has been received.

      Returns:
      true if disconnected false otherwise
    • connectProfile

      public boolean connectProfile(String _uuid)
      From bluez Documentation:

      This method connects a specific profile of this
      device. The UUID provided is the remote service
      UUID for the profile.

      Parameters:
      _uuid - profile uuid
      Returns:
      true if connected to given profile, false otherwise
    • disconnectProfile

      public boolean disconnectProfile(String _uuid)
      From bluez Documentation:

      This method disconnects a specific profile of
      this device. The profile needs to be registered
      client profile.

      There is no connection tracking for a profile, so
      as long as the profile is registered this will always
      succeed.

      Parameters:
      _uuid - profile uuid
      Returns:
      true if profile disconnected, false otherwise
    • pair

      public boolean pair()
      From bluez Documentation:

      This method will connect to the remote device,
      initiate pairing and then retrieve all SDP records
      (or GATT primary services).

      If the application has registered its own agent,
      then that specific agent will be used. Otherwise
      it will use the default agent.

      Only for applications like a pairing wizard it
      would make sense to have its own agent. In almost
      all other cases the default agent will handle
      this just fine.

      In case there is no application agent and also
      no default agent present, this method will fail.

      Returns:
      true on successful pair, false otherwise
    • cancelPairing

      public boolean cancelPairing()
      From bluez Documentation:

      This method can be used to cancel a pairing
      operation initiated by the Pair method.

      Returns:
      true if cancel succeeds, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object