Add high power whitelist for apps

 - Strings not final!
 - New UX for power usage details (more preferency)
 - Add high power apps list shows on/off and screen to
   change (when possible)
 - Link from power usage summary to high power list
 - Link from advanced apps to high power list

Bug: 19991702
Change-Id: I97c927ed82d3b89041e4429b427508545763d66c
diff --git a/res/layout/horizontal_preference.xml b/res/layout/horizontal_preference.xml
new file mode 100644
index 0000000..540b7e3
--- /dev/null
+++ b/res/layout/horizontal_preference.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 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.
+-->
+
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="horizontal"
+    android:paddingTop="3dp"
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+
+    <TextView
+        android:id="@android:id/title"
+        android:textAppearance="?android:attr/textAppearanceListItem"
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        android:layout_weight="1" />
+
+    <TextView
+        android:id="@android:id/summary"
+        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+        android:textColor="?android:attr/textColorSecondary"
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        android:layout_weight="1"
+        android:gravity="end" />
+
+</LinearLayout>
diff --git a/res/layout/power_usage_action_item.xml b/res/layout/power_usage_action_item.xml
deleted file mode 100644
index 9e8551e..0000000
--- a/res/layout/power_usage_action_item.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
-    android:gravity="center_vertical"
-    android:paddingStart="4dip"
-    android:focusable="true"
-    android:orientation="vertical"
-    android:paddingEnd="?android:attr/scrollbarSize">
-
-    <TextView android:id="@+id/summary"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="2dip"
-            android:paddingBottom="4dip"
-            android:ellipsize="marquee"
-            android:textAppearance="?android:attr/textAppearanceMedium"/>
-
-    <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal">
-        <!-- Spacer -->
-        <View
-                android:id="@+id/buttons_spacer_left"
-                android:layout_width="0dip"
-                android:layout_height="wrap_content"
-                android:layout_weight="0.7"
-                android:visibility="invisible" />
-
-        <Button
-                android:id="@+id/action_button"
-                android:layout_width="150dip"
-                android:paddingEnd="6dip"
-                android:layout_weight="0.3"
-                android:layout_height="wrap_content"/>
-    </LinearLayout>
-</LinearLayout>
diff --git a/res/layout/power_usage_detail_item_text.xml b/res/layout/power_usage_detail_item_text.xml
deleted file mode 100644
index 04b48b8..0000000
--- a/res/layout/power_usage_detail_item_text.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<RelativeLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content">
-
-    <!--Label for the item-->
-    <TextView
-        android:id="@+id/label"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textStyle="bold"
-        android:singleLine="true"
-        android:ellipsize="middle"
-        android:layout_alignParentStart="true"
-        android:layout_toStartOf="@+id/value"
-        android:layout_marginBottom="4dip"
-        android:layout_marginTop="4dip"
-        android:layout_marginEnd="4dip"/>
-
-    <TextView
-        android:id="@+id/value"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentEnd="true"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textStyle="normal"
-        android:singleLine="true"
-        android:layout_marginBottom="4dip"
-        android:layout_marginTop="4dip" />
-
-</RelativeLayout>
diff --git a/res/layout/power_usage_details.xml b/res/layout/power_usage_details.xml
deleted file mode 100644
index f711d9a..0000000
--- a/res/layout/power_usage_details.xml
+++ /dev/null
@@ -1,111 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<ScrollView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:clipToPadding="false"
-    android:scrollbarStyle="@integer/preference_scrollbar_style">
-
-    <LinearLayout
-        android:id="@+id/all_details"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-        android:paddingTop="5dip"
-        android:paddingBottom="5dip"
-        android:orientation="vertical">
-
-        <include layout="@layout/app_percentage_item" />
-
-        <!-- Force stop and report buttons -->
-        <LinearLayout
-                android:id="@+id/two_buttons_panel"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:paddingBottom="6dip"
-                android:orientation="vertical">
-            <include
-                    layout="@layout/two_buttons_panel"/>
-        </LinearLayout>
-
-        <TextView
-                style="?android:attr/listSeparatorTextViewStyle"
-                android:text="@string/details_subtitle" />
-
-        <LinearLayout
-                android:id="@+id/details"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:paddingStart="6dip"
-                android:orientation="vertical">
-
-            <!-- Insert detail items here -->
-
-        </LinearLayout>
-
-        <LinearLayout
-                android:id="@+id/controls"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="vertical">
-
-            <TextView
-                    android:id="@+id/controls_title"
-                    style="?android:attr/listSeparatorTextViewStyle"
-                    android:layout_marginTop="6dip"
-                    android:text="@string/controls_subtitle" />
-
-            <!-- Controls go here ... -->
-
-        </LinearLayout>
-
-        <LinearLayout
-                android:id="@+id/messages"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="vertical">
-
-            <TextView
-                    android:id="@+id/messages_title"
-                    style="?android:attr/listSeparatorTextViewStyle"
-                    android:layout_marginTop="6dip" />
-
-            <!-- Messages go here ... -->
-
-        </LinearLayout>
-
-        <TextView
-                android:id="@+id/packages_section_title"
-                style="?android:attr/listSeparatorTextViewStyle"
-                android:layout_marginTop="6dip"
-                android:text="@string/packages_subtitle" />
-
-        <LinearLayout
-                android:id="@+id/packages_section"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:paddingStart="6dip"
-                android:orientation="vertical">
-
-            <!-- Insert detail items here -->
-
-        </LinearLayout>
-
-    </LinearLayout>
-</ScrollView>
diff --git a/res/layout/power_usage_message_item.xml b/res/layout/power_usage_message_item.xml
deleted file mode 100644
index 6f9e619..0000000
--- a/res/layout/power_usage_message_item.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 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.
--->
-
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/message"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="2dip"
-        android:minHeight="?android:attr/listPreferredItemHeight"
-        android:paddingStart="4dip"
-        android:paddingEnd="?android:attr/scrollbarSize"
-        android:paddingBottom="4dip"
-        android:ellipsize="marquee"
-        android:textAppearance="?android:attr/textAppearanceMedium" />
diff --git a/res/layout/power_usage_package_item.xml b/res/layout/power_usage_package_item.xml
deleted file mode 100644
index 6c31792..0000000
--- a/res/layout/power_usage_package_item.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<TextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/label"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:textAppearance="?android:attr/textAppearanceMedium"
-    android:singleLine="true"
-    android:layout_alignParentStart="true"
-    android:layout_marginBottom="2dip"
-    android:layout_marginTop="2dip" />
diff --git a/res/layout/preference_batteryhistory.xml b/res/layout/preference_batteryhistory.xml
deleted file mode 100644
index 8697059..0000000
--- a/res/layout/preference_batteryhistory.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical"
-        android:minHeight="@dimen/battery_history_chart_height">
-
-    <include layout="@layout/battery_history_chart" />
-
-    <TextView android:id="@+id/labelsHeader"
-              android:layout_width="match_parent"
-              android:layout_height="48dp"
-              android:textAppearance="?android:attr/textAppearanceMedium"
-              android:textSize="14sp"
-              android:textColor="?android:attr/colorControlActivated"
-              android:gravity="start|center_vertical"
-              android:text="@string/power_usage_list_summary"
-              android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-              android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
-
-</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3da13e7..7e52036 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6642,4 +6642,31 @@
     <!-- Label for process [CHAR LIMIT=25] -->
     <string name="process_format">Process <xliff:g id="count" example="3">%1$d</xliff:g></string>
 
