Accommodate BATT protocol modifications.

Bug: 380790573
Test: atest com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderControllerTest and Manual
Flag: com.android.settings.flags.enable_battery_level_display

Change-Id: Ibc4eb66aacedaf3a4111d4a411dada6cde1a5b9c
This commit is contained in:
Chung Tang
2024-12-29 18:03:57 +00:00
parent 047c38856a
commit 8a6ea1a106
2 changed files with 134 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
private static final String ESTIMATE_READY = "estimate_ready";
private static final String DATABASE_ID = "id";
private static final String DATABASE_BLUETOOTH = "Bluetooth";
private static final String TAG_BATT = "BATT";
private static final long TIME_OF_HOUR = TimeUnit.SECONDS.toMillis(3600);
private static final long TIME_OF_MINUTE = TimeUnit.SECONDS.toMillis(60);
private static final int LEFT_DEVICE_ID = 1;
@@ -268,6 +269,30 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
BluetoothDevice.METADATA_MAIN_BATTERY)
!= BluetoothUtils.META_INT_ERROR);
});
Supplier<Boolean> isBattEnabled =
Suppliers.memoize(
() ->
Boolean.valueOf(
BluetoothUtils.getFastPairCustomizedField(
mCachedDevice.getDevice(), TAG_BATT)));
Supplier<Integer> leftBatteryLevel =
Suppliers.memoize(
() ->
BluetoothUtils.getIntMetaData(
mCachedDevice.getDevice(),
BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY));
Supplier<Integer> rightBatteryLevel =
Suppliers.memoize(
() ->
BluetoothUtils.getIntMetaData(
mCachedDevice.getDevice(),
BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY));
Supplier<Integer> caseBatteryLevel =
Suppliers.memoize(
() ->
BluetoothUtils.getIntMetaData(
mCachedDevice.getDevice(),
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY));
preloadAndRun(
List.of(deviceName, disconnected, isUntetheredHeadset, summaryText),
() -> {
@@ -277,7 +302,16 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
final TextView summary =
mLayoutPreference.findViewById(R.id.entity_header_summary);
if (disconnected.get()) {
final boolean isBatteryLevelAvailable =
Flags.enableBatteryLevelDisplay()
&& isBattEnabled.get()
&& (leftBatteryLevel.get() > BluetoothUtils.META_INT_ERROR
|| rightBatteryLevel.get()
> BluetoothUtils.META_INT_ERROR
|| caseBatteryLevel.get()
> BluetoothUtils.META_INT_ERROR);
if (disconnected.get() && !isBatteryLevelAvailable) {
summary.setText(summaryText.get());
updateDisconnectLayout();
return;