Merge "Fix b/265054711: Settings crash on changing device orientation from battery usage page."
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 00a15a0..b2d85da 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5031,42 +5031,14 @@
     <!-- Title for battery usage amount by this app. [CHAR LIMIT=80] -->
     <string name="battery_detail_power_usage">Battery usage</string>
 
-    <!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background since last full charge. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_and_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background\nsince last full charge</string>
-    <!-- Description for battery total and background usage time in a time period for an app, i.e. 1 hr 15 min total • 39 min background for 12 am-2 am. Note: ^1, ^2 and ^3 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_and_bg_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background\nfor <xliff:g id="time_period" example="12 am-2 am">^3</xliff:g></string>
-
-    <!-- Description for battery total usage time is less than a minute for an app since last full charge [CHAR LIMIT=120] -->
-    <string name="battery_total_usage_less_minute">Total less than a minute since last full charge</string>
-    <!-- Description for battery total usage time is less than a minute in a time period for an app, i.e. Total less than a minute for 12 am-2 am. Note: ^1 should be used in all translations[CHAR LIMIT=120] -->
-    <string name="battery_total_usage_less_minute_with_period">Total less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string>
-
-    <!-- Description for battery background usage time is less than a minute for an app since last full charge [CHAR LIMIT=120] -->
-    <string name="battery_bg_usage_less_minute">Background less than a minute since last full charge</string>
-    <!-- Description for battery background usage time is less than a minute in a time period for an app, i.e. Background less than a minute for 12 am-2 am. Note: ^1 should be used in all translations[CHAR LIMIT=120] -->
-    <string name="battery_bg_usage_less_minute_with_period">Background less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string>
-
-    <!-- Description for battery total usage time for an app, i.e. 1 hr 15 min total since last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total since last full charge</string>
-    <!-- Description for battery total usage time in a time period for an app, i.e. 1 hr 15 min total for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
-
-    <!-- Description for battery background usage time for an app, i.e. 1 hr 15 min background since last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background since last full charge</string>
-    <!-- Description for battery background usage time in a time period for an app, i.e. 1 hr 15 min background for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_bg_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
-
-    <!-- Description for battery total usage with background usage time less than a minute for an app, i.e. 1 hr 15 min total • background less than a minute since last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_usage_and_bg_less_minute_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute\nsince last full charge</string>
-    <!-- Description for battery total usage with background usage time less than a minute in a time period for an app, i.e. 1 hr 15 min total • background less than a minute for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
-    <string name="battery_total_usage_and_bg_less_minute_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute\nfor <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
-
     <!-- Description for no any battery usage since last full charge [CHAR LIMIT=120] -->
     <string name="battery_not_usage">No usage since last full charge</string>
     <!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] -->
     <string name="battery_not_usage_24hr">No usage for past 24 hr</string>
     <!-- Description for no usage time but have battery usage [CHAR LIMIT=120] -->
     <string name="battery_usage_without_time"></string>
+    <!-- Description for the specific time slot in the battery usage page [CHAR LIMIT=120] -->
+    <string name="battery_usage_since_last_full_charge">since last full charge</string>
    <!-- Description for system apps aggregated battery usage data [CHAR LIMIT=120] -->
     <string name="battery_usage_system_apps">System apps</string>
     <!-- Description for others battery usage data [CHAR LIMIT=120] -->
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java b/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java
new file mode 100644
index 0000000..184e1d1
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics2.ui.model;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+/**
+ * Enrolling status message (help or error)
+ */
+public final class EnrollmentStatusMessage {
+
+    private final int mMsgId;
+    @NonNull private final CharSequence mStr;
+
+    public EnrollmentStatusMessage(int msgId, @Nullable CharSequence str) {
+        mMsgId = msgId;
+        mStr = str != null ? str : "";
+    }
+
+    public int getMsgId() {
+        return mMsgId;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
+                + "{id:" + mMsgId + ", str:" + mStr + "}";
+    }
+
+    /**
+     * Gets status string
+     */
+    @NonNull
+    public CharSequence getStr() {
+        return mStr;
+    }
+}
diff --git a/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollProgressViewModel.java b/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollProgressViewModel.java
index cec9475..0483c6f 100644
--- a/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollProgressViewModel.java
+++ b/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollProgressViewModel.java
@@ -38,6 +38,7 @@
 import com.android.settings.biometrics.fingerprint.FingerprintUpdater;
 import com.android.settings.biometrics.fingerprint.MessageDisplayController;
 import com.android.settings.biometrics2.ui.model.EnrollmentProgress;
