OSDN Git Service

Update battery settings strings
authorLei Yu <jackqdyulei@google.com>
Mon, 9 Apr 2018 21:35:12 +0000 (14:35 -0700)
committerLei Yu <jackqdyulei@google.com>
Thu, 12 Apr 2018 00:50:30 +0000 (17:50 -0700)
1. Change "screenTime" to "lastFullChargeTime" in high usage dialog
2. Update "Background restriction" strings
3. Update footer string

Bug: 73018395
Test: RunSettingsRoboTests
Change-Id: I07c149123c4ee1a69dd81c9a9e6eaa5df69b60b4

res/values/strings.xml
src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java

index 029f2ad..8d81880 100644 (file)
     <string name="background_activity_title">Background restriction</string>
     <!-- Summary for the background activity [CHAR_LIMIT=120] -->
     <string name="background_activity_summary">Allow the app to run in the background</string>
-    <!-- Summary for the background activity when it is on [CHAR_LIMIT=120] -->
-    <string name="background_activity_summary_on">App can run in the background when not in use</string>
-    <!-- Summary for the background activity when it is off [CHAR_LIMIT=120] -->
-    <string name="background_activity_summary_off">App\'s background activity is limited when not in use</string>
     <!-- Summary for the background activity when it is disabled [CHAR_LIMIT=120] -->
     <string name="background_activity_summary_disabled">App not allowed to run in background</string>
     <!-- TODO: Pending UX review. Summary for the background activity when it is whitlisted [CHAR_LIMIT=120] -->
     <!-- Summary for the battery high usage tip, which presents battery may run out soon [CHAR LIMIT=NONE] -->
     <string name="battery_tip_high_usage_summary">Battery may run out soon</string>
     <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
-    <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+    <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
     <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
-    <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+    <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
     <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
-    <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last charge:</string>
+    <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
     <!-- Title for restricted app preference, showing how many app need to be restricted [CHAR LIMIT=NONE] -->
     <plurals name="battery_tip_restrict_title">
         <item quantity="one">Restrict %1$d app</item>
     </plurals>
 
     <!-- Footer message for restrict app details page -->
-    <string name="restricted_app_detail_footer">Apps shown here aren\'t behaving properly and have been using battery in the background.\n\nThese apps are now blocked from using battery in the background. As a result, some app notifications may be delayed.</string>
+    <string name="restricted_app_detail_footer">These apps have been using battery in the background. Restricted apps may not work properly and notifications may be delayed.</string>
 
     <!-- Title for auto restriction toggle -->
     <string name="battery_auto_restriction_title">Use Battery Manager</string>
     <string name="encryption_interstitial_no">No</string>
 
     <!-- Label to say yes to the question of whether app is restricted. [CHAR LIMIT=20] -->
-    <string name="restricted_true_label">App can\u2019t use battery in background</string>
+    <string name="restricted_true_label">Restricted</string>
     <!-- Label to say no to the question of whether app is restricted. [CHAR LIMIT=20] -->
     <string name="restricted_false_label">App can use battery in background</string>
 
index de88279..74c65f9 100644 (file)
@@ -102,7 +102,10 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
 
                 return new AlertDialog.Builder(context)
                         .setMessage(getString(R.string.battery_tip_dialog_message,
-                                highUsageTip.getHighUsageAppList().size()))
+                                highUsageTip.getHighUsageAppList().size(),
+                                StringUtil.formatRelativeTime(context,
+                                        highUsageTip.getLastFullChargeTimeMs(),
+                                        false /* withSeconds */)))
                         .setView(view)
                         .setPositiveButton(android.R.string.ok, null)
                         .create();
