Implement advanced device battery prediction

This CL implements prediction of advanced device to
let users know what time their advanced device will
be out of battery.

Bug: 153706138
Test: make -j42 SettingsGoogle
Change-Id: Iadf2f1fa425ff5f0fa1abed681d82d13c392db62
This commit is contained in:
Hugh Chen
2020-09-10 15:24:23 +08:00
parent f0cdd9cdb4
commit fa75a469da
4 changed files with 168 additions and 7 deletions

View File

@@ -42,6 +42,7 @@ import com.android.settings.fuelgauge.BatteryMeterView;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
@@ -285,6 +286,68 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
verify(mBitmap).recycle();
}
@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));
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));
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
View.GONE);
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_middle),
View.GONE);
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
View.GONE);
}
@Test
public void showBatteryPredictionIfNecessary_estimateReadyIsAvailable_showCorrectValue() {
final String leftBatteryPrediction =
StringUtil.formatElapsedTime(mContext, 12000000, false).toString();
final String rightBatteryPrediction =
StringUtil.formatElapsedTime(mContext, 1200000, false).toString();
mController.showBatteryPredictionIfNecessary(1, 12000000,
mLayoutPreference.findViewById(R.id.layout_left));
mController.showBatteryPredictionIfNecessary(1, 1200000,
mLayoutPreference.findViewById(R.id.layout_right));
assertBatteryPrediction(mLayoutPreference.findViewById(R.id.layout_left),
leftBatteryPrediction);
assertBatteryPrediction(mLayoutPreference.findViewById(R.id.layout_right),
rightBatteryPrediction);
}
private void assertBatteryPredictionVisible(LinearLayout linearLayout, int visible) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
assertThat(textView.getVisibility()).isEqualTo(visible);
}
private void assertBatteryPrediction(LinearLayout linearLayout, String prediction) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
assertThat(textView.getText().toString()).isEqualTo(prediction);
}
private void assertBatteryLevel(LinearLayout linearLayout, int batteryLevel) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
assertThat(textView.getText().toString()).isEqualTo(