+import com.android.settings.biometrics2.ui.model.EnrollmentStatusMessage;
 
 /**
  * Progress ViewModel handles the state around biometric enrollment. It manages the state of
@@ -51,6 +52,10 @@
 
     private final MutableLiveData<EnrollmentProgress> mProgressLiveData = new MutableLiveData<>(
             new EnrollmentProgress(INITIAL_STEPS, INITIAL_REMAINING));
+    private final MutableLiveData<EnrollmentStatusMessage> mHelpMessageLiveData =
+            new MutableLiveData<>();
+    private final MutableLiveData<EnrollmentStatusMessage> mErrorMessageLiveData =
+            new MutableLiveData<>();
 
     private byte[] mToken = null;
     private int mUserId = UserHandle.myUserId();
@@ -75,12 +80,12 @@
 
         @Override
         public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
-            // TODO add LiveData for help message during implementing b/260957933
+            mHelpMessageLiveData.postValue(new EnrollmentStatusMessage(helpMsgId, helpString));
         }
 
         @Override
         public void onEnrollmentError(int errMsgId, CharSequence errString) {
-            // TODO add LiveData for error message during implementing b/260957933
+            mErrorMessageLiveData.postValue(new EnrollmentStatusMessage(errMsgId, errString));
         }
     };
 
@@ -91,15 +96,16 @@
         final Resources res = application.getResources();
         mMessageDisplayController =
                 res.getBoolean(R.bool.enrollment_message_display_controller_flag)
-                ? new MessageDisplayController(
-                        application.getMainThreadHandler(),
-                        mEnrollmentCallback,
-                        SystemClock.elapsedRealtimeClock(),
-                        res.getInteger(R.integer.enrollment_help_minimum_time_display),
-                        res.getInteger(R.integer.enrollment_progress_minimum_time_display),
-                        res.getBoolean(R.bool.enrollment_progress_priority_over_help),
-                        res.getBoolean(R.bool.enrollment_prioritize_acquire_messages),
-                        res.getInteger(R.integer.enrollment_collect_time)) : null;
+                        ? new MessageDisplayController(
+                                application.getMainThreadHandler(),
+                                mEnrollmentCallback,
+                                SystemClock.elapsedRealtimeClock(),
+                                res.getInteger(R.integer.enrollment_help_minimum_time_display),
+                                res.getInteger(R.integer.enrollment_progress_minimum_time_display),
+                                res.getBoolean(R.bool.enrollment_progress_priority_over_help),
+                                res.getBoolean(R.bool.enrollment_prioritize_acquire_messages),
+                                res.getInteger(R.integer.enrollment_collect_time))
+                        : null;
     }
 
     public void setToken(byte[] token) {
@@ -121,6 +127,14 @@
         return mProgressLiveData;
     }
 
+    public LiveData<EnrollmentStatusMessage> getHelpMessageLiveData() {
+        return mHelpMessageLiveData;
+    }
+
+    public LiveData<EnrollmentStatusMessage> getErrorMessageLiveData() {
+        return mErrorMessageLiveData;
+    }
+
     /**
      * Starts enrollment and return latest isEnrolling() result
      */
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index e091300..e9818fb 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -26,7 +26,6 @@
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.text.TextUtils;
-import android.text.format.DateUtils;
 import android.util.Log;
 import android.view.View;
 
@@ -51,7 +50,6 @@
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.instrumentation.Instrumentable;
-import com.android.settingslib.utils.StringUtil;
 import com.android.settingslib.widget.FooterPreference;
 import com.android.settingslib.widget.LayoutPreference;
 import com.android.settingslib.widget.SelectorWithWidgetPreference;
@@ -74,6 +72,7 @@
     public static final String EXTRA_PACKAGE_NAME = "extra_package_name";
     public static final String EXTRA_FOREGROUND_TIME = "extra_foreground_time";
     public static final String EXTRA_BACKGROUND_TIME = "extra_background_time";
+    public static final String EXTRA_SCREEN_ON_TIME = "extra_screen_on_time";
     public static final String EXTRA_SLOT_TIME = "extra_slot_time";
     public static final String EXTRA_LABEL = "extra_label";
     public static final String EXTRA_ICON_ID = "extra_icon_id";
@@ -87,6 +86,8 @@
     private static final String KEY_FOOTER_PREFERENCE = "app_usage_footer_preference";
     private static final String PACKAGE_NAME_NONE = "none";
 
+    private static final String HEADER_SUMMARY_FORMAT = "%s\n(%s)";
+
     private static final int REQUEST_UNINSTALL = 0;
     private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1;
 
@@ -129,6 +130,7 @@
         private int mConsumedPower;
         private long mForegroundTimeMs;
         private long mBackgroundTimeMs;
+        private long mScreenOnTimeMs;
         private boolean mIsUserEntry;
     }
 
@@ -156,6 +158,7 @@
         launchArgs.mConsumedPower = (int) diffEntry.mConsumePower;
         launchArgs.mForegroundTimeMs = diffEntry.mForegroundUsageTimeInMs;
         launchArgs.mBackgroundTimeMs = diffEntry.mBackgroundUsageTimeInMs;
+        launchArgs.mScreenOnTimeMs = diffEntry.mScreenOnTimeInMs;
         launchArgs.mIsUserEntry = histEntry.isUserEntry();
         startBatteryDetailPage(context, sourceMetricsCategory, launchArgs);
     }
@@ -191,6 +194,7 @@
         args.putInt(EXTRA_UID, launchArgs.mUid);
         args.putLong(EXTRA_BACKGROUND_TIME, launchArgs.mBackgroundTimeMs);
         args.putLong(EXTRA_FOREGROUND_TIME, launchArgs.mForegroundTimeMs);
