A really useful feature for those of us with Bluetooth headsets and other devices is finally making its way to AOSP: Bluetooth battery level indicators. This means that users of Google, Motorola, Sony, and other devices with near-stock Android software should be able to tell the battery level of their Bluetooth connected devices without the need of a third-party application. There’s no telling exactly how this Bluetooth battery level indicator will appear in its final state, but the existence of this new API in AOSP means that developers can implement Bluetooth battery indicators however they like.
Now, for those of you on certain custom ROMs (such as LineageOS) or with devices from certain manufacturers (such as those from Samsung, LG, Huawei, OnePlus, or Xiaomi) this is not a new feature. Battery level indicators for connected Bluetooth devices has been supported on many custom ROMs and third-party OEM devices for years, but such a feature has notably been missing from the Android Open Source Project (AOSP), which means that any Google phone on the stock firmware will not support it.
Users with Bluetooth devices that are lucky enough to have a companion application available on the Google Play Store can retrieve battery level information that way, but otherwise there are few options. A popular application on the Play Store called BatON attempted to add this feature, but it is quite limited in what range of devices it can support (by no fault of its own) and is also known to be quite buggy (with many users reporting frequent Bluetooth disconnecting).
Rather than rely on third party applications that either work only with a single Bluetooth device that you own or that only support a handful of devices out there, it would be great if Google stepped in to offer a feature that has been available on other devices for years. And finally, it looks like they’re doing just that.
Bluetooth Battery Level APIs in AOSP
The Bluetooth Special Interest Group (Bluetooth SIG), the body that oversees the standards for each Bluetooth iteration, has already defined a Battery service (BAS) in GATT (Generic Attributes services), but it’s up for Bluetooth to support BAS. According to some new commits we found while digging through AOSP, Google is preparing to add new APIs to “get remote device’s battery level.” In particular, they mention the following additions to AOSP:
From this, we can see that Google will add a new method in the BluetoothDevice class called getBatteryLevel() which will retrieve the current battery level of a connected device when called. According to the source code, this returns a value between 0 and 100 (or -1 if Bluetooth is disabled, the device is disconnected, or does not support reporting its battery level). Hence this means that it’s possible for the battery level to be shown in a way that is more informative than a simple bar. A developer could show a notification or widget with the exact percent, for instance.
But that’s not all, an application that subscribes to the ACTION_BATTERY_LEVEL_CHANGED broadcast intent will be notified when the connected device’s battery level has changed. With a broadcast receiver, an application that is listening for changes in the connected Bluetooth device’s battery state will be notified when the battery level has changed, so there will be no need to implement a persistent background polling service of any kind. This value is sent as an integer between 0 and 100% through the intent extra EXTRA_BATTERY_LEVEL, and the application can differentiate between connected devices by filtering through the intent extra EXTRA_DEVICE.
Even certain devices which send battery information in their own way, such as Plantronics’ XEvent or Apple’s VSC, will also be supported. There is also work being done on Bluetooth Low Energy (BLE) battery level reporting being supported, though this is listed as “cannot merge” at the moment.
Possible Feature for Android 8.1?
Android O is almost upon us. The fourth Developer Preview was recently released and was mostly aimed at bug fixes, though there were a few minor UI tweaks here and there. However, Google announced that the third Developer Preview featured all of the finalized Android O APIs that developers can use to get ready for the next version of Android. As such, this means the new connected Bluetooth battery level reporting API won’t make its way to the first release of Android O – Android 8.0.
However, that doesn’t mean it won’t be coming. It’s possible that Google will introduce this API officially (when it’s actually finished) with the eventual release of Android 8.1. At the same time, they may even decide to have this feature be supported through the Android Support Library, bringing it to earlier Android versions. If that ends up happening, then users won’t have to wait months to enjoy such a feature (though we always encourage users to try out one of the many custom ROMs available on our awesome forums).
Nonetheless, this should be exciting news for fans of the stock software on their phone. Hopefully you won’t have to be jealous of users with Apple, Samsung, Huawei, LG, and other devices with this nifty feature that should have been available in Android a long, long time ago. Given the recent outpouring of support for the idea over on Reddit, we’re sure that this will be a welcome feature – when it eventually comes to stock Android.