Merge "Fix battery color tint issue." into qt-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a8fa7cc..68a7cbb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1475,7 +1475,7 @@
         <!-- Lock screen settings -->
         <activity android:name=".password.ConfirmDeviceCredentialActivity"
             android:exported="true"
-            android:taskAffinity=".password.ConfirmDeviceCredentialActivity"
+            android:taskAffinity="com.android.settings.workmode"
             android:theme="@android:style/Theme.Translucent.NoTitleBar">
             <intent-filter android:priority="1">
                 <action android:name="android.app.action.CONFIRM_DEVICE_CREDENTIAL" />
@@ -1493,7 +1493,7 @@
             android:exported="false"
             android:permission="android.permission.MANAGE_USERS"
             android:resizeableActivity="false"
-            android:taskAffinity=".password.ConfirmDeviceCredentialActivity"
+            android:taskAffinity="com.android.settings.workmode"
             android:theme="@android:style/Theme.Translucent.NoTitleBar">
             <intent-filter android:priority="1">
                 <action android:name="android.app.action.CONFIRM_DEVICE_CREDENTIAL_WITH_USER" />
@@ -2810,6 +2810,7 @@
 
         <activity android:name=".enterprise.ActionDisabledByAdminDialog"
                 android:theme="@style/Transparent"
+                android:taskAffinity="com.android.settings.enterprise"
                 android:excludeFromRecents="true"
                 android:launchMode="singleTop">
             <intent-filter android:priority="1">
diff --git a/res/layout/panel_layout.xml b/res/layout/panel_layout.xml
index 233a01b..3a8045f 100644
--- a/res/layout/panel_layout.xml
+++ b/res/layout/panel_layout.xml
@@ -31,8 +31,6 @@
         android:textColor="?android:attr/colorPrimary"
         android:textSize="20sp"/>
 
-    <include layout="@layout/horizontal_divider"/>
-
     <include layout="@layout/panel_slice_list"/>
 
     <LinearLayout
diff --git a/res/layout/panel_slice_row.xml b/res/layout/panel_slice_row.xml
index 3288c40..4e1184b 100644
--- a/res/layout/panel_slice_row.xml
+++ b/res/layout/panel_slice_row.xml
@@ -26,6 +26,4 @@
         android:layout_height="wrap_content"
         android:paddingStart="20dp"
         android:paddingEnd="20dp"/>
-
-    <include layout="@layout/horizontal_divider"/>
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/preference_tts_engine.xml b/res/layout/preference_tts_engine.xml
deleted file mode 100644
index 19401f0..0000000
--- a/res/layout/preference_tts_engine.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 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="?android:attr/listPreferredItemHeight"
-    android:paddingStart="@dimen/preference_no_icon_padding_start"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:layout_gravity="center_vertical">
-
-    <RadioButton
-        android:id="@+id/tts_engine_radiobutton"
-        android:layout_width="0dp"
-        android:layout_height="match_parent"
-        android:clickable="true"
-        android:layout_weight="1"
-        android:maxLines="2"
-        android:textAppearance="?android:attr/textAppearanceListItem"
-        android:ellipsize="marquee"/>
-</LinearLayout>
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 0938c09..75db3e1 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -125,6 +125,17 @@
     public static final String OS_PKG = "os";
 
     /**
+     * Whether to disable the new device identifier access restrictions.
+     */
+    public static final String PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED =
+            "device_identifier_access_restrictions_disabled";
+
+    /**
+     * Whether to show the Permissions Hub.
+     */
+    public static final String PROPERTY_PERMISSIONS_HUB_ENABLED = "permissions_hub_enabled";
+
+    /**
      * Finds a matching activity for a preference's intent. If a matching
      * activity is not found, it will remove the preference.
      *
diff --git a/src/com/android/settings/applications/AllAppsInfoPreferenceController.java b/src/com/android/settings/applications/AllAppsInfoPreferenceController.java
index d39c6e9..325b25a 100644
--- a/src/com/android/settings/applications/AllAppsInfoPreferenceController.java
+++ b/src/com/android/settings/applications/AllAppsInfoPreferenceController.java
@@ -19,39 +19,54 @@
 import android.app.usage.UsageStats;
 import android.content.Context;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 
 import java.util.List;
 
-public class AllAppsInfoPreferenceController extends BasePreferenceController {
+public class AllAppsInfoPreferenceController extends BasePreferenceController
+        implements RecentAppStatsMixin.RecentAppStatsListener {
 
-    private List<UsageStats> mRecentApps;
+    @VisibleForTesting
+    Preference mPreference;
 
     public AllAppsInfoPreferenceController(Context context, String key) {
         super(context, key);
     }
 
-    public void setRecentApps(List<UsageStats> recentApps) {
-        mRecentApps = recentApps;
-    }
-
     @Override
     public int getAvailabilityStatus() {
-        return mRecentApps == null || mRecentApps.isEmpty() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+        return AVAILABLE;
     }
 
     @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        mPreference = screen.findPreference(getPreferenceKey());
+        // In most cases, device has recently opened apps. So, we hide it by default.
+        mPreference.setVisible(false);
+    }
+
+    @Override
+    public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) {
+        // If device has recently opened apps, we don't show all apps preference.
+        if (!recentApps.isEmpty()) {
+            mPreference.setVisible(false);
+            return;
+        }
+
+        mPreference.setVisible(true);
         // Show total number of installed apps as See all's summary.
         new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
                 mContext.getPackageManager()) {
             @Override
             protected void onCountComplete(int num) {
-                preference.setSummary(mContext.getString(R.string.apps_summary, num));
+                mPreference.setSummary(mContext.getString(R.string.apps_summary, num));
             }
         }.execute();
     }
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index c32a33d..5e57908 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -17,8 +17,13 @@
 package com.android.settings.applications;
 
 import android.app.settings.SettingsEnums;
+import android.app.usage.UsageStats;
 import android.content.Context;
+import android.os.Bundle;
 import android.provider.SearchIndexableResource;
+import android.view.View;
+
+import androidx.annotation.NonNull;
 
 import com.android.settings.R;
 import com.android.settings.Utils;
@@ -27,17 +32,21 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.widget.AppEntitiesHeaderController;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 @SearchIndexable
-public class AppAndNotificationDashboardFragment extends DashboardFragment {
+public class AppAndNotificationDashboardFragment extends DashboardFragment
+        implements RecentAppStatsMixin.RecentAppStatsListener {
 
     private static final String TAG = "AppAndNotifDashboard";
 
-    private boolean mIsFirstLaunch;
+    private View mProgressHeader;
+    private View mProgressAnimation;
+    private RecentAppStatsMixin mRecentAppStatsMixin;
     private RecentAppsPreferenceController mRecentAppsPreferenceController;
     private AllAppsInfoPreferenceController mAllAppsInfoPreferenceController;
 
@@ -66,29 +75,40 @@
         super.onAttach(context);
 
         use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle());
+
+        mRecentAppStatsMixin = new RecentAppStatsMixin(context,
+                AppEntitiesHeaderController.MAXIMUM_APPS);
+        getSettingsLifecycle().addObserver(mRecentAppStatsMixin);
+        mRecentAppStatsMixin.addListener(this);
+
         mRecentAppsPreferenceController = use(RecentAppsPreferenceController.class);
         mRecentAppsPreferenceController.setFragment(this /* fragment */);
+        mRecentAppStatsMixin.addListener(mRecentAppsPreferenceController);
 
         mAllAppsInfoPreferenceController = use(AllAppsInfoPreferenceController.class);
-        mAllAppsInfoPreferenceController.setRecentApps(
-                mRecentAppsPreferenceController.getRecentApps());
-
-        mIsFirstLaunch = true;
+        mRecentAppStatsMixin.addListener(mAllAppsInfoPreferenceController);
     }
 
     @Override
-    public void onResume() {
-        if (!mIsFirstLaunch) {
-            mRecentAppsPreferenceController.reloadData();
-            mAllAppsInfoPreferenceController.setRecentApps(
-                    mRecentAppsPreferenceController.getRecentApps());
-        }
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        mProgressHeader = setPinnedHeaderView(R.layout.progress_header);
+        mProgressAnimation = mProgressHeader.findViewById(R.id.progress_bar_animation);
+        setLoadingEnabled(false);
+    }
 
-        super.onResume();
-        mIsFirstLaunch = false;
+    @Override
+    public void onStart() {
+        super.onStart();
+        setLoadingEnabled(true);
+    }
 
-        if (mRecentAppsPreferenceController.isAvailable()) {
-            Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(), getListView());
+    @Override
+    public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) {
+        setLoadingEnabled(false);
+        if (!recentApps.isEmpty()) {
+            Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(),
+                    getListView());
         }
     }
 
@@ -97,6 +117,13 @@
         return buildPreferenceControllers(context);
     }
 