+        args.putLong(EXTRA_SCREEN_ON_TIME, launchArgs.mScreenOnTimeMs);
         args.putString(EXTRA_SLOT_TIME, launchArgs.mSlotInformation);
         args.putString(EXTRA_POWER_USAGE_PERCENT, launchArgs.mUsagePercent);
         args.putInt(EXTRA_POWER_USAGE_AMOUNT, launchArgs.mConsumedPower);
@@ -323,7 +327,7 @@
             controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
         }
 
-        controller.setSummary(getAppActiveTime(bundle));
+        controller.setSummary(getHeaderSummary(bundle));
         controller.done(context, true /* rebindActions */);
     }
 
@@ -474,113 +478,20 @@
         }
     }
 
-    private CharSequence getAppActiveTime(Bundle bundle) {
+    private CharSequence getHeaderSummary(Bundle bundle) {
         final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
         final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
+        final long screenOnTimeInMs = bundle.getLong(EXTRA_SCREEN_ON_TIME);
         final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
-        final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
-        final CharSequence usageTimeSummary;
+        final String usageSummary = BatteryUtils.buildBatteryUsageTimeSummary(getContext(),
+                /* isSystem= */ false, foregroundTimeMs, backgroundTimeMs, screenOnTimeInMs);
 
-        if (totalTimeMs == 0) {
-            usageTimeSummary = getText(R.string.battery_usage_without_time);
-        } else if (slotTime == null) {
-            // Shows summary text with last full charge if slot time is null.
-            usageTimeSummary = getAppFullChargeActiveSummary(
-                    foregroundTimeMs, backgroundTimeMs, totalTimeMs);
+        if (usageSummary.isEmpty()) {
+            return getText(R.string.battery_usage_without_time);
         } else {
-            // Shows summary text with slot time.
-            usageTimeSummary = getAppActiveSummaryWithSlotTime(
-                    foregroundTimeMs, backgroundTimeMs, totalTimeMs, slotTime);
-        }
-        return usageTimeSummary;
-    }
-
-    private CharSequence getAppFullChargeActiveSummary(
-            long foregroundTimeMs, long backgroundTimeMs, long totalTimeMs) {
-        // Shows background summary only if we don't have foreground usage time.
-        if (foregroundTimeMs == 0 && backgroundTimeMs != 0) {
-            return backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS ?
-                    getText(R.string.battery_bg_usage_less_minute) :
-                    TextUtils.expandTemplate(getText(R.string.battery_bg_usage),
-                            StringUtil.formatElapsedTime(
-                                    getContext(),
-                                    backgroundTimeMs,
-                                    /* withSeconds */ false,
-                                    /* collapseTimeUnit */ false));
-        // Shows total usage summary only if total usage time is small.
-        } else if (totalTimeMs < DateUtils.MINUTE_IN_MILLIS) {
-            return getText(R.string.battery_total_usage_less_minute);
-        // Shows different total usage summary when background usage time is small.
-        } else if (backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS) {
-            return TextUtils.expandTemplate(
-                    getText(backgroundTimeMs == 0 ?
-                            R.string.battery_total_usage :
-                            R.string.battery_total_usage_and_bg_less_minute_usage),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            totalTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false));
-        // Shows default summary.
-        } else {
-            return TextUtils.expandTemplate(
-                    getText(R.string.battery_total_and_bg_usage),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            totalTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            backgroundTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false));
-        }
-    }
-
-    private CharSequence getAppActiveSummaryWithSlotTime(
-            long foregroundTimeMs, long backgroundTimeMs, long totalTimeMs, String slotTime) {
-        // Shows background summary only if we don't have foreground usage time.
-        if (foregroundTimeMs == 0 && backgroundTimeMs != 0) {
-            return backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS ?
-                    TextUtils.expandTemplate(
-                            getText(R.string.battery_bg_usage_less_minute_with_period),
-                            slotTime) :
-                    TextUtils.expandTemplate(getText(R.string.battery_bg_usage_with_period),
-                            StringUtil.formatElapsedTime(
-                                    getContext(),
-                                    backgroundTimeMs,
-                                    /* withSeconds */ false,
-                                    /* collapseTimeUnit */ false), slotTime);
-        // Shows total usage summary only if total usage time is small.
-        } else if (totalTimeMs < DateUtils.MINUTE_IN_MILLIS) {
-            return TextUtils.expandTemplate(
-                    getText(R.string.battery_total_usage_less_minute_with_period), slotTime);
-        // Shows different total usage summary when background usage time is small.
-        } else if (backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS) {
-            return TextUtils.expandTemplate(
-                    getText(backgroundTimeMs == 0 ?
-                            R.string.battery_total_usage_with_period :
-                            R.string.battery_total_usage_and_bg_less_minute_usage_with_period),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            totalTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false), slotTime);
-        // Shows default summary.
-        } else {
-            return TextUtils.expandTemplate(
-                    getText(R.string.battery_total_and_bg_usage_with_period),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            totalTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false),
-                    StringUtil.formatElapsedTime(
-                            getContext(),
-                            backgroundTimeMs,
-                            /* withSeconds */ false,
-                            /* collapseTimeUnit */ false), slotTime);
+            CharSequence slotSummary = slotTime == null
+                    ? getText(R.string.battery_usage_since_last_full_charge) : slotTime;
+            return String.format("%s\n(%s)", usageSummary, slotSummary);
         }
     }
 }
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 7b44fd3..98defbd 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -34,6 +34,7 @@
 import android.os.UidBatteryConsumer;
 import android.os.UserHandle;
 import android.provider.Settings;
