Class AbstractBluetoothDevice

java.lang.Object
oshi.hardware.common.AbstractBluetoothDevice
All Implemented Interfaces:
BluetoothDevice
Direct Known Subclasses:
LinuxBluetoothDevice, MacBluetoothDevice

@Immutable public abstract class AbstractBluetoothDevice extends Object implements BluetoothDevice
Abstract base class for BluetoothDevice implementations.
  • Constructor Details

    • AbstractBluetoothDevice

      protected AbstractBluetoothDevice(String name, String address, String majorDeviceClass, boolean connected, boolean paired, int batteryLevel, String adapterName)
      Creates an AbstractBluetoothDevice with the given parameters.
      Parameters:
      name - the device name
      address - the MAC address
      majorDeviceClass - the major device class
      connected - whether the device is connected
      paired - whether the device is paired
      batteryLevel - the battery level (0–100), or -1 if unavailable
      adapterName - the adapter name
  • Method Details

    • getName

      public String getName()
      Description copied from interface: BluetoothDevice
      The user-visible name of the Bluetooth device.
      Specified by:
      getName in interface BluetoothDevice
      Returns:
      The device name, or an empty string if unknown.
    • getAddress

      public String getAddress()
      Description copied from interface: BluetoothDevice
      The MAC address of the Bluetooth device in colon-separated format (e.g., AA:BB:CC:DD:EE:FF).
      Specified by:
      getAddress in interface BluetoothDevice
      Returns:
      The device MAC address.
    • getMajorDeviceClass

      public String getMajorDeviceClass()
      Description copied from interface: BluetoothDevice
      The major Bluetooth device class (e.g., "Audio", "Phone", "Computer", "Peripheral", "Networking").

      Derived from the Class of Device (CoD) field when available.

      Specified by:
      getMajorDeviceClass in interface BluetoothDevice
      Returns:
      The major device class string, or an empty string if unknown.
    • isConnected

      public boolean isConnected()
      Description copied from interface: BluetoothDevice
      Whether the device is currently connected to this system.
      Specified by:
      isConnected in interface BluetoothDevice
      Returns:
      true if connected, false otherwise.
    • isPaired

      public boolean isPaired()
      Description copied from interface: BluetoothDevice
      Whether the device is paired (bonded) with this system.
      Specified by:
      isPaired in interface BluetoothDevice
      Returns:
      true if paired, false otherwise.
    • getBatteryLevel

      public int getBatteryLevel()
      Description copied from interface: BluetoothDevice
      The battery level of the device as a percentage (0–100).
      Specified by:
      getBatteryLevel in interface BluetoothDevice
      Returns:
      The battery percentage, or -1 if not available.
    • getAdapterName

      public String getAdapterName()
      Description copied from interface: BluetoothDevice
      The name of the adapter (e.g., hci0) through which this device is known.
      Specified by:
      getAdapterName in interface BluetoothDevice
      Returns:
      The adapter name.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parseMajorDeviceClass

      public static String parseMajorDeviceClass(int cod)
      Parses the major device class from the Bluetooth Class of Device (CoD) integer.

      The major device class is bits 12–8 of the CoD value.

      Parameters:
      cod - the Class of Device integer
      Returns:
      a human-readable major device class string