+    <!-- Label for whether app is allowed to use a lot ef power [CHAR LIMIT=25]-->
+    <string name="high_power" translatable="false">High power</string>
+
+    <!-- List of apps that are allowed to use a lot of power [CHAR LIMIT=25]-->
+    <string name="high_power_apps" translatable="false">High power apps</string>
+
+    <!-- Summary of app allowed to use a lot of power [CHAR LIMIT=25] -->
+    <string name="high_power_on">On</string>
+
+    <!-- Summary of app not allowed to use a lot of power [CHAR LIMIT=25] -->
+    <string name="high_power_off">Off</string>
+
+    <!-- Description of high power switch [CHAR LIMIT=NONE] -->
+    <string name="high_power_desc" translatable="false">High powered apps description text goes here.  This is a placeholder.</string>
+
+    <!-- Description of number of apps with high power turned on [CHAR LIMIT=NONE] -->
+    <plurals name="high_power_count" translatable="false">
+        <item quantity="one">1 app is allowed to ignore restrictions like battery saver mode, sync etc.</item>
+        <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps is allowed to ignore restrictions like battery saver mode, sync etc.</item>
+    </plurals>
+
+    <!-- Summary of power usage for an app [CHAR LIMIT=NONE] -->
+    <string name="battery_summary" translatable="false"><xliff:g id="percentage" example="2">%1$d</xliff:g>%% use since last full charge</string>
+
+    <!-- Summary for app with no battery usage [CHAR LIMIT=NONE] -->
+    <string name="no_battery_summary" translatable="false">No battery use since last full charge</string>
+
 </resources>