+    private void setLoadingEnabled(boolean enabled) {
+        if (mProgressHeader != null && mProgressAnimation != null) {
+            mProgressHeader.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
+            mProgressAnimation.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
+        }
+    }
+
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new EmergencyBroadcastPreferenceController(context,
diff --git a/src/com/android/settings/applications/RecentAppStatsMixin.java b/src/com/android/settings/applications/RecentAppStatsMixin.java
new file mode 100644
index 0000000..4bf3864
--- /dev/null
+++ b/src/com/android/settings/applications/RecentAppStatsMixin.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2019 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.applications;
+
+import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
+
+import android.app.Application;
+import android.app.usage.UsageStats;
+import android.app.usage.UsageStatsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.PowerManager;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settingslib.applications.AppUtils;
+import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+public class RecentAppStatsMixin implements Comparator<UsageStats>, LifecycleObserver, OnStart {
+
+    private static final String TAG = "RecentAppStatsMixin";
+    private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();
+
+    @VisibleForTesting
+    final List<UsageStats> mRecentApps;
+    private final int mUserId;
+    private final int mMaximumApps;
+    private final Context mContext;
+    private final PackageManager mPm;
+    private final PowerManager mPowerManager;;
+    private final UsageStatsManager mUsageStatsManager;
+    private final ApplicationsState mApplicationsState;
+    private final List<RecentAppStatsListener> mAppStatsListeners;
+    private Calendar mCalendar;
+
+    static {
+        SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList(
+                "android",
+                "com.android.phone",
+                SETTINGS_PACKAGE_NAME,
+                "com.android.systemui",
+                "com.android.providers.calendar",
+                "com.android.providers.media"
+        ));
+    }
+
+    public RecentAppStatsMixin(Context context, int maximumApps) {
+        mContext = context;
+        mMaximumApps = maximumApps;
+        mUserId = UserHandle.myUserId();
+        mPm = mContext.getPackageManager();
+        mPowerManager = mContext.getSystemService(PowerManager.class);
+        mUsageStatsManager = mContext.getSystemService(UsageStatsManager.class);
+        mApplicationsState = ApplicationsState.getInstance(
+                (Application) mContext.getApplicationContext());
+        mRecentApps = new ArrayList<>();
+        mAppStatsListeners = new ArrayList<>();
+    }
+
+    @Override
+    public void onStart() {
+        ThreadUtils.postOnBackgroundThread(() -> {
+            loadDisplayableRecentApps(mMaximumApps);
+            for (RecentAppStatsListener listener : mAppStatsListeners) {
+                ThreadUtils.postOnMainThread(() -> listener.onReloadDataCompleted(mRecentApps));
+            }
+        });
+    }
+
+    @Override
+    public final int compare(UsageStats a, UsageStats b) {
+        // return by descending order
+        return Long.compare(b.getLastTimeUsed(), a.getLastTimeUsed());
+    }
+
+    public void addListener(@NonNull RecentAppStatsListener listener) {
+        mAppStatsListeners.add(listener);
+    }
+
+    @VisibleForTesting
+    void loadDisplayableRecentApps(int number) {
+        mRecentApps.clear();
+        mCalendar = Calendar.getInstance();
+        mCalendar.add(Calendar.DAY_OF_YEAR, -1);
+        final List<UsageStats> mStats = mPowerManager.isPowerSaveMode()
+                ? new ArrayList<>()
+                : mUsageStatsManager.queryUsageStats(
+                        UsageStatsManager.INTERVAL_BEST, mCalendar.getTimeInMillis(),
+                        System.currentTimeMillis());
+
+        final Map<String, UsageStats> map = new ArrayMap<>();
+        final int statCount = mStats.size();
+        for (int i = 0; i < statCount; i++) {
+            final UsageStats pkgStats = mStats.get(i);
+            if (!shouldIncludePkgInRecents(pkgStats)) {
+                continue;
+            }
+            final String pkgName = pkgStats.getPackageName();
+            final UsageStats existingStats = map.get(pkgName);
+            if (existingStats == null) {
+                map.put(pkgName, pkgStats);
+            } else {
+                existingStats.add(pkgStats);
+            }
+        }
+        final List<UsageStats> packageStats = new ArrayList<>();
+        packageStats.addAll(map.values());
+        Collections.sort(packageStats, this /* comparator */);
+        int count = 0;
+        for (UsageStats stat : packageStats) {
+            final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(
+                    stat.getPackageName(), mUserId);
+            if (appEntry == null) {
+                continue;
+            }
+            mRecentApps.add(stat);
+            count++;
+            if (count >= number) {
+                break;
+            }
+        }
+    }
+
+    /**
+     * Whether or not the app should be included in recent list.
+     */
+    private boolean shouldIncludePkgInRecents(UsageStats stat) {
+        final String pkgName = stat.getPackageName();
+        if (stat.getLastTimeUsed() < mCalendar.getTimeInMillis()) {
+            Log.d(TAG, "Invalid timestamp (usage time is more than 24 hours ago), skipping "
+                    + pkgName);
+            return false;
+        }
+
+        if (SKIP_SYSTEM_PACKAGES.contains(pkgName)) {
+            Log.d(TAG, "System package, skipping " + pkgName);
+            return false;
+        }
+        if (AppUtils.isHiddenSystemModule(mContext, pkgName)) {
+            return false;
+        }
+        final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER)
+                .setPackage(pkgName);
+
+        if (mPm.resolveActivity(launchIntent, 0) == null) {
+            // Not visible on launcher -> likely not a user visible app, skip if non-instant.
+            final ApplicationsState.AppEntry appEntry =
+                    mApplicationsState.getEntry(pkgName, mUserId);
+            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
+                Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public interface RecentAppStatsListener {
+
+        void onReloadDataCompleted(List<UsageStats> recentApps);
+    }
+}
diff --git a/src/com/android/settings/applications/RecentAppsPreferenceController.java b/src/com/android/settings/applications/RecentAppsPreferenceController.java
index be86dd5..4f5ec01 100644
--- a/src/com/android/settings/applications/RecentAppsPreferenceController.java
+++ b/src/com/android/settings/applications/RecentAppsPreferenceController.java
@@ -16,24 +16,17 @@
 
 package com.android.settings.applications;
 
-import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
-
 import android.app.Application;
 import android.app.settings.SettingsEnums;
 import android.app.usage.UsageStats;
-import android.app.usage.UsageStatsManager;
 import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.icu.text.RelativeDateTimeFormatter;
-import android.os.PowerManager;
 import android.os.UserHandle;
-import android.util.ArrayMap;
-import android.util.ArraySet;
 import android.util.IconDrawableFactory;
 import android.util.Log;
 import android.view.View;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.fragment.app.Fragment;
 import androidx.preference.Preference;
@@ -44,35 +37,24 @@
 import com.android.settings.applications.manageapplications.ManageApplications;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.core.SubSettingLauncher;
-import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.utils.StringUtil;
 import com.android.settingslib.widget.AppEntitiesHeaderController;
 import com.android.settingslib.widget.AppEntityInfo;
 import com.android.settingslib.widget.LayoutPreference;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 /**
  * This controller displays up to three recently used apps.
  * If there is no recently used app, we only show up an "App Info" preference.
  */
 public class RecentAppsPreferenceController extends BasePreferenceController
-        implements Comparator<UsageStats> {
+        implements RecentAppStatsMixin.RecentAppStatsListener {
 
     @VisibleForTesting
     static final String KEY_DIVIDER = "recent_apps_divider";
 
-    private static final String TAG = "RecentAppsCtrl";
-    private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();
-
     @VisibleForTesting
     AppEntitiesHeaderController mAppEntitiesController;
     @VisibleForTesting
@@ -80,41 +62,19 @@
     @VisibleForTesting
     Preference mDivider;
 
-    private final PackageManager mPm;
-    private final UsageStatsManager mUsageStatsManager;
     private final ApplicationsState mApplicationsState;
     private final int mUserId;
     private final IconDrawableFactory mIconDrawableFactory;
-    private final PowerManager mPowerManager;
 
     private Fragment mHost;
-    private Calendar mCal;
-    private List<UsageStats> mStats;
     private List<UsageStats> mRecentApps;
-    private boolean mHasRecentApps;
-
-    static {
-        SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList(
-                "android",
-                "com.android.phone",
-                SETTINGS_PACKAGE_NAME,
-                "com.android.systemui",
-                "com.android.providers.calendar",
-                "com.android.providers.media"
-        ));
-    }
 
     public RecentAppsPreferenceController(Context context, String key) {
         super(context, key);
         mApplicationsState = ApplicationsState.getInstance(
                 (Application) mContext.getApplicationContext());
         mUserId = UserHandle.myUserId();
-        mPm = mContext.getPackageManager();
         mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
-        mPowerManager = mContext.getSystemService(PowerManager.class);
-        mUsageStatsManager = mContext.getSystemService(UsageStatsManager.class);
-        mRecentApps = new ArrayList<>();
-        reloadData();
     }
 
     public void setFragment(Fragment fragment) {
@@ -123,7 +83,7 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return mRecentApps.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
+        return AVAILABLE_UNSEARCHABLE;
     }
 
     @Override
@@ -131,7 +91,7 @@
         super.displayPreference(screen);
 
         mDivider = screen.findPreference(KEY_DIVIDER);
-        mRecentAppsPreference = (LayoutPreference) screen.findPreference(getPreferenceKey());
+        mRecentAppsPreference = screen.findPreference(getPreferenceKey());
         final View view = mRecentAppsPreference.findViewById(R.id.app_entities_header);
         mAppEntitiesController = AppEntitiesHeaderController.newInstance(mContext, view)
                 .setHeaderTitleRes(R.string.recent_app_category_title)
@@ -143,14 +103,11 @@
                             .setSourceMetricsCategory(SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY)
                             .launch();
                 });