+import android.text.format.DateUtils;
 import android.util.Base64;
 import android.util.Log;
 
@@ -43,6 +44,7 @@
 import androidx.annotation.WorkerThread;
 
 import com.android.internal.util.ArrayUtils;
+import com.android.settings.R;
 import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
 import com.android.settings.fuelgauge.batterytip.AnomalyInfo;
 import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
@@ -53,6 +55,7 @@
 import com.android.settingslib.fuelgauge.EstimateKt;
 import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
 import com.android.settingslib.utils.PowerUtil;
+import com.android.settingslib.utils.StringUtil;
 import com.android.settingslib.utils.ThreadUtils;
 
 import com.google.protobuf.InvalidProtocolBufferException;
@@ -616,4 +619,45 @@
         }
         return DockDefenderMode.DISABLED;
     }
+
+    /** Builds the battery usage time summary. */
+    public static String buildBatteryUsageTimeSummary(final Context context, final boolean isSystem,
+            final long foregroundUsageTimeInMs, final long backgroundUsageTimeInMs,
+            final long screenOnTimeInMs) {
+        StringBuilder summary = new StringBuilder();
+        if (isSystem) {
+            final long totalUsageTimeInMs = foregroundUsageTimeInMs + backgroundUsageTimeInMs;
+            if (totalUsageTimeInMs != 0) {
+                summary.append(buildBatteryUsageTimeInfo(context, totalUsageTimeInMs,
+                        R.string.battery_usage_total_less_than_one_minute,
+                        R.string.battery_usage_for_total_time));
+            }
+        } else {
+            if (screenOnTimeInMs != 0) {
+                summary.append(buildBatteryUsageTimeInfo(context, screenOnTimeInMs,
+                        R.string.battery_usage_screen_time_less_than_one_minute,
+                        R.string.battery_usage_screen_time));
+            }
+            if (screenOnTimeInMs != 0 && backgroundUsageTimeInMs != 0) {
+                summary.append('\n');
+            }
+            if (backgroundUsageTimeInMs != 0) {
+                summary.append(buildBatteryUsageTimeInfo(context, backgroundUsageTimeInMs,
+                        R.string.battery_usage_background_less_than_one_minute,
+                        R.string.battery_usage_for_background_time));
+            }
+        }
+        return summary.toString();
+    }
+
+    /** Builds the battery usage time information for one timestamp. */
+    private static String buildBatteryUsageTimeInfo(final Context context, long timeInMs,
+            final int lessThanOneMinuteResId, final int normalResId) {
+        if (timeInMs < DateUtils.MINUTE_IN_MILLIS) {
+            return context.getString(lessThanOneMinuteResId);
+        }
+        final CharSequence timeSequence = StringUtil.formatElapsedTime(
+                context, (double) timeInMs, /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
+        return context.getString(normalResId, timeSequence);
+    }
 }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 69ae478..c151517 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -36,6 +36,11 @@
     boolean isBatteryUsageEnabled();
 
     /**
+     * Returns a threshold (mA) for the minimal comsume power in battery usage list
+     */
+    double getBatteryUsageListConsumePowerThreshold();
+
+    /**
      * Returns an allowlist of app names combined into the system-apps item
      */
     List<String> getSystemAppsAllowlist();
@@ -46,7 +51,7 @@
     boolean isLocationSettingEnabled(String[] packages);
 
     /**
-     * Gets an {@link Intent} to show additional battery info.
+     * Gets an {@link Intent} to show additional battery info
      */
     Intent getAdditionalBatteryInfoIntent();
 
@@ -61,37 +66,37 @@
     boolean isTypeSystem(int uid, String[] packages);
 
     /**
-     * Returns an improved prediction for battery time remaining.
+     * Returns an improved prediction for battery time remaining
      */
     Estimate getEnhancedBatteryPrediction(Context context);
 
     /**
-     * Returns an improved projection curve for future battery level.
+     * Returns an improved projection curve for future battery level
      *
      * @param zeroTime timestamps (array keys) are shifted by this amount
      */
     SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime);
 
     /**
-     * Checks whether the toggle for enhanced battery predictions is enabled.
+     * Checks whether the toggle for enhanced battery predictions is enabled
      */
     boolean isEnhancedBatteryPredictionEnabled(Context context);
 
     /**
-     * Checks whether debugging should be enabled for battery estimates.
+     * Checks whether debugging should be enabled for battery estimates
      */
     boolean isEstimateDebugEnabled();
 
     /**
      * Converts the provided string containing the remaining time into a debug string for enhanced
-     * estimates.
+     * estimates
      *
      * @return A string containing the estimate and a label indicating it is an enhanced estimate
      */
     String getEnhancedEstimateDebugString(String timeRemaining);
 
     /**
-     * Converts the provided string containing the remaining time into a debug string.
+     * Converts the provided string containing the remaining time into a debug string
      *
      * @return A string containing the estimate and a label indicating it is a normal estimate
      */
