Merge "Fix build" into nyc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b788d09..6418cba 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1005,7 +1005,7 @@
     <string name="lock_settings_picker_title">Choose screen lock</string>
 
     <!--  Title for security picker to choose the profile unlock method: None/Pattern/PIN/Password [CHAR LIMIT=22] -->
-    <string name="lock_settings_picker_title_profile">Choose profile screen lock</string>
+    <string name="lock_settings_picker_title_profile">Choose work lock</string>
 
     <!--  Title for security picker in setup wizard to choose the unlock method: None/Pattern/PIN/Password [CHAR LIMIT=22] -->
     <string name="setup_lock_settings_picker_title">Protect your phone</string>
@@ -1029,15 +1029,15 @@
 
     <!--  Profile Security lock settings --><skip />
     <!--  Title for PreferenceScreen to launch picker for security method for the managed profile when there is none [CHAR LIMIT=22] -->
-    <string name="unlock_set_unlock_launch_picker_title_profile">Profile screen lock</string>
+    <string name="unlock_set_unlock_launch_picker_title_profile">Work profile lock</string>
 
     <!--  Title for PreferenceScreen to change security method: None/Pattern/PIN/Password [CHAR LIMIT=22] -->
     <string name="unlock_set_unlock_launch_picker_change_title">Change lock screen</string>
 
-    <!--  Summary for PreferenceScreen to changeecurity method: None/Pattern/PIN/Password [CHAR LIMIT=45]  -->
+    <!--  Summary for PreferenceScreen to change security method: None/Pattern/PIN/Password [CHAR LIMIT=45]  -->
     <string name="unlock_set_unlock_launch_picker_change_summary">Change or disable pattern, PIN, or password security</string>
 
-    <!--  Summary for PreferenceScreen to changeecurity method: None/Pattern/PIN/Password [CHAR LIMIT=45]  -->
+    <!--  Summary for PreferenceScreen to change security method: None/Pattern/PIN/Password [CHAR LIMIT=45]  -->
     <string name="unlock_set_unlock_launch_picker_enable_summary">Choose a method to lock the screen</string>
 
     <!-- Title for preference that disables unlock security [CHAR LIMIT=22] -->
@@ -3087,15 +3087,15 @@
     <!-- Message to be used to explain the user that he needs to enter his password to continue a
          particular operation. [CHAR LIMIT=70]-->
     <string name="lockpassword_confirm_your_password_generic">Enter your device password to continue.</string>
-    <!-- Message to be used to explain the user that he needs to enter his profile pattern to continue a
+    <!-- Message to be used to explain the user that he needs to enter his work pattern to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pattern_generic_profile">Use your profile pattern to continue.</string>
-    <!-- Message to be used to explain the user that he needs to enter his profile PIN to continue a
+    <string name="lockpassword_confirm_your_pattern_generic_profile">Use your work pattern to continue.</string>
+    <!-- Message to be used to explain the user that he needs to enter his work PIN to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_pin_generic_profile">Enter your profile PIN to continue.</string>
-    <!-- Message to be used to explain the user that he needs to enter his profile password to continue a
+    <string name="lockpassword_confirm_your_pin_generic_profile">Enter your work PIN to continue.</string>
+    <!-- Message to be used to explain the user that he needs to enter his work password to continue a
          particular operation. [CHAR LIMIT=70]-->
-    <string name="lockpassword_confirm_your_password_generic_profile">Enter your profile password to continue.</string>
+    <string name="lockpassword_confirm_your_password_generic_profile">Enter your work password to continue.</string>
 
     <!-- Security & location settings screen, change security method screen instruction if user
          enters incorrect PIN [CHAR LIMIT=30] -->
@@ -3165,21 +3165,21 @@
 
     <!-- Profile Lock settings -->
     <!-- Security & location settings screen, header for profile specific section -->
