diff options
author | Tim Peng <timhypeng@google.com> | 2021-03-23 15:14:13 +0800 |
---|---|---|
committer | Tim Peng <timhypeng@google.com> | 2021-03-24 09:32:26 +0800 |
commit | 7e6762de8ac6ca32e06b970dcf47abf006851786 (patch) | |
tree | 11efc8d12cc09395bfb71dec510ba4b2dfb7cb20 /src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java | |
parent | 90df1c9de163363ab3a7e0272f7d1f091b9e4a30 (diff) | |
download | packages_apps_Settings-7e6762de8ac6ca32e06b970dcf47abf006851786.tar.gz packages_apps_Settings-7e6762de8ac6ca32e06b970dcf47abf006851786.tar.bz2 packages_apps_Settings-7e6762de8ac6ca32e06b970dcf47abf006851786.zip |
Get low battery level through metadata
Bug: 183469297
Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=AdvancedBluetoothDetailsHeaderControllerTest
Change-Id: Iae8971a5c1f183fe141d4246e23d8feb6d68d0ff
Diffstat (limited to 'src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java')
-rw-r--r-- | src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java index 096c2c5e06..bc5aa470eb 100644 --- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java @@ -192,6 +192,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle), BluetoothDevice.METADATA_MAIN_ICON, BluetoothDevice.METADATA_MAIN_BATTERY, + BluetoothDevice.METADATA_MAIN_LOW_BATTERY_THRESHOLD, BluetoothDevice.METADATA_MAIN_CHARGING, /* titleResId */ 0, MAIN_DEVICE_ID); @@ -202,6 +203,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont updateSubLayout(mLayoutPreference.findViewById(R.id.layout_left), BluetoothDevice.METADATA_UNTETHERED_LEFT_ICON, BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY, + BluetoothDevice.METADATA_UNTETHERED_LEFT_LOW_BATTERY_THRESHOLD, BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING, R.string.bluetooth_left_name, LEFT_DEVICE_ID); @@ -209,6 +211,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle), BluetoothDevice.METADATA_UNTETHERED_CASE_ICON, BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY, + BluetoothDevice.METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD, BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING, R.string.bluetooth_middle_name, CASE_DEVICE_ID); @@ -216,6 +219,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont updateSubLayout(mLayoutPreference.findViewById(R.id.layout_right), BluetoothDevice.METADATA_UNTETHERED_RIGHT_ICON, BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY, + BluetoothDevice.METADATA_UNTETHERED_RIGHT_LOW_BATTERY_THRESHOLD, BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING, R.string.bluetooth_right_name, RIGHT_DEVICE_ID); @@ -243,7 +247,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont } private void updateSubLayout(LinearLayout linearLayout, int iconMetaKey, int batteryMetaKey, - int chargeMetaKey, int titleResId, int deviceId) { + int lowBatteryMetaKey, int chargeMetaKey, int titleResId, int deviceId) { if (linearLayout == null) { return; } @@ -273,7 +277,15 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont linearLayout.setVisibility(View.VISIBLE); batterySummaryView.setText(com.android.settings.Utils.formatPercentage(batteryLevel)); batterySummaryView.setVisibility(View.VISIBLE); - showBatteryIcon(linearLayout, batteryLevel, charging, batteryMetaKey); + 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); @@ -354,11 +366,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont }); } - private void showBatteryIcon(LinearLayout linearLayout, int level, boolean charging, - int batteryMetaKey) { - final int lowBatteryLevel = - batteryMetaKey == BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY - ? CASE_LOW_BATTERY_LEVEL : LOW_BATTERY_LEVEL; + private void showBatteryIcon(LinearLayout linearLayout, int level, int lowBatteryLevel, + boolean charging) { final boolean enableLowBattery = level <= lowBatteryLevel && !charging; final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon); if (enableLowBattery) { |