@@ -103,7 +108,7 @@
     boolean isSmartBatterySupported();
 
     /**
-     * Checks whether we should show usage information by slots or not.
+     * Checks whether we should show usage information by slots or not
      */
     boolean isChartGraphSlotsEnabled(Context context);
 
@@ -123,7 +128,7 @@
     boolean isExtraDefend();
 
     /**
-     * Returns {@code true} if delay the hourly job when device is booting.
+     * Returns {@code true} if delay the hourly job when device is booting
      */
     boolean delayHourlyJobWhenBooting();
 
@@ -133,27 +138,27 @@
     Intent getResumeChargeIntent(boolean isDockDefender);
 
     /**
-     * Returns {@link Set} for the system component ids which are combined into others.
+     * Returns {@link Set} for the system component ids which are combined into others
      */
     Set<Integer> getOthersSystemComponentSet();
 
     /**
-     * Returns {@link Set} for hiding system component ids in the usage screen.
+     * Returns {@link Set} for hiding system component ids in the usage screen
      */
     Set<Integer> getHideSystemComponentSet();
 
     /**
-     * Returns {@link Set} for hiding application package names in the usage screen.
+     * Returns {@link Set} for hiding application package names in the usage screen
      */
     Set<String> getHideApplicationSet();
 
     /**
-     * Returns {@link Set} for hiding applications background usage time.
+     * Returns {@link Set} for hiding applications background usage time
      */
     Set<String> getHideBackgroundUsageTimeSet();
 
     /**
-     * Returns {@link Set} for ignoring task root class names for screen on time.
+     * Returns {@link Set} for ignoring task root class names for screen on time
      */
     Set<String> getIgnoreScreenOnTimeTaskRootSet();
 }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 399d478..657e5c6 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -72,6 +72,11 @@
     }
 
     @Override
+    public double getBatteryUsageListConsumePowerThreshold() {
+        return 0.0;
+    }
+
+    @Override
     public List<String> getSystemAppsAllowlist() {
         return null;
     }
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
index a1a92bf..a3c77de 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffData.java
@@ -48,7 +48,7 @@
         if (!isAccumulated) {
             final PowerUsageFeatureProvider featureProvider =
                     FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
-            purgeFakeAndHiddenPackages(featureProvider);
+            purgeBatteryDiffData(featureProvider);
             combineBatteryDiffEntry(context, featureProvider);
         }
 
@@ -65,9 +65,9 @@
     }
 
     /** Removes fake usage data and hidden packages. */
-    private void purgeFakeAndHiddenPackages(final PowerUsageFeatureProvider featureProvider) {
-        purgeFakeAndHiddenPackages(featureProvider, mAppEntries);
-        purgeFakeAndHiddenPackages(featureProvider, mSystemEntries);
+    private void purgeBatteryDiffData(final PowerUsageFeatureProvider featureProvider) {
+        purgeBatteryDiffData(featureProvider, mAppEntries);
+        purgeBatteryDiffData(featureProvider, mSystemEntries);
     }
 
     /** Combines into SystemAppsBatteryDiffEntry and OthersBatteryDiffEntry. */
@@ -89,9 +89,11 @@
         Collections.sort(mSystemEntries, BatteryDiffEntry.COMPARATOR);
     }
 