-
-        refreshUi();
     }
 
     @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-
+    public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) {
+        mRecentApps = recentApps;
         refreshUi();
         // Show total number of installed apps as See all's summary.
         new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
@@ -164,38 +121,17 @@
         }.execute();
     }
 
-    @Override
-    public final int compare(UsageStats a, UsageStats b) {
-        // return by descending order
-        return Long.compare(b.getLastTimeUsed(), a.getLastTimeUsed());
-    }
-
-    List<UsageStats> getRecentApps() {
-        return mRecentApps;
-    }
-
-    @VisibleForTesting
-    void refreshUi() {
-        if (mRecentApps != null && !mRecentApps.isEmpty()) {
+    private void refreshUi() {
+        if (!mRecentApps.isEmpty()) {
             displayRecentApps();
+            mRecentAppsPreference.setVisible(true);
+            mDivider.setVisible(true);
         } else {
             mDivider.setVisible(false);
+            mRecentAppsPreference.setVisible(false);
         }
     }
 
-    @VisibleForTesting
-    void reloadData() {
-        mCal = Calendar.getInstance();
-        mCal.add(Calendar.DAY_OF_YEAR, -1);
-        mStats = mPowerManager.isPowerSaveMode()
-                ? new ArrayList<>()
-                : mUsageStatsManager.queryUsageStats(
-                        UsageStatsManager.INTERVAL_BEST, mCal.getTimeInMillis(),
-                        System.currentTimeMillis());
-
-        updateDisplayableRecentAppList();
-    }
-
     private void displayRecentApps() {
         int showAppsCount = 0;
 
@@ -209,8 +145,6 @@
                 break;
             }
         }
-        mAppEntitiesController.apply();
-        mDivider.setVisible(true);
     }
 
     private AppEntityInfo createAppEntity(UsageStats stat) {
@@ -234,73 +168,4 @@
                                 SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY))
                 .build();
     }
-
-    private void updateDisplayableRecentAppList() {
-        mRecentApps.clear();
-        final Map<String, UsageStats> map = new ArrayMap<>();
-        final int statCount = mStats.size();
-        for (int i = 0; i < statCount; i++) {
-            final UsageStats pkgStats = mStats.get(i);
-            if (!shouldIncludePkgInRecents(pkgStats)) {
-                continue;
-            }
-            final String pkgName = pkgStats.getPackageName();
-            final UsageStats existingStats = map.get(pkgName);
-            if (existingStats == null) {
-                map.put(pkgName, pkgStats);
-            } else {
-                existingStats.add(pkgStats);
-            }
-        }
-        final List<UsageStats> packageStats = new ArrayList<>();
-        packageStats.addAll(map.values());
-        Collections.sort(packageStats, this /* comparator */);
-        int count = 0;
-        for (UsageStats stat : packageStats) {
-            final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(
-                    stat.getPackageName(), mUserId);
-            if (appEntry == null) {
-                continue;
-            }
-            mRecentApps.add(stat);
-            count++;
-            if (count >= AppEntitiesHeaderController.MAXIMUM_APPS) {
-                break;
-            }
-        }
-    }
-
-
-    /**
-     * Whether or not the app should be included in recent list.
-     */
-    private boolean shouldIncludePkgInRecents(UsageStats stat) {
-        final String pkgName = stat.getPackageName();
-        if (stat.getLastTimeUsed() < mCal.getTimeInMillis()) {
-            Log.d(TAG, "Invalid timestamp (usage time is more than 24 hours ago), skipping "
-                    + pkgName);
-            return false;
-        }
-
-        if (SKIP_SYSTEM_PACKAGES.contains(pkgName)) {
-            Log.d(TAG, "System package, skipping " + pkgName);
-            return false;
-        }
-        if (AppUtils.isHiddenSystemModule(mContext, pkgName)) {
-            return false;
-        }
-        final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER)
-                .setPackage(pkgName);
-
-        if (mPm.resolveActivity(launchIntent, 0) == null) {
-            // Not visible on launcher -> likely not a user visible app, skip if non-instant.
-            final ApplicationsState.AppEntry appEntry =
-                    mApplicationsState.getEntry(pkgName, mUserId);
-            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
-                Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
-                return false;
-            }
-        }
-        return true;
-    }
 }
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index b07635f..55b31d2 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -26,7 +26,6 @@
     public static final String MOBILE_NETWORK_V2 = "settings_mobile_network_v2";
     public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2";
     public static final String SLICE_INJECTION = "settings_slice_injection";
-    public static final String MAINLINE_MODULE = "settings_mainline_module";
     public static final String WIFI_DETAILS_SAVED_SCREEN = "settings_wifi_details_saved_screen";
     public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
             "settings_wifi_details_datausage_header";
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index e9fc759..77b104b 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -480,7 +480,6 @@
         controllers.add(new ResizableActivityPreferenceController(context));
         controllers.add(new FreeformWindowsPreferenceController(context));
         controllers.add(new DesktopModePreferenceController(context));
-        controllers.add(new SmsAccessRestrictionPreferenceController(context));
         controllers.add(new DeviceIdentifierAccessRestrictionsPreferenceController(context));
         controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
         controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
diff --git a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java b/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
index f709771..f4e5953 100644
--- a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
+++ b/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
@@ -24,6 +24,7 @@
 import androidx.preference.Preference;
 import androidx.preference.SwitchPreference;
 
+import com.android.settings.Utils;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
 
@@ -53,10 +54,8 @@
     public boolean isAvailable() {
         // If the new access restrictions have been disabled from the server side then do not
         // display the option.
-        boolean disabledFromServerSide = Boolean.parseBoolean(
-                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
-                        DeviceConfig.Privacy.
-                                PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED));
+        boolean disabledFromServerSide = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
+                        Utils.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED, false);
         return !disabledFromServerSide;
     }
 
