Class BluetoothAdapter

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

public class BluetoothAdapter extends AbstractBluetoothObject
Wrapper class which represents an bluetooth adapter.
Author:
hypfvieh
  • Constructor Details

    • BluetoothAdapter

      public BluetoothAdapter(Adapter1 _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
    • getRawAdapter

      public Adapter1 getRawAdapter()
      Get the raw Adapter1 object wrapped by this BluetoothAdapter object.
      Returns:
      adapter
    • getDeviceName

      public String getDeviceName()
      Get the deviceName used in DBus (e.g. hci0).
      Returns:
      the device name
    • getAlias

      public String getAlias()
      The changeable bluetooth friendly name.
      Returns:
      the alias name
    • setAlias

      public void setAlias(String _alias)
      Change the current bluetooth friendly name.
      Parameters:
      _alias - new alias to set
    • isPowered

      public boolean isPowered()
      Returns if the adapter is powered on (true) or powered off (false).
      Returns:
      power status
    • setPowered

      public void setPowered(boolean _powered)
      Turn adapter on (true) or off (false).
      Parameters:
      _powered - set power status
    • isDiscoverable

      public Boolean isDiscoverable()
      True if device is discoverable (= visible for others), false otherwise.
      Returns:
      maybe null if feature is not supported
    • setDiscoverable

      public void setDiscoverable(boolean _discoverable)
      Set to true to enable device visibility for other bluetooth devices nearby.
      Parameters:
      _discoverable - set device visible for others
    • getDiscoverableTimeout

      public Integer getDiscoverableTimeout()
      The current timeout (in seconds) configured before disabling discoverbility.
      If 0 discoverbility will never be disabled automatically.
      Returns:
      integer maybe null
    • setDiscoverableTimeout

      public void setDiscoverableTimeout(Integer _discoverableTimeout)
      Timeout (in seconds) to set before the device visibility for others will be disabled.
      If set to 0, device will stay visible forever.
      Parameters:
      _discoverableTimeout - timeout to set
    • isPairable

      public Boolean isPairable()
      True if pairing with this adapter is allowed for others.
      Returns:
      maybe null if feature is not supported
    • setPairable

      public void setPairable(boolean _pairable)
      Set to true to allow pairing of other devices with this adapter.
      This is a global setting and effects all applications using this adapter.
      Parameters:
      _pairable - set pairing
    • getPairableTimeout

      public Integer getPairableTimeout()
      Current configured timeout (in seconds) before the pairable mode is disabled.
      If 0, timeout is disabled and pairability will never be disabled.
      Returns:
      integer maybe null
    • setPairableTimeout

      public void setPairableTimeout(Integer _pairableTimeout)
      Set the timeout (in seconds) before the pairable mode is disabled.
      Setting this to 0 disables the timeout.
      Parameters:
      _pairableTimeout - set pairable timeout
    • getAddress

      public String getAddress()
      Returns the bluetooth device (MAC) address.
      Returns:
      mac address, maybe null
    • getName

      public String getName()
      From bluez Documentation:

      The Bluetooth system name (pretty hostname). This property is either a static system default or controlled by an external daemon providing access to the pretty hostname configuration.

      Returns:
      name, maybe null
    • getDeviceClass

      public Integer getDeviceClass()
      From bluez Documentation:

      The Bluetooth class of device. This property represents the value that is either automatically configured by DMI/ACPI information or provided as static configuration.

      Returns:
      integer, maybe null
    • isDiscovering

      public Boolean isDiscovering()
      True if discovery procedure is active, false otherwise.
      Returns:
      discovering status
    • getUuids

      public String[] getUuids()
      From bluez Documentation:

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

      Returns:
      String[], maybe null
    • getModAlias

      public String getModAlias()
      From bluez Documentation:

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

      Returns:
      String, maybe null
    • startDiscovery

      public boolean startDiscovery()
      Start a new discovery operation to find any devices nearby.
      Returns:
      true if discovery is running, false otherwise
    • stopDiscovery

      public boolean stopDiscovery()
      Stops the current discovery operation.
      Returns:
      true if discovery was stopped, false otherwise
    • removeDevice

      public void removeDevice(Device1 _device) throws BluezFailedException, BluezInvalidArgumentsException
      Remove a device and it's pairing information.
      Parameters:
      _device - device to remove
      Throws:
      BluezFailedException - on failure when something went wrong
      BluezInvalidArgumentsException - when argument is invalid when device was invalid
    • setDiscoveryFilter

      public void setDiscoveryFilter(Map<String,org.freedesktop.dbus.types.Variant<?>> _filter) throws BluezInvalidArgumentsException, BluezNotReadyException, BluezNotSupportedException, BluezFailedException
      Use this to set a discovery filter.
      This will cause the bluez library to only add device objects which are matching the given criterias.

      Support values for the Map:
       Type     KeyName   : Purpose
       ============================================
       String[] UUIDs     : filtered service UUIDs
       Short    RSSI      : RSSI threshold value
       UInt16   Pathloss  : Pathloss threshold value
       String   Transport : type of scan to run
       

      The 'Transport' Key supports the following options:
       Value     - Description
       ============================================
       "auto"    - interleaved scan, default value
       "bredr"   - BR/EDR inquiry
       "le"      - LE scan only
       
      If a transport mode is used which is not supported by the device, a BluezNotSupportedException is thrown.
      Parameters:
      _filter - filter to use
      Throws:
      BluezInvalidArgumentsException - when argument is invalid thrown if any arguments in the map are not supported
      BluezNotReadyException - when bluez not ready if adapter not ready
      BluezNotSupportedException - when operation not supported if operation not supported
      BluezFailedException - on failure any other error
    • toString

      public String toString()
      Overrides:
      toString in class Object