#AndroidDev Finding – BluetoothClass

By -

If you are andorid developer, you might have thought over this point, how android wear companion app is only listing down android wear devices.

Every bluetooth device is having defined bluetooth class and device class. If you do reverse engineering of the android wear companion application, you would get below code:

  public static boolean isWatch(BluetoothDevice paramBluetoothDevice, BluetoothClass paramBluetoothClass)
  {
    return (paramBluetoothClass != null) && (paramBluetoothClass.getDeviceClass() == 1796);
  }
  
  public static boolean isWatchConfig(Context paramContext, ConnectionConfiguration paramConnectionConfiguration)
  {
    int i = 1;
    if ((!paramConnectionConfiguration.isValid()) || (paramConnectionConfiguration.getType() != i) || (paramConnectionConfiguration.getAddress() == null)) {
      return false;
    }
    BluetoothDevice localBluetoothDevice = getBluetoothDevice(paramContext, paramConnectionConfiguration.getAddress());
    if (localBluetoothDevice != null) {}
    try
    {
      boolean bool = isWatch(localBluetoothDevice, localBluetoothDevice.getBluetoothClass());
      if (bool) {}
      for (;;)
      {
        return i;
        int j = 0;
      }
      return false;
    }
    catch (NullPointerException localNullPointerException)
    {
      Log.w("ClockworkCompanion", "Failed to get BT class: ", localNullPointerException);
    }
  }

Finding:

BluetoothClass represents a Bluetooth class, which describes the general characteristics and capabilities of a device. For example, a Bluetooth class will specify the general device type such as a phone, tablet or wearable wrist, and whether it’s capable of services such as audio or telephony.

Using getBluetoothClass() of BluetoothDevice class, we can retrieve the class for a remote device.

Using getDeviceClass() of BluetoothClass, we can retrieve the device class encoded in the Bluetooth class. Value retrieved using getDeviceClass() can be compared with the public constants defined in the BluetoothClass.Device.

public static final int WEARABLE_WRIST_WATCH

Added in API level 5
Constant Value: 1796 (0x00000704)

So as per the android wear app logic, it is comparing bluetooth class with 1796 which is nothing but a constant WEARABLE_WRIST_WATCH declared in BluetoothClass.Device class.

Explore:

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

Loading Facebook Comments ...
Loading Disqus Comments ...