-    <string name="lock_settings_profile_title">Work profile</string>
-    <!-- Security & location settings screen, setting option name -->
-    <string name="lock_settings_profile_label">Work profile security</string>
+    <string name="lock_settings_profile_title">Work profile security</string>
     <!-- Security & location settings screen, title when changing or confirming the work profile lock -->
     <string name="lock_settings_profile_screen_lock_title">Work profile screen lock</string>
     <!-- Security & location settings screen, setting option name to unify work and personal locks -->
     <string name="lock_settings_profile_unification_title">Use the same lock</string>
     <!-- Security & location settings screen, setting option explanation to unify work and personal locks -->
-    <string name="lock_settings_profile_unification_summary">Change device screen lock to match work profile?</string>
+    <string name="lock_settings_profile_unification_summary">Change device screen lock to match work profile</string>
     <!-- Security & location settings screen, title of the dialog asking if the user wants to unify work and personal locks -->
-    <string name="lock_settings_profile_unification_dialog_title">Use the same screen lock?</string>
+    <string name="lock_settings_profile_unification_dialog_title">Use the same lock?</string>
     <!-- Security & location settings screen, explanation in the dialog asking if the user wants to unify work and personal locks -->
-    <string name="lock_settings_profile_unification_dialog_body">You can use this lock for your device but it will include all screen lock related policies set by your IT admin on the work profile.\nDo you want to use the same screen lock for your device?</string>
+    <string name="lock_settings_profile_unification_dialog_body">You can use your work profile lock for your device screen lock as well. If you do, any work lock policies will also apply to your device screen lock.</string>
     <!-- Security & location settings screen, explanation in the dialog asking if the user wants to create a new lock for personal and work as the current work lock is not enough for the device. -->
-    <string name="lock_settings_profile_unification_dialog_uncompliant_body">Your work screen lock doesn\'t meet your organization\'s security requirements.\nYou can set a new screen lock for both your device and your work profile, but any work screen lock policies will apply to your device screen lock as well.</string>
+    <string name="lock_settings_profile_unification_dialog_uncompliant_body">Your work profile lock doesn\'t meet your organization\'s security requirements.\n\nYou can set a new screen lock for both your device and your work profile, but any work lock policies will apply to your device screen lock as well.</string>
+    <!-- Security & location settings screen, confirmation button of the dialog asking if the user wants to create a new lock for both personal and work profiles. -->
+    <string name="lock_settings_profile_unification_dialog_confirm">Change device lock</string>
     <!-- Security & location settings screen, confirmation button of the dialog asking if the user wants to create a new lock for both personal and work profiles. -->
     <string name="lock_settings_profile_unification_dialog_uncompliant_confirm">Change lock</string>
     <!-- Security & location settings screen, summary of the item that changes your work profile lock when it is unified with the personal lock -->
@@ -5938,18 +5938,18 @@
     <string name="lock_screen_notifications_interstitial_title">Notifications</string>
 
     <!-- Configure Notifications: Value for lockscreen notifications:  all information will be
-         shown in profile notifications shown on a secure lock screen
+         shown in work notifications shown on a secure lock screen
          [CHAR LIMIT=50] -->
-    <string name="lock_screen_notifications_summary_show_profile">Show all profile notification content</string>
+    <string name="lock_screen_notifications_summary_show_profile">Show all work notification content</string>
 
     <!-- Configure Notifications: Value for lockscreen notifications: sensitive information will be
-         hidden or redacted from profile notifications shown on a secure lock screen
+         hidden or redacted from work notifications shown on a secure lock screen
          [CHAR LIMIT=50] -->
-    <string name="lock_screen_notifications_summary_hide_profile">Hide sensitive profile notification content</string>
+    <string name="lock_screen_notifications_summary_hide_profile">Hide sensitive work notification content</string>
 
-    <!-- Configure Notifications: Value for lockscreen notifications: profile notifications will not appear on a secure lock screen
+    <!-- Configure Notifications: Value for lockscreen notifications: work notifications will not appear on a secure lock screen
          [CHAR LIMIT=50] -->