diff --git a/res/xml/advanced_apps.xml b/res/xml/advanced_apps.xml
index e808210..62431c3 100644
--- a/res/xml/advanced_apps.xml
+++ b/res/xml/advanced_apps.xml
@@ -26,12 +26,6 @@
         settings:keywords="@string/keywords_default_apps" />
 
     <PreferenceScreen
-        android:key="manage_perms"
-        android:fragment="com.android.settings.applications.ManagePermissions"
-        android:title="@string/app_permissions"
-        settings:keywords="@string/keywords_app_permissions" />
-
-    <PreferenceScreen
             android:key="domain_urls"
             android:title="@string/domain_urls_title"
             android:fragment="com.android.settings.applications.ManageApplications">
@@ -40,4 +34,19 @@
                 android:value="com.android.settings.Settings$DomainsURLsAppListActivity" />
     </PreferenceScreen>
 
+    <PreferenceScreen
+        android:key="manage_perms"
+        android:fragment="com.android.settings.applications.ManagePermissions"
+        android:title="@string/app_permissions"
+        settings:keywords="@string/keywords_app_permissions" />
+
+    <PreferenceScreen
+        android:key="high_power_apps"
+        android:title="@string/high_power_apps"
+        android:fragment="com.android.settings.applications.ManageApplications">
+        <extra
+            android:name="classname"
+            android:value="com.android.settings.Settings$HighPowerApplicationsActivity" />
+    </PreferenceScreen>
+
 </PreferenceScreen>
diff --git a/res/xml/high_power_details.xml b/res/xml/high_power_details.xml
new file mode 100644
index 0000000..81f7806
--- /dev/null
+++ b/res/xml/high_power_details.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+    android:title="@string/high_power">
+
+    <SwitchPreference
+        android:key="high_power_switch"
+        android:title="@string/high_power" />
+
+    <Preference
+        android:summary="@string/high_power_desc"
+        android:selectable="false" />
+
+</PreferenceScreen>
diff --git a/res/xml/installed_app_details.xml b/res/xml/installed_app_details.xml
index 233331d..deab13b 100644
--- a/res/xml/installed_app_details.xml
+++ b/res/xml/installed_app_details.xml
@@ -18,7 +18,8 @@
                   android:title="@string/application_info_label">
     <com.android.settings.applications.LayoutPreference
         android:key="header_view"
-        android:layout="@layout/installed_app_details" />
+        android:layout="@layout/installed_app_details"
+        android:selectable="false" />
 
     <Preference
         android:key="storage_settings"
@@ -44,4 +45,10 @@
         android:key="preferred_settings"
         android:title="@string/launch_by_default"
         android:selectable="true" />
+
+    <Preference
+        android:key="battery"
+        android:title="@string/power_usage_summary_title"
+        android:selectable="true" />
+
 </PreferenceScreen>
diff --git a/res/xml/power_usage_details.xml b/res/xml/power_usage_details.xml
new file mode 100644
index 0000000..ca84e89
--- /dev/null
+++ b/res/xml/power_usage_details.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+        <com.android.settings.fuelgauge.BatteryHistoryPreference
+            android:key="battery_history" />
+
+        <com.android.settings.applications.LayoutPreference
+            android:key="two_buttons"
+            android:layout="@layout/two_buttons_panel"
+            android:selectable="false" />
+
+        <Preference
+            android:key="high_power"
+            android:title="@string/high_power" />
+
+        <PreferenceCategory
+            android:key="details_parent"
+            android:title="@string/details_subtitle" />
+
+        <PreferenceCategory
+            android:key="controls_parent"
+            android:title="@string/controls_subtitle" />
+
+        <PreferenceCategory
+            android:key="messages_parent" />
+
+        <PreferenceCategory
+            android:key="packages_parent"
+            android:title="@string/packages_subtitle" />
+
+</PreferenceScreen>
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 0622513..3f39d47 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -17,6 +17,13 @@
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
         android:title="@string/power_usage_summary_title"
-        settings:keywords="@string/keywords_battery"
-        android:key="app_list">
+        settings:keywords="@string/keywords_battery">
+
+        <com.android.settings.fuelgauge.BatteryHistoryPreference
+            android:key="battery_history" />
+
+        <PreferenceCategory
+            android:key="app_list"
+            android:title="@string/power_usage_list_summary" />
+
 </PreferenceScreen>