-    private static void purgeFakeAndHiddenPackages(
+    private static void purgeBatteryDiffData(
             final PowerUsageFeatureProvider featureProvider,
             final List<BatteryDiffEntry> entries) {
+        final double consumePowerThreshold =
+                featureProvider.getBatteryUsageListConsumePowerThreshold();
         final Set<Integer> hideSystemComponentSet = featureProvider.getHideSystemComponentSet();
         final Set<String> hideBackgroundUsageTimeSet =
                 featureProvider.getHideBackgroundUsageTimeSet();
@@ -99,9 +101,11 @@
         final Iterator<BatteryDiffEntry> iterator = entries.iterator();
         while (iterator.hasNext()) {
             final BatteryDiffEntry entry = iterator.next();
+            final double comsumePower = entry.mConsumePower;
             final String packageName = entry.getPackageName();
             final Integer componentId = entry.mBatteryHistEntry.mDrainType;
-            if (ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
+            if (comsumePower < consumePowerThreshold
+                    || ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
                     || hideSystemComponentSet.contains(componentId)
                     || (packageName != null && hideApplicationSet.contains(packageName))) {
                 iterator.remove();
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
index 1bb3d01..b95920e 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
@@ -22,7 +22,6 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.text.TextUtils;
-import android.text.format.DateUtils;
 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
@@ -38,12 +37,12 @@
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.core.InstrumentedPreferenceFragment;
 import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
+import com.android.settings.fuelgauge.BatteryUtils;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnDestroy;
-import com.android.settingslib.utils.StringUtil;
 import com.android.settingslib.widget.FooterPreference;
 
 import java.util.HashMap;
@@ -296,43 +295,9 @@
     @VisibleForTesting
     void setPreferenceSummary(
             PowerGaugePreference preference, BatteryDiffEntry entry) {
-        final long screenOnTimeInMs = entry.mScreenOnTimeInMs;
-        final long foregroundUsageTimeInMs = entry.mForegroundUsageTimeInMs;
-        final long backgroundUsageTimeInMs = entry.mBackgroundUsageTimeInMs;
-        final long totalUsageTimeInMs = foregroundUsageTimeInMs + backgroundUsageTimeInMs;
-
-        StringBuilder usageTimeSummary = new StringBuilder();
-        if (entry.isSystemEntry()) {
-            if (totalUsageTimeInMs != 0) {
-                usageTimeSummary.append(buildUsageTimeInfo(totalUsageTimeInMs,
-                        R.string.battery_usage_total_less_than_one_minute,
-                        R.string.battery_usage_for_total_time));
-            }
-        } else {
-            if (screenOnTimeInMs != 0) {
-                usageTimeSummary.append(buildUsageTimeInfo(screenOnTimeInMs,
-                        R.string.battery_usage_screen_time_less_than_one_minute,
-                        R.string.battery_usage_screen_time));
-            }
-            if (screenOnTimeInMs != 0 && backgroundUsageTimeInMs != 0) {
-                usageTimeSummary.append('\n');
-            }
-            if (backgroundUsageTimeInMs != 0) {
-                usageTimeSummary.append(buildUsageTimeInfo(backgroundUsageTimeInMs,
-                        R.string.battery_usage_background_less_than_one_minute,
-                        R.string.battery_usage_for_background_time));
-            }
-        }
-        preference.setSummary(usageTimeSummary);
-    }
-
-    private String buildUsageTimeInfo(long timeInMs, int lessThanOneMinuteResId, int normalResId) {
-        if (timeInMs < DateUtils.MINUTE_IN_MILLIS) {
-            return mPrefContext.getString(lessThanOneMinuteResId);
-        }
-        final CharSequence timeSequence =
-                StringUtil.formatElapsedTime(mPrefContext, (double) timeInMs,
-                        /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
-        return mPrefContext.getString(normalResId, timeSequence);
+        preference.setSummary(
+                BatteryUtils.buildBatteryUsageTimeSummary(mPrefContext, entry.isSystemEntry(),
+                        entry.mForegroundUsageTimeInMs, entry.mBackgroundUsageTimeInMs,
+                        entry.mScreenOnTimeInMs));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index d39ba48..6363a8f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -89,7 +89,6 @@
     private static final String SLOT_TIME = "12 am-2 am";
     private static final int ICON_ID = 123;
     private static final int UID = 1;
-    private static final int POWER_MAH = 150;
     private static final long BACKGROUND_TIME_MS = 100;
     private static final long FOREGROUND_ACTIVITY_TIME_MS = 123;
     private static final long FOREGROUND_SERVICE_TIME_MS = 444;
@@ -270,10 +269,11 @@
     }
 
     @Test
-    public void initHeader_noUsageTime_hasCorrectSummary() {
-        Bundle bundle = new Bundle(2);
+    public void initHeader_noAnyTimeNoConsumedPower_hasEmptySummary() {
+        Bundle bundle = new Bundle();
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
         when(mFragment.getArguments()).thenReturn(bundle);
 
         mFragment.initHeader();
@@ -284,10 +284,11 @@
     }
 
     @Test
-    public void initHeader_noUsageTimeButConsumedPower_hasEmptySummary() {
-        Bundle bundle = new Bundle(3);
+    public void initHeader_noAnyTimeButConsumedPower_hasEmptySummary() {
+        Bundle bundle = new Bundle();
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
         bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
         when(mFragment.getArguments()).thenReturn(bundle);
 
@@ -299,12 +300,14 @@
     }
 
     @Test
-    public void initHeader_backgroundTwoMinForegroundZero_hasCorrectSummary() {
+    public void initHeader_ScreenTimeZerobackgroundTwoMin_hasCorrectSummary() {
         final long backgroundTimeTwoMinutes = 120000;
         final long foregroundTimeZero = 0;
-        Bundle bundle = new Bundle(2);
+        final long screenOnTimeZero = 0;
+        Bundle bundle = new Bundle();
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
         when(mFragment.getArguments()).thenReturn(bundle);
 
         mFragment.initHeader();
@@ -312,17 +315,19 @@
         ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
         verify(mEntityHeaderController).setSummary(captor.capture());
         assertThat(captor.getValue().toString())
-                .isEqualTo("2 min background since last full charge");
+                .isEqualTo("Background: 2 min\n(since last full charge)");
     }
 
     @Test
-    public void initHeader_backgroundLessThanAMinForegroundZero_hasCorrectSummary() {
+    public void initHeader_ScreenTimeZerobackgroundLessThanAMin_hasCorrectSummary() {
         final long backgroundTimeLessThanAMinute = 59999;
         final long foregroundTimeZero = 0;
-        Bundle bundle = new Bundle(2);
+        final long screenOnTimeZero = 0;
+        Bundle bundle = new Bundle();
         bundle.putLong(
                 AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
         when(mFragment.getArguments()).thenReturn(bundle);
 
         mFragment.initHeader();
@@ -330,35 +335,18 @@
         ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
         verify(mEntityHeaderController).setSummary(captor.capture());
         assertThat(captor.getValue().toString())
-                .isEqualTo("Background less than a minute since last full charge");
+                .isEqualTo("Background: less than a min\n(since last full charge)");
     }
 
     @Test
-    public void initHeader_totalUsageLessThanAMin_hasCorrectSummary() {
-        final long backgroundTimeLessThanHalfMinute = 20000;
-        final long foregroundTimeLessThanHalfMinute = 20000;
-        Bundle bundle = new Bundle(2);
-        bundle.putLong(
-                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanHalfMinute);
-        bundle.putLong(
-                AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeLessThanHalfMinute);
-        when(mFragment.getArguments()).thenReturn(bundle);
-
-        mFragment.initHeader();
-
-        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
-        verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("Total less than a minute since last full charge");
-    }
-
-    @Test
-    public void initHeader_TotalAMinutesBackgroundLessThanAMin_hasCorrectSummary() {
-        final long backgroundTimeZero = 59999;
-        final long foregroundTimeTwoMinutes = 1;
-        Bundle bundle = new Bundle(2);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
+    public void initHeader_ScreenTimeAMinuteBackgroundTwoMin_hasCorrectSummary() {
+        final long backgroundTimeTwoMinutes = 120000;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
         when(mFragment.getArguments()).thenReturn(bundle);
 
         mFragment.initHeader();
@@ -366,106 +354,149 @@
         ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
         verify(mEntityHeaderController).setSummary(captor.capture());
         assertThat(captor.getValue().toString()).isEqualTo(
-                "1 min total • background less than a minute\nsince last full charge");
+                "Screen time: 1 min\nBackground: 2 min\n(since last full charge)");
     }
 
     @Test
-    public void initHeader_TotalAMinBackgroundZero_hasCorrectSummary() {
-        final long backgroundTimeZero = 0;
-        final long foregroundTimeAMinutes = 60000;
-        Bundle bundle = new Bundle(2);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeAMinutes);
-        when(mFragment.getArguments()).thenReturn(bundle);
-
-        mFragment.initHeader();
-
-        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
-        verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("1 min total since last full charge");
-    }
-
-    @Test
-    public void initHeader_foregroundTwoMinBackgroundFourMin_hasCorrectSummary() {
-        final long backgroundTimeFourMinute = 240000;
+    public void initHeader_ScreenTimeAMinuteBackgroundLessThanAMin_hasCorrectSummary() {
+        final long backgroundTimeLessThanAMinute = 59999;
         final long foregroundTimeTwoMinutes = 120000;
-        Bundle bundle = new Bundle(2);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeFourMinute);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
-        when(mFragment.getArguments()).thenReturn(bundle);
-
-        mFragment.initHeader();
-
-        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
-        verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("6 min total • 4 min background\nsince last full charge");
-    }
-
-    @Test
-    public void initHeader_totalUsageLessThanAMinWithSlotTime_hasCorrectSummary() {
-        final long backgroundTimeLessThanHalfMinute = 20000;
-        final long foregroundTimeLessThanHalfMinute = 20000;
-        Bundle bundle = new Bundle(3);
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
         bundle.putLong(
-                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanHalfMinute);
-        bundle.putLong(
-                AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeLessThanHalfMinute);
-        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
-        when(mFragment.getArguments()).thenReturn(bundle);
-
-        mFragment.initHeader();
-
-        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
-        verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("Total less than a minute for 12 am-2 am");
-    }
-
-    @Test
-    public void initHeader_TotalAMinBackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
-        final long backgroundTimeZero = 59999;
-        final long foregroundTimeTwoMinutes = 1;
-        Bundle bundle = new Bundle(3);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
+                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
-        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
         when(mFragment.getArguments()).thenReturn(bundle);
 
         mFragment.initHeader();
 
         ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
         verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("1 min total • background less than a minute\nfor 12 am-2 am");
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: 1 min\nBackground: less than a min\n(since last full charge)");
     }
 
     @Test
-    public void initHeader_TotalAMinBackgroundZeroWithSlotTime_hasCorrectSummary() {
-        final long backgroundTimeZero = 0;
-        final long foregroundTimeAMinutes = 60000;
-        Bundle bundle = new Bundle(3);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeAMinutes);
-        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
-        when(mFragment.getArguments()).thenReturn(bundle);
-
-        mFragment.initHeader();
-
-        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
-        verify(mEntityHeaderController).setSummary(captor.capture());
-        assertThat(captor.getValue().toString())
-                .isEqualTo("1 min total for 12 am-2 am");
-    }
-
-    @Test
-    public void initHeader_foregroundTwoMinBackgroundFourMinWithSlotTime_hasCorrectSummary() {
-        final long backgroundTimeFourMinute = 240000;
+    public void initHeader_ScreenTimeAMinuteBackgroundZero_hasCorrectSummary() {
+        final long backgroundTimezero = 0;
         final long foregroundTimeTwoMinutes = 120000;
-        Bundle bundle = new Bundle(3);
-        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeFourMinute);
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: 1 min\n(since last full charge)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessThanAMinBackgroundTwoMin_hasCorrectSummary() {
+        final long backgroundTimeTwoMinutes = 120000;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\nBackground: 2 min\n(since last full charge)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessThanAMinBackgroundLessThanAMin_hasCorrectSummary() {
+        final long backgroundTimeLessThanAMinute = 59999;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(
+                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\nBackground: less than a min\n(since last full "
+                        + "charge)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessThanAMinBackgroundZero_hasCorrectSummary() {
+        final long backgroundTimezero = 0;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\n(since last full charge)");
+    }
+
+    @Test
+    public void initHeader_noAnyTimeNoConsumedPowerWithSlotTime_hasEmptySummary() {
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEmpty();
+    }
+
+    @Test
+    public void initHeader_noAnyTimeButConsumedPowerWithSlotTime_hasEmptySummary() {
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, /* value */ 0);
+        bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEmpty();
+    }
+
+    @Test
+    public void initHeader_ScreenTimeZerobackgroundTwoMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeTwoMinutes = 120000;
+        final long foregroundTimeZero = 0;
+        final long screenOnTimeZero = 0;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
         bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
         when(mFragment.getArguments()).thenReturn(bundle);
 
@@ -474,14 +505,158 @@
         ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
         verify(mEntityHeaderController).setSummary(captor.capture());
         assertThat(captor.getValue().toString())
-                .isEqualTo("6 min total • 4 min background\nfor 12 am-2 am");
+                .isEqualTo("Background: 2 min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeZerobackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeLessThanAMinute = 59999;
+        final long foregroundTimeZero = 0;
+        final long screenOnTimeZero = 0;
+        Bundle bundle = new Bundle();
+        bundle.putLong(
+                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeZero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeZero);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString())
+                .isEqualTo("Background: less than a min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeAMinuteBackgroundTwoMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeTwoMinutes = 120000;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: 1 min\nBackground: 2 min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeAMinuteBackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeLessThanAMinute = 59999;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
+        bundle.putLong(
+                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: 1 min\nBackground: less than a min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeAMinuteBackgroundZeroWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimezero = 0;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeAMinute = 60000;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: 1 min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessThanAMinBackgroundTwoMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeTwoMinutes = 120000;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\nBackground: 2 min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessAMinBackgroundLessAMinWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimeLessThanAMinute = 59999;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(
+                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanAMinute);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\nBackground: less than a min\n(12 am-2 am)");
+    }
+
+    @Test
+    public void initHeader_ScreenTimeLessThanAMinBackgroundZeroWithSlotTime_hasCorrectSummary() {
+        final long backgroundTimezero = 0;
+        final long foregroundTimeTwoMinutes = 120000;
+        final long screenOnTimeLessThanAMinute = 59999;
+        Bundle bundle = new Bundle();
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimezero);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, screenOnTimeLessThanAMinute);
+        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
+        when(mFragment.getArguments()).thenReturn(bundle);
+
+        mFragment.initHeader();
+
+        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
+        verify(mEntityHeaderController).setSummary(captor.capture());
+        assertThat(captor.getValue().toString()).isEqualTo(
+                "Screen time: less than a min\n(12 am-2 am)");
     }
 
     @Test
     public void initHeader_systemUidWithChartIsEnabled_notNullSummary() {
-        Bundle bundle = new Bundle(3);
+        Bundle bundle = new Bundle();
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, 240000);
         bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, 120000);
+        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME, 120000);
         bundle.putInt(AdvancedPowerUsageDetail.EXTRA_UID, Process.SYSTEM_UID);
         when(mFragment.getArguments()).thenReturn(bundle);
 
@@ -502,6 +677,8 @@
                 .isEqualTo(0);
         assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME))
                 .isEqualTo(0);
+        assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_SCREEN_ON_TIME))
+                .isEqualTo(0);
         assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT))
                 .isEqualTo(USAGE_PERCENT);
     }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index 9f62352..ea325a1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -68,6 +68,11 @@
     }
 
     @Test
+    public void testGetBatteryUsageListConsumePowerThreshold_return0() {
+        assertThat(mPowerFeatureProvider.getBatteryUsageListConsumePowerThreshold()).isEqualTo(0.0);
+    }
+
+    @Test
     public void testIsTypeSystem_uidRoot_returnTrue() {
         assertThat(mPowerFeatureProvider.isTypeSystem(Process.ROOT_UID, null)).isTrue();
     }