Update StringUtil#formatElapsedTime method (2/3)
- Update the usage and the test case
- Update discharging string to follow new string doc
Bug: 183689347
Test: make RunSettingsRoboTests
Change-Id: I1e14e7da8cb02755d8cf6e12626a0d94fad87121
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index 4c30baa..e502d65 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -364,7 +364,12 @@
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
if (estimateReady == 1) {
textView.setVisibility(View.VISIBLE);
- textView.setText(StringUtil.formatElapsedTime(mContext, batteryEstimate, false));
+ textView.setText(
+ StringUtil.formatElapsedTime(
+ mContext,
+ batteryEstimate,
+ /* withSeconds */ false,
+ /* collapseTimeUnit */ false));
} else {
textView.setVisibility(View.GONE);
}
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreference.java b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
index 9cbb921..f1728b6 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreference.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
@@ -318,7 +318,10 @@
textResourceId = R.string.no_carrier_update_text;
}
updateTime = StringUtil.formatElapsedTime(
- getContext(), updateAgeMillis, false /* withSeconds */);
+ getContext(),
+ updateAgeMillis,
+ false /* withSeconds */,
+ false /* collapseTimeUnit */);
}
carrierInfo.setText(TextUtils.expandTemplate(
getContext().getText(textResourceId),
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 399a84d..f4bdfb3 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -229,10 +229,18 @@
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
mForegroundPreference.setSummary(
TextUtils.expandTemplate(getText(R.string.battery_used_for),
- StringUtil.formatElapsedTime(context, foregroundTimeMs, false)));
+ StringUtil.formatElapsedTime(
+ context,
+ foregroundTimeMs,
+ /* withSeconds */ false,
+ /* collapseTimeUnit */ false)));
mBackgroundPreference.setSummary(
TextUtils.expandTemplate(getText(R.string.battery_active_for),
- StringUtil.formatElapsedTime(context, backgroundTimeMs, false)));
+ StringUtil.formatElapsedTime(
+ context,
+ backgroundTimeMs,
+ /* withSeconds */ false,
+ /* collapseTimeUnit */ false)));
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
index a55d0d3..4053e86 100644
--- a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
@@ -380,7 +380,7 @@
final long usageTimeMs = entry.getTimeInForegroundMs();
if (shouldShowSummary(entry) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
final CharSequence timeSequence =
- StringUtil.formatElapsedTime(mContext, usageTimeMs, false);
+ StringUtil.formatElapsedTime(mContext, usageTimeMs, false, false);
preference.setSummary(
entry.isHidden()
? timeSequence
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index a4dd86c..832936c 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -263,8 +263,11 @@
context.getString(chargingLimitedResId, info.batteryPercentString);
} else if (chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
- CharSequence timeString = StringUtil.formatElapsedTime(context,
- PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */);
+ final CharSequence timeString = StringUtil.formatElapsedTime(
+ context,
+ PowerUtil.convertUsToMs(info.remainingTimeUs),
+ false /* withSeconds */,
+ true /* collapseTimeUnit */);
int resId = R.string.power_charging_duration;
info.remainingLabel = context.getString(
R.string.power_remaining_charging_duration_only, timeString);
@@ -287,7 +290,7 @@
context,
PowerUtil.convertUsToMs(drainTimeUs),
null /* percentageString */,
- estimate.isBasedOnUsage() && !shortString
+ false /* basedOnUsage */
);
info.chargeLabel = PowerUtil.getBatteryRemainingStringFormatted(
context,
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index 0c3f42d..3c312b8 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -480,7 +480,7 @@
return mContext.getString(R.string.wifi_time_remaining, StringUtil.formatElapsedTime(
mContext,
Duration.between(now, expiryTime).getSeconds() * 1000,
- false /* withSeconds */));
+ false /* withSeconds */, false /* collapseTimeUnit */));
}
// For more than 2 days, show the expiry date
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 215cddb..5350d45 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -473,9 +473,9 @@
@Test
public void showBatteryPredictionIfNecessary_estimateReadyIsAvailable_showCorrectValue() {
final String leftBatteryPrediction =
- StringUtil.formatElapsedTime(mContext, 12000000, false).toString();
+ StringUtil.formatElapsedTime(mContext, 12000000, false, false).toString();
final String rightBatteryPrediction =
- StringUtil.formatElapsedTime(mContext, 1200000, false).toString();
+ StringUtil.formatElapsedTime(mContext, 1200000, false, false).toString();
mController.showBatteryPredictionIfNecessary(1, 12000000,
mLayoutPreference.findViewById(R.id.layout_left));
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index afec5cb..8eed2cb 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -150,10 +150,9 @@
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
true /* shortString */);
- // We only add special mention for the long string
- assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
+ // Both long and short strings should not have extra text
+ assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
assertThat(info.suggestionLabel).contains(BATTERY_RUN_OUT_PREFIX);
- // shortened string should not have extra text
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
assertThat(info2.suggestionLabel).contains(BATTERY_RUN_OUT_PREFIX);
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
index 3e0e22f..4360a09 100644
--- a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
@@ -579,7 +579,11 @@
ZoneId.of("Europe/London"));
doShouldShowRemainingTimeTest(fakeNow, timeRemainingMs);
final String expectedSummary = mContext.getString(R.string.wifi_time_remaining,
- StringUtil.formatElapsedTime(mContext, timeRemainingMs, false /* withSeconds */));
+ StringUtil.formatElapsedTime(
+ mContext,
+ timeRemainingMs,
+ false /* withSeconds */,
+ false /* collapseTimeUnit */));
final InOrder inOrder = inOrder(mMockHeaderController);
inOrder.verify(mMockHeaderController).setSecondSummary(expectedSummary);