Merge "Fix an override filter bug." into oc-dev
diff --git a/res/layout/preference_widget_seekbar_settings.xml b/res/layout/preference_widget_seekbar_settings.xml
index 87fea99..c25c598 100644
--- a/res/layout/preference_widget_seekbar_settings.xml
+++ b/res/layout/preference_widget_seekbar_settings.xml
@@ -19,36 +19,36 @@
     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:layout_marginTop="6dp"
+    android:layout_marginBottom="6dp"
     android:gravity="center_vertical"
+    android:minHeight="?android:attr/listPreferredItemHeight"
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:paddingBottom="6dp"
-    android:paddingTop="6dp">
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
     <TextView
         android:id="@android:id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="60dp"
-        android:layout_marginEnd="8dp"
+        android:ellipsize="marquee"
+        android:fadingEdge="horizontal"
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp"
         android:singleLine="true"
         android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-        android:textColor="?android:attr/textColorPrimary"
-        android:ellipsize="marquee"
-        android:fadingEdge="horizontal" />
+        android:textColor="?android:attr/textColorPrimary" />
 
     <TextView
         android:id="@android:id/summary"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="60dp"
-        android:layout_marginEnd="8dp"
-        android:layout_below="@android:id/title"
         android:layout_alignStart="@android:id/title"
+        android:layout_below="@android:id/title"
+        android:maxLines="4"
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp"
         android:textAppearance="?android:attr/textAppearanceListItemSecondary"
-        android:textColor="?android:attr/textColorSecondary"
-        android:maxLines="4" />
+        android:textColor="?android:attr/textColorSecondary" />
 
     <com.android.settings.widget.DefaultIndicatorSeekBar
         android:id="@*android:id/seekbar"
@@ -57,7 +57,7 @@
         android:layout_height="48dp"
         android:layout_alignParentEnd="true"
         android:layout_below="@android:id/summary"
-        android:layout_marginEnd="8dp"
-        android:layout_marginStart="44dp" />
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp" />
 
 </RelativeLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b631f8b..89be8c7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4307,11 +4307,6 @@
          can't verify user consent. [CHAR LIMIT=NONE] -->
     <string name="touch_filtered_warning">Because an app is obscuring a permission request, Settings
         can’t verify your response.</string>
-    <!-- Warning shown when user input has been blocked due to another app overlaying screen
-         content. Since we don't know what the app is showing on top of the input target, we
-         can't verify user consent. [CHAR LIMIT=NONE] -->
-    <string name="window_obscured_warning">Because another app is displaying on top of these options,
-        Settings can\u2019t respond to your action.</string>
     <!-- Warning that the device data will not be encrypted with password or PIN if
         enabling an accessibility service and there is a secure lock setup. [CHAR LIMIT=NONE] -->
     <string name="enable_service_encryption_warning">If you turn on <xliff:g id="service"
diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml
index 2a4416e..d10440e 100644
--- a/res/xml/security_lockscreen_settings.xml
+++ b/res/xml/security_lockscreen_settings.xml
@@ -15,21 +15,32 @@
 -->
 
 <PreferenceScreen
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:title="@string/lockscreen_settings_title">
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/lockscreen_settings_title">
+
+    <com.android.settings.notification.RestrictedDropDownPreference
+        android:key="security_setting_lock_screen_notif"
+        android:title="@string/lock_screen_notifications_title"
+        android:summary="@string/summary_placeholder" />
+
+    <com.android.settingslib.RestrictedSwitchPreference
+        android:key="add_users_when_locked"
+        android:title="@string/user_add_on_lockscreen_menu" />
+
+    <com.android.settingslib.RestrictedPreference
+        android:key="owner_info_settings"
+        android:title="@string/owner_info_settings_title"
+        android:summary="@string/owner_info_settings_summary" />
+
+    <PreferenceCategory
+        android:key="security_setting_lock_screen_notif_work_header"
+        android:title="@string/profile_section_header">
 
         <com.android.settings.notification.RestrictedDropDownPreference
-            android:key="lock_screen_notifications"
+            android:key="security_setting_lock_screen_notif_work"
             android:title="@string/lock_screen_notifications_title"
-            android:summary="@string/summary_placeholder"/>
+            android:summary="@string/summary_placeholder" />
 