index 8435c52..b511ee0 100644 (file)
@@ -63,7 +63,8 @@ public class HighUsageDetector implements BatteryTipDetector {
 
     @Override
     public BatteryTip detect() {
-        final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
+        final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(
+                mBatteryStatsHelper, System.currentTimeMillis());
         if (mPolicy.highUsageEnabled) {
             parseBatteryData();
             if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
@@ -99,7 +100,7 @@ public class HighUsageDetector implements BatteryTipDetector {
             }
         }
 
-        return new HighUsageTip(screenUsageTimeMs, mHighUsageAppList);
+        return new HighUsageTip(lastFullChargeTimeMs, mHighUsageAppList);
     }
 
     @VisibleForTesting
index 72d1fa4..c6b235b 100644 (file)
@@ -26,7 +26,7 @@ import com.android.settings.R;
 import com.android.settings.fuelgauge.batterytip.AppInfo;
 
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.utils.StringUtil;
+
 import java.util.List;
 
 /**
@@ -34,28 +34,28 @@ import java.util.List;
  */
 public class HighUsageTip extends BatteryTip {
 
-    private final long mScreenTimeMs;
+    private final long mLastFullChargeTimeMs;
     @VisibleForTesting
     final List<AppInfo> mHighUsageAppList;
 
-    public HighUsageTip(long screenTimeMs, List<AppInfo> appList) {
+    public HighUsageTip(long lastFullChargeTimeMs, List<AppInfo> appList) {
         super(TipType.HIGH_DEVICE_USAGE, appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
                 true /* showDialog */);
-        mScreenTimeMs = screenTimeMs;
+        mLastFullChargeTimeMs = lastFullChargeTimeMs;
         mHighUsageAppList = appList;
     }
 
     @VisibleForTesting
     HighUsageTip(Parcel in) {
         super(in);
-        mScreenTimeMs = in.readLong();
+        mLastFullChargeTimeMs = in.readLong();
         mHighUsageAppList = in.createTypedArrayList(AppInfo.CREATOR);
     }
 
     @Override
     public void writeToParcel(Parcel dest, int flags) {
         super.writeToParcel(dest, flags);
-        dest.writeLong(mScreenTimeMs);
+        dest.writeLong(mLastFullChargeTimeMs);
         dest.writeTypedList(mHighUsageAppList);
     }
 
@@ -91,8 +91,8 @@ public class HighUsageTip extends BatteryTip {
         }
     }
 
-    public long getScreenTimeMs() {
-        return mScreenTimeMs;
+    public long getLastFullChargeTimeMs() {
+        return mLastFullChargeTimeMs;
     }
 
     public List<AppInfo> getHighUsageAppList() {
index 5e045c1..389b714 100644 (file)
@@ -183,7 +183,7 @@ public class BackgroundActivityPreferenceControllerTest {
 
         mController.updateSummary(mPreference);
 
-        assertThat(mPreference.getSummary()).isEqualTo("App can\u2019t use battery in background");
+        assertThat(mPreference.getSummary()).isEqualTo("Restricted");
     }
 
     @Test
index e07df09..1de1e48 100644 (file)
@@ -112,8 +112,8 @@ public class BatteryTipDialogFragmentTest {
         final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
         ShadowAlertDialog shadowDialog = shadowOf(dialog);
 
-        assertThat(shadowDialog.getMessage())
-                .isEqualTo(mContext.getString(R.string.battery_tip_dialog_message, 1));
+        assertThat(shadowDialog.getMessage()).isEqualTo(
+                mContext.getString(R.string.battery_tip_dialog_message, 1, "60 minutes ago"));
     }
 
     @Test
index ca1cba3..1ff21f8 100644 (file)
@@ -43,6 +43,7 @@ public class HighUsageTipTest {
 
     private static final String PACKAGE_NAME = "com.android.app";
     private static final long SCREEN_TIME = 30 * DateUtils.MINUTE_IN_MILLIS;
+    private static final long LAST_FULL_CHARGE_TIME = 20 * DateUtils.MINUTE_IN_MILLIS;
 
     @Mock
     private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -60,7 +61,7 @@ public class HighUsageTipTest {
                 .setPackageName(PACKAGE_NAME)
                 .setScreenOnTimeMs(SCREEN_TIME)
                 .build());
-        mBatteryTip = new HighUsageTip(SCREEN_TIME, mUsageAppList);
+        mBatteryTip = new HighUsageTip(LAST_FULL_CHARGE_TIME, mUsageAppList);
     }
 
     @Test
@@ -75,7 +76,7 @@ public class HighUsageTipTest {
         assertThat(parcelTip.getTitle(mContext)).isEqualTo("Phone used more than usual");
         assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.HIGH_DEVICE_USAGE);
         assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
-        assertThat(parcelTip.getScreenTimeMs()).isEqualTo(SCREEN_TIME);
+        assertThat(parcelTip.getLastFullChargeTimeMs()).isEqualTo(LAST_FULL_CHARGE_TIME);
         assertThat(parcelTip.mHighUsageAppList).isNotNull();
         assertThat(parcelTip.mHighUsageAppList.size()).isEqualTo(1);
         final AppInfo app = parcelTip.mHighUsageAppList.get(0);