diff --git a/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java b/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java
deleted file mode 100644
index 6091614..0000000
--- a/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2018 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.development;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-
-// STOPSHIP b/118694572: remove the kill switch once the feature is tested and stable
-public class SmsAccessRestrictionPreferenceController extends DeveloperOptionsPreferenceController
-        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
-
-    private static final String SMS_ACCESS_RESTRICTION_ENABLED_KEY
-            = "sms_access_restriction_enabled";
-
-    public SmsAccessRestrictionPreferenceController(Context context) {
-        super(context);
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return SMS_ACCESS_RESTRICTION_ENABLED_KEY;
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        writeSetting((boolean) newValue);
-        return true;
-    }
-
-    private void writeSetting(boolean isEnabled) {
-        Settings.Global.putInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED,
-                isEnabled ? 1 : 0);
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0);
-        ((SwitchPreference) mPreference).setChecked(mode != 0);
-    }
-
-    @Override
-    protected void onDeveloperOptionsSwitchDisabled() {
-        super.onDeveloperOptionsSwitchDisabled();
-        writeSetting(false);
-        ((SwitchPreference) mPreference).setChecked(false);
-    }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java
index 174cb8c..ff9352a 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java
@@ -21,14 +21,12 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
 import android.util.Log;
 
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
 
 import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.FeatureFlags;
 
 public class MainlineModuleVersionPreferenceController extends BasePreferenceController {
 
@@ -49,16 +47,10 @@
 
     @Override
     public int getAvailabilityStatus() {
-        if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
-            return UNSUPPORTED_ON_DEVICE;
-        }
         return !TextUtils.isEmpty(mModuleVersion) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 
     private void initModules() {
-        if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
-            return;
-        }
         final String moduleProvider = mContext.getString(
                 com.android.internal.R.string.config_defaultModuleMetadataProvider);
         if (!TextUtils.isEmpty(moduleProvider)) {
diff --git a/src/com/android/settings/display/DisplayWhiteBalancePreferenceController.java b/src/com/android/settings/display/DisplayWhiteBalancePreferenceController.java
index c603dee..dc569aa 100644
--- a/src/com/android/settings/display/DisplayWhiteBalancePreferenceController.java
+++ b/src/com/android/settings/display/DisplayWhiteBalancePreferenceController.java
@@ -41,15 +41,12 @@
 
     @Override
     public boolean isChecked() {
-        return Secure.getIntForUser(mContext.getContentResolver(),
-                Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
+        return getColorDisplayManager().isDisplayWhiteBalanceEnabled();
     }
 
     @Override
     public boolean setChecked(boolean isChecked) {
-        Secure.putIntForUser(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED,
-                isChecked ? 1 : 0, UserHandle.USER_CURRENT);
-        return true;
+        return getColorDisplayManager().setDisplayWhiteBalanceEnabled(isChecked);
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionController.java b/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionController.java
index c6466e8..f847612 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionController.java
@@ -23,6 +23,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.hardware.display.ColorDisplayManager;
+import android.os.UserHandle;
 import android.util.Log;
 
 import com.android.settings.R;
@@ -115,7 +116,8 @@
     private void sendBroadcast() {
         final Intent intent = new Intent(ACTION_GRAYSCALE_CHANGED);
         intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
-        mAppContext.sendBroadcast(intent, Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS);
+        mAppContext.sendBroadcastAsUser(intent, UserHandle.CURRENT,
+                Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS);
     }
 
     public class Receiver extends BroadcastReceiver {
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index e4c64f7..f44e107 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -26,6 +26,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.location.RecentLocationAccesses;
@@ -62,8 +63,8 @@
     @Override
     public boolean isAvailable() {
         return Boolean.parseBoolean(
-                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
-                        DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED));
+                DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                        Utils.PROPERTY_PERMISSIONS_HUB_ENABLED));
     }
 
     @Override
diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
index bca6750..e982a6b 100644
--- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
@@ -28,6 +28,7 @@
 import com.android.settings.network.SubscriptionUtil;
 import com.android.settings.network.SubscriptionsChangeListener;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import androidx.lifecycle.Lifecycle;
@@ -124,27 +125,29 @@
 
         // We'll have one entry for each available subscription, plus one for a "ask me every
         // time" entry at the end.
-        final CharSequence[] displayNames = new CharSequence[subs.size() + 1];
-        final CharSequence[] subscriptionIds = new CharSequence[subs.size() + 1];
+        final ArrayList<CharSequence> displayNames = new ArrayList<>();
+        final ArrayList<CharSequence> subscriptionIds = new ArrayList<>();
 
         final int serviceDefaultSubId = getDefaultSubscriptionId();
         boolean subIsAvailable = false;
 
-        int i = 0;
-        for (; i < subs.size(); i++) {
-            displayNames[i] = subs.get(i).getDisplayName();
-            final int subId = subs.get(i).getSubscriptionId();
-            subscriptionIds[i] = Integer.toString(subId);
+        for (SubscriptionInfo sub : subs) {
+            if (sub.isOpportunistic()) {
+                continue;
+            }
+            displayNames.add(sub.getDisplayName());
+            final int subId = sub.getSubscriptionId();
+            subscriptionIds.add(Integer.toString(subId));
             if (subId == serviceDefaultSubId) {
                 subIsAvailable = true;
             }
         }
         // Add the extra "Ask every time" value at the end.
-        displayNames[i] = mContext.getString(R.string.calls_and_sms_ask_every_time);
-        subscriptionIds[i] = Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+        displayNames.add(mContext.getString(R.string.calls_and_sms_ask_every_time));
+        subscriptionIds.add(Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
 
-        mPreference.setEntries(displayNames);
-        mPreference.setEntryValues(subscriptionIds);
+        mPreference.setEntries(displayNames.toArray(new CharSequence[0]));
+        mPreference.setEntryValues(subscriptionIds.toArray(new CharSequence[0]));
 
         if (subIsAvailable) {
             mPreference.setValue(Integer.toString(serviceDefaultSubId));
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 20421d0..f1391dc 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -37,6 +37,7 @@
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.panel.PanelLoggingContract.PanelClosedKeys;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.google.android.setupdesign.DividerItemDecoration;
 
 public class PanelFragment extends Fragment {
 
@@ -93,6 +94,10 @@
         mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
         mPanelSlices.setAdapter(mAdapter);
 
+        DividerItemDecoration itemDecoration = new DividerItemDecoration(getActivity());
+        itemDecoration.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
+        mPanelSlices.addItemDecoration(itemDecoration);
+
         mTitleView.setText(mPanel.getTitle());
 
         mSeeMoreButton.setOnClickListener(getSeeMoreListener());
diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java
index 47ff631..0eec534 100644
--- a/src/com/android/settings/panel/PanelSlicesAdapter.java
+++ b/src/com/android/settings/panel/PanelSlicesAdapter.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.panel;
 
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
+
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.net.Uri;
@@ -33,6 +35,7 @@
 
 import com.android.settings.R;
 import com.android.settings.overlay.FeatureFactory;
+import com.google.android.setupdesign.DividerItemDecoration;
 
 import java.util.List;
 
@@ -80,10 +83,13 @@
     /**
      * ViewHolder for binding Slices to SliceViews.
      */
-    public static class SliceRowViewHolder extends RecyclerView.ViewHolder {
+    public static class SliceRowViewHolder extends RecyclerView.ViewHolder
+            implements DividerItemDecoration.DividedViewHolder {
 
         private final PanelContent mPanelContent;
 
+        private boolean mDividerAllowedAbove = true;
+
         @VisibleForTesting
         LiveData<Slice> sliceLiveData;
 
@@ -103,6 +109,11 @@
             sliceLiveData = SliceLiveData.fromUri(context, sliceUri);
             sliceLiveData.observe(fragment.getViewLifecycleOwner(), sliceView);
 
+            // Do not show the divider above media devices switcher slice per request
+            if (sliceUri.equals(MEDIA_OUTPUT_INDICATOR_SLICE_URI)) {
+                mDividerAllowedAbove = false;
+            }
+
             // Log Panel interaction
             sliceView.setOnSliceActionListener(
                     ((eventInfo, sliceItem) -> {
@@ -116,5 +127,15 @@
                     })
             );
         }
+
+        @Override
+        public boolean isDividerAllowedAbove() {
+            return mDividerAllowedAbove;
+        }
+
+        @Override
+        public boolean isDividerAllowedBelow() {
+            return true;
+        }
     }
 }
diff --git a/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java b/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
index bcf8f47..da4b100 100644
--- a/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
+++ b/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
@@ -25,6 +25,7 @@
 import androidx.preference.Preference;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 import com.android.settings.core.BasePreferenceController;
 
 import java.util.List;
@@ -46,8 +47,8 @@
     @Override
     public int getAvailabilityStatus() {
         return (mEnabledServiceInfos.isEmpty() || !Boolean.parseBoolean(
-                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
-                        DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED)))
+                DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                        Utils.PROPERTY_PERMISSIONS_HUB_ENABLED)))
                 ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
     }
 
diff --git a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
index 9358392..d8c66e4 100644
--- a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
+++ b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
@@ -20,8 +20,6 @@
 import static android.Manifest.permission_group.LOCATION;
 import static android.Manifest.permission_group.MICROPHONE;
 
-import static com.android.settingslib.widget.BarChartPreference.MAXIMUM_BAR_VIEWS;
-
 import static java.util.concurrent.TimeUnit.DAYS;
 
 import android.content.Context;
@@ -51,7 +49,6 @@
 import com.android.settingslib.widget.BarViewInfo;
 
 import java.util.ArrayList;
-import java.util.Comparator;
 import java.util.List;
 
 
@@ -93,8 +90,8 @@
     @Override
     public int getAvailabilityStatus() {
         return Boolean.parseBoolean(
-                DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
-                        DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED)) ?
+                DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                        com.android.settings.Utils.PROPERTY_PERMISSIONS_HUB_ENABLED)) ?
                 AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
     }
 
diff --git a/src/com/android/settings/tts/TtsEnginePreference.java b/src/com/android/settings/tts/TtsEnginePreference.java
index 7dc00fe..6ea414d 100644
--- a/src/com/android/settings/tts/TtsEnginePreference.java
+++ b/src/com/android/settings/tts/TtsEnginePreference.java
@@ -18,7 +18,6 @@
 
 import android.content.Context;
 import android.content.DialogInterface;
-import android.content.Intent;
 import android.speech.tts.TextToSpeech.EngineInfo;
 import android.util.Log;
 import android.widget.Checkable;
@@ -30,7 +29,6 @@
 import androidx.preference.PreferenceViewHolder;
 
 import com.android.settings.R;
-import com.android.settings.SettingsActivity;
 
 
 public class TtsEnginePreference extends Preference {
@@ -54,21 +52,20 @@
      */
     private volatile boolean mPreventRadioButtonCallbacks;
 
-    private RadioButton mRadioButton;
-    private Intent mVoiceCheckData;
-
     private final CompoundButton.OnCheckedChangeListener mRadioChangeListener =
-        new CompoundButton.OnCheckedChangeListener() {
-            @Override
-            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-                onRadioButtonClicked(buttonView, isChecked);
-            }
-        };
+            new CompoundButton.OnCheckedChangeListener() {
+                @Override
+                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                    onRadioButtonClicked(buttonView, isChecked);
+                }
+            };
 
-    public TtsEnginePreference(Context context, EngineInfo info, RadioButtonGroupState state,
-            SettingsActivity prefActivity) {
+    public TtsEnginePreference(Context context, EngineInfo info, RadioButtonGroupState state) {
         super(context);
-        setLayoutResource(R.layout.preference_tts_engine);
+
+        setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
+        setLayoutResource(R.layout.preference_radio);
+        setIconSpaceReserved(false);
 
         mSharedState = state;
         mEngineInfo = info;
@@ -87,9 +84,8 @@
                     "setSharedState()");
         }
 
-        final RadioButton rb = (RadioButton) view.findViewById(R.id.tts_engine_radiobutton);
+        final RadioButton rb = view.itemView.findViewById(android.R.id.checkbox);
         rb.setOnCheckedChangeListener(mRadioChangeListener);