-    <string name="lock_screen_notifications_summary_disable_profile">Don\u2019t show profile notifications at all</string>
+    <string name="lock_screen_notifications_summary_disable_profile">Don\u2019t show work notifications at all</string>
 
     <!-- Security > Choose PIN/PW/Pattern > Notification redaction interstitial: Message asking the user how they want their profile notifications to appear when the device is locked [CHAR LIMIT=NONE] -->
     <string name="lock_screen_notifications_interstitial_message_profile">When your device is locked, how do you want profile notifications to show?</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index ffc421d..afe5947 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -286,6 +286,7 @@
     </style>
     <style name="Theme.ConfirmDeviceCredentialsWork" parent="Theme.ConfirmDeviceCredentialsDark">
         <item name="@*android:regularColor">@*android:color/white</item>
+        <item name="android:colorAccent">@*android:color/white</item>
     </style>
 
     <style name="Theme.FingerprintEnroll" parent="@*android:style/Theme.Material.Settings.NoActionBar">
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index c6ec4a9..4097d04 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -29,7 +29,6 @@
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.Bundle;
@@ -53,10 +52,8 @@
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
-
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.widget.LockPatternUtils;
-import com.android.settings.TimeoutListPreference;
 import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
 import com.android.settings.fingerprint.FingerprintSettings;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -71,7 +68,6 @@
 import java.util.List;
 
 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
