[Rohan] Two battery level, but no charging status in Rohan Setting

-show/hide battery information by device type

Bug: 187692468
Test: atest AdvancedBluetoothDetailsHeaderControllerTest

Change-Id: I22b4f2cddaf1143dd48ffec2fa3114d685689633
This commit is contained in:
Tim Peng
2021-05-13 13:33:05 +08:00
parent bcc288e801
commit 6cbeb65a05

View File

@@ -274,37 +274,43 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
showBatteryPredictionIfNecessary(linearLayout, deviceId, batteryLevel); showBatteryPredictionIfNecessary(linearLayout, deviceId, batteryLevel);
} }
final TextView batterySummaryView = linearLayout.findViewById(R.id.bt_battery_summary); final TextView batterySummaryView = linearLayout.findViewById(R.id.bt_battery_summary);
if (batteryLevel != BluetoothUtils.META_INT_ERROR) { if (isUntetheredHeadset(bluetoothDevice)) {
linearLayout.setVisibility(View.VISIBLE); if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
batterySummaryView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
batterySummaryView.setVisibility(View.VISIBLE);
int lowBatteryLevel = BluetoothUtils.getIntMetaData(bluetoothDevice, lowBatteryMetaKey);
if (lowBatteryLevel == BluetoothUtils.META_INT_ERROR) {
if (batteryMetaKey == BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY) {
lowBatteryLevel = CASE_LOW_BATTERY_LEVEL;
} else {
lowBatteryLevel = LOW_BATTERY_LEVEL;
}
}
showBatteryIcon(linearLayout, batteryLevel, lowBatteryLevel, charging);
} else {
if (deviceId == MAIN_DEVICE_ID) {
linearLayout.setVisibility(View.VISIBLE); linearLayout.setVisibility(View.VISIBLE);
linearLayout.findViewById(R.id.bt_battery_icon).setVisibility(View.GONE); batterySummaryView.setText(
int level = bluetoothDevice.getBatteryLevel(); com.android.settings.Utils.formatPercentage(batteryLevel));
if (level != BluetoothDevice.BATTERY_LEVEL_UNKNOWN batterySummaryView.setVisibility(View.VISIBLE);
&& level != BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF) { int lowBatteryLevel = BluetoothUtils.getIntMetaData(bluetoothDevice,
batterySummaryView.setText(com.android.settings.Utils.formatPercentage(level)); lowBatteryMetaKey);
batterySummaryView.setVisibility(View.VISIBLE); if (lowBatteryLevel == BluetoothUtils.META_INT_ERROR) {
} else { if (batteryMetaKey == BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY) {
batterySummaryView.setVisibility(View.GONE); lowBatteryLevel = CASE_LOW_BATTERY_LEVEL;
} else {
lowBatteryLevel = LOW_BATTERY_LEVEL;
}
} }
showBatteryIcon(linearLayout, batteryLevel, lowBatteryLevel, charging);
} else { } else {
// Hide it if it doesn't have battery information if (deviceId == MAIN_DEVICE_ID) {
linearLayout.setVisibility(View.GONE); linearLayout.setVisibility(View.VISIBLE);
linearLayout.findViewById(R.id.bt_battery_icon).setVisibility(View.GONE);
int level = bluetoothDevice.getBatteryLevel();
if (level != BluetoothDevice.BATTERY_LEVEL_UNKNOWN
&& level != BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF) {
batterySummaryView.setText(
com.android.settings.Utils.formatPercentage(level));
batterySummaryView.setVisibility(View.VISIBLE);
} else {
batterySummaryView.setVisibility(View.GONE);
}
} else {
// Hide it if it doesn't have battery information
linearLayout.setVisibility(View.GONE);
}
} }
} else {
batterySummaryView.setVisibility(View.GONE);
} }
final TextView textView = linearLayout.findViewById(R.id.header_title); final TextView textView = linearLayout.findViewById(R.id.header_title);
if (deviceId == MAIN_DEVICE_ID) { if (deviceId == MAIN_DEVICE_ID) {
textView.setVisibility(View.GONE); textView.setVisibility(View.GONE);
@@ -314,6 +320,14 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
} }
} }
private boolean isUntetheredHeadset(BluetoothDevice bluetoothDevice) {
return BluetoothUtils.getBooleanMetaData(bluetoothDevice,
BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)
|| TextUtils.equals(BluetoothUtils.getStringMetaData(bluetoothDevice,
BluetoothDevice.METADATA_DEVICE_TYPE),
BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET);
}
private void showBatteryPredictionIfNecessary(LinearLayout linearLayout, int batteryId, private void showBatteryPredictionIfNecessary(LinearLayout linearLayout, int batteryId,
int batteryLevel) { int batteryLevel) {
ThreadUtils.postOnBackgroundThread(() -> { ThreadUtils.postOnBackgroundThread(() -> {