-        rb.setText(mEngineInfo.label);
 
         boolean isChecked = getKey().equals(mSharedState.getCurrentKey());
         if (isChecked) {
@@ -99,12 +95,6 @@
         mPreventRadioButtonCallbacks = true;
         rb.setChecked(isChecked);
         mPreventRadioButtonCallbacks = false;
-
-        mRadioButton = rb;
-    }
-
-    public void setVoiceDataDetails(Intent data) {
-        mVoiceCheckData = data;
     }
 
     private boolean shouldDisplayDataAlert() {
@@ -145,7 +135,7 @@
                     public void onClick(DialogInterface dialog, int which) {
                         makeCurrentEngine(buttonView);
                     }
-                },new DialogInterface.OnClickListener() {
+                }, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                         // Undo the click.
@@ -176,9 +166,11 @@
      */
     public interface RadioButtonGroupState {
         String getCurrentKey();
+
         Checkable getCurrentChecked();
 
         void setCurrentKey(String key);
+
         void setCurrentChecked(Checkable current);
     }
 
diff --git a/src/com/android/settings/tts/TtsEnginePreferenceFragment.java b/src/com/android/settings/tts/TtsEnginePreferenceFragment.java
index 43bb459..244e5b1 100644
--- a/src/com/android/settings/tts/TtsEnginePreferenceFragment.java
+++ b/src/com/android/settings/tts/TtsEnginePreferenceFragment.java
@@ -15,7 +15,6 @@
 import androidx.preference.PreferenceCategory;
 
 import com.android.settings.R;
-import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
@@ -87,12 +86,10 @@
 
         mEnginePreferenceCategory.removeAll();
 
-        SettingsActivity activity = (SettingsActivity) getActivity();
-
         List<EngineInfo> engines = mEnginesHelper.getEngines();
         for (EngineInfo engine : engines) {
             TtsEnginePreference enginePref =
-                    new TtsEnginePreference(getPrefContext(), engine, this, activity);
+                    new TtsEnginePreference(getPrefContext(), engine, this);
             mEnginePreferenceCategory.addPreference(enginePref);
         }
     }