-
 import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 
 /**
@@ -212,6 +208,14 @@
         return resid;
     }
 
+    @Override
+    public void setPreferenceScreen(PreferenceScreen preferenceScreen) {
+        if (!preferenceScreen.isAttached()) {
+            preferenceScreen.setShouldUseGeneratedIds(false);
+        }
+        super.setPreferenceScreen(preferenceScreen);
+    }
+
     /**
      * Important!
      *
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 69fd8e7..448a77d 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -58,11 +58,14 @@
 
     private static final String SUGGESTIONS = "suggestions";
 
+    private static final String EXTRA_SCROLL_POSITION = "scroll_position";
+
     private FocusRecyclerView mDashboard;
     private DashboardAdapter mAdapter;
     private SummaryLoader mSummaryLoader;
     private ConditionManager mConditionManager;
     private SuggestionParser mSuggestionParser;
+    private LinearLayoutManager mLayoutManager;
 
     @Override
     protected int getMetricsCategory() {
@@ -134,16 +137,27 @@
     }
 
     @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putInt(EXTRA_SCROLL_POSITION, mLayoutManager.findFirstVisibleItemPosition());
+    }
+
+    @Override
     public void onViewCreated(View view, Bundle bundle) {
         mDashboard = (FocusRecyclerView) view.findViewById(R.id.dashboard_container);
-        LinearLayoutManager llm = new LinearLayoutManager(getContext());
-        llm.setOrientation(LinearLayoutManager.VERTICAL);
-        mDashboard.setLayoutManager(llm);
+        mLayoutManager = new LinearLayoutManager(getContext());
+        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
+        if (bundle != null) {
+            int scrollPosition = bundle.getInt(EXTRA_SCROLL_POSITION);
+            mLayoutManager.scrollToPosition(scrollPosition);
+        }
+        mDashboard.setLayoutManager(mLayoutManager);
         mDashboard.setHasFixedSize(true);
         mDashboard.setListener(this);
         mAdapter = new DashboardAdapter(getContext());
         mAdapter.setConditions(mConditionManager.getConditions());
         mAdapter.setSuggestions(mSuggestionParser);
+        mDashboard.setAdapter(mAdapter);
         mSummaryLoader.setAdapter(mAdapter);
         ConditionAdapterUtils.addDismiss(mDashboard);
 
@@ -164,7 +178,6 @@
 
         // recheck to see if any suggestions have been changed.
         mAdapter.setSuggestions(mSuggestionParser);
-        mDashboard.setAdapter(mAdapter);
 
         long delta = System.currentTimeMillis() - start;
         Log.d(TAG, "rebuildUI took: " + delta + " ms");
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
index 571b6b5..b64a595 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
@@ -61,8 +61,9 @@
     public static void bindViews(final Condition condition,
             DashboardAdapter.DashboardItemHolder view, boolean isExpanded,
             View.OnClickListener onClickListener, View.OnClickListener onExpandListener) {
-        view.itemView.setTag(condition);
-        view.itemView.setOnClickListener(onClickListener);
+        View card = view.itemView.findViewById(R.id.content);
+        card.setTag(condition);
+        card.setOnClickListener(onClickListener);
         view.icon.setImageIcon(condition.getIcon());
         view.title.setText(condition.getTitle());
         ImageView expand = (ImageView) view.itemView.findViewById(R.id.expand_indicator);
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java b/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
index b2cb73a..25d5292 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
@@ -28,13 +28,13 @@
 import android.widget.TextView;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.InstrumentedFragment;
 import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.fuelgauge.BatteryActiveView.BatteryActiveProvider;
 import com.android.settingslib.BatteryInfo;
 import com.android.settingslib.graph.UsageView;
 
-public class BatteryHistoryDetail extends InstrumentedFragment {
+public class BatteryHistoryDetail extends SettingsPreferenceFragment {
     public static final String EXTRA_STATS = "stats";
     public static final String EXTRA_BROADCAST = "broadcast";
 
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index bc44eeb..1712734 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -28,6 +28,7 @@
 import android.os.UserHandle;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
+import android.text.TextUtils;
 import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.Menu;
@@ -167,9 +168,14 @@
     }
 
     private void addNotAvailableMessage() {
-        Preference notAvailable = new Preference(getPrefContext());
-        notAvailable.setTitle(R.string.power_usage_not_available);
-        mAppListGroup.addPreference(notAvailable);
+        final String NOT_AVAILABLE = "not_available";
+        Preference notAvailable = getCachedPreference(NOT_AVAILABLE);
+        if (notAvailable == null) {
+            notAvailable = new Preference(getPrefContext());
+            notAvailable.setKey(NOT_AVAILABLE);
+            notAvailable.setTitle(R.string.power_usage_not_available);
+            mAppListGroup.addPreference(notAvailable);
+        }
     }
 
     private static boolean isSharedGid(int uid) {
@@ -274,7 +280,7 @@
         super.refreshStats();
         PowerWhitelistBackend powerWhiteist = PowerWhitelistBackend.getInstance();
         updatePreference(mHistPref);
-        mAppListGroup.removeAll();
+        cacheRemoveAllPrefs(mAppListGroup);
         mAppListGroup.setOrderingAsAdded(false);
         boolean addedSome = false;
 
@@ -336,8 +342,16 @@
                         userHandle);
                 final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(),
                         userHandle);
-                final PowerGaugePreference pref = new PowerGaugePreference(getPrefContext(),
-                        badgedIcon, contentDescription, entry);
+                final String key = sipper.drainType == DrainType.APP ? sipper.getPackages() != null
+                        ? TextUtils.concat(sipper.getPackages()).toString()
+                        : String.valueOf(sipper.getUid())
+                        : sipper.drainType.toString();
+                PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
+                if (pref == null) {
+                    pref = new PowerGaugePreference(getPrefContext(), badgedIcon,
+                            contentDescription, entry);
+                    pref.setKey(key);
+                }
 
                 final double percentOfMax = (sipper.totalPowerMah * 100)
                         / mStatsHelper.getMaxPower();
@@ -368,6 +382,7 @@
         if (!addedSome) {
             addNotAvailableMessage();
         }
+        removeCachedPrefs(mAppListGroup);
 
         BatteryEntry.startRequestQueue();
     }