Merge "More updates to battery optimization whitelist" into mnc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index afe8777..ebf1fb4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5860,6 +5860,7 @@
     <string name="keywords_all_apps">apps download applications system</string>
     <string name="keywords_app_permissions">apps permissions security</string>
     <string name="keywords_default_apps">apps default</string>
+    <string name="keywords_ignore_optimizations">ignore optimizations doze app standby</string>
     <!-- Search keywords for different screen unlock modes : slide to unlock, password, pattern and PIN [CHAR LIMIT=none] -->
     <string name="keywords_lockscreen">slide password pattern pin</string>
 
@@ -6564,22 +6565,19 @@
     <!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
     <string name="high_power_filter_on">Allowed</string>
 
-    <!-- Filter for apps not allowed to use a lot of power [CHAR LIMIT=25] -->
-    <string name="high_power_filter_off">Not allowed</string>
-
     <!-- Summary of app allowed to use a lot of power [CHAR LIMIT=60] -->
-    <string name="high_power_on">Allowed to ignore optimizations</string>
+    <string name="high_power_on">Ignoring battery optimizations</string>
 
     <!-- Summary of app not allowed to use a lot of power [CHAR LIMIT=60] -->
-    <string name="high_power_off">Not allowed to ignore optimizations</string>
+    <string name="high_power_off">Off</string>
 
     <!-- Description of high power switch [CHAR LIMIT=NONE] -->
-    <string name="high_power_desc">Ignore optimizations including Battery saver, allow instant content refresh etc.</string>
+    <string name="high_power_desc">Don\'t apply battery optimizations. May drain your battery more quickly.</string>
 
     <!-- Description of number of apps with high power turned on [CHAR LIMIT=NONE] -->
     <plurals name="high_power_count">
-        <item quantity="one">1 app is allowed to ignore battery optimizations</item>
-        <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps are allowed to battery optimizations</item>
+        <item quantity="one">1 app allowed to ignore battery optimizations</item>
+        <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps allowed to ignore battery optimizations</item>
     </plurals>
 
     <!-- Summary of power usage for an app [CHAR LIMIT=NONE] -->
diff --git a/res/xml/advanced_apps.xml b/res/xml/advanced_apps.xml
index 62431c3..1bb9c58 100644
--- a/res/xml/advanced_apps.xml
+++ b/res/xml/advanced_apps.xml
@@ -43,7 +43,8 @@
     <PreferenceScreen
         android:key="high_power_apps"
         android:title="@string/high_power_apps"
-        android:fragment="com.android.settings.applications.ManageApplications">
+        android:fragment="com.android.settings.applications.ManageApplications"
+        settings:keywords="@string/keywords_ignore_optimizations">
         <extra
             android:name="classname"
             android:value="com.android.settings.Settings$HighPowerApplicationsActivity" />
diff --git a/res/xml/power_usage_details.xml b/res/xml/power_usage_details.xml
index 3ad6547..ad28650 100644
--- a/res/xml/power_usage_details.xml
+++ b/res/xml/power_usage_details.xml
@@ -25,23 +25,28 @@
             android:layout="@layout/two_buttons_panel"
             android:selectable="false" />
 
-        <Preference
-            android:key="high_power"
-            android:title="@string/high_power_apps" />
+        <PreferenceCategory
+            android:key="controls_parent"
+            android:title="@string/controls_subtitle">
+
+            <Preference
+                android:key="high_power"
+                android:title="@string/high_power_apps" />
+
+        </PreferenceCategory>
 
         <PreferenceCategory
             android:key="details_parent"
+            android:layout="@layout/tall_preference_category"
             android:title="@string/details_subtitle" />
 
         <PreferenceCategory
-            android:key="controls_parent"
-            android:title="@string/controls_subtitle" />
-
-        <PreferenceCategory
-            android:key="messages_parent" />
+            android:key="messages_parent"
+            android:layout="@layout/tall_preference_category" />
 
         <PreferenceCategory
             android:key="packages_parent"
+            android:layout="@layout/tall_preference_category"
             android:title="@string/packages_subtitle" />
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 1ef20f2..c74e23d 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -109,22 +109,22 @@
 
     // Filter options used for displayed list of applications
     // The order which they appear is the order they will show when spinner is present.