@@ -161,6 +158,7 @@
     public void onUpdateEngine(int status) {
         if (status == TextToSpeech.SUCCESS) {
             Log.d(
+
                     TAG,
                     "Updating engine: Successfully bound to the engine: "
                             + mTts.getCurrentEngine());
diff --git a/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java
index ec3cf65..2944db2 100644
--- a/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java
@@ -17,16 +17,25 @@
 package com.android.settings.applications;
 
 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
 import android.app.usage.UsageStats;
 import android.content.Context;
+import android.os.UserManager;
+
+import androidx.preference.Preference;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 
@@ -36,29 +45,45 @@
 @RunWith(RobolectricTestRunner.class)
 public class AllAppsInfoPreferenceControllerTest {
 
+    @Mock
+    private UserManager mUserManager;
     private AllAppsInfoPreferenceController mController;
 
     @Before
     public void setUp() {
-        final Context context = RuntimeEnvironment.application;
+        MockitoAnnotations.initMocks(this);
+        final Context context = spy(RuntimeEnvironment.application);
+        final Preference preference = new Preference(context);
+        doReturn(mUserManager).when(context).getSystemService(Context.USER_SERVICE);
+        when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
         mController = new AllAppsInfoPreferenceController(context, "test_key");
+        mController.mPreference = preference;
     }
 
     @Test
-    public void getAvailabilityStatus_hasRecentApps_shouldReturnConditionallyUnavailable() {
+    public void getAvailabilityStatus_shouldReturnAVAILABLE() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void onReloadDataCompleted_recentAppsSet_hidePreference() {
         final List<UsageStats> stats = new ArrayList<>();
         final UsageStats stat1 = new UsageStats();
         stat1.mLastTimeUsed = System.currentTimeMillis();
         stat1.mPackageName = "pkg.class";
         stats.add(stat1);
-        mController.setRecentApps(stats);
 
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+        mController.onReloadDataCompleted(stats);
+
+        assertThat(mController.mPreference.isVisible()).isFalse();
     }
 
     @Test
-    public void getAvailabilityStatus_noRecentApps_shouldReturnAvailable() {
-        // No data
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    public void onReloadDataCompleted_noRecentAppSet_showPreference() {
+        final List<UsageStats> stats = new ArrayList<>();
+
+        mController.onReloadDataCompleted(stats);
+
+        assertThat(mController.mPreference.isVisible()).isTrue();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/applications/RecentAppStatsMixinTest.java b/tests/robotests/src/com/android/settings/applications/RecentAppStatsMixinTest.java
new file mode 100644
index 0000000..0fb2a7e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/RecentAppStatsMixinTest.java
@@ -0,0 +1,309 @@
+/*
+ * Copyright (C) 2019 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.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.usage.UsageStats;
+import android.app.usage.UsageStatsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.PowerManager;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.settingslib.applications.AppUtils;
+import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class RecentAppStatsMixinTest {
+
+    @Mock
+    private UsageStatsManager mUsageStatsManager;
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private ApplicationsState mAppState;
+    @Mock
+    private PackageManager mPackageManager;
+    @Mock
+    private ApplicationsState.AppEntry mAppEntry;
+    @Mock
+    private ApplicationInfo mApplicationInfo;
+    @Mock
+    private PowerManager mPowerManager;
+
+    private RecentAppStatsMixin mRecentAppStatsMixin;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        final Context context = spy(RuntimeEnvironment.application);
+        when(context.getApplicationContext()).thenReturn(context);
+        ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mAppState);
+        doReturn(mUsageStatsManager).when(context).getSystemService(Context.USAGE_STATS_SERVICE);
+        doReturn(mUserManager).when(context).getSystemService(Context.USER_SERVICE);
+        doReturn(mPackageManager).when(context).getPackageManager();
+        doReturn(mPowerManager).when(context).getSystemService(PowerManager.class);
+        when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
+
+        mRecentAppStatsMixin = new RecentAppStatsMixin(context, 3 /* maximumApps */);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_oneValidRecentAppSet_shouldHaveOneRecentApp() {
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+        // stat1 is valid app.
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+                .thenReturn(new ResolveInfo());
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+        mAppEntry.info = mApplicationInfo;
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_threeValidRecentAppsSet_shouldHaveThreeRecentApps() {
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+        final UsageStats stat2 = new UsageStats();
+        final UsageStats stat3 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+
+        stat2.mLastTimeUsed = System.currentTimeMillis();
+        stat2.mPackageName = "pkg.class2";
+        stats.add(stat2);
+
+        stat3.mLastTimeUsed = System.currentTimeMillis();
+        stat3.mPackageName = "pkg.class3";
+        stats.add(stat3);
+
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat3.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+                .thenReturn(new ResolveInfo());
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+        mAppEntry.info = mApplicationInfo;
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(3);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_oneValidAndTwoInvalidSet_shouldHaveOneRecentApp() {
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+        final UsageStats stat2 = new UsageStats();
+        final UsageStats stat3 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+
+        stat2.mLastTimeUsed = System.currentTimeMillis();
+        stat2.mPackageName = "com.android.settings";
+        stats.add(stat2);
+
+        stat3.mLastTimeUsed = System.currentTimeMillis();
+        stat3.mPackageName = "pkg.class3";
+        stats.add(stat3);
+
+        // stat1, stat2 are valid apps. stat3 is invalid.
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat3.mPackageName, UserHandle.myUserId()))
+                .thenReturn(null);
+        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+                .thenReturn(new ResolveInfo());
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+        mAppEntry.info = mApplicationInfo;
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        // Only stat1. stat2 is skipped because of the package name, stat3 skipped because
+        // it's invalid app.
+        assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_oneInstantAppSet_shouldHaveOneRecentApp() {
+        final List<UsageStats> stats = new ArrayList<>();
+        // Instant app.
+        final UsageStats stat = new UsageStats();
+        stat.mLastTimeUsed = System.currentTimeMillis() + 200;
+        stat.mPackageName = "com.foo.barinstant";
+        stats.add(stat);
+
+        ApplicationsState.AppEntry statEntry = mock(ApplicationsState.AppEntry.class);
+        statEntry.info = mApplicationInfo;
+
+        when(mAppState.getEntry(stat.mPackageName, UserHandle.myUserId())).thenReturn(statEntry);
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+
+        // Make sure stat is considered an instant app.
+        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+                (InstantAppDataProvider) (ApplicationInfo info) -> info == statEntry.info);
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_withNullAppEntryOrInfo_shouldNotCrash() {
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+        final UsageStats stat2 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+
+        stat2.mLastTimeUsed = System.currentTimeMillis();
+        stat2.mPackageName = "pkg.class2";
+        stats.add(stat2);
+
+        // app1 has AppEntry with null info, app2 has null AppEntry.
+        mAppEntry.info = null;
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
+                .thenReturn(null);
+
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+
+        // We should not crash here.
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_hiddenSystemModuleSet_shouldNotHaveHiddenSystemModule() {
+        final List<UsageStats> stats = new ArrayList<>();
+        // Regular app.
+        final UsageStats stat1 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "com.foo.bar";
+        stats.add(stat1);
+
+        // Hidden system module.
+        final UsageStats stat2 = new UsageStats();
+        stat2.mLastTimeUsed = System.currentTimeMillis() + 200;
+        stat2.mPackageName = "com.foo.hidden";
+        stats.add(stat2);
+
+        ApplicationsState.AppEntry stat1Entry = mock(ApplicationsState.AppEntry.class);
+        ApplicationsState.AppEntry stat2Entry = mock(ApplicationsState.AppEntry.class);
+        stat1Entry.info = mApplicationInfo;
+        stat2Entry.info = mApplicationInfo;
+
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(stat1Entry);
+        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(stat2Entry);
+
+        final ModuleInfo moduleInfo1 = new ModuleInfo();
+        moduleInfo1.setPackageName(stat1.mPackageName);
+        moduleInfo1.setHidden(false);
+
+        final ModuleInfo moduleInfo2 = new ModuleInfo();
+        moduleInfo2.setPackageName(stat2.mPackageName);
+        moduleInfo2.setHidden(true);
+
+        ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", null);
+        final List<ModuleInfo> modules = new ArrayList<>();
+        modules.add(moduleInfo2);
+        when(mPackageManager.getInstalledModules(anyInt() /* flags */))
+                .thenReturn(modules);
+
+        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+                .thenReturn(new ResolveInfo());
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
+    }
+
+    @Test
+    public void loadDisplayableRecentApps_powerSaverModeOn_shouldHaveEmptyList() {
+        when(mPowerManager.isPowerSaveMode()).thenReturn(true);
+
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+
+        // stat1, stat2 are valid apps. stat3 is invalid.
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+                .thenReturn(new ResolveInfo());
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+        mAppEntry.info = mApplicationInfo;
+
+        mRecentAppStatsMixin.loadDisplayableRecentApps(3);
+
+        assertThat(mRecentAppStatsMixin.mRecentApps).isEmpty();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
index 1a28f37..2928d6f 100644
--- a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
@@ -16,33 +16,23 @@
 
 package com.android.settings.applications;
 
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
 import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
-import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.usage.UsageStats;
-import android.app.usage.UsageStatsManager;
 import android.content.Context;
-import android.content.Intent;
 import android.content.pm.ApplicationInfo;
-import android.content.pm.ModuleInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.PowerManager;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.view.LayoutInflater;
@@ -53,9 +43,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
-import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState;
-import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
 import com.android.settingslib.widget.AppEntitiesHeaderController;
 import com.android.settingslib.widget.AppEntityInfo;
 import com.android.settingslib.widget.LayoutPreference;
@@ -63,7 +51,6 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatcher;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
@@ -79,8 +66,6 @@
     @Mock
     private PreferenceScreen mScreen;
     @Mock
-    private UsageStatsManager mUsageStatsManager;
-    @Mock
     private UserManager mUserManager;
     @Mock
     private ApplicationsState mAppState;
@@ -91,11 +76,8 @@
     @Mock
     private ApplicationInfo mApplicationInfo;
     @Mock
-    private PowerManager mPowerManager;
-    @Mock
     private Fragment mFragment;
 
-    private LayoutPreference mRecentAppsPreference;
     private RecentAppsPreferenceController mController;
 
     @Before
@@ -104,92 +86,33 @@
         final Context context = spy(RuntimeEnvironment.application);
         when(context.getApplicationContext()).thenReturn(context);
         ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mAppState);
-        doReturn(mUsageStatsManager).when(context).getSystemService(Context.USAGE_STATS_SERVICE);
         doReturn(mUserManager).when(context).getSystemService(Context.USER_SERVICE);
         doReturn(mPackageManager).when(context).getPackageManager();
-        doReturn(mPowerManager).when(context).getSystemService(PowerManager.class);
         when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
 
         final View appEntitiesHeaderView = LayoutInflater.from(context).inflate(
                 R.layout.app_entities_header, null /* root */);
         final Preference dividerPreference = new Preference(context);
-        mRecentAppsPreference = spy(new LayoutPreference(context, appEntitiesHeaderView));
+        final LayoutPreference recentAppsPreference =
+                spy(new LayoutPreference(context, appEntitiesHeaderView));
 
         mController = spy(new RecentAppsPreferenceController(context, "test_key"));
         mController.setFragment(mFragment);
+
         mController.mAppEntitiesController = mock(AppEntitiesHeaderController.class);
-        mController.mRecentAppsPreference = mRecentAppsPreference;
+        mController.mRecentAppsPreference = recentAppsPreference;
         mController.mDivider = dividerPreference;
 
         when(mScreen.findPreference(RecentAppsPreferenceController.KEY_DIVIDER))
                 .thenReturn(dividerPreference);
-        when(mScreen.findPreference("test_key")).thenReturn(mRecentAppsPreference);
-        when(mRecentAppsPreference.findViewById(R.id.app_entities_header)).thenReturn(
+        when(mScreen.findPreference("test_key")).thenReturn(recentAppsPreference);
+        when(recentAppsPreference.findViewById(R.id.app_entities_header)).thenReturn(
                 appEntitiesHeaderView);
     }
 
     @Test
-    public void getAvailabilityStatus_hasRecentApps_shouldReturnAvailable() {
-        final List<UsageStats> stats = new ArrayList<>();
-        final UsageStats stat1 = new UsageStats();
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "pkg.class";
-        stats.add(stat1);
-        // stat1 is valid app.
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
-                .thenReturn(mAppEntry);
-        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-        mAppEntry.info = mApplicationInfo;
-        mController.reloadData();
-
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
-    }
-
-    @Test
-    public void getAvailabilityStatus_noRecentApps_shouldReturnConditionallyUnavailable() {
-        // No data
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
-    }
-
-    @Test
-    public void getAvailabilityStatus_powerSaverModeOn_shouldReturnConditionallyUnavailable() {
-        when(mPowerManager.isPowerSaveMode()).thenReturn(true);
-
-        final List<UsageStats> stats = new ArrayList<>();
-        final UsageStats stat1 = new UsageStats();
-
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "pkg.class";
-        stats.add(stat1);
-
-        // stat1, stat2 are valid apps. stat3 is invalid.
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
-                .thenReturn(mAppEntry);
-        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-        mAppEntry.info = mApplicationInfo;
-        mController.reloadData();
-
-        assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
-    }
-
-    @Test
-    public void displayPreference_shouldNotReloadData() {
-        mController.displayPreference(mScreen);
-
-        verify(mController, never()).reloadData();
-    }
-
-    @Test
-    public void displayPreference_shouldRefreshUi() {
-        mController.displayPreference(mScreen);
-
-        verify(mController).refreshUi();
+    public void getAvailabilityStatus_shouldReturnAVAILABLE_UNSEARCHABLE() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
     }
 
     @Test
@@ -200,7 +123,7 @@
     }
 
     @Test
-    public void updateState_threeValidRecentOpenAppsSet_setAppEntityThreeTime() {
+    public void onReloadDataCompleted_threeValidRecentOpenAppsSet_setAppEntityThreeTime() {
         final List<UsageStats> stats = new ArrayList<>();
         final UsageStats stat1 = new UsageStats();
         final UsageStats stat2 = new UsageStats();
@@ -216,22 +139,15 @@
         stat3.mLastTimeUsed = System.currentTimeMillis();
         stat3.mPackageName = "pkg.class3";
         stats.add(stat3);
-
-        // stat1, stat2 are valid apps. stat3 is invalid.
         when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
                 .thenReturn(mAppEntry);
         when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
                 .thenReturn(mAppEntry);
         when(mAppState.getEntry(stat3.mPackageName, UserHandle.myUserId()))
                 .thenReturn(mAppEntry);
-        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
         mAppEntry.info = mApplicationInfo;
-        mController.reloadData();
 
-        mController.updateState(mRecentAppsPreference);
+        mController.onReloadDataCompleted(stats);
 
         verify(mController.mAppEntitiesController, times(3))
                 .setAppEntity(anyInt(), any(AppEntityInfo.class));
@@ -240,165 +156,12 @@
     }
 
     @Test
-    public void updateState_oneValidRecentOpenAppSet_setAppEntityOneTime() {
+    public void onReloadDataCompleted_noRecentOpenAppsSet_shouldHideRecentAppPreference() {
         final List<UsageStats> stats = new ArrayList<>();
-        final UsageStats stat1 = new UsageStats();
-        final UsageStats stat2 = new UsageStats();
-        final UsageStats stat3 = new UsageStats();
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "pkg.class";
-        stats.add(stat1);
 
-        stat2.mLastTimeUsed = System.currentTimeMillis();
-        stat2.mPackageName = "com.android.settings";
-        stats.add(stat2);
+        mController.onReloadDataCompleted(stats);
 
-        stat3.mLastTimeUsed = System.currentTimeMillis();
-        stat3.mPackageName = "pkg.class3";
-        stats.add(stat3);
-
-        // stat1, stat2 are valid apps. stat3 is invalid.
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
-                .thenReturn(mAppEntry);
-        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
-                .thenReturn(mAppEntry);
-        when(mAppState.getEntry(stat3.mPackageName, UserHandle.myUserId()))
-                .thenReturn(null);
-        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-        mAppEntry.info = mApplicationInfo;
-        mController.reloadData();
-
-        mController.updateState(mRecentAppsPreference);
-
-        // Only add stat1. stat2 is skipped because of the package name, stat3 skipped because
-        // it's invalid app.
-        verify(mController.mAppEntitiesController, times(1))
-                .setAppEntity(anyInt(), any(AppEntityInfo.class));
-        assertThat(mController.mRecentAppsPreference.isVisible()).isTrue();
-        assertThat(mController.mDivider.isVisible()).isTrue();
-    }
-
-    @Test
-    public void updateState_instantAppSet_shouldSetAppEntityForInstantApp() {
-        // Regular app.
-        final List<UsageStats> stats = new ArrayList<>();
-        final UsageStats stat1 = new UsageStats();
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "com.foo.bar";
-        stats.add(stat1);
-
-        // Instant app.
-        final UsageStats stat2 = new UsageStats();
-        stat2.mLastTimeUsed = System.currentTimeMillis() + 200;
-        stat2.mPackageName = "com.foo.barinstant";
-        stats.add(stat2);
-
-        ApplicationsState.AppEntry stat1Entry = mock(ApplicationsState.AppEntry.class);
-        ApplicationsState.AppEntry stat2Entry = mock(ApplicationsState.AppEntry.class);
-        stat1Entry.info = mApplicationInfo;
-        stat2Entry.info = mApplicationInfo;
-
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(stat1Entry);
-        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(stat2Entry);
-
-        // Only the regular app stat1 should have its intent resolve.
-        when(mPackageManager.resolveActivity(argThat(intentMatcher(stat1.mPackageName)), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-
-        // Make sure stat2 is considered an instant app.
-        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
-                (InstantAppDataProvider) (ApplicationInfo info) -> info == stat2Entry.info);
-        mController.reloadData();
-
-        mController.updateState(mRecentAppsPreference);
-
-        verify(mController.mAppEntitiesController, times(2))
-                .setAppEntity(anyInt(), any(AppEntityInfo.class));
-    }
-
-    @Test
-    public void updateState_withNullAppEntryOrInfo_shouldNotCrash() {
-        final List<UsageStats> stats = new ArrayList<>();
-        final UsageStats stat1 = new UsageStats();
-        final UsageStats stat2 = new UsageStats();
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "pkg.class";
-        stats.add(stat1);
-
-        stat2.mLastTimeUsed = System.currentTimeMillis();
-        stat2.mPackageName = "pkg.class2";
-        stats.add(stat2);
-
-        // app1 has AppEntry with null info, app2 has null AppEntry.
-        mAppEntry.info = null;
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
-                .thenReturn(mAppEntry);
-        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
-                .thenReturn(null);
-
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-
-        // We should not crash here.
-        mController.updateState(mRecentAppsPreference);
-    }
-
-    @Test
-    public void updateState_hiddenSystemModuleSet_shouldNotShowHiddenSystemModule() {
-        final List<UsageStats> stats = new ArrayList<>();
-        // Regular app.
-        final UsageStats stat1 = new UsageStats();
-        stat1.mLastTimeUsed = System.currentTimeMillis();
-        stat1.mPackageName = "com.foo.bar";
-        stats.add(stat1);
-
-        // Hidden system module.
-        final UsageStats stat2 = new UsageStats();
-        stat2.mLastTimeUsed = System.currentTimeMillis() + 200;
-        stat2.mPackageName = "com.foo.hidden";
-        stats.add(stat2);
-
-        ApplicationsState.AppEntry stat1Entry = mock(ApplicationsState.AppEntry.class);
-        ApplicationsState.AppEntry stat2Entry = mock(ApplicationsState.AppEntry.class);
-        stat1Entry.info = mApplicationInfo;
-        stat2Entry.info = mApplicationInfo;
-
-        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(stat1Entry);
-        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(stat2Entry);
-
-        final ModuleInfo moduleInfo1 = new ModuleInfo();
-        moduleInfo1.setPackageName(stat1.mPackageName);
-        moduleInfo1.setHidden(false);
-
-        final ModuleInfo moduleInfo2 = new ModuleInfo();
-        moduleInfo2.setPackageName(stat2.mPackageName);
-        moduleInfo2.setHidden(true);
-
-        ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", null);
-        final List<ModuleInfo> modules = new ArrayList<>();
-        modules.add(moduleInfo2);
-        when(mPackageManager.getInstalledModules(anyInt() /* flags */))
-                .thenReturn(modules);
-
-        when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
-                .thenReturn(new ResolveInfo());
-        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
-                .thenReturn(stats);
-        mController.reloadData();
-
-        mController.updateState(mRecentAppsPreference);
-
-        // Only add stat1. stat2 is skipped because it is hidden module.
-        verify(mController.mAppEntitiesController).setAppEntity(anyInt(), any(AppEntityInfo.class));
-    }
-
-    // Used for matching an intent with a specific package name.
-    private static ArgumentMatcher<Intent> intentMatcher(String packageName) {
-        return intent -> packageName.equals(intent.getPackage());
+        assertThat(mController.mRecentAppsPreference.isVisible()).isFalse();
+        assertThat(mController.mDivider.isVisible()).isFalse();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java
deleted file mode 100644
index ecfe35a..0000000
--- a/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.development;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-@RunWith(RobolectricTestRunner.class)
-public class SmsAccessRestrictionPreferenceControllerTest {
-
-    @Mock
-    private SwitchPreference mPreference;
-    @Mock
-    private PreferenceScreen mPreferenceScreen;
-
-    private Context mContext;
-    private SmsAccessRestrictionPreferenceController mController;
-
-    @Before
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
-        mController = new SmsAccessRestrictionPreferenceController(mContext);
-        when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
-            .thenReturn(mPreference);
-        mController.displayPreference(mPreferenceScreen);
-    }
-
-    @Test
-    public void onPreferenceChange_settingEnabled_enableSmsRestrictionShouldBeOn() {
-        mController.onPreferenceChange(mPreference, true /* new value */);
-
-        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
-
-        assertThat(mode).isEqualTo(1);
-    }
-
-    @Test
-    public void onPreferenceChange_settingDisabled_enableSmsRestrictionShouldBeOff() {
-        mController.onPreferenceChange(mPreference, false /* new value */);
-
-        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
-
-        assertThat(mode).isEqualTo(0);
-    }
-
-    @Test
-    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
-        Settings.Global.putInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0);
-        mController.updateState(mPreference);
-
-        verify(mPreference).setChecked(false);
-    }
-
-    @Test
-    public void updateState_settingEnabled_preferenceShouldBeChecked() {
-        Settings.Global.putInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 1);
-        mController.updateState(mPreference);
-
-        verify(mPreference).setChecked(true);
-    }
-
-    @Test
-    public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
-        mController.onDeveloperOptionsSwitchDisabled();
-
-        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
-
-        assertThat(mode).isEqualTo(0);
-        verify(mPreference).setChecked(false);
-        verify(mPreference).setEnabled(false);
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
index f391aac..adddc96 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
@@ -60,18 +60,6 @@
         mContext = spy(RuntimeEnvironment.application);
         mPreference = new Preference(mContext);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
-
-        FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, true);
-    }
-
-    @Test
-    public void getAvailabilityStatus_featureDisabled_unavailable() {
-        FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, false);
-
-        final MainlineModuleVersionPreferenceController controller =
-                new MainlineModuleVersionPreferenceController(mContext, "key");
-
-        assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/display/DisplayWhiteBalancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/DisplayWhiteBalancePreferenceControllerTest.java
index 59820e6..d0dbc0b 100644
--- a/tests/robotests/src/com/android/settings/display/DisplayWhiteBalancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/DisplayWhiteBalancePreferenceControllerTest.java
@@ -5,10 +5,7 @@
 import static org.mockito.Mockito.when;
 import static com.google.common.truth.Truth.assertThat;
 
-import android.content.Context;
 import android.hardware.display.ColorDisplayManager;
-import android.provider.Settings;
-import android.provider.Settings.Secure;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import org.junit.After;
 import org.junit.Before;
@@ -26,7 +23,6 @@
 })
 public class DisplayWhiteBalancePreferenceControllerTest {
 
-  private Context mContext;
   private DisplayWhiteBalancePreferenceController mController;
 
   @Mock
@@ -40,8 +36,7 @@
   @Before
   public void setUp() {
     MockitoAnnotations.initMocks(this);
-    mContext = RuntimeEnvironment.application;
-    mController = spy(new DisplayWhiteBalancePreferenceController(mContext,
+    mController = spy(new DisplayWhiteBalancePreferenceController(RuntimeEnvironment.application,
         "display_white_balance"));
     doReturn(mColorDisplayManager).when(mController).getColorDisplayManager();
   }
@@ -77,30 +72,26 @@
   }
 
   @Test
-  public void setChecked_true() {
-    mController.setChecked(true);
-    assertThat(Settings.Secure
-        .getInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0) == 1)
-        .isTrue();
+  public void setChecked_true_setSuccessfully() {
+    when(mColorDisplayManager.setDisplayWhiteBalanceEnabled(true)).thenReturn(true);
+    assertThat(mController.setChecked(true)).isTrue();
   }
 
   @Test
-  public void setChecked_false() {
-    mController.setChecked(false);
-    assertThat(Settings.Secure
-        .getInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0) == 1)
-        .isFalse();
+  public void setChecked_false_setSuccessfully() {
+    when(mColorDisplayManager.setDisplayWhiteBalanceEnabled(false)).thenReturn(true);
+    assertThat(mController.setChecked(false)).isTrue();
   }
 
   @Test
   public void isChecked_true() {
-    Settings.Secure.putInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 1);
+    when(mColorDisplayManager.isDisplayWhiteBalanceEnabled()).thenReturn(true);
     assertThat(mController.isChecked()).isTrue();
   }
 
   @Test
   public void isChecked_false() {
-    Settings.Secure.putInt(mContext.getContentResolver(), Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0);
+    when(mColorDisplayManager.isDisplayWhiteBalanceEnabled()).thenReturn(false);
     assertThat(mController.isChecked()).isFalse();
   }
 }
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
index 2fe4697..58a8d5b 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
@@ -26,6 +26,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.hardware.display.ColorDisplayManager;
+import android.os.UserHandle;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -87,6 +88,7 @@
     public void onActionClick_shouldSendBroadcast() {
         mController.onActionClick();
 
-        verify(mContext).sendBroadcast(any(Intent.class), any(String.class));
+        verify(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class),
+                any(String.class));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 2d3cb0c..d210c7b 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -33,6 +33,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
 import com.android.settingslib.location.RecentLocationAccesses;
 import com.android.settingslib.widget.LayoutPreference;
@@ -94,8 +95,8 @@
 
     @Test
     public void isAvailable_permissionHubEnabled_shouldReturnTrue() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
 
         assertThat(mController.isAvailable()).isEqualTo(true);
     }
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
index f7a2567..e503d70 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
@@ -148,6 +148,34 @@
     }
 
     @Test
+    public void displayPreference_threeSubsOneIsOpportunistic_correctListPreferenceValues() {
+        final SubscriptionInfo sub1 = createMockSub(111, "sub1");
+        final SubscriptionInfo sub2 = createMockSub(222, "sub2");
+        final SubscriptionInfo sub3 = createMockSub(333, "sub3");
+
+        // Mark sub2 as opportunistic; then it should not appear in the list of entries/entryValues.
+        when(sub2.isOpportunistic()).thenReturn(true);
+
+        SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2, sub3));
+        doReturn(sub1.getSubscriptionId()).when(mController).getDefaultSubscriptionId();
+
+        mController.displayPreference(mScreen);
+
+        final CharSequence[] entries = mListPreference.getEntries();
+        assertThat(entries.length).isEqualTo(3);
+        assertThat(entries[0]).isEqualTo("sub1");
+        assertThat(entries[1]).isEqualTo("sub3");
+        assertThat(entries[2]).isEqualTo(mContext.getString(R.string.calls_and_sms_ask_every_time));
+
+        final CharSequence[] entryValues = mListPreference.getEntryValues();
+        assertThat(entryValues.length).isEqualTo(3);
+        assertThat(entryValues[0]).isEqualTo("111");
+        assertThat(entryValues[1]).isEqualTo("333");
+        assertThat(entryValues[2]).isEqualTo(
+                Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
+    }
+
+    @Test
     public void onPreferenceChange_prefChangedToSub2_callbackCalledCorrectly() {
         final SubscriptionInfo sub1 = createMockSub(111, "sub1");
         final SubscriptionInfo sub2 = createMockSub(222, "sub2");
diff --git a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
index 4dce15e..9795b55 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
@@ -16,13 +16,18 @@
 
 package com.android.settings.panel;
 
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
+import android.app.settings.SettingsEnums;
 import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
 
@@ -39,6 +44,9 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.android.controller.ActivityController;
 
+import java.util.Arrays;
+import java.util.List;
+
 @RunWith(RobolectricTestRunner.class)
 public class PanelSlicesAdapterTest {
 
@@ -48,8 +56,6 @@
     private FakeFeatureFactory mFakeFeatureFactory;
     private PanelFeatureProvider mPanelFeatureProvider;
 
-    private PanelSlicesAdapter mAdapter;
-
     @Before
     public void setUp() {
         mContext = RuntimeEnvironment.application;
@@ -70,28 +76,83 @@
                                 .get()
                                 .getSupportFragmentManager()
                                 .findFragmentById(R.id.main_content));
-
-        mAdapter = new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
     }
 
     @Test
     public void onCreateViewHolder_returnsSliceRowViewHolder() {
+        final PanelSlicesAdapter adapter =
+                new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
         final ViewGroup view = new FrameLayout(mContext);
         final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
-                mAdapter.onCreateViewHolder(view, 0);
+                adapter.onCreateViewHolder(view, 0);
 
         assertThat(viewHolder.sliceView).isNotNull();
     }
 
     @Test
     public void onBindViewHolder_bindsSlice() {
+        final PanelSlicesAdapter adapter =
+                new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
         final int position = 0;
         final ViewGroup view = new FrameLayout(mContext);
         final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
-                mAdapter.onCreateViewHolder(view, 0 /* view type*/);
+                adapter.onCreateViewHolder(view, 0 /* view type*/);
 
-        mAdapter.onBindViewHolder(viewHolder, position);
+        adapter.onBindViewHolder(viewHolder, position);
 
         assertThat(viewHolder.sliceLiveData).isNotNull();
     }
+
+    @Test
+    public void nonMediaOutputIndicatorSlice_shouldAllowDividerAboveAndBelow() {
+        final PanelSlicesAdapter adapter =
+                new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
+        final int position = 0;
+        final ViewGroup view = new FrameLayout(mContext);
+        final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
+                adapter.onCreateViewHolder(view, 0 /* view type*/);
+
+        adapter.onBindViewHolder(viewHolder, position);
+
+        assertThat(viewHolder.isDividerAllowedAbove()).isTrue();
+        assertThat(viewHolder.isDividerAllowedBelow()).isTrue();
+    }
+
+    @Test
+    public void mediaOutputIndicatorSlice_shouldNotAllowDividerAbove() {
+        PanelContent mediaOutputIndicatorSlicePanelContent = new PanelContent() {
+            @Override
+            public CharSequence getTitle() {
+                return "title";
+            }
+
+            @Override
+            public List<Uri> getSlices() {
+                return Arrays.asList(
+                        MEDIA_OUTPUT_INDICATOR_SLICE_URI
+                );
+            }
+
+            @Override
+            public Intent getSeeMoreIntent() {
+                return new Intent();
+            }
+
+            @Override
+            public int getMetricsCategory() {
+                return SettingsEnums.TESTING;
+            }
+        };
+
+        final PanelSlicesAdapter adapter =
+                new PanelSlicesAdapter(mPanelFragment, mediaOutputIndicatorSlicePanelContent);
+        final int position = 0;
+        final ViewGroup view = new FrameLayout(mContext);
+        final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
+                adapter.onCreateViewHolder(view, 0 /* view type*/);
+
+        adapter.onBindViewHolder(viewHolder, position);
+
+        assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
+    }
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
index 05ce30a..1fbd66f 100644
--- a/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
@@ -25,6 +25,7 @@
 import android.provider.DeviceConfig;
 import android.view.accessibility.AccessibilityManager;
 
+import com.android.settings.Utils;
 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
 
 import org.junit.After;
@@ -74,8 +75,8 @@
 
     @Test
     public void getAvailabilityStatus_noEnabledServices_shouldReturnUnsupported() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
         mAccessibilityManager.setEnabledAccessibilityServiceList(new ArrayList<>());
         AccessibilityUsagePreferenceController controller =
                 new AccessibilityUsagePreferenceController(mContext, "test_key");
@@ -85,8 +86,8 @@
 
     @Test
     public void getAvailabilityStatus_enabledServices_shouldReturnAvailableUnsearchable() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
         mAccessibilityManager.setEnabledAccessibilityServiceList(
                 new ArrayList<>(Arrays.asList(new AccessibilityServiceInfo())));
         AccessibilityUsagePreferenceController controller =
diff --git a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
index 9888168..dc824ed 100644
--- a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
@@ -46,6 +46,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.Utils;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
 import com.android.settings.testutils.shadow.ShadowPermissionControllerManager;
@@ -119,8 +120,9 @@
 
     @Test
     public void getAvailabilityStatus_permissionHubEnabled_shouldReturnAvailableUnsearchable() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
+                "true", true);
 
         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
     }