-        <com.android.settingslib.RestrictedSwitchPreference
-            android:key="add_users_when_locked"
-            android:title="@string/user_add_on_lockscreen_menu"/>
-
-        <com.android.settingslib.RestrictedPreference
-            android:key="owner_info_settings"
-            android:title="@string/owner_info_settings_title"
-            android:summary="@string/owner_info_settings_summary"/>
+    </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index 3bb82cf..fb2f29f 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -65,8 +65,6 @@
 import com.android.settings.users.UserDialogs;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-import com.android.settingslib.SecureTouchListener;
-
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
@@ -352,8 +350,6 @@
 
         final View restrictedAction = findViewById(R.id.restricted_action);
         restrictedAction.setFilterTouchesWhenObscured(true);
-        restrictedAction.setOnTouchListener(
-                new SecureTouchListener(getString(R.string.window_obscured_warning)));
         restrictedAction.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 if (mAdding) {
diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java
index 6ed2c34..4820161 100644
--- a/src/com/android/settings/accounts/AccountPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountPreferenceController.java
@@ -299,6 +299,11 @@
         final ProfileData data = mProfiles.get(userInfo.id);
         if (data != null) {
             data.pendingRemoval = false;
+            if (userInfo.isEnabled()) {
+                // recreate the authentication helper to refresh the list of enabled accounts
+                data.authenticatorHelper =
+                    new AuthenticatorHelper(mContext, userInfo.getUserHandle(), this);
+            }
             return;
         }
         final Context context = mContext;
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 849144a..3d9dbb6 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -31,6 +31,8 @@
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -213,6 +215,19 @@
         return (powerUsageMah / (totalPowerMah - hiddenPowerMah)) * dischargeAmount;
     }
 
+    /**
+     * Sort the {@code usageList} based on {@link BatterySipper#totalPowerMah}
+     * @param usageList
+     */
+    public void sortUsageList(List<BatterySipper> usageList) {
+        Collections.sort(usageList, new Comparator<BatterySipper>() {
+            @Override
+            public int compare(BatterySipper a, BatterySipper b) {
+                return Double.compare(b.totalPowerMah, a.totalPowerMah);
+            }
+        });
+    }
+
     private long convertUsToMs(long timeUs) {
         return timeUs / 1000;
     }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index cd93c4b..8b4257b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -66,8 +66,6 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -311,7 +309,7 @@
      *
      * @return A sorted list of apps using power.
      */
-    private static List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
+    private List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
         final SparseArray<BatterySipper> uidList = new SparseArray<>();
 
         final ArrayList<BatterySipper> results = new ArrayList<>();
@@ -386,12 +384,7 @@
         }
 
         // The sort order must have changed, so re-sort based on total power use.
-        Collections.sort(results, new Comparator<BatterySipper>() {
-            @Override
-            public int compare(BatterySipper a, BatterySipper b) {
-                return Double.compare(b.totalPowerMah, a.totalPowerMah);
-            }
-        });
+        mBatteryUtils.sortUsageList(results);
         return results;
     }
 
@@ -434,9 +427,9 @@
         if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
             final List<BatterySipper> usageList = getCoalescedUsageList(
                     USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
-
             double hiddenPowerMah = mShowAllApps ? 0 :
                     mBatteryUtils.removeHiddenBatterySippers(usageList);
+            mBatteryUtils.sortUsageList(usageList);
 
             final int numSippers = usageList.size();
             for (int i = 0; i < numSippers; i++) {
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 2035cd2..efcb5a1 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -203,7 +203,8 @@
             final NotificationChannel channel) {
         MasterSwitchPreference channelPref = new MasterSwitchPreference(
                 getPrefContext());
-        channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && !mAppRow.systemApp);
+        channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
+                &&  isChannelBlockable(mAppRow.systemApp, channel));
         channelPref.setKey(channel.getId());
         channelPref.setTitle(channel.getName());
         channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 27e60c7..8c43a3f 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -232,7 +232,7 @@
         mBlockBar.setKey(KEY_BLOCK);
         getPreferenceScreen().addPreference(mBlockBar);
 