-    public static final int FILTER_APPS_ALL                     = 0;
-    public static final int FILTER_APPS_ENABLED                 = 1;
-    public static final int FILTER_APPS_DISABLED                = 2;
-    public static final int FILTER_APPS_BLOCKED                 = 3;
-    public static final int FILTER_APPS_PRIORITY                = 4;
-    public static final int FILTER_APPS_NO_PEEKING              = 5;
-    public static final int FILTER_APPS_SENSITIVE               = 6;
-    public static final int FILTER_APPS_PERSONAL                = 7;
-    public static final int FILTER_APPS_WORK                    = 8;
-    public static final int FILTER_APPS_WITH_DOMAIN_URLS        = 9;
-    public static final int FILTER_APPS_USAGE_ACCESS            = 10;
-    public static final int FILTER_APPS_POWER_WHITELIST         = 11;
-    public static final int FILTER_APPS_POWER_NO_WHITELIST      = 12;
+    public static final int FILTER_APPS_POWER_WHITELIST         = 0;
+    public static final int FILTER_APPS_ALL                     = 1;
+    public static final int FILTER_APPS_ENABLED                 = 2;
+    public static final int FILTER_APPS_DISABLED                = 3;
+    public static final int FILTER_APPS_BLOCKED                 = 4;
+    public static final int FILTER_APPS_PRIORITY                = 5;
+    public static final int FILTER_APPS_NO_PEEKING              = 6;
+    public static final int FILTER_APPS_SENSITIVE               = 7;
+    public static final int FILTER_APPS_PERSONAL                = 8;
+    public static final int FILTER_APPS_WORK                    = 9;
+    public static final int FILTER_APPS_WITH_DOMAIN_URLS        = 10;
+    public static final int FILTER_APPS_USAGE_ACCESS            = 11;
 
     // This is the string labels for the filter modes above, the order must be kept in sync.
     public static final int[] FILTER_LABELS = new int[] {
+        R.string.high_power_filter_on,        // High power whitelist, on
         R.string.filter_all_apps,      // All apps
         R.string.filter_enabled_apps,  // Enabled
         R.string.filter_apps_disabled, // Disabled
@@ -136,12 +136,11 @@
         R.string.filter_work_apps,     // Work
         R.string.filter_with_domain_urls_apps,     // Domain URLs
         R.string.filter_all_apps,      // Usage access screen, never displayed
-        R.string.high_power_filter_on,        // High power whitelist, on
-        R.string.high_power_filter_off,       // High power whitelist, off
     };
     // This is the actual mapping to filters from FILTER_ constants above, the order must
     // be kept in sync.
     public static final AppFilter[] FILTERS = new AppFilter[] {
+        AppStatePowerBridge.FILTER_POWER_WHITELISTED,     // High power whitelist, on
         ApplicationsState.FILTER_EVERYTHING,  // All apps
         ApplicationsState.FILTER_ALL_ENABLED, // Enabled
         ApplicationsState.FILTER_DISABLED,    // Disabled
@@ -153,8 +152,6 @@
         ApplicationsState.FILTER_WORK,        // Work
         ApplicationsState.FILTER_WITH_DOMAIN_URLS,   // Apps with Domain URLs
         AppStateUsageBridge.FILTER_APP_USAGE, // Apps with Domain URLs
-        AppStatePowerBridge.FILTER_POWER_WHITELISTED,     // High power whitelist, on
-        AppStatePowerBridge.FILTER_POWER_NOT_WHITELISTED, // High power whitelist, off
     };
 
     // sort order
@@ -321,7 +318,7 @@
             mFilterAdapter.enableFilter(FILTER_APPS_NO_PEEKING);
         }
         if (mListType == LIST_TYPE_HIGH_POWER) {
-            mFilterAdapter.enableFilter(FILTER_APPS_POWER_NO_WHITELIST);
+            mFilterAdapter.enableFilter(FILTER_APPS_ALL);
         }
         if (mListType == LIST_TYPE_STORAGE) {
             mApplications.setOverrideFilter(new VolumeFilter(mVolumeUuid));
diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
index 5e11baf..6313ff5 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
@@ -358,6 +358,8 @@
         if (mHighPower != null) {
             mHighPower.setSummary(HighPowerDetail.getSummary(getActivity(), mApp.packageName));
         }
+
+        setupHeader();
     }
 
     private void createDetails() {
@@ -370,8 +372,6 @@
         mNoCoverage = args.getDouble(EXTRA_NO_COVERAGE, 0);
         mShowLocationButton = args.getBoolean(EXTRA_SHOW_LOCATION_BUTTON);
 
-        setupHeader();
-
         mTypes = args.getIntArray(EXTRA_DETAIL_TYPES);
         mValues = args.getDoubleArray(EXTRA_DETAIL_VALUES);
 
@@ -445,14 +445,14 @@
     private void setupHeader() {
         final Bundle args = getArguments();
         String title = args.getString(EXTRA_TITLE);
-        String iconPackage = args.getString(EXTRA_ICON_PACKAGE);
+        String pkg = args.getString(EXTRA_ICON_PACKAGE);
         int iconId = args.getInt(EXTRA_ICON_ID, 0);
         Drawable appIcon = null;
 
-        if (!TextUtils.isEmpty(iconPackage)) {
+        if (!TextUtils.isEmpty(pkg)) {
             try {
                 final PackageManager pm = getActivity().getPackageManager();
-                ApplicationInfo ai = pm.getPackageInfo(iconPackage, 0).applicationInfo;
+                ApplicationInfo ai = pm.getPackageInfo(pkg, 0).applicationInfo;
                 if (ai != null) {
                     appIcon = ai.loadIcon(pm);
                 }
@@ -466,8 +466,11 @@
             appIcon = getActivity().getPackageManager().getDefaultActivityIcon();
         }
 
+        if (pkg == null && mPackages != null) {
+            pkg = mPackages[0];
+        }
         AppHeader.createAppHeader(this, appIcon, title,
-                AppInfoWithHeader.getInfoIntent(this, iconPackage),
+                pkg != null ? AppInfoWithHeader.getInfoIntent(this, pkg) : null,
                 mDrainType != DrainType.APP ? android.R.color.white : 0);
     }
 
@@ -629,7 +632,6 @@
     private void addControl(int pageSummary, int actionTitle, final int action) {
         Preference pref = new Preference(getActivity());
         pref.setTitle(actionTitle);
-        pref.setSummary(pageSummary);
         pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             @Override
             public boolean onPreferenceClick(Preference preference) {