summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/res/values/strings.xml13
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java49
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/PowerUtilTest.java149
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java11
4 files changed, 2 insertions, 220 deletions
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 96876747c082..6eaabbb389c2 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -1098,19 +1098,6 @@
<!-- Used to let users know that they have more than some amount of battery life remaining. ex: more than 1 day remaining [CHAR LIMIT = 40] -->
<string name="power_remaining_only_more_than_subtext">More than <xliff:g id="time_remaining">%1$s</xliff:g> left</string>
- <!-- [CHAR_LIMIT=50] Short label for imminent shutdown warning of device -->
- <string name="power_remaining_duration_only_shutdown_imminent" product="default">Phone may shut down soon</string>
- <!-- [CHAR_LIMIT=50] Short label for imminent shutdown warning of device -->
- <string name="power_remaining_duration_only_shutdown_imminent" product="tablet">Tablet may shut down soon</string>
- <!-- [CHAR_LIMIT=50] Short label for imminent shutdown warning of device -->
- <string name="power_remaining_duration_only_shutdown_imminent" product="device">Device may shut down soon</string>
- <!-- [CHAR_LIMIT=60] Label for battery level chart when shutdown is imminent-->
- <string name="power_remaining_duration_shutdown_imminent" product="default">Phone may shut down soon (<xliff:g id="level">%1$s</xliff:g>)</string>
- <!-- [CHAR_LIMIT=60] Label for battery level chart when shutdown is imminent-->
- <string name="power_remaining_duration_shutdown_imminent" product="tablet">Tablet may shut down soon (<xliff:g id="level">%1$s</xliff:g>)</string>
- <!-- [CHAR_LIMIT=60] Label for battery level chart when shutdown is imminent-->
- <string name="power_remaining_duration_shutdown_imminent" product="device">Device may shut down soon (<xliff:g id="level">%1$s</xliff:g>)</string>
-
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging -->
<string name="power_charging"><xliff:g id="level">%1$s</xliff:g> - <xliff:g id="state">%2$s</xliff:g></string>
<!-- [CHAR_LIMIT=40] Label for estimated remaining duration of battery charging -->
diff --git a/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java b/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java
index 673f2438de8a..22726549ce05 100644
--- a/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java
+++ b/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java
@@ -44,45 +44,6 @@ public class PowerUtil {
private static final long ONE_MIN_MILLIS = TimeUnit.MINUTES.toMillis(1);
/**
- * This method produces the text used in various places throughout the system to describe the
- * remaining battery life of the phone in a consistent manner.
- *
- * @param context
- * @param drainTimeMs The estimated time remaining before the phone dies in milliseconds.
- * @param percentageString An optional percentage of battery remaining string.
- * @param basedOnUsage Whether this estimate is based on usage or simple extrapolation.
- * @return a properly formatted and localized string describing how much time remains
- * before the battery runs out.
- */
- public static String getBatteryRemainingStringFormatted(Context context, long drainTimeMs,
- @Nullable String percentageString, boolean basedOnUsage) {
- if (drainTimeMs > 0) {
- if (drainTimeMs <= SEVEN_MINUTES_MILLIS) {
- // show a imminent shutdown warning if less than 7 minutes remain
- return getShutdownImminentString(context, percentageString);
- } else if (drainTimeMs <= FIFTEEN_MINUTES_MILLIS) {
- // show a less than 15 min remaining warning if appropriate
- CharSequence timeString = StringUtil.formatElapsedTime(context,
- FIFTEEN_MINUTES_MILLIS,
- false /* withSeconds */, false /* collapseTimeUnit */);
- return getUnderFifteenString(context, timeString, percentageString);
- } else if (drainTimeMs >= TWO_DAYS_MILLIS) {
- // just say more than two day if over 48 hours
- return getMoreThanTwoDaysString(context, percentageString);
- } else if (drainTimeMs >= ONE_DAY_MILLIS) {
- // show remaining days & hours if more than a day
- return getMoreThanOneDayString(context, drainTimeMs,
- percentageString, basedOnUsage);
- } else {
- // show the time of day we think you'll run out
- return getRegularTimeRemainingString(context, drainTimeMs,
- percentageString, basedOnUsage);
- }
- }
- return null;
- }
-
- /**
* Method to produce a shortened string describing the remaining battery. Suitable for Quick
* Settings and other areas where space is constrained.
*
@@ -128,14 +89,6 @@ public class PowerUtil {
}
}
- private static String getShutdownImminentString(Context context, String percentageString) {
- return TextUtils.isEmpty(percentageString)
- ? context.getString(R.string.power_remaining_duration_only_shutdown_imminent)
- : context.getString(
- R.string.power_remaining_duration_shutdown_imminent,
- percentageString);
- }
-
private static String getUnderFifteenString(Context context, CharSequence timeString,
String percentageString) {
return TextUtils.isEmpty(percentageString)
@@ -268,4 +221,4 @@ public class PowerUtil {
return time - remainder + multiple;
}
}
-} \ No newline at end of file
+}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/PowerUtilTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/PowerUtilTest.java
index ae542062ce50..2e7905f2e1e4 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/PowerUtilTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/PowerUtilTest.java
@@ -59,155 +59,6 @@ public class PowerUtilTest {
}
@Test
- public void testGetBatteryRemainingStringFormatted_moreThanFifteenMinutes_withPercentage() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- SEVENTEEN_MIN_MILLIS,
- TEST_BATTERY_LEVEL_10,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- SEVENTEEN_MIN_MILLIS,
- TEST_BATTERY_LEVEL_10,
- false /* basedOnUsage */);
-
- // We only add special mention for the long string
- // ex: Will last about 1:15 PM based on your usage (10%)
- assertThat(info).containsMatch(Pattern.compile(
- NORMAL_CASE_EXPECTED_PREFIX
- + TIME_OF_DAY_REGEX
- + ENHANCED_SUFFIX
- + PERCENTAGE_REGEX));
- // shortened string should not have extra text
- // ex: Will last about 1:15 PM (10%)
- assertThat(info2).containsMatch(Pattern.compile(
- NORMAL_CASE_EXPECTED_PREFIX
- + TIME_OF_DAY_REGEX
- + PERCENTAGE_REGEX));
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_moreThanFifteenMinutes_noPercentage() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- SEVENTEEN_MIN_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- SEVENTEEN_MIN_MILLIS,
- null /* percentageString */,
- false /* basedOnUsage */);
-
- // We only have % when it is provided
- // ex: Will last about 1:15 PM based on your usage
- assertThat(info).containsMatch(Pattern.compile(
- NORMAL_CASE_EXPECTED_PREFIX
- + TIME_OF_DAY_REGEX
- + ENHANCED_SUFFIX
- + "(" + PERCENTAGE_REGEX + "){0}")); // no percentage
- // shortened string should not have extra text
- // ex: Will last about 1:15 PM
- assertThat(info2).containsMatch(Pattern.compile(
- NORMAL_CASE_EXPECTED_PREFIX
- + TIME_OF_DAY_REGEX
- + "(" + PERCENTAGE_REGEX + "){0}")); // no percentage
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_lessThanSevenMinutes_usesCorrectString() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- FIVE_MINUTES_MILLIS,
- TEST_BATTERY_LEVEL_10 /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- FIVE_MINUTES_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
-
- // additional battery percentage in this string
- assertThat(info.contains("may shut down soon (10%)")).isTrue();
- // shortened string should not have percentage
- assertThat(info2.contains("may shut down soon")).isTrue();
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_betweenSevenAndFifteenMinutes_usesCorrectString() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- TEN_MINUTES_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- TEN_MINUTES_MILLIS,
- TEST_BATTERY_LEVEL_10 /* percentageString */,
- true /* basedOnUsage */);
-
- // shortened string should not have percentage
- assertThat(info).isEqualTo("Less than 15 min left");
- // Add percentage to string when provided
- assertThat(info2).isEqualTo("Less than 15 min left (10%)");
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_betweenOneAndTwoDays_usesCorrectString() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- THIRTY_HOURS_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- THIRTY_HOURS_MILLIS,
- TEST_BATTERY_LEVEL_10 /* percentageString */,
- false /* basedOnUsage */);
- String info3 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- THIRTY_HOURS_MILLIS + TEN_MINUTES_MILLIS,
- null /* percentageString */,
- false /* basedOnUsage */);
-
- // We only add special mention for the long string
- assertThat(info).isEqualTo("About 1 day, 6 hr left based on your usage");
- // shortened string should not have extra text
- assertThat(info2).isEqualTo("About 1 day, 6 hr left (10%)");
- // present 2 time unit at most
- assertThat(info3).isEqualTo("About 1 day, 6 hr left");
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_lessThanOneDay_usesCorrectString() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- TEN_HOURS_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- TEN_HOURS_MILLIS,
- TEST_BATTERY_LEVEL_10 /* percentageString */,
- false /* basedOnUsage */);
- String info3 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- TEN_HOURS_MILLIS + TEN_MINUTES_MILLIS + TEN_SEC_MILLIS,
- null /* percentageString */,
- false /* basedOnUsage */);
-
- // We only add special mention for the long string
- assertThat(info).isEqualTo("About 10 hr left based on your usage");
- // shortened string should not have extra text
- assertThat(info2).isEqualTo("About 10 hr left (10%)");
- // present 2 time unit at most
- assertThat(info3).isEqualTo("About 10 hr, 10 min left");
- }
-
- @Test
- public void testGetBatteryRemainingStringFormatted_moreThanTwoDays_usesCorrectString() {
- String info = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- THREE_DAYS_MILLIS,
- null /* percentageString */,
- true /* basedOnUsage */);
- String info2 = PowerUtil.getBatteryRemainingStringFormatted(mContext,
- THREE_DAYS_MILLIS,
- TEST_BATTERY_LEVEL_10 /* percentageString */,
- true /* basedOnUsage */);
-
- // shortened string should not have percentage
- assertThat(info).isEqualTo("More than 2 days left");
- // Add percentage to string when provided
- assertThat(info2).isEqualTo("More than 2 days left (10%)");
- }
-
- @Test
public void getBatteryTipStringFormatted_moreThanOneDay_usesCorrectString() {
String info = PowerUtil.getBatteryTipStringFormatted(mContext,
THREE_DAYS_MILLIS);
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
index 38204ab1b6d9..a6c623391bb0 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
@@ -64,14 +64,13 @@ import com.android.internal.logging.UiEventLogger;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.settingslib.Utils;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
-import com.android.settingslib.utils.PowerUtil;
-import com.android.systemui.res.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.animation.DialogCuj;
import com.android.systemui.animation.DialogLaunchAnimator;
import com.android.systemui.broadcast.BroadcastSender;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.plugins.ActivityStarter;
+import com.android.systemui.res.R;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.BatteryController;
@@ -376,14 +375,6 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
TAG_AUTO_SAVER, SystemMessage.NOTE_AUTO_SAVER_SUGGESTION, n, UserHandle.ALL);
}
- private String getHybridContentString(String percentage) {
- return PowerUtil.getBatteryRemainingStringFormatted(
- mContext,
- mCurrentBatterySnapshot.getTimeRemainingMillis(),
- percentage,
- mCurrentBatterySnapshot.isBasedOnUsage());
- }
-
private PendingIntent pendingBroadcast(String action) {
return PendingIntent.getBroadcastAsUser(
mContext,