From 827910d3c3018a06def9338757e95fafb185f569 Mon Sep 17 00:00:00 2001 From: Hugh Chen Date: Thu, 17 Feb 2022 09:10:49 +0000 Subject: [PATCH] Show prediction time when both value are ready Bug: 215767460 Test: make -j64 RunSettingsRoboTests Change-Id: I07947b3eca1f656e0dc603f9b9839825dd3149fd --- ...ancedBluetoothDetailsHeaderController.java | 34 ++++++++++-- ...dBluetoothDetailsHeaderControllerTest.java | 52 +++++++++++++------ 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java index b60f1b64c38..1c12c6a2ed2 100644 --- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java @@ -99,6 +99,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont @VisibleForTesting boolean mIsRegisterCallback = false; @VisibleForTesting + boolean mIsLeftDeviceEstimateReady; + @VisibleForTesting + boolean mIsRightDeviceEstimateReady; + @VisibleForTesting final BluetoothAdapter.OnMetadataChangedListener mMetadataListener = new BluetoothAdapter.OnMetadataChangedListener() { @Override @@ -226,6 +230,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING, R.string.bluetooth_right_name, RIGHT_DEVICE_ID); + + showBothDevicesBatteryPredictionIfNecessary(); } } } @@ -365,8 +371,13 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont + ", ESTIMATE_READY : " + estimateReady + ", BATTERY_ESTIMATE : " + batteryEstimate); } - showBatteryPredictionIfNecessary(estimateReady, batteryEstimate, - linearLayout); + + showBatteryPredictionIfNecessary(estimateReady, batteryEstimate, linearLayout); + if (batteryId == LEFT_DEVICE_ID) { + mIsLeftDeviceEstimateReady = estimateReady == 1; + } else if (batteryId == RIGHT_DEVICE_ID) { + mIsRightDeviceEstimateReady = estimateReady == 1; + } } } finally { cursor.close(); @@ -380,7 +391,6 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont ThreadUtils.postOnMainThread(() -> { final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction); if (estimateReady == 1) { - textView.setVisibility(View.VISIBLE); textView.setText( StringUtil.formatElapsedTime( mContext, @@ -393,6 +403,24 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont }); } + @VisibleForTesting + void showBothDevicesBatteryPredictionIfNecessary() { + TextView leftDeviceTextView = + mLayoutPreference.findViewById(R.id.layout_left) + .findViewById(R.id.bt_battery_prediction); + TextView rightDeviceTextView = + mLayoutPreference.findViewById(R.id.layout_right) + .findViewById(R.id.bt_battery_prediction); + + boolean isBothDevicesEstimateReady = + mIsLeftDeviceEstimateReady && mIsRightDeviceEstimateReady; + int visibility = isBothDevicesEstimateReady ? View.VISIBLE : View.GONE; + ThreadUtils.postOnMainThread(() -> { + leftDeviceTextView.setVisibility(visibility); + rightDeviceTextView.setVisibility(visibility); + }); + } + private void showBatteryIcon(LinearLayout linearLayout, int level, int lowBatteryLevel, boolean charging) { final boolean enableLowBattery = level <= lowBatteryLevel && !charging; diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java index 6087ef2c2ac..51cad70763c 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -387,34 +387,52 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { } @Test - public void showBatteryPredictionIfNecessary_estimateReadyIsAvailable_showView() { - mController.showBatteryPredictionIfNecessary(1, 14218009, - mLayoutPreference.findViewById(R.id.layout_left)); - mController.showBatteryPredictionIfNecessary(1, 14218009, - mLayoutPreference.findViewById(R.id.layout_middle)); - mController.showBatteryPredictionIfNecessary(1, 14218009, - mLayoutPreference.findViewById(R.id.layout_right)); + public void estimateReadyIsBothAvailable_showsView() { + mController.mIsLeftDeviceEstimateReady = true; + mController.mIsRightDeviceEstimateReady = true; + + mController.showBothDevicesBatteryPredictionIfNecessary(); assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left), View.VISIBLE); - assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_middle), - View.VISIBLE); assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right), View.VISIBLE); } @Test - public void showBatteryPredictionIfNecessary_estimateReadyIsNotAvailable_notShowView() { - mController.showBatteryPredictionIfNecessary(0, 14218009, - mLayoutPreference.findViewById(R.id.layout_left)); - mController.showBatteryPredictionIfNecessary(0, 14218009, - mLayoutPreference.findViewById(R.id.layout_middle)); - mController.showBatteryPredictionIfNecessary(0, 14218009, - mLayoutPreference.findViewById(R.id.layout_right)); + public void leftDeviceEstimateIsReadyRightDeviceIsNotReady_notShowView() { + mController.mIsLeftDeviceEstimateReady = true; + mController.mIsRightDeviceEstimateReady = false; + + mController.showBothDevicesBatteryPredictionIfNecessary(); assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left), View.GONE); - assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_middle), + assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right), + View.GONE); + } + + @Test + public void leftDeviceEstimateIsNotReadyRightDeviceIsReady_notShowView() { + mController.mIsLeftDeviceEstimateReady = false; + mController.mIsRightDeviceEstimateReady = true; + + mController.showBothDevicesBatteryPredictionIfNecessary(); + + assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left), + View.GONE); + assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right), + View.GONE); + } + + @Test + public void bothDevicesEstimateIsNotReady_notShowView() { + mController.mIsLeftDeviceEstimateReady = false; + mController.mIsRightDeviceEstimateReady = false; + + mController.showBothDevicesBatteryPredictionIfNecessary(); + + assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left), View.GONE); assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right), View.GONE);