@@ -180,8 +182,9 @@
 
     @Test
     public void onStart_usageInfosNotSetAndPermissionHubEnabled_shouldShowProgressBar() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
+                "true", true);
         mController.displayPreference(mScreen);
 
         mController.onStart();
@@ -192,8 +195,9 @@
 
     @Test
     public void onStart_usageInfosSetAndPermissionHubEnabled_shouldNotUpdatePrefLoadingState() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
+                "true", true);
         final RuntimePermissionUsageInfo info1 =
                 new RuntimePermissionUsageInfo("permission 1", 10);
         mController.mOldUsageInfos.add(info1);
@@ -207,8 +211,9 @@
 
     @Test
     public void onStart_permissionHubDisabled_shouldNotShowProgressBar() {
-        DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
-                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "false", false);
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
+                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
+                "false", true);
 
         mController.onStart();
 
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPermissionControllerManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPermissionControllerManager.java
index 091b244..6a6f710 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPermissionControllerManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPermissionControllerManager.java
@@ -18,6 +18,7 @@
 
 import android.annotation.CallbackExecutor;
 import android.content.Context;
+import android.os.Handler;
 import android.permission.PermissionControllerManager;
 
 import androidx.annotation.NonNull;
@@ -30,7 +31,7 @@
 @Implements(PermissionControllerManager.class)
 public class ShadowPermissionControllerManager {
 
-    protected void __constructor__(Context context) {
+    protected void __constructor__(Context contexts, Handler handler) {
         // no nothing, everything is shadowed
     }