-        if (mAppRow.systemApp && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
+        if (!isChannelBlockable(mAppRow.systemApp, mChannel)) {
             setVisible(mBlockBar, false);
         }
 
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index d9da051..a06d069 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -65,7 +65,10 @@
         final PulseNotificationPreferenceController pulseController =
                 new PulseNotificationPreferenceController(context);
         final LockScreenNotificationPreferenceController lockScreenNotificationController =
-                new LockScreenNotificationPreferenceController(context);
+                new LockScreenNotificationPreferenceController(context,
+                        "lock_screen_notifications",
+                        "lock_screen_notifications_profile_header",
+                        "lock_screen_notifications_profile");
         if (lifecycle != null) {
             lifecycle.addObserver(pulseController);
             lifecycle.addObserver(lockScreenNotificationController);
diff --git a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
index 73469b0..1f0c4a8 100644
--- a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
@@ -26,6 +26,7 @@
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
 import android.util.Log;
 
 import com.android.internal.widget.LockPatternUtils;
@@ -46,11 +47,10 @@
         Preference.OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
 
     private static final String TAG = "LockScreenNotifPref";
-    private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
-    private static final String KEY_LOCK_SCREEN_PROFILE_HEADER =
-            "lock_screen_notifications_profile_header";
-    private static final String KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS =
-            "lock_screen_notifications_profile";
+
+    private final String mSettingKey;
+    private final String mWorkSettingCategoryKey;
+    private final String mWorkSettingKey;
 
     private RestrictedDropDownPreference mLockscreen;
     private RestrictedDropDownPreference mLockscreenProfile;
@@ -64,7 +64,16 @@
     private int mLockscreenSelectedValueProfile;
 
     public LockScreenNotificationPreferenceController(Context context) {
+        this(context, null, null, null);
+    }
+
+    public LockScreenNotificationPreferenceController(Context context,
+            String settingKey, String workSettingCategoryKey, String workSettingKey) {
         super(context);
+        mSettingKey = settingKey;
+        mWorkSettingCategoryKey = workSettingCategoryKey;
+        mWorkSettingKey = workSettingKey;
+
         mProfileChallengeUserId = Utils.getManagedProfileId(
                 UserManager.get(context), UserHandle.myUserId());
         final LockPatternUtils utils = new LockPatternUtils(context);
@@ -79,17 +88,17 @@
     public void displayPreference(PreferenceScreen screen) {
         super.displayPreference(screen);
         mLockscreen =
-                (RestrictedDropDownPreference) screen.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
+                (RestrictedDropDownPreference) screen.findPreference(mSettingKey);
         if (mLockscreen == null) {
-            Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
+            Log.i(TAG, "Preference not found: " + mSettingKey);
             return;
         }
         if (mProfileChallengeUserId != UserHandle.USER_NULL) {
             mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference(
-                    KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
+                    mWorkSettingKey);
         } else {
-            removePreference(screen, KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
-            removePreference(screen, KEY_LOCK_SCREEN_PROFILE_HEADER);
+            removePreference(screen, mWorkSettingKey);
+            removePreference(screen, mWorkSettingCategoryKey);
         }
         mSettingObserver = new SettingObserver();
         initLockScreenNotificationPrefDisplay();
@@ -136,7 +145,7 @@
 
     private void initLockscreenNotificationPrefForProfile() {
         if (mLockscreenProfile == null) {
-            Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
+            Log.i(TAG, "Preference not found: " + mWorkSettingKey);
             return;
         }
         ArrayList<CharSequence> entries = new ArrayList<>();
@@ -205,8 +214,8 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        switch (preference.getKey()) {
-            case KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS: {
+        final String key = preference.getKey();
+        if (TextUtils.equals(mWorkSettingKey, key)) {
                 final int val = Integer.parseInt((String) newValue);
                 if (val == mLockscreenSelectedValueProfile) {
                     return false;
@@ -223,8 +232,7 @@
                         enabled ? 1 : 0, mProfileChallengeUserId);
                 mLockscreenSelectedValueProfile = val;
                 return true;
-            }
-            case KEY_LOCK_SCREEN_NOTIFICATIONS: {
+        } else if (TextUtils.equals(mSettingKey, key)) {
                 final int val = Integer.parseInt((String) newValue);
                 if (val == mLockscreenSelectedValue) {
                     return false;
@@ -238,10 +246,8 @@
                         Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
                 mLockscreenSelectedValue = val;
                 return true;
-            }
-            default:
-                return false;
         }
+        return false;
     }
 
     private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
@@ -295,6 +301,7 @@
         final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
         final boolean allowPrivate = !mSecureProfile
                 || getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
+        mLockscreenProfile.setSummary("%s");
         mLockscreenSelectedValueProfile = !enabled
                 ? R.string.lock_screen_notifications_summary_disable_profile
                 : (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 695c796..bfa9355 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -443,4 +443,12 @@
 
         return lockscreenSecure;
     }
+
+    protected boolean isChannelBlockable(boolean systemApp, NotificationChannel channel) {
+        if (!mAppRow.systemApp) {
+            return true;
+        }
+        return channel.isBlockableSystem()
+                || channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
+    }
 }
diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java
index b781fbb..3137863 100644
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -18,6 +18,8 @@
 
 import android.content.Context;
 import android.provider.SearchIndexableResource;
+import android.support.annotation.VisibleForTesting;
+
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
@@ -26,6 +28,7 @@
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.notification.LockScreenNotificationPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -38,6 +41,15 @@
 
     private static final String TAG = "LockscreenDashboardFragment";
 
+    @VisibleForTesting
+    static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif";
+    @VisibleForTesting
+    static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER =
+            "security_setting_lock_screen_notif_work_header";
+    @VisibleForTesting
+    static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE =
+            "security_setting_lock_screen_notif_work";
+
     private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
 
     @Override
@@ -60,7 +72,10 @@
         final List<PreferenceController> controllers = new ArrayList<>();
         final Lifecycle lifecycle = getLifecycle();
         final LockScreenNotificationPreferenceController notificationController =
-            new LockScreenNotificationPreferenceController(context);
+            new LockScreenNotificationPreferenceController(context,
+                    KEY_LOCK_SCREEN_NOTIFICATON,
+                    KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
+                    KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
         lifecycle.addObserver(notificationController);
         controllers.add(notificationController);
         final AddUserWhenLockedPreferenceController addUserWhenLockedController =
diff --git a/tests/robotests/assets/whitelist_duplicate_index_key b/tests/robotests/assets/whitelist_duplicate_index_key
index 6ced706..020957e 100644
--- a/tests/robotests/assets/whitelist_duplicate_index_key
+++ b/tests/robotests/assets/whitelist_duplicate_index_key
@@ -1,6 +1,5 @@
 add_users_when_locked
 additional_system_update_settings
 dashboard_tile_placeholder
-lock_screen_notifications
 screen_zoom
 usage_access
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index 66f5549..f1ad142 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -493,6 +493,42 @@
 
     @Test
     @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
+    public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
+        final List<UserInfo> infos = new ArrayList<>();
+        infos.add(new UserInfo(1, "user 1", 0));
+        infos.add(new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
+        when(mUserManager.isManagedProfile()).thenReturn(false);
+        when(mUserManager.isLinkedUser()).thenReturn(false);
+        when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
+
+        AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
+        when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+        when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
+            preferenceGroup);
+
+        // First time resume will build the UI with no account
+        mController.onResume();
+
+        // Add new account
+        Account[] accounts = {new Account("Acct1", "com.acct1")};
+        when(mAccountManager.getAccountsAsUser(2)).thenReturn(accounts);
+        when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
+            .thenReturn(accounts);
+
+        AuthenticatorDescription[] authDescs = {
+            new AuthenticatorDescription("com.acct1", "com.android.settings",
+                R.string.account_settings_title, 0, 0, 0, false)
+        };
+        when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
+
+        // Resume should show the newly added account
+        mController.onResume();
+
+        verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct1")));
+    }
+
+    @Test
+    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index 03759ec..009a91c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -278,6 +278,19 @@
                 BATTERY_APP_USAGE + BATTERY_SCREEN_USAGE);
     }
 
+    @Test
+    public void testSortUsageList() {
+        final List<BatterySipper> sippers = new ArrayList<>();
+        sippers.add(mNormalBatterySipper);
+        sippers.add(mScreenBatterySipper);
+        sippers.add(mSystemBatterySipper);
+
+        mBatteryUtils.sortUsageList(sippers);
+
+        assertThat(sippers).containsExactly(mNormalBatterySipper, mSystemBatterySipper,
+                mScreenBatterySipper);
+    }
+
     private BatterySipper createTestSmearBatterySipper(long activityTime, double totalPowerMah,
             int uidCode, boolean isUidNull) {
         final BatterySipper sipper = mock(BatterySipper.class);
diff --git a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
new file mode 100644
index 0000000..c6a0e53
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 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.security;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.XmlTestUtils;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LockscreenDashboardFragmentTest {
+
+    private LockscreenDashboardFragment mFragment;
+
+    @Test
+    public void containsNotificationSettingsForPrimaryUserAndWorkProfile() {
+        mFragment = new LockscreenDashboardFragment();
+
+        List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(RuntimeEnvironment.application,
+                mFragment.getPreferenceScreenResId());
+
+        assertThat(keys).containsAllOf(LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON,
+                LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE,
+                LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER);
+    }
+}