Merge "Log different type of values into different constants"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 038b184..0ca1628 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -378,6 +378,11 @@
     <!-- Description for bluetooth device name summary [CHAR LIMIT=none] -->
     <string name="bluetooth_device_name_summary">Visible as <xliff:g id="device_name">^1</xliff:g> to other devices</string>
 
+    <!-- Title for paired device group [CHAR LIMIT=none] -->
+    <string name="bluetooth_paired_device_title">Your devices</string>
+    <!-- Title for pairing bluetooth device page [CHAR LIMIT=none] -->
+    <string name="bluetooth_pairing_page_title">Pair bluetooth device</string>
+
     <!-- Date & time settings screen title -->
     <string name="date_and_time">Date &amp; time</string>
     <!-- The title of the activity to pick a time zone. -->
diff --git a/res/xml/bluetooth_pairing_detail.xml b/res/xml/bluetooth_pairing_detail.xml
new file mode 100644
index 0000000..30eaf09
--- /dev/null
+++ b/res/xml/bluetooth_pairing_detail.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/bluetooth_settings">
+
+    <Preference
+        android:key="device_name"/>
+
+    <com.android.settings.bluetooth.BluetoothProgressCategory
+        android:key="available_devices"
+        android:title="@string/bluetooth_paired_device_title"/>
+
+    <com.android.settingslib.widget.FooterPreference/>
+
+</PreferenceScreen>
diff --git a/res/xml/bluetooth_settings.xml b/res/xml/bluetooth_settings.xml
index 783a860..046295b 100644
--- a/res/xml/bluetooth_settings.xml
+++ b/res/xml/bluetooth_settings.xml
@@ -4,9 +4,9 @@
      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.
@@ -16,6 +16,15 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:title="@string/bluetooth_settings" >
+    android:title="@string/bluetooth_settings">
+
+    <Preference
+        android:key="device_name"/>
+
+    <PreferenceCategory
+        android:key="paired_devices"
+        android:title="@string/bluetooth_paired_device_title"/>
+
+    <com.android.settingslib.widget.FooterPreference/>
 
 </PreferenceScreen>
diff --git a/res/xml/bluetooth_settings_obsolete.xml b/res/xml/bluetooth_settings_obsolete.xml
new file mode 100644
index 0000000..55a099c
--- /dev/null
+++ b/res/xml/bluetooth_settings_obsolete.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/bluetooth_settings" >
+
+</PreferenceScreen>
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index d70cc33..ecbcbd1 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -19,7 +19,6 @@
     android:title="@string/connected_devices_dashboard_title">
 
     <com.android.settings.widget.MasterSwitchPreference
-      android:fragment="com.android.settings.bluetooth.BluetoothSettings"
       android:key="toggle_bluetooth"
       android:title="@string/bluetooth_settings_title"
       android:icon="@drawable/ic_settings_bluetooth"
diff --git a/res/xml/suggestion_ordering.xml b/res/xml/suggestion_ordering.xml
index f0388a3..e21fe5b 100644
--- a/res/xml/suggestion_ordering.xml
+++ b/res/xml/suggestion_ordering.xml
@@ -18,7 +18,7 @@
     <step category="com.android.settings.suggested.category.DEFERRED_SETUP"
           exclusive="true" />
     <step category="com.android.settings.suggested.category.FIRST_IMPRESSION"
-          exclusiveExpireDays="7"
+          exclusiveExpireDays="14"
           exclusive="true"
           multiple="true" />
     <step category="com.android.settings.suggested.category.LOCK_SCREEN" />
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 5aee39f..843b7fc 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -109,7 +109,7 @@
         mRemoveAccountController = new RemoveAccountPreferenceController(context, this);
         controllers.add(mRemoveAccountController);
         controllers.add(new AccountHeaderPreferenceController(
-                context, getActivity(), this, getArguments()));
+                context, getLifecycle(), getActivity(), this, getArguments()));
         return controllers;
     }
 
diff --git a/src/com/android/settings/accounts/AccountHeaderPreferenceController.java b/src/com/android/settings/accounts/AccountHeaderPreferenceController.java
index 4730e9e..d0ce58d 100644
--- a/src/com/android/settings/accounts/AccountHeaderPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountHeaderPreferenceController.java
@@ -18,10 +18,10 @@
 
 import android.accounts.Account;
 import android.app.Activity;
-import android.app.Fragment;
 import android.content.Context;
 import android.os.Bundle;
 import android.os.UserHandle;
+import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.R;
@@ -29,6 +29,7 @@
 import com.android.settings.core.PreferenceController;
 import com.android.settings.widget.EntityHeaderController;
 import com.android.settingslib.accounts.AuthenticatorHelper;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import static com.android.settings.accounts.AccountDetailDashboardFragment.KEY_ACCOUNT;
 import static com.android.settings.accounts.AccountDetailDashboardFragment.KEY_USER_HANDLE;
@@ -38,15 +39,17 @@
     private static final String KEY_ACCOUNT_HEADER = "account_header";
 
     private final Activity mActivity;
-    private final Fragment mHost;
+    private final PreferenceFragment mHost;
     private final Account mAccount;
     private final UserHandle mUserHandle;
+    private final Lifecycle mLifecycle;
 
-    public AccountHeaderPreferenceController(Context context, Activity activity, Fragment host,
-            Bundle args) {
+    public AccountHeaderPreferenceController(Context context, Lifecycle lifecycle,
+            Activity activity, PreferenceFragment host, Bundle args) {
         super(context);
         mActivity = activity;
         mHost = host;
+        mLifecycle = lifecycle;
         if (args != null && args.containsKey(KEY_ACCOUNT)) {
             mAccount = args.getParcelable(KEY_ACCOUNT);
         } else {
@@ -80,6 +83,7 @@
 
         EntityHeaderController
                 .newInstance(mActivity, mHost, headerPreference.findViewById(R.id.entity_header))
+                .setRecyclerView(mHost.getListView(), mLifecycle)
                 .setLabel(mAccount.name)
                 .setIcon(helper.getDrawableForType(mContext, mAccount.type))
                 .done(mActivity, true /* rebindButtons */);
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index bbcec3c..95877e9 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -43,6 +43,7 @@
         final Activity activity = getActivity();
         final Preference pref = EntityHeaderController
                 .newInstance(activity, this, null /* header */)
+                .setRecyclerView(getListView(), getLifecycle())
                 .setIcon(IconDrawableFactory.newInstance(activity)
                         .getBadgedIcon(mPackageInfo.applicationInfo))
                 .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 3021f75..0eaad8e 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -408,6 +408,7 @@
         mHeader = (LayoutPreference) findPreference(KEY_HEADER);
         mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
         EntityHeaderController.newInstance(activity, this, mHeader.findViewById(R.id.entity_header))
+                .setRecyclerView(getListView(), getLifecycle())
                 .setPackageName(mPackageName)
                 .setButtonActions(EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
                         EntityHeaderController.ActionType.ACTION_NONE)
@@ -585,11 +586,11 @@
         final CharSequence summary =
                 isInstantApp ? null : getString(Utils.getInstallationStatus(mAppEntry.info));
         EntityHeaderController.newInstance(activity, this, appSnippet)
-            .setLabel(mAppEntry)
-            .setIcon(mAppEntry)
-            .setSummary(summary)
-            .setIsInstantApp(isInstantApp)
-            .done(activity, false /* rebindActions */);
+                .setLabel(mAppEntry)
+                .setIcon(mAppEntry)
+                .setSummary(summary)
+                .setIsInstantApp(isInstantApp)
+                .done(activity, false /* rebindActions */);
         mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
     }
 
diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index 9f229af..b9c3826 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -128,16 +128,17 @@
         final Activity activity = getActivity();
         final Preference pref = EntityHeaderController
                 .newInstance(activity, this, null /* appHeader */)
-            .setIcon(mApp.mUiTargetApp != null
-                ? IconDrawableFactory.newInstance(activity).getBadgedIcon(mApp.mUiTargetApp)
-                : new ColorDrawable(0))
-            .setLabel(mApp.mUiLabel)
-            .setPackageName(mApp.mPackage)
-            .setUid(mApp.mUiTargetApp != null
-                ? mApp.mUiTargetApp.uid
-                : UserHandle.USER_NULL)
-            .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
-            .done(activity, getPrefContext());
+                .setRecyclerView(getListView(), getLifecycle())
+                .setIcon(mApp.mUiTargetApp != null
+                        ? IconDrawableFactory.newInstance(activity).getBadgedIcon(mApp.mUiTargetApp)
+                        : new ColorDrawable(0))
+                .setLabel(mApp.mUiLabel)
+                .setPackageName(mApp.mPackage)
+                .setUid(mApp.mUiTargetApp != null
+                        ? mApp.mUiTargetApp.uid
+                        : UserHandle.USER_NULL)
+                .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+                .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
 
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
index db4c3e0..baab3fc 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
@@ -78,6 +78,11 @@
     }
 
     @Override
+    public void displayPreference(PreferenceScreen screen) {
+        mPreference = screen.findPreference(KEY_DEVICE_NAME);
+    }
+
+    @Override
     public void onStart() {
         mContext.registerReceiver(mReceiver,
                 new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED));
diff --git a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
index f9b7975..6d474ee 100644
--- a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
@@ -15,11 +15,16 @@
  */
 package com.android.settings.bluetooth;
 
+import android.app.Fragment;
 import android.content.Context;
+import android.os.UserHandle;
+import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.core.PreferenceController;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.widget.MasterSwitchController;
@@ -43,19 +48,27 @@
     private BluetoothEnabler mBluetoothEnabler;
     private BluetoothSummaryUpdater mSummaryUpdater;
     private RestrictionUtils mRestrictionUtils;
+    private Fragment mFragment;
+    private SettingsActivity mActivity;
+    private BluetoothFeatureProvider mBluetoothFeatureProvider;
 
     public BluetoothMasterSwitchPreferenceController(Context context,
-            LocalBluetoothManager bluetoothManager) {
-        this(context, bluetoothManager, new RestrictionUtils());
+            LocalBluetoothManager bluetoothManager, Fragment fragment, SettingsActivity activity) {
+        this(context, bluetoothManager, new RestrictionUtils(), fragment, activity);
     }
 
     @VisibleForTesting
     public BluetoothMasterSwitchPreferenceController(Context context,
-            LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils) {
+            LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils,
+            Fragment fragment, SettingsActivity activity) {
         super(context);
         mBluetoothManager = bluetoothManager;
         mSummaryUpdater = new BluetoothSummaryUpdater(mContext, this, mBluetoothManager);
         mRestrictionUtils = restrictionUtils;
+        mFragment = fragment;
+        mActivity = activity;
+        mBluetoothFeatureProvider = FeatureFactory.getFactory(
+                mContext).getBluetoothFeatureProvider(mContext);
     }
 
     @Override
@@ -63,10 +76,23 @@
         super.displayPreference(screen);
         mBtPreference = (MasterSwitchPreference) screen.findPreference(KEY_TOGGLE_BLUETOOTH);
         mBluetoothEnabler = new BluetoothEnabler(mContext,
-            new MasterSwitchController(mBtPreference),
-            FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
-            MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
-            mRestrictionUtils);
+                new MasterSwitchController(mBtPreference),
+                FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
+                MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
+                mRestrictionUtils);
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (KEY_TOGGLE_BLUETOOTH.equals(preference.getKey())) {
+            final String fragmentClass = mBluetoothFeatureProvider.isPairingPageEnabled() ?
+                    BluetoothSettings.class.getName() :
+                    BluetoothSettingsObsolete.class.getName();
+            mActivity.startPreferencePanelAsUser(mFragment, fragmentClass, null, R.string.bluetooth,
+                    null, new UserHandle(UserHandle.myUserId()));
+            return true;
+        }
+        return super.handlePreferenceTreeClick(preference);
     }
 
     @Override
@@ -79,6 +105,7 @@
         return KEY_TOGGLE_BLUETOOTH;
     }
 
+    @Override
     public void onResume() {
         mSummaryUpdater.register(true);
     }
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
new file mode 100644
index 0000000..7e2978d
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
@@ -0,0 +1,194 @@
+/*
+ * 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.bluetooth;
+
+import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.widget.FooterPreference;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * BluetoothPairingDetail is a page to scan bluetooth devices and pair them.
+ */
+public class BluetoothPairingDetail extends DeviceListPreferenceFragment implements
+        Indexable {
+    private static final String TAG = "BluetoothPairingDetail";
+
+    @VisibleForTesting
+    static final String KEY_AVAIL_DEVICES = "available_devices";
+    @VisibleForTesting
+    static final String KEY_FOOTER_PREF = "footer_preference";
+
+    @VisibleForTesting
+    BluetoothDeviceNamePreferenceController mDeviceNamePrefController;
+    @VisibleForTesting
+    BluetoothProgressCategory mAvailableDevicesCategory;
+    @VisibleForTesting
+    FooterPreference mFooterPreference;
+
+    private boolean mInitialScanStarted;
+
+    public BluetoothPairingDetail() {
+        super(DISALLOW_CONFIG_BLUETOOTH);
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        mInitialScanStarted = false;
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+
+        if (mLocalAdapter != null) {
+            updateContent(mLocalAdapter.getBluetoothState());
+            mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
+        }
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+
+        // Make the device only visible to connected devices.
+        mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
+        mLocalAdapter.stopScanning();
+    }
+
+    @Override
+    void initPreferencesFromPreferenceScreen() {
+        mAvailableDevicesCategory = (BluetoothProgressCategory) findPreference(KEY_AVAIL_DEVICES);
+        mFooterPreference = (FooterPreference) findPreference(KEY_FOOTER_PREF);
+        mFooterPreference.setSelectable(false);
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        //TODO(b/38383542): add bluetooth pairing category
+        return MetricsEvent.BLUETOOTH;
+    }
+
+    @VisibleForTesting
+    void startScanning() {
+        if (mAvailableDevicesCategory != null) {
+            removeAllDevices();
+        }
+
+        mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
+        mInitialScanStarted = true;
+        mLocalAdapter.startScanning(true);
+    }
+
+    @Override
+    void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
+        mLocalAdapter.stopScanning();
+        super.onDevicePreferenceClick(btPreference);
+    }
+
+    @Override
+    public void onScanningStateChanged(boolean started) {
+        mAvailableDevicesCategory.setProgress(started);
+    }
+
+    @VisibleForTesting
+    void updateContent(int bluetoothState) {
+        switch (bluetoothState) {
+            case BluetoothAdapter.STATE_ON:
+                mDevicePreferenceMap.clear();
+                mLocalAdapter.setBluetoothEnabled(true);
+
+                addDeviceCategory(mAvailableDevicesCategory,
+                        R.string.bluetooth_preference_found_devices,
+                        BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, mInitialScanStarted);
+                updateFooterPreference(mFooterPreference);
+
+                if (!mInitialScanStarted) {
+                    startScanning();
+                }
+
+                // mLocalAdapter.setScanMode is internally synchronized so it is okay for multiple
+                // threads to execute.
+                mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+                break;
+
+            case BluetoothAdapter.STATE_OFF:
+                finish();
+                break;
+        }
+    }
+
+    @Override
+    public void onBluetoothStateChanged(int bluetoothState) {
+        super.onBluetoothStateChanged(bluetoothState);
+        updateContent(bluetoothState);
+    }
+
+    @Override
+    public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+        if (bondState == BluetoothDevice.BOND_BONDED) {
+            // If one device is connected(bonded), then close this fragment.
+            finish();
+        }
+    }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_bluetooth;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.bluetooth_pairing_detail;
+    }
+
+    @Override
+    protected List<PreferenceController> getPreferenceControllers(Context context) {
+        List<PreferenceController> controllers = new ArrayList<>();
+        mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context,
+                this, getLifecycle());
+        controllers.add(mDeviceNamePrefController);
+
+        return controllers;
+    }
+
+    @Override
+    public String getDeviceListKey() {
+        return KEY_AVAIL_DEVICES;
+    }
+
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
index 6409d3b..ab99aad 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
@@ -16,12 +16,12 @@
 
 package com.android.settings.bluetooth;
 
-import android.app.Fragment;
 import android.content.Context;
 import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
+import android.os.UserHandle;
 
+import com.android.settings.SettingsActivity;
 import com.android.settings.core.PreferenceController;
 import com.android.settings.R;
 
@@ -34,11 +34,14 @@
 
     public static final String KEY_PAIRING = "pref_bt_pairing";
     private PreferenceFragment mFragment;
+    private SettingsActivity mActivity;
     private Preference mPreference;
 
-    public BluetoothPairingPreferenceController(Context context, PreferenceFragment fragment) {
-       super(context);
+    public BluetoothPairingPreferenceController(Context context, PreferenceFragment fragment,
+            SettingsActivity activity) {
+        super(context);
         mFragment = fragment;
+        mActivity = activity;
     }
 
     @Override
@@ -54,7 +57,9 @@
     @Override
     public boolean handlePreferenceTreeClick(Preference preference) {
         if (KEY_PAIRING.equals(preference.getKey())) {
-            //TODO: open the pairing page
+            mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
+                    null, R.string.bluetooth_pairing_page_title, null,
+                    new UserHandle(UserHandle.myUserId()));
             return true;
         }
 
@@ -66,10 +71,11 @@
      *
      * @return bluetooth preference that created in this method
      */
-    public Preference createBluetoothPairingPreference() {
+    public Preference createBluetoothPairingPreference(int order) {
         mPreference = new Preference(mFragment.getPreferenceScreen().getContext());
         mPreference.setKey(KEY_PAIRING);
         mPreference.setIcon(R.drawable.ic_add);
+        mPreference.setOrder(order);
         mPreference.setTitle(R.string.bluetooth_pairing_pref_title);
 
         return mPreference;
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index ed2629e..b37770a 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -19,7 +19,6 @@
 import android.app.Activity;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
-import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -29,10 +28,8 @@
 import android.provider.Settings;
 import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceGroup;
 import android.support.v7.preference.PreferenceScreen;
-import android.text.BidiFormatter;
 import android.text.Spannable;
 import android.text.style.TextAppearanceSpan;
 import android.util.Log;
@@ -49,6 +46,7 @@
 import com.android.settings.core.PreferenceController;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.location.ScanningSettings;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 import com.android.settings.search.SearchIndexableRaw;
@@ -64,7 +62,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Locale;
 import java.util.Set;
 
 import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
@@ -72,11 +69,11 @@
 /**
  * BluetoothSettings is the Settings screen for Bluetooth configuration and
  * connection management.
+ *
  */
 public class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable {
     private static final String TAG = "BluetoothSettings";
 
-    private static final int MENU_ID_SCAN = Menu.FIRST;
     private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 1;
 
     /* Private intent to show the list of received files */
@@ -85,45 +82,31 @@
     private static final String BTOPP_PACKAGE =
             "com.android.bluetooth";
 
-    private static final String KEY_PAIRED_DEVICES = "paired_devices";
+    private static final int PAIRED_DEVICE_ORDER = 1;
+    private static final int PAIRING_PREF_ORDER = 2;
 
-    private static View mSettingsDialogView = null;
+    @VisibleForTesting
+    static final String KEY_PAIRED_DEVICES = "paired_devices";
+    @VisibleForTesting
+    static final String KEY_FOOTER_PREF = "footer_preference";
 
-    private BluetoothEnabler mBluetoothEnabler;
-
-    private PreferenceGroup mPairedDevicesCategory;
-    private PreferenceGroup mAvailableDevicesCategory;
-    private Preference mDeviceNamePreference;
+    @VisibleForTesting
+    PreferenceGroup mPairedDevicesCategory;
+    @VisibleForTesting
+    FooterPreference mFooterPreference;
     private Preference mPairingPreference;
-    private boolean mAvailableDevicesCategoryIsPresent;
-
-    private boolean mInitialScanStarted;
-    private boolean mInitiateDiscoverable;
+    private BluetoothEnabler mBluetoothEnabler;
 
     private SwitchBar mSwitchBar;
 
     private final IntentFilter mIntentFilter;
     private BluetoothDeviceNamePreferenceController mDeviceNamePrefController;
-    private BluetoothPairingPreferenceController mPairingPrefController;
+    @VisibleForTesting
+    BluetoothPairingPreferenceController mPairingPrefController;
 
     // For Search
-    private static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth";
-
-    // accessed from inner class (not private to avoid thunks)
-    FooterPreference mMyDevicePreference;
-
-    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            final int state =
-                    intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
-
-            if (state == BluetoothAdapter.STATE_ON) {
-                mInitiateDiscoverable = true;
-            }
-        }
-    };
+    @VisibleForTesting
+    static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth";
 
     public BluetoothSettings() {
         super(DISALLOW_CONFIG_BLUETOOTH);
@@ -138,15 +121,13 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        mInitialScanStarted = false;
-        mInitiateDiscoverable = true;
 
         final SettingsActivity activity = (SettingsActivity) getActivity();
         mSwitchBar = activity.getSwitchBar();
 
         mBluetoothEnabler = new BluetoothEnabler(activity, new SwitchBarController(mSwitchBar),
-            mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
-            MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
+                mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
+                MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
         mBluetoothEnabler.setupSwitchController();
     }
 
@@ -158,28 +139,11 @@
     }
 
     @Override
-    void addPreferencesForActivity() {
-        final Context prefContext = getPrefContext();
-
-        mDeviceNamePreference = mDeviceNamePrefController.createBluetoothDeviceNamePreference(
-                getPreferenceScreen(), 1 /* order */);
-
-        mPairedDevicesCategory = new PreferenceCategory(prefContext);
-        mPairedDevicesCategory.setKey(KEY_PAIRED_DEVICES);
-        mPairedDevicesCategory.setOrder(2);
-        getPreferenceScreen().addPreference(mPairedDevicesCategory);
-
-        mAvailableDevicesCategory = new BluetoothProgressCategory(prefContext);
-        mAvailableDevicesCategory.setSelectable(false);
-        mAvailableDevicesCategory.setOrder(3);
-        getPreferenceScreen().addPreference(mAvailableDevicesCategory);
-
-        mMyDevicePreference = mFooterPreferenceMixin.createFooterPreference();
-        mMyDevicePreference.setSelectable(false);
-
-        mPairingPreference = mPairingPrefController.createBluetoothPairingPreference();
-
-        setHasOptionsMenu(true);
+    void initPreferencesFromPreferenceScreen() {
+        mPairingPreference = mPairingPrefController.createBluetoothPairingPreference(
+                PAIRING_PREF_ORDER);
+        mFooterPreference = (FooterPreference) findPreference(KEY_FOOTER_PREF);
+        mPairedDevicesCategory = (PreferenceGroup) findPreference(KEY_PAIRED_DEVICES);
     }
 
     @Override
@@ -190,19 +154,14 @@
             mBluetoothEnabler.resume(getActivity());
         }
         super.onStart();
-
-        mInitiateDiscoverable = true;
-
         if (isUiRestricted()) {
-            setDeviceListGroup(getPreferenceScreen());
+            getPreferenceScreen().removeAll();
             if (!isUiRestrictedByOnlyAdmin()) {
                 getEmptyTextView().setText(R.string.bluetooth_empty_list_user_restricted);
             }
-            removeAllDevices();
             return;
         }
 
-        getActivity().registerReceiver(mReceiver, mIntentFilter);
         if (mLocalAdapter != null) {
             updateContent(mLocalAdapter.getBluetoothState());
         }
@@ -221,8 +180,6 @@
         if (isUiRestricted()) {
             return;
         }
-
-        getActivity().unregisterReceiver(mReceiver);
     }
 
     @Override
@@ -231,13 +188,6 @@
         // If the user is not allowed to configure bluetooth, do not show the menu.
         if (isUiRestricted()) return;
 
-        boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
-        boolean isDiscovering = mLocalAdapter.isDiscovering();
-        int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
-                R.string.bluetooth_search_for_devices;
-        menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
-                .setEnabled(bluetoothIsEnabled && !isDiscovering)
-                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         super.onCreateOptionsMenu(menu, inflater);
@@ -246,14 +196,6 @@
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
-            case MENU_ID_SCAN:
-                if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON) {
-                    mMetricsFeatureProvider.action(getActivity(),
-                            MetricsEvent.ACTION_BLUETOOTH_SCAN);
-                    startScanning();
-                }
-                return true;
-
             case MENU_ID_SHOW_RECEIVED:
                 mMetricsFeatureProvider.action(getActivity(),
                         MetricsEvent.ACTION_BLUETOOTH_FILES);
@@ -265,104 +207,37 @@
         return super.onOptionsItemSelected(item);
     }
 
-    private void startScanning() {
-        if (isUiRestricted()) {
-            return;
-        }
-
-        if (!mAvailableDevicesCategoryIsPresent) {
-            getPreferenceScreen().addPreference(mAvailableDevicesCategory);
-            mAvailableDevicesCategoryIsPresent = true;
-        }
-
-        if (mAvailableDevicesCategory != null) {
-            setDeviceListGroup(mAvailableDevicesCategory);
-            removeAllDevices();
-        }
-
-        mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
-        mAvailableDevicesCategory.removeAll();
-        mInitialScanStarted = true;
-        mLocalAdapter.startScanning(true);
-    }
-
     @Override
-    void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
-        mLocalAdapter.stopScanning();
-        super.onDevicePreferenceClick(btPreference);
-    }
-
-    private void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
-            BluetoothDeviceFilter.Filter filter, boolean addCachedDevices) {
-        cacheRemoveAllPrefs(preferenceGroup);
-        preferenceGroup.setTitle(titleId);
-        setFilter(filter);
-        setDeviceListGroup(preferenceGroup);
-        if (addCachedDevices) {
-            addCachedDevices();
-        }
-        preferenceGroup.setEnabled(true);
-        removeCachedPrefs(preferenceGroup);
+    public String getDeviceListKey() {
+        return KEY_PAIRED_DEVICES;
     }
 
     private void updateContent(int bluetoothState) {
-        final PreferenceScreen preferenceScreen = getPreferenceScreen();
         int messageId = 0;
 
         switch (bluetoothState) {
             case BluetoothAdapter.STATE_ON:
+                displayEmptyMessage(false);
                 mDevicePreferenceMap.clear();
 
                 if (isUiRestricted()) {
                     messageId = R.string.bluetooth_empty_list_user_restricted;
                     break;
                 }
-                getPreferenceScreen().removeAll();
-                getPreferenceScreen().addPreference(mDeviceNamePreference);
-                getPreferenceScreen().addPreference(mPairedDevicesCategory);
-                getPreferenceScreen().addPreference(mAvailableDevicesCategory);
-                getPreferenceScreen().addPreference(mMyDevicePreference);
 
-                // Paired devices category
                 addDeviceCategory(mPairedDevicesCategory,
                         R.string.bluetooth_preference_paired_devices,
                         BluetoothDeviceFilter.BONDED_DEVICE_FILTER, true);
                 mPairedDevicesCategory.addPreference(mPairingPreference);
-                int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
+                updateFooterPreference(mFooterPreference);
 
-                if (isUiRestricted() || numberOfPairedDevices <= 0) {
-                    if (preferenceScreen.findPreference(KEY_PAIRED_DEVICES) != null) {
-                        preferenceScreen.removePreference(mPairedDevicesCategory);
-                    }
-                } else {
-                    if (preferenceScreen.findPreference(KEY_PAIRED_DEVICES) == null) {
-                        preferenceScreen.addPreference(mPairedDevicesCategory);
-                    }
-                }
-
-                // Available devices category
-                addDeviceCategory(mAvailableDevicesCategory,
-                        R.string.bluetooth_preference_found_devices,
-                        BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, mInitialScanStarted);
-
-                if (!mInitialScanStarted) {
-                    startScanning();
-                }
-
-                updateMyDevicePreference(mMyDevicePreference);
                 getActivity().invalidateOptionsMenu();
-
-                // mLocalAdapter.setScanMode is internally synchronized so it is okay for multiple
-                // threads to execute.
-                if (mInitiateDiscoverable) {
-                    // Make the device visible to other devices.
-                    mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
-                    mInitiateDiscoverable = false;
-                }
+                mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                 return; // not break
 
             case BluetoothAdapter.STATE_TURNING_OFF:
                 messageId = R.string.bluetooth_turning_off;
+                mLocalAdapter.stopScanning();
                 break;
 
             case BluetoothAdapter.STATE_OFF:
@@ -374,12 +249,10 @@
 
             case BluetoothAdapter.STATE_TURNING_ON:
                 messageId = R.string.bluetooth_turning_on;
-                mInitialScanStarted = false;
                 break;
         }
 
-        setDeviceListGroup(preferenceScreen);
-        removeAllDevices();
+        displayEmptyMessage(true);
         if (messageId != 0) {
             getEmptyTextView().setText(messageId);
         }
@@ -418,18 +291,21 @@
                 }
             });
         }
-        getPreferenceScreen().removeAll();
         setTextSpan(emptyView.getText(), briefText);
     }
 
+    @VisibleForTesting
+    void displayEmptyMessage(boolean display) {
+        final Activity activity = getActivity();
+        activity.findViewById(android.R.id.list_container).setVisibility(
+                display ? View.INVISIBLE : View.VISIBLE);
+        activity.findViewById(android.R.id.empty).setVisibility(
+                display ? View.VISIBLE : View.GONE);
+    }
+
     @Override
     public void onBluetoothStateChanged(int bluetoothState) {
         super.onBluetoothStateChanged(bluetoothState);
-        // If BT is turned off/on staying in the same BT Settings screen
-        // discoverability to be set again
-        if (BluetoothAdapter.STATE_ON == bluetoothState) {
-            mInitiateDiscoverable = true;
-        }
         updateContent(bluetoothState);
     }
 
@@ -437,15 +313,14 @@
     public void onScanningStateChanged(boolean started) {
         super.onScanningStateChanged(started);
         // Update options' enabled state
-        if (getActivity() != null) {
-            getActivity().invalidateOptionsMenu();
+        final Activity activity = getActivity();
+        if (activity != null) {
+            activity.invalidateOptionsMenu();
         }
     }
 
     @Override
     public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
-        setDeviceListGroup(getPreferenceScreen());
-        removeAllDevices();
         updateContent(mLocalAdapter.getBluetoothState());
     }
 
@@ -454,21 +329,12 @@
         if (text instanceof Spannable) {
             Spannable boldSpan = (Spannable) text;
             boldSpan.setSpan(
-                new TextAppearanceSpan(getActivity(), android.R.style.TextAppearance_Medium), 0,
-                briefText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+                    new TextAppearanceSpan(getActivity(), android.R.style.TextAppearance_Medium), 0,
+                    briefText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
         }
     }
 
     @VisibleForTesting
-    void updateMyDevicePreference(Preference myDevicePreference) {
-        final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
-
-        myDevicePreference.setTitle(getString(
-                R.string.bluetooth_footer_mac_message,
-                bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
-    }
-
-    @VisibleForTesting
     void setLocalBluetoothAdapter(LocalBluetoothAdapter localAdapter) {
         mLocalAdapter = localAdapter;
     }
@@ -501,6 +367,7 @@
      */
     @Override
     void initDevicePreference(BluetoothDevicePreference preference) {
+        preference.setOrder(PAIRED_DEVICE_ORDER);
         CachedBluetoothDevice cachedDevice = preference.getCachedDevice();
         if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
             // Only paired device have an associated advanced settings screen
@@ -528,7 +395,8 @@
         List<PreferenceController> controllers = new ArrayList<>();
         mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context,
                 this, getLifecycle());
-        mPairingPrefController = new BluetoothPairingPreferenceController(context, this);
+        mPairingPrefController = new BluetoothPairingPreferenceController(context, this,
+                (SettingsActivity) getActivity());
         controllers.add(mDeviceNamePrefController);
         controllers.add(mPairingPrefController);
 
@@ -593,23 +461,18 @@
                     data.key = DATA_KEY_REFERENCE;
                     result.add(data);
 
-                    // Add cached paired BT devices
-                    LocalBluetoothManager lbtm = Utils.getLocalBtManager(context);
-                    // LocalBluetoothManager.getInstance can return null if the device does not
-                    // support bluetooth (e.g. the emulator).
-                    if (lbtm != null) {
-                        Set<BluetoothDevice> bondedDevices =
-                                lbtm.getBluetoothAdapter().getBondedDevices();
-
-                        for (BluetoothDevice device : bondedDevices) {
-                            data = new SearchIndexableRaw(context);
-                            data.title = device.getName();
-                            data.screenTitle = res.getString(R.string.bluetooth_settings);
-                            data.enabled = enabled;
-                            result.add(data);
-                        }
-                    }
+                    // Removed paired bluetooth device indexing. See BluetoothSettingsObsolete.java.
                     return result;
                 }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    List<String> keys = super.getNonIndexableKeys(context);
+                    if (!FeatureFactory.getFactory(context).getBluetoothFeatureProvider(
+                            context).isPairingPageEnabled()) {
+                        keys.add(DATA_KEY_REFERENCE);
+                    }
+                    return keys;
+                }
             };
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothSettingsObsolete.java b/src/com/android/settings/bluetooth/BluetoothSettingsObsolete.java
new file mode 100644
index 0000000..207d313
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothSettingsObsolete.java
@@ -0,0 +1,625 @@
+/*
+ * 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.bluetooth;
+
+import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
+
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.BidiFormatter;
+import android.text.Spannable;
+import android.text.style.TextAppearanceSpan;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.LinkifyUtils;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.location.ScanningSettings;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.widget.GearPreference;
+import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBarController;
+import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.widget.FooterPreference;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * BluetoothSettingsObsolete is the Settings screen for Bluetooth configuration and
+ * connection management.
+ *
+ * This fragment stores old implementation of {@link BluetoothSettings} and is
+ * deprecated, please use {@link BluetoothSettings} instead.
+ */
+@Deprecated
+public class BluetoothSettingsObsolete extends DeviceListPreferenceObsoleteFragment
+        implements Indexable {
+    private static final String TAG = "BluetoothSettingsObsolete";
+
+    private static final int MENU_ID_SCAN = Menu.FIRST;
+    private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 1;
+
+    /* Private intent to show the list of received files */
+    private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
+            "android.btopp.intent.action.OPEN_RECEIVED_FILES";
+    private static final String BTOPP_PACKAGE =
+            "com.android.bluetooth";
+
+    private static final String KEY_PAIRED_DEVICES = "paired_devices";
+
+    private static View mSettingsDialogView = null;
+
+    private BluetoothEnabler mBluetoothEnabler;
+
+    private PreferenceGroup mPairedDevicesCategory;
+    private PreferenceGroup mAvailableDevicesCategory;
+    private Preference mDeviceNamePreference;
+    private boolean mAvailableDevicesCategoryIsPresent;
+
+    private boolean mInitialScanStarted;
+    private boolean mInitiateDiscoverable;
+
+    private SwitchBar mSwitchBar;
+
+    private final IntentFilter mIntentFilter;
+    private BluetoothDeviceNamePreferenceController mDeviceNamePrefController;
+
+    // For Search
+    @VisibleForTesting
+    static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth_obsolete";
+
+    // accessed from inner class (not private to avoid thunks)
+    FooterPreference mMyDevicePreference;
+
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            final int state =
+                    intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
+
+            if (state == BluetoothAdapter.STATE_ON) {
+                mInitiateDiscoverable = true;
+            }
+        }
+    };
+
+    public BluetoothSettingsObsolete() {
+        super(DISALLOW_CONFIG_BLUETOOTH);
+        mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsEvent.BLUETOOTH;
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        mInitialScanStarted = false;
+        mInitiateDiscoverable = true;
+
+        final SettingsActivity activity = (SettingsActivity) getActivity();
+        mSwitchBar = activity.getSwitchBar();
+
+        mBluetoothEnabler = new BluetoothEnabler(activity, new SwitchBarController(mSwitchBar),
+                mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
+                MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
+        mBluetoothEnabler.setupSwitchController();
+    }
+
+    @Override
+    public void onDestroyView() {
+        super.onDestroyView();
+
+        mBluetoothEnabler.teardownSwitchController();
+    }
+
+    @Override
+    void addPreferencesForActivity() {
+        final Context prefContext = getPrefContext();
+
+        mDeviceNamePreference = mDeviceNamePrefController.createBluetoothDeviceNamePreference(
+                getPreferenceScreen(), 1 /* order */);
+
+        mPairedDevicesCategory = new PreferenceCategory(prefContext);
+        mPairedDevicesCategory.setKey(KEY_PAIRED_DEVICES);
+        mPairedDevicesCategory.setOrder(2);
+        getPreferenceScreen().addPreference(mPairedDevicesCategory);
+
+        mAvailableDevicesCategory = new BluetoothProgressCategory(prefContext);
+        mAvailableDevicesCategory.setSelectable(false);
+        mAvailableDevicesCategory.setOrder(3);
+        getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+
+        mMyDevicePreference = mFooterPreferenceMixin.createFooterPreference();
+        mMyDevicePreference.setSelectable(false);
+
+        setHasOptionsMenu(true);
+    }
+
+    @Override
+    public void onStart() {
+        // resume BluetoothEnabler before calling super.onStart() so we don't get
+        // any onDeviceAdded() callbacks before setting up view in updateContent()
+        if (mBluetoothEnabler != null) {
+            mBluetoothEnabler.resume(getActivity());
+        }
+        super.onStart();
+
+        mInitiateDiscoverable = true;
+
+        if (isUiRestricted()) {
+            setDeviceListGroup(getPreferenceScreen());
+            if (!isUiRestrictedByOnlyAdmin()) {
+                getEmptyTextView().setText(R.string.bluetooth_empty_list_user_restricted);
+            }
+            removeAllDevices();
+            return;
+        }
+
+        getActivity().registerReceiver(mReceiver, mIntentFilter);
+        if (mLocalAdapter != null) {
+            updateContent(mLocalAdapter.getBluetoothState());
+        }
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        if (mBluetoothEnabler != null) {
+            mBluetoothEnabler.pause();
+        }
+
+        // Make the device only visible to connected devices.
+        mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
+
+        if (isUiRestricted()) {
+            return;
+        }
+
+        getActivity().unregisterReceiver(mReceiver);
+    }
+
+    @Override
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        if (mLocalAdapter == null) return;
+        // If the user is not allowed to configure bluetooth, do not show the menu.
+        if (isUiRestricted()) return;
+
+        boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
+        boolean isDiscovering = mLocalAdapter.isDiscovering();
+        int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
+                R.string.bluetooth_search_for_devices;
+        menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
+                .setEnabled(bluetoothIsEnabled && !isDiscovering)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        super.onCreateOptionsMenu(menu, inflater);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case MENU_ID_SCAN:
+                if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON) {
+                    mMetricsFeatureProvider.action(getActivity(),
+                            MetricsEvent.ACTION_BLUETOOTH_SCAN);
+                    startScanning();
+                }
+                return true;
+
+            case MENU_ID_SHOW_RECEIVED:
+                mMetricsFeatureProvider.action(getActivity(),
+                        MetricsEvent.ACTION_BLUETOOTH_FILES);
+                Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
+                intent.setPackage(BTOPP_PACKAGE);
+                getActivity().sendBroadcast(intent);
+                return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    private void startScanning() {
+        if (isUiRestricted()) {
+            return;
+        }
+
+        if (!mAvailableDevicesCategoryIsPresent) {
+            getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+            mAvailableDevicesCategoryIsPresent = true;
+        }
+
+        if (mAvailableDevicesCategory != null) {
+            setDeviceListGroup(mAvailableDevicesCategory);
+            removeAllDevices();
+        }
+
+        mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
+        mAvailableDevicesCategory.removeAll();
+        mInitialScanStarted = true;
+        mLocalAdapter.startScanning(true);
+    }
+
+    @Override
+    void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
+        mLocalAdapter.stopScanning();
+        super.onDevicePreferenceClick(btPreference);
+    }
+
+    private void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
+            BluetoothDeviceFilter.Filter filter, boolean addCachedDevices) {
+        cacheRemoveAllPrefs(preferenceGroup);
+        preferenceGroup.setTitle(titleId);
+        setFilter(filter);
+        setDeviceListGroup(preferenceGroup);
+        if (addCachedDevices) {
+            addCachedDevices();
+        }
+        preferenceGroup.setEnabled(true);
+        removeCachedPrefs(preferenceGroup);
+    }
+
+    private void updateContent(int bluetoothState) {
+        final PreferenceScreen preferenceScreen = getPreferenceScreen();
+        int messageId = 0;
+
+        switch (bluetoothState) {
+            case BluetoothAdapter.STATE_ON:
+                mDevicePreferenceMap.clear();
+
+                if (isUiRestricted()) {
+                    messageId = R.string.bluetooth_empty_list_user_restricted;
+                    break;
+                }
+                getPreferenceScreen().removeAll();
+                getPreferenceScreen().addPreference(mDeviceNamePreference);
+                getPreferenceScreen().addPreference(mPairedDevicesCategory);
+                getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+                getPreferenceScreen().addPreference(mMyDevicePreference);
+
+                // Paired devices category
+                addDeviceCategory(mPairedDevicesCategory,
+                        R.string.bluetooth_preference_paired_devices,
+                        BluetoothDeviceFilter.BONDED_DEVICE_FILTER, true);
+                int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
+
+                if (isUiRestricted() || numberOfPairedDevices <= 0) {
+                    if (preferenceScreen.findPreference(KEY_PAIRED_DEVICES) != null) {
+                        preferenceScreen.removePreference(mPairedDevicesCategory);
+                    }
+                } else {
+                    if (preferenceScreen.findPreference(KEY_PAIRED_DEVICES) == null) {
+                        preferenceScreen.addPreference(mPairedDevicesCategory);
+                    }
+                }
+
+                // Available devices category
+                addDeviceCategory(mAvailableDevicesCategory,
+                        R.string.bluetooth_preference_found_devices,
+                        BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, mInitialScanStarted);
+
+                if (!mInitialScanStarted) {
+                    startScanning();
+                }
+
+                updateMyDevicePreference(mMyDevicePreference);
+                getActivity().invalidateOptionsMenu();
+
+                // mLocalAdapter.setScanMode is internally synchronized so it is okay for multiple
+                // threads to execute.
+                if (mInitiateDiscoverable) {
+                    // Make the device visible to other devices.
+                    mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+                    mInitiateDiscoverable = false;
+                }
+                return; // not break
+
+            case BluetoothAdapter.STATE_TURNING_OFF:
+                messageId = R.string.bluetooth_turning_off;
+                break;
+
+            case BluetoothAdapter.STATE_OFF:
+                setOffMessage();
+                if (isUiRestricted()) {
+                    messageId = R.string.bluetooth_empty_list_user_restricted;
+                }
+                break;
+
+            case BluetoothAdapter.STATE_TURNING_ON:
+                messageId = R.string.bluetooth_turning_on;
+                mInitialScanStarted = false;
+                break;
+        }
+
+        setDeviceListGroup(preferenceScreen);
+        removeAllDevices();
+        if (messageId != 0) {
+            getEmptyTextView().setText(messageId);
+        }
+        if (!isUiRestricted()) {
+            getActivity().invalidateOptionsMenu();
+        }
+    }
+
+    private void setOffMessage() {
+        final TextView emptyView = getEmptyTextView();
+        if (emptyView == null) {
+            return;
+        }
+        final CharSequence briefText = getText(R.string.bluetooth_empty_list_bluetooth_off);
+
+        final ContentResolver resolver = getActivity().getContentResolver();
+        final boolean bleScanningMode = Settings.Global.getInt(
+                resolver, Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+
+        if (!bleScanningMode) {
+            // Show only the brief text if the scanning mode has been turned off.
+            emptyView.setText(briefText, TextView.BufferType.SPANNABLE);
+        } else {
+            final StringBuilder contentBuilder = new StringBuilder();
+            contentBuilder.append(briefText);
+            contentBuilder.append("\n\n");
+            contentBuilder.append(getText(R.string.ble_scan_notify_text));
+            LinkifyUtils.linkify(emptyView, contentBuilder, new LinkifyUtils.OnClickListener() {
+                @Override
+                public void onClick() {
+                    final SettingsActivity activity =
+                            (SettingsActivity) BluetoothSettingsObsolete.this.getActivity();
+                    activity.startPreferencePanel(BluetoothSettingsObsolete.this,
+                            ScanningSettings.class.getName(), null,
+                            R.string.location_scanning_screen_title, null, null, 0);
+                }
+            });
+        }
+        getPreferenceScreen().removeAll();
+        setTextSpan(emptyView.getText(), briefText);
+    }
+
+    @Override
+    public void onBluetoothStateChanged(int bluetoothState) {
+        super.onBluetoothStateChanged(bluetoothState);
+        // If BT is turned off/on staying in the same BT Settings screen
+        // discoverability to be set again
+        if (BluetoothAdapter.STATE_ON == bluetoothState) {
+            mInitiateDiscoverable = true;
+        }
+        updateContent(bluetoothState);
+    }
+
+    @Override
+    public void onScanningStateChanged(boolean started) {
+        super.onScanningStateChanged(started);
+        // Update options' enabled state
+        if (getActivity() != null) {
+            getActivity().invalidateOptionsMenu();
+        }
+    }
+
+    @Override
+    public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+        setDeviceListGroup(getPreferenceScreen());
+        removeAllDevices();
+        updateContent(mLocalAdapter.getBluetoothState());
+    }
+
+    @VisibleForTesting
+    void setTextSpan(CharSequence text, CharSequence briefText) {
+        if (text instanceof Spannable) {
+            Spannable boldSpan = (Spannable) text;
+            boldSpan.setSpan(
+                    new TextAppearanceSpan(getActivity(), android.R.style.TextAppearance_Medium), 0,
+                    briefText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+        }
+    }
+
+    @VisibleForTesting
+    void updateMyDevicePreference(Preference myDevicePreference) {
+        final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
+
+        myDevicePreference.setTitle(getString(
+                R.string.bluetooth_footer_mac_message,
+                bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
+    }
+
+    @VisibleForTesting
+    void setLocalBluetoothAdapter(LocalBluetoothAdapter localAdapter) {
+        mLocalAdapter = localAdapter;
+    }
+
+    private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
+        // User clicked on advanced options icon for a device in the list
+        if (!(pref instanceof BluetoothDevicePreference)) {
+            Log.w(TAG, "onClick() called for other View: " + pref);
+            return;
+        }
+        final CachedBluetoothDevice device =
+                ((BluetoothDevicePreference) pref).getBluetoothDevice();
+        if (device == null) {
+            Log.w(TAG, "No BT device attached with this pref: " + pref);
+            return;
+        }
+        final Bundle args = new Bundle();
+        args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS,
+                device.getDevice().getAddress());
+        final DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
+        profileSettings.setArguments(args);
+        profileSettings.show(getFragmentManager(),
+                DeviceProfilesSettings.class.getSimpleName());
+    };
+
+    /**
+     * Add a listener, which enables the advanced settings icon.
+     *
+     * @param preference the newly added preference
+     */
+    @Override
+    void initDevicePreference(BluetoothDevicePreference preference) {
+        CachedBluetoothDevice cachedDevice = preference.getCachedDevice();
+        if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
+            // Only paired device have an associated advanced settings screen
+            preference.setOnGearClickListener(mDeviceProfilesListener);
+        }
+    }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_bluetooth;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.bluetooth_settings_obsolete;
+    }
+
+    @Override
+    protected List<PreferenceController> getPreferenceControllers(Context context) {
+        List<PreferenceController> controllers = new ArrayList<>();
+        mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context,
+                this, getLifecycle());
+        controllers.add(mDeviceNamePrefController);
+
+        return controllers;
+    }
+
+    @VisibleForTesting
+    static class SummaryProvider implements SummaryLoader.SummaryProvider, OnSummaryChangeListener {
+
+        private final LocalBluetoothManager mBluetoothManager;
+        private final Context mContext;
+        private final SummaryLoader mSummaryLoader;
+
+        @VisibleForTesting
+        BluetoothSummaryUpdater mSummaryUpdater;
+
+        public SummaryProvider(Context context, SummaryLoader summaryLoader,
+                LocalBluetoothManager bluetoothManager) {
+            mBluetoothManager = bluetoothManager;
+            mContext = context;
+            mSummaryLoader = summaryLoader;
+            mSummaryUpdater = new BluetoothSummaryUpdater(mContext, this, mBluetoothManager);
+        }
+
+        @Override
+        public void setListening(boolean listening) {
+            mSummaryUpdater.register(listening);
+        }
+
+        @Override
+        public void onSummaryChanged(String summary) {
+            if (mSummaryLoader != null) {
+                mSummaryLoader.setSummary(this, summary);
+            }
+        }
+    }
+
+    public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
+            = new SummaryLoader.SummaryProviderFactory() {
+        @Override
+        public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
+                SummaryLoader summaryLoader) {
+
+            return new SummaryProvider(activity, summaryLoader, Utils.getLocalBtManager(activity));
+        }
+    };
+
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
+                        boolean enabled) {
+
+                    final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
+
+                    final Resources res = context.getResources();
+
+                    // Add fragment title
+                    SearchIndexableRaw data = new SearchIndexableRaw(context);
+                    data.title = res.getString(R.string.bluetooth_settings);
+                    data.screenTitle = res.getString(R.string.bluetooth_settings);
+                    data.key = DATA_KEY_REFERENCE;
+                    result.add(data);
+
+                    // Add cached paired BT devices
+                    LocalBluetoothManager lbtm = Utils.getLocalBtManager(context);
+                    // LocalBluetoothManager.getInstance can return null if the device does not
+                    // support bluetooth (e.g. the emulator).
+                    if (lbtm != null) {
+                        Set<BluetoothDevice> bondedDevices =
+                                lbtm.getBluetoothAdapter().getBondedDevices();
+
+                        for (BluetoothDevice device : bondedDevices) {
+                            data = new SearchIndexableRaw(context);
+                            data.title = device.getName();
+                            data.screenTitle = res.getString(R.string.bluetooth_settings);
+                            data.enabled = enabled;
+                            result.add(data);
+                        }
+                    }
+                    return result;
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    List<String> keys = super.getNonIndexableKeys(context);
+                    if (FeatureFactory.getFactory(context).getBluetoothFeatureProvider(
+                            context).isPairingPageEnabled()) {
+                        keys.add(DATA_KEY_REFERENCE);
+                    }
+                    return keys;
+                }
+
+            };
+}
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index 4034316..714704e 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -19,12 +19,15 @@
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
 import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceGroup;
+import android.text.BidiFormatter;
 import android.util.Log;
 
 import com.android.settings.dashboard.RestrictedDashboardFragment;
+import com.android.settings.R;
 import com.android.settingslib.bluetooth.BluetoothCallback;
 import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -41,12 +44,12 @@
  * @see BluetoothSettings
  * @see DevicePickerFragment
  */
+// TODO: Refactor this fragment
 public abstract class DeviceListPreferenceFragment extends
         RestrictedDashboardFragment implements BluetoothCallback {
 
     private static final String TAG = "DeviceListPreferenceFragment";
 
-    private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
     private static final String KEY_BT_SCAN = "bt_scan";
 
     private BluetoothDeviceFilter.Filter mFilter;
@@ -56,7 +59,8 @@
     LocalBluetoothAdapter mLocalAdapter;
     LocalBluetoothManager mLocalManager;
 
-    private PreferenceGroup mDeviceListGroup;
+    @VisibleForTesting
+    PreferenceGroup mDeviceListGroup;
 
     final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
             new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
@@ -85,17 +89,13 @@
         }
         mLocalAdapter = mLocalManager.getBluetoothAdapter();
 
-        addPreferencesForActivity();
+        initPreferencesFromPreferenceScreen();
 
-        mDeviceListGroup = (PreferenceCategory) findPreference(KEY_BT_DEVICE_LIST);
+        mDeviceListGroup = (PreferenceCategory) findPreference(getDeviceListKey());
     }
 
-    void setDeviceListGroup(PreferenceGroup preferenceGroup) {
-        mDeviceListGroup = preferenceGroup;
-    }
-
-    /** Add preferences from the subclass. */
-    abstract void addPreferencesForActivity();
+    /** find and update preference that already existed in preference screen */
+    abstract void initPreferencesFromPreferenceScreen();
 
     @Override
     public void onStart() {
@@ -104,8 +104,6 @@
 
         mLocalManager.setForegroundActivity(getActivity());
         mLocalManager.getEventManager().registerCallback(this);
-
-        updateProgressUi(mLocalAdapter.isDiscovering());
     }
 
     @Override
@@ -121,7 +119,6 @@
     }
 
     void removeAllDevices() {
-        mLocalAdapter.stopScanning();
         mDevicePreferenceMap.clear();
         mDeviceListGroup.removeAll();
     }
@@ -156,6 +153,7 @@
         btPreference.onClicked();
     }
 
+    @Override
     public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
         if (mDevicePreferenceMap.get(cachedDevice) != null) {
             return;
@@ -201,6 +199,16 @@
         // Does nothing by default
     }
 
+    @VisibleForTesting
+    void updateFooterPreference(Preference myDevicePreference) {
+        final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
+
+        myDevicePreference.setTitle(getString(
+                R.string.bluetooth_footer_mac_message,
+                bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
+    }
+
+    @Override
     public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
         BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
         if (preference != null) {
@@ -208,21 +216,39 @@
         }
     }
 
-    public void onScanningStateChanged(boolean started) {
-        updateProgressUi(started);
-    }
+    @Override
+    public void onScanningStateChanged(boolean started) {}
 
-    private void updateProgressUi(boolean start) {
-        if (mDeviceListGroup instanceof BluetoothProgressCategory) {
-            ((BluetoothProgressCategory) mDeviceListGroup).setProgress(start);
-        }
-    }
+    @Override
+    public void onBluetoothStateChanged(int bluetoothState) {}
 
-    public void onBluetoothStateChanged(int bluetoothState) {
-        if (bluetoothState == BluetoothAdapter.STATE_OFF) {
-            updateProgressUi(false);
+    /**
+     * Add bluetooth device preferences to {@code preferenceGroup} which satisfy the {@code filter}
+     *
+     * This method will also (1) set the title for {@code preferenceGroup} and (2) change the
+     * default preferenceGroup and filter
+     * @param preferenceGroup
+     * @param titleId
+     * @param filter
+     * @param addCachedDevices
+     */
+    public void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
+            BluetoothDeviceFilter.Filter filter, boolean addCachedDevices) {
+        cacheRemoveAllPrefs(preferenceGroup);
+        preferenceGroup.setTitle(titleId);
+        mDeviceListGroup = preferenceGroup;
+        setFilter(filter);
+        if (addCachedDevices) {
+            addCachedDevices();
         }
+        preferenceGroup.setEnabled(true);
+        removeCachedPrefs(preferenceGroup);
     }
 
     public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }
+
+    /**
+     * Return the key of the {@link PreferenceGroup} that contains the bluetooth devices
+     */
+    public abstract String getDeviceListKey();
 }
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceObsoleteFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceObsoleteFragment.java
new file mode 100644
index 0000000..84d8558
--- /dev/null
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceObsoleteFragment.java
@@ -0,0 +1,232 @@
+/*
+ * 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.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceGroup;
+import android.util.Log;
+
+import com.android.settings.dashboard.RestrictedDashboardFragment;
+import com.android.settingslib.bluetooth.BluetoothCallback;
+import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+import java.util.Collection;
+import java.util.WeakHashMap;
+
+/**
+ * Parent class for settings fragments that contain a list of Bluetooth
+ * devices.
+ *
+ * This fragment stores old implementation of {@link DeviceListPreferenceFragment} and is
+ * deprecated, please use {@link DeviceListPreferenceFragment} instead.
+ *
+ * @see BluetoothSettingsObsolete
+ * @see DevicePickerFragment
+ */
+@Deprecated
+public abstract class DeviceListPreferenceObsoleteFragment extends
+        RestrictedDashboardFragment implements BluetoothCallback {
+
+    private static final String TAG = "DeviceListPreferenceFragment";
+
+    private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
+    private static final String KEY_BT_SCAN = "bt_scan";
+
+    private BluetoothDeviceFilter.Filter mFilter;
+
+    BluetoothDevice mSelectedDevice;
+
+    LocalBluetoothAdapter mLocalAdapter;
+    LocalBluetoothManager mLocalManager;
+
+    private PreferenceGroup mDeviceListGroup;
+
+    final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
+            new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
+
+    DeviceListPreferenceObsoleteFragment(String restrictedKey) {
+        super(restrictedKey);
+        mFilter = BluetoothDeviceFilter.ALL_FILTER;
+    }
+
+    final void setFilter(BluetoothDeviceFilter.Filter filter) {
+        mFilter = filter;
+    }
+
+    final void setFilter(int filterType) {
+        mFilter = BluetoothDeviceFilter.getFilter(filterType);
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mLocalManager = Utils.getLocalBtManager(getActivity());
+        if (mLocalManager == null) {
+            Log.e(TAG, "Bluetooth is not supported on this device");
+            return;
+        }
+        mLocalAdapter = mLocalManager.getBluetoothAdapter();
+
+        addPreferencesForActivity();
+
+        mDeviceListGroup = (PreferenceCategory) findPreference(KEY_BT_DEVICE_LIST);
+    }
+
+    void setDeviceListGroup(PreferenceGroup preferenceGroup) {
+        mDeviceListGroup = preferenceGroup;
+    }
+
+    /** Add preferences from the subclass. */
+    abstract void addPreferencesForActivity();
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        if (mLocalManager == null || isUiRestricted()) return;
+
+        mLocalManager.setForegroundActivity(getActivity());
+        mLocalManager.getEventManager().registerCallback(this);
+
+        updateProgressUi(mLocalAdapter.isDiscovering());
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        if (mLocalManager == null || isUiRestricted()) {
+            return;
+        }
+
+        removeAllDevices();
+        mLocalManager.setForegroundActivity(null);
+        mLocalManager.getEventManager().unregisterCallback(this);
+    }
+
+    void removeAllDevices() {
+        mLocalAdapter.stopScanning();
+        mDevicePreferenceMap.clear();
+        mDeviceListGroup.removeAll();
+    }
+
+    void addCachedDevices() {
+        Collection<CachedBluetoothDevice> cachedDevices =
+                mLocalManager.getCachedDeviceManager().getCachedDevicesCopy();
+        for (CachedBluetoothDevice cachedDevice : cachedDevices) {
+            onDeviceAdded(cachedDevice);
+        }
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(Preference preference) {
+        if (KEY_BT_SCAN.equals(preference.getKey())) {
+            mLocalAdapter.startScanning(true);
+            return true;
+        }
+
+        if (preference instanceof BluetoothDevicePreference) {
+            BluetoothDevicePreference btPreference = (BluetoothDevicePreference) preference;
+            CachedBluetoothDevice device = btPreference.getCachedDevice();
+            mSelectedDevice = device.getDevice();
+            onDevicePreferenceClick(btPreference);
+            return true;
+        }
+
+        return super.onPreferenceTreeClick(preference);
+    }
+
+    void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
+        btPreference.onClicked();
+    }
+
+    public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
+        if (mDevicePreferenceMap.get(cachedDevice) != null) {
+            return;
+        }
+
+        // Prevent updates while the list shows one of the state messages
+        if (mLocalAdapter.getBluetoothState() != BluetoothAdapter.STATE_ON) return;
+
+        if (mFilter.matches(cachedDevice.getDevice())) {
+            createDevicePreference(cachedDevice);
+        }
+    }
+
+    void createDevicePreference(CachedBluetoothDevice cachedDevice) {
+        if (mDeviceListGroup == null) {
+            Log.w(TAG, "Trying to create a device preference before the list group/category "
+                    + "exists!");
+            return;
+        }
+
+        String key = cachedDevice.getDevice().getAddress();
+        BluetoothDevicePreference preference = (BluetoothDevicePreference) getCachedPreference(key);
+
+        if (preference == null) {
+            preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice);
+            preference.setKey(key);
+            mDeviceListGroup.addPreference(preference);
+        } else {
+            // Tell the preference it is being re-used in case there is new info in the
+            // cached device.
+            preference.rebind();
+        }
+
+        initDevicePreference(preference);
+        mDevicePreferenceMap.put(cachedDevice, preference);
+    }
+
+    /**
+     * Overridden in {@link BluetoothSettings} to add a listener.
+     * @param preference the newly added preference
+     */
+    void initDevicePreference(BluetoothDevicePreference preference) {
+        // Does nothing by default
+    }
+
+    public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
+        BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
+        if (preference != null) {
+            mDeviceListGroup.removePreference(preference);
+        }
+    }
+
+    public void onScanningStateChanged(boolean started) {
+        updateProgressUi(started);
+    }
+
+    private void updateProgressUi(boolean start) {
+        if (mDeviceListGroup instanceof BluetoothProgressCategory) {
+            ((BluetoothProgressCategory) mDeviceListGroup).setProgress(start);
+        }
+    }
+
+    public void onBluetoothStateChanged(int bluetoothState) {
+        if (bluetoothState == BluetoothAdapter.STATE_OFF) {
+            updateProgressUi(false);
+        }
+    }
+
+    public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }
+}
diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java
index 8bf8202..0cf13a3 100644
--- a/src/com/android/settings/bluetooth/DevicePickerFragment.java
+++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java
@@ -42,6 +42,7 @@
  */
 public final class DevicePickerFragment extends DeviceListPreferenceFragment {
     private static final int MENU_ID_REFRESH = Menu.FIRST;
+    private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
     private static final String TAG = "DevicePickerFragment";
 
     public DevicePickerFragment() {
@@ -54,7 +55,7 @@
     private boolean mStartScanOnStart;
 
     @Override
-    void addPreferencesForActivity() {
+    void initPreferencesFromPreferenceScreen() {
         Intent intent = getActivity().getIntent();
         mNeedAuth = intent.getBooleanExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
         setFilter(intent.getIntExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE,
@@ -167,6 +168,11 @@
         return null;
     }
 
+    @Override
+    public String getDeviceListKey() {
+        return KEY_BT_DEVICE_LIST;
+    }
+
     private void sendDevicePickedIntent(BluetoothDevice device) {
         Intent intent = new Intent(BluetoothDevicePicker.ACTION_DEVICE_SELECTED);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 6b172c2..27492ce 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -23,6 +23,7 @@
 
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
 import com.android.settings.bluetooth.Utils;
 import com.android.settings.core.PreferenceController;
@@ -71,7 +72,8 @@
         controllers.add(mUsbPrefController);
         final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
                 new BluetoothMasterSwitchPreferenceController(
-                        context, Utils.getLocalBtManager(context));
+                        context, Utils.getLocalBtManager(context), this,
+                        (SettingsActivity) getActivity());
         lifecycle.addObserver(bluetoothPreferenceController);
         controllers.add(bluetoothPreferenceController);
         return controllers;
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index a47e135..af6306d 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -327,6 +327,7 @@
         final Activity activity = getActivity();
         final Preference pref = EntityHeaderController
                 .newInstance(activity, this, null /* header */)
+                .setRecyclerView(getListView(), getLifecycle())
                 .setButtonActions(showInfoButton
                                 ? EntityHeaderController.ActionType.ACTION_APP_INFO
                                 : EntityHeaderController.ActionType.ACTION_NONE,
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 1822341..9bab3ce 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -184,6 +184,7 @@
         final Bundle bundle = getArguments();
         EntityHeaderController controller = EntityHeaderController
                 .newInstance(context, this, appSnippet)
+                .setRecyclerView(getListView(), getLifecycle())
                 .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
                         EntityHeaderController.ActionType.ACTION_NONE);
 
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 92ad3f1..e7be62f 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -132,6 +132,7 @@
         final Activity activity = getActivity();
         final Preference pref = EntityHeaderController
                 .newInstance(activity, this /* fragment */, null /* header */)
+                .setRecyclerView(getListView(), getLifecycle())
                 .setIcon(mAppRow.icon)
                 .setLabel(mAppRow.label)
                 .setPackageName(mAppRow.pkg)
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 85a56ba..f7bf1ca 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -112,6 +112,7 @@
         final Activity activity = getActivity();
         final Preference pref = EntityHeaderController
                 .newInstance(activity, this /* fragment */, null /* header */)
+                .setRecyclerView(getListView(), getLifecycle())
                 .setIcon(mAppRow.icon)
                 .setLabel(mChannel.getName())
                 .setSummary(mAppRow.label)
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index ce8135c..ab1af49 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -40,6 +40,7 @@
 import com.android.settings.backup.BackupSettingsActivity;
 import com.android.settings.backup.BackupSettingsFragment;
 import com.android.settings.bluetooth.BluetoothSettings;
+import com.android.settings.bluetooth.BluetoothSettingsObsolete;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
 import com.android.settings.datausage.DataUsageMeteredSettings;
 import com.android.settings.datausage.DataUsageSummary;
@@ -110,6 +111,7 @@
         addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID,
                 R.drawable.ic_settings_wireless);
         addIndex(BluetoothSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth);
+        addIndex(BluetoothSettingsObsolete.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth);
         addIndex(SimSettings.class, NO_DATA_RES_ID, R.drawable.ic_sim_sd);
         addIndex(DataUsageSummary.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
         addIndex(DataUsageMeteredSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
diff --git a/src/com/android/settings/search2/CursorToSearchResultConverter.java b/src/com/android/settings/search2/CursorToSearchResultConverter.java
index 706f33b..30afbd0 100644
--- a/src/com/android/settings/search2/CursorToSearchResultConverter.java
+++ b/src/com/android/settings/search2/CursorToSearchResultConverter.java
@@ -74,6 +74,7 @@
     private static final String[] whiteList = {
             "main_toggle_wifi",
             "main_toggle_bluetooth",
+            "main_toggle_bluetooth_obsolete",
             "toggle_airplane",
             "tether_settings",
             "battery_saver",
diff --git a/src/com/android/settings/widget/ActionBarShadowController.java b/src/com/android/settings/widget/ActionBarShadowController.java
new file mode 100644
index 0000000..75bdf0e
--- /dev/null
+++ b/src/com/android/settings/widget/ActionBarShadowController.java
@@ -0,0 +1,97 @@
+/*
+ * 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.widget;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+public class ActionBarShadowController implements LifecycleObserver, OnStart, OnStop {
+
+    private ScrollChangeWatcher mScrollChangeWatcher;
+    private RecyclerView mRecyclerView;
+    private boolean isScrollWatcherAttached;
+
+    public static ActionBarShadowController attachToRecyclerView(Activity activity,
+            Lifecycle lifecycle, RecyclerView recyclerView) {
+        return new ActionBarShadowController(activity, lifecycle, recyclerView);
+    }
+
+    private ActionBarShadowController(Activity activity, Lifecycle lifecycle,
+            RecyclerView recyclerView) {
+        mScrollChangeWatcher = new ScrollChangeWatcher(activity);
+        mRecyclerView = recyclerView;
+        attachScrollWatcher();
+        lifecycle.addObserver(this);
+    }
+
+    @Override
+    public void onStop() {
+        detachScrollWatcher();
+    }
+
+    private void detachScrollWatcher() {
+        mRecyclerView.removeOnScrollListener(mScrollChangeWatcher);
+        isScrollWatcherAttached = false;
+    }
+
+    @Override
+    public void onStart() {
+        attachScrollWatcher();
+    }
+
+    private void attachScrollWatcher() {
+        if (!isScrollWatcherAttached) {
+            isScrollWatcherAttached = true;
+            mRecyclerView.addOnScrollListener(mScrollChangeWatcher);
+            mScrollChangeWatcher.updateDropShadow(mRecyclerView);
+        }
+    }
+
+    /**
+     * Update the drop shadow as the scrollable entity is scrolled.
+     */
+    private final class ScrollChangeWatcher extends RecyclerView.OnScrollListener {
+
+        private Activity mActivity;
+
+        public ScrollChangeWatcher(Activity activity) {
+            mActivity = activity;
+        }
+
+        // RecyclerView scrolled.
+        @Override
+        public void onScrolled(RecyclerView view, int dx, int dy) {
+            updateDropShadow(view);
+        }
+
+        public void updateDropShadow(View view) {
+            final boolean shouldShowShadow = view.canScrollVertically(-1);
+            final ActionBar actionBar = mActivity.getActionBar();
+            if (actionBar != null) {
+                actionBar.setElevation(shouldShowShadow ? 8 : 0);
+            }
+        }
+    }
+
+}
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index d7ba35a..70d3ce5 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -30,6 +30,7 @@
 import android.os.UserHandle;
 import android.support.annotation.IntDef;
 import android.support.annotation.VisibleForTesting;
+import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -46,6 +47,7 @@
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -68,11 +70,13 @@
 
     private static final String TAG = "AppDetailFeature";
 
-    private final Context mContext;
+    private final Context mAppContext;
+    private final Activity mActivity;
     private final Fragment mFragment;
     private final int mMetricsCategory;
     private final View mHeader;
-
+    private Lifecycle mLifecycle;
+    private RecyclerView mRecyclerView;
     private Drawable mIcon;
     private CharSequence mLabel;
     private CharSequence mSummary;
@@ -93,15 +97,16 @@
      * @param fragment The fragment that header will be placed in.
      * @param header   Optional: header view if it's already created.
      */
-    public static EntityHeaderController newInstance(Context context, Fragment fragment,
+    public static EntityHeaderController newInstance(Activity activity, Fragment fragment,
             View header) {
-        return new EntityHeaderController(context.getApplicationContext(), fragment, header);
+        return new EntityHeaderController(activity, fragment, header);
     }
 
-    private EntityHeaderController(Context context, Fragment fragment, View header) {
-        mContext = context;
+    private EntityHeaderController(Activity activity, Fragment fragment, View header) {
+        mActivity = activity;
+        mAppContext = activity.getApplicationContext();
         mFragment = fragment;
-        mMetricsCategory = FeatureFactory.getFactory(context).getMetricsFeatureProvider()
+        mMetricsCategory = FeatureFactory.getFactory(mAppContext).getMetricsFeatureProvider()
                 .getMetricsCategory(fragment);
         if (header != null) {
             mHeader = header;
@@ -111,16 +116,22 @@
         }
     }
 
+    public EntityHeaderController setRecyclerView(RecyclerView recyclerView, Lifecycle lifecycle) {
+        mRecyclerView = recyclerView;
+        mLifecycle = lifecycle;
+        return this;
+    }
+
     public EntityHeaderController setIcon(Drawable icon) {
         if (icon != null) {
-            mIcon = icon.getConstantState().newDrawable(mContext.getResources());
+            mIcon = icon.getConstantState().newDrawable(mAppContext.getResources());
         }
         return this;
     }
 
     public EntityHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
         if (appEntry.icon != null) {
-            mIcon = appEntry.icon.getConstantState().newDrawable(mContext.getResources());
+            mIcon = appEntry.icon.getConstantState().newDrawable(mAppContext.getResources());
         }
         return this;
     }
@@ -233,6 +244,9 @@
         actionBar.setBackgroundDrawable(
                 new ColorDrawable(Utils.getColorAttr(activity, android.R.attr.colorSecondary)));
         actionBar.setElevation(0);
+        if (mRecyclerView != null && mLifecycle != null) {
+            ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);
+        }
 
         return this;
     }
@@ -257,7 +271,7 @@
                     button.setVisibility(View.GONE);
                 } else {
                     button.setContentDescription(
-                            mContext.getString(R.string.application_info_label));
+                            mAppContext.getString(R.string.application_info_label));
                     button.setImageResource(com.android.settings.R.drawable.ic_info);
                     button.setOnClickListener(new View.OnClickListener() {
                         @Override
@@ -311,7 +325,7 @@
     }
 
     private Intent resolveIntent(Intent i) {
-        ResolveInfo result = mContext.getPackageManager().resolveActivity(i, 0);
+        ResolveInfo result = mAppContext.getPackageManager().resolveActivity(i, 0);
         if (result != null) {
             return new Intent(i.getAction())
                     .setClassName(result.activityInfo.packageName, result.activityInfo.name);
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index e21b76c..c668779 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -1,4 +1,5 @@
 com.android.settings.bluetooth.DevicePickerFragment
+com.android.settings.bluetooth.BluetoothPairingDetail
 com.android.settings.notification.ZenModePrioritySettings
 com.android.settings.accounts.AccountDetailDashboardFragment
 com.android.settings.fuelgauge.PowerUsageAnomalyDetails
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index 0668379..64c2e9e 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -18,10 +18,10 @@
 
 import android.accounts.Account;
 import android.app.Activity;
-import android.app.Fragment;
 import android.content.Context;
 import android.os.Bundle;
 import android.os.UserHandle;
+import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.PreferenceScreen;
 import android.widget.TextView;
 
@@ -31,6 +31,7 @@
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settingslib.accounts.AuthenticatorHelper;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -57,7 +58,7 @@
     @Mock
     private Activity mActivity;
     @Mock
-    private Fragment mFragment;
+    private PreferenceFragment mFragment;
     @Mock
     private PreferenceScreen mScreen;
 
@@ -76,7 +77,7 @@
     @Test
     public void isAvailable_noArgs_shouldReturnNull() {
         mController = new AccountHeaderPreferenceController(RuntimeEnvironment.application,
-                mActivity, mFragment, null /* args */);
+                new Lifecycle(), mActivity, mFragment, null /* args */);
 
         assertThat(mController.isAvailable()).isFalse();
     }
@@ -89,7 +90,7 @@
         args.putParcelable(AccountDetailDashboardFragment.KEY_ACCOUNT, account);
         args.putParcelable(AccountDetailDashboardFragment.KEY_USER_HANDLE, UserHandle.CURRENT);
         mController = new AccountHeaderPreferenceController(RuntimeEnvironment.application,
-                mActivity, mFragment, args);
+                new Lifecycle(), mActivity, mFragment, args);
 
         assertThat(mController.isAvailable()).isTrue();
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
index 177130e..f0fb91c 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
@@ -16,14 +16,18 @@
 
 package com.android.settings.bluetooth;
 
+import android.app.Fragment;
 import android.content.Context;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.widget.MasterSwitchPreference;
 import com.android.settingslib.bluetooth.BluetoothCallback;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -38,7 +42,10 @@
 import org.robolectric.annotation.Config;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -54,17 +61,26 @@
     private MasterSwitchPreference mPreference;
     @Mock
     private RestrictionUtils mRestrictionUtils;
+    @Mock
+    private Fragment mFragment;
+    @Mock
+    private SettingsActivity mActivity;
 
     private Context mContext;
     private BluetoothMasterSwitchPreferenceController mController;
+    private FakeFeatureFactory mFeatureFactory;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application.getApplicationContext();
+        mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
         mController = new BluetoothMasterSwitchPreferenceController(
-                mContext, mBluetoothManager, mRestrictionUtils);
+                mContext, mBluetoothManager, mRestrictionUtils, mFragment, mActivity);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
     }
 
     @Test
@@ -84,7 +100,7 @@
         mController.onPause();
 
         verify(mBluetoothManager.getEventManager()).unregisterCallback(
-            any(BluetoothCallback.class));
+                any(BluetoothCallback.class));
     }
 
     @Test
@@ -114,4 +130,22 @@
         verify(mPreference).setSummary("test summary");
     }
 
+    @Test
+    public void testHandlePreferenceTreeClick_pairPageEnabled_showNewPage() {
+        when(mFeatureFactory.bluetoothFeatureProvider.isPairingPageEnabled()).thenReturn(true);
+
+        mController.handlePreferenceTreeClick(mPreference);
+
+        verify(mActivity).startPreferencePanelAsUser(eq(mFragment),
+                eq(BluetoothSettings.class.getName()), any(), eq(R.string.bluetooth), any(), any());
+    }
+
+    @Test
+    public void testHandlePreferenceTreeClick_pairPageDisabled_showOldPage() {
+        mController.handlePreferenceTreeClick(mPreference);
+
+        verify(mActivity).startPreferencePanelAsUser(eq(mFragment),
+                eq(BluetoothSettingsObsolete.class.getName()), any(), eq(R.string.bluetooth), any(),
+                any());
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
new file mode 100644
index 0000000..6774ba9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.bluetooth;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.UserManager;
+import android.support.v7.preference.PreferenceGroup;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.widget.FooterPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BluetoothPairingDetailTest {
+
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private Resources mResource;
+    @Mock
+    private LocalBluetoothAdapter mLocalAdapter;
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private LocalBluetoothManager mLocalManager;
+    @Mock
+    private PreferenceGroup mPreferenceGroup;
+    private BluetoothPairingDetail mFragment;
+    private Context mContext;
+    private BluetoothProgressCategory mAvailableDevicesCategory;
+    private FooterPreference mFooterPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mContext = RuntimeEnvironment.application;
+        mFragment = spy(new BluetoothPairingDetail());
+        doReturn(mContext).when(mFragment).getContext();
+        doReturn(mResource).when(mFragment).getResources();
+
+        mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext));
+        mFooterPreference = new FooterPreference(mContext);
+
+        mFragment.mLocalAdapter = mLocalAdapter;
+        mFragment.mLocalManager = mLocalManager;
+        mFragment.mDeviceListGroup = mPreferenceGroup;
+    }
+
+    @Test
+    public void testInitPreferencesFromPreferenceScreen_findPreferences() {
+        doReturn(mAvailableDevicesCategory).when(mFragment).findPreference(
+                BluetoothPairingDetail.KEY_AVAIL_DEVICES);
+        doReturn(mFooterPreference).when(mFragment).findPreference(
+                BluetoothPairingDetail.KEY_FOOTER_PREF);
+
+        mFragment.initPreferencesFromPreferenceScreen();
+
+        assertThat(mFragment.mAvailableDevicesCategory).isEqualTo(mAvailableDevicesCategory);
+        assertThat(mFragment.mFooterPreference).isEqualTo(mFooterPreference);
+    }
+
+    @Test
+    public void testStartScanning_startScanAndRemoveDevices() {
+        mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
+        mFragment.mDeviceListGroup = mAvailableDevicesCategory;
+
+        mFragment.startScanning();
+
+        verify(mLocalAdapter).startScanning(true);
+        verify(mAvailableDevicesCategory).removeAll();
+    }
+
+    @Test
+    public void testUpdateContent_stateOn_addDevices() {
+        mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
+        mFragment.mFooterPreference = mFooterPreference;
+        doNothing().when(mFragment).addDeviceCategory(any(), anyInt(), any(), anyBoolean());
+
+        mFragment.updateContent(BluetoothAdapter.STATE_ON);
+
+        verify(mFragment).addDeviceCategory(mAvailableDevicesCategory,
+                R.string.bluetooth_preference_found_devices,
+                BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, false);
+        verify(mLocalAdapter).setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+    }
+
+    @Test
+    public void testUpdateContent_stateOff_finish() {
+        mFragment.updateContent(BluetoothAdapter.STATE_OFF);
+
+        verify(mFragment).finish();
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
index 24325b3..937b31f 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
@@ -18,6 +18,11 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.FragmentManager;
@@ -27,6 +32,7 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
+import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.R;
@@ -45,7 +51,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class BluetoothPairingPreferenceControllerTest {
-
+    private static final int ORDER = 1;
     private Context mContext;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private PreferenceFragment mFragment;
@@ -59,6 +65,8 @@
     private FragmentTransaction mFragmentTransaction;
     @Mock
     private PreferenceScreen mPreferenceScreen;
+    @Mock
+    private SettingsActivity mSettingsActivity;
     private Preference mPreference;
 
     private BluetoothPairingPreferenceController mController;
@@ -70,16 +78,29 @@
         mContext = RuntimeEnvironment.application;
         when(mFragment.getPreferenceScreen().getContext()).thenReturn(mContext);
 
-        mController = new BluetoothPairingPreferenceController(mContext, mFragment);
+        mPreference = new Preference(mContext);
+        mPreference.setKey(BluetoothPairingPreferenceController.KEY_PAIRING);
+
+        mController = new BluetoothPairingPreferenceController(mContext, mFragment,
+                mSettingsActivity);
     }
 
     @Test
     public void testCreateBluetoothPairingPreference() {
-        Preference pref = mController.createBluetoothPairingPreference();
+        Preference pref = mController.createBluetoothPairingPreference(ORDER);
 
         assertThat(pref.getKey()).isEqualTo(BluetoothPairingPreferenceController.KEY_PAIRING);
         assertThat(pref.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_add));
+        assertThat(pref.getOrder()).isEqualTo(ORDER);
         assertThat(pref.getTitle()).isEqualTo(
                 mContext.getString(R.string.bluetooth_pairing_pref_title));
     }
+
+    @Test
+    public void testHandlePreferenceTreeClick_startFragment() {
+        mController.handlePreferenceTreeClick(mPreference);
+
+        verify(mSettingsActivity).startPreferencePanelAsUser(eq(mFragment), anyString(), any(),
+                anyInt(), any(), any());
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsObsoleteTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsObsoleteTest.java
new file mode 100644
index 0000000..549eeb7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsObsoleteTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.bluetooth;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BluetoothSettingsObsoleteTest {
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    private BluetoothSettingsObsolete mFragment;
+    private FakeFeatureFactory mFeatureFactory;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
+        mFragment = spy(new BluetoothSettingsObsolete());
+        doReturn(mContext).when(mFragment).getContext();
+    }
+
+    @Test
+    public void testSearchIndexProvider_pairPageEnabled_keyAdded() {
+        doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).contains(BluetoothSettingsObsolete.DATA_KEY_REFERENCE);
+    }
+
+    @Test
+    public void testSearchIndexProvider_pairPageDisabled_keyNotAdded() {
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).doesNotContain(BluetoothSettingsObsolete.DATA_KEY_REFERENCE);
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
index 35207f5..6ceca41 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
@@ -23,24 +23,33 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
+import android.app.Activity;
 import android.content.Context;
 import android.content.res.Resources;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.view.View;
+import android.widget.TextView;
 
 import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.widget.FooterPreference;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
+import java.util.List;
+
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class BluetoothSettingsTest {
@@ -51,23 +60,42 @@
     @Mock
     private Resources mResource;
     @Mock
-    private Context mContext;
-    @Mock
     private LocalBluetoothAdapter mLocalAdapter;
+    @Mock
+    private Activity mActivity;
+    @Mock
+    private PreferenceGroup mPairedDevicesCategory;
+    @Mock
+    private BluetoothPairingPreferenceController mPairingPreferenceController;
+    private Context mContext;
     private BluetoothSettings mFragment;
-    private Preference mMyDevicePreference;
+    private FakeFeatureFactory mFeatureFactory;
+    private Preference mFooterPreference;
+    private TextView mEmptyMessage;
+    private View mContainer;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
+        mContext = spy(RuntimeEnvironment.application);
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
         mFragment = spy(new BluetoothSettings());
+
         doReturn(mContext).when(mFragment).getContext();
         doReturn(mResource).when(mFragment).getResources();
+        doReturn(mActivity).when(mFragment).getActivity();
 
-        mMyDevicePreference = new Preference(RuntimeEnvironment.application);
+        mContainer = new View(mContext);
+        mEmptyMessage = new TextView(mContext);
+        doReturn(mContainer).when(mActivity).findViewById(android.R.id.list_container);
+        doReturn(mEmptyMessage).when(mActivity).findViewById(android.R.id.empty);
 
+        mFooterPreference = new FooterPreference(RuntimeEnvironment.application);
         mFragment.setLocalBluetoothAdapter(mLocalAdapter);
+        mFragment.mPairingPrefController = mPairingPreferenceController;
     }
 
     @Test
@@ -81,9 +109,56 @@
         doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
                 eq(R.string.bluetooth_footer_mac_message), any());
 
-        mFragment.updateMyDevicePreference(mMyDevicePreference);
+        mFragment.updateFooterPreference(mFooterPreference);
 
-        assertThat(mMyDevicePreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
+        assertThat(mFooterPreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
+    }
+
+    @Test
+    public void testDisplayEmptyMessage_showEmptyMessage() {
+        mFragment.displayEmptyMessage(true);
+
+        assertThat(mContainer.getVisibility()).isEqualTo(View.INVISIBLE);
+        assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.VISIBLE);
+    }
+
+    @Test
+    public void testDisplayEmptyMessage_hideEmptyMessage() {
+        mFragment.displayEmptyMessage(false);
+
+        assertThat(mContainer.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.GONE);
+    }
+
+    @Test
+    public void testInitPreferencesFromPreferenceScreen() {
+        doReturn(mPairedDevicesCategory).when(mFragment).findPreference(
+                BluetoothSettings.KEY_PAIRED_DEVICES);
+        doReturn(mFooterPreference).when(mFragment).findPreference(
+                BluetoothSettings.KEY_FOOTER_PREF);
+
+        mFragment.initPreferencesFromPreferenceScreen();
+
+        assertThat(mFragment.mPairedDevicesCategory).isEqualTo(mPairedDevicesCategory);
+        assertThat(mFragment.mFooterPreference).isEqualTo(mFooterPreference);
+    }
+
+    @Test
+    public void testSearchIndexProvider_pairPageEnabled_keyNotAdded() {
+        doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).doesNotContain(BluetoothSettings.DATA_KEY_REFERENCE);
+    }
+
+    @Test
+    public void testSearchIndexProvider_pairPageDisabled_keyAdded() {
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).contains(BluetoothSettings.DATA_KEY_REFERENCE);
     }
 
 }
diff --git a/tests/robotests/src/com/android/settings/bluetooth/DeviceListPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/DeviceListPreferenceFragmentTest.java
new file mode 100644
index 0000000..bbb7359
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/DeviceListPreferenceFragmentTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.bluetooth;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceController;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DeviceListPreferenceFragmentTest {
+    private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
+
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private Resources mResource;
+    @Mock
+    private Context mContext;
+    @Mock
+    private LocalBluetoothAdapter mLocalAdapter;
+    private TestFragment mFragment;
+    private Preference mMyDevicePreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mFragment = spy(new TestFragment());
+        doReturn(mContext).when(mFragment).getContext();
+        doReturn(mResource).when(mFragment).getResources();
+        mFragment.mLocalAdapter = mLocalAdapter;
+
+        mMyDevicePreference = new Preference(RuntimeEnvironment.application);
+    }
+
+    @Test
+    public void setUpdateMyDevicePreference_setTitleCorrectly() {
+        doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
+                eq(R.string.bluetooth_footer_mac_message), any());
+
+        mFragment.updateFooterPreference(mMyDevicePreference);
+
+        assertThat(mMyDevicePreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
+    }
+
+    /**
+     * Fragment to test since {@code DeviceListPreferenceFragment} is abstract
+     */
+    public static class TestFragment extends DeviceListPreferenceFragment {
+
+        public TestFragment() {
+            super("");
+        }
+
+        @Override
+        public int getMetricsCategory() {
+            return 0;
+        }
+
+        @Override
+        public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+
+        }
+
+        @Override
+        void initPreferencesFromPreferenceScreen() {
+
+        }
+
+        @Override
+        public String getDeviceListKey() {
+            return null;
+        }
+
+        @Override
+        protected String getLogTag() {
+            return null;
+        }
+
+        @Override
+        protected int getPreferenceScreenResId() {
+            return 0;
+        }
+
+        @Override
+        protected List<PreferenceController> getPreferenceControllers(Context context) {
+            return null;
+        }
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index 7421570..72cbf4e 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -22,10 +22,10 @@
 import android.provider.SearchIndexableResource;
 
 import com.android.settings.R;
+import com.android.settings.nfc.NfcPreferenceController;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.nfc.NfcPreferenceController;
 import com.android.settings.testutils.XmlTestUtils;
 import com.android.settingslib.drawer.CategoryKey;
 
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 2d0f031..8cbe947 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -42,11 +42,13 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
+import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
@@ -74,6 +76,8 @@
     @Test
     public void bindAppHeader_allWorkApps_shouldNotShowAppInfoLink() {
         ShadowEntityHeaderController.setUseMock(mHeaderController);
+        when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
+
         mFragment = spy(new AppDataUsage());
 
         doReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS))
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 7b2d8cc..c5fcbf5 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -23,6 +23,7 @@
 import android.graphics.drawable.Drawable;
 import android.os.BatteryStats;
 import android.os.Bundle;
+import android.support.v7.widget.RecyclerView;
 
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
@@ -36,6 +37,7 @@
 import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.After;
 import org.junit.Before;
@@ -123,6 +125,8 @@
 
         ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
         doReturn(mEntityHeaderController).when(mEntityHeaderController)
+                .setRecyclerView(any(RecyclerView.class), any(Lifecycle.class));
+        doReturn(mEntityHeaderController).when(mEntityHeaderController)
                 .setButtonActions(anyInt(), anyInt());
         doReturn(mEntityHeaderController).when(mEntityHeaderController)
                 .setIcon(any(Drawable.class));
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowEntityHeaderController.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowEntityHeaderController.java
index bccb297..4ec48d3 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowEntityHeaderController.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowEntityHeaderController.java
@@ -16,8 +16,8 @@
 
 package com.android.settings.testutils.shadow;
 
+import android.app.Activity;
 import android.app.Fragment;
-import android.content.Context;
 import android.view.View;
 
 import com.android.settings.widget.EntityHeaderController;
@@ -41,7 +41,7 @@
     }
 
     @Implementation
-    public static EntityHeaderController newInstance(Context context, Fragment fragment,
+    public static EntityHeaderController newInstance(Activity activity, Fragment fragment,
             View header) {
         return sMockController;
     }
diff --git a/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
new file mode 100644
index 0000000..b8f7820
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.widget;
+
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.support.v7.widget.RecyclerView;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ActionBarShadowControllerTest {
+
+    @Mock
+    private RecyclerView mRecyclerView;
+    @Mock
+    private Activity mActivity;
+    @Mock
+    private ActionBar mActionBar;
+    private Lifecycle mLifecycle;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mActivity.getActionBar()).thenReturn(mActionBar);
+        mLifecycle = new Lifecycle();
+    }
+
+    @Test
+    public void attachToRecyclerView_shouldAddScrollWatcherAndUpdateActionBar() {
+        when(mRecyclerView.canScrollVertically(-1)).thenReturn(false);
+
+        ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);
+
+        verify(mActionBar).setElevation(0);
+    }
+
+
+    @Test
+    public void attachToRecyclerView_lifecycleChange_shouldAttachDetach() {
+        ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);
+
+        List<LifecycleObserver> observers = ReflectionHelpers.getField(mLifecycle, "mObservers");
+        assertThat(observers).hasSize(1);
+        verify(mRecyclerView).addOnScrollListener(any());
+
+        mLifecycle.onStop();
+        verify(mRecyclerView).removeOnScrollListener(any());
+
+        mLifecycle.onStart();
+        verify(mRecyclerView, times(2)).addOnScrollListener(any());
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index e6c742a..e386282 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -66,7 +66,6 @@
     @Mock
     private Fragment mFragment;
 
-    private FakeFeatureFactory mFeatureFactory;
     private Context mShadowContext;
     private LayoutInflater mLayoutInflater;
     private PackageInfo mInfo;
@@ -76,8 +75,8 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
         mShadowContext = RuntimeEnvironment.application;
+        when(mActivity.getApplicationContext()).thenReturn(mShadowContext);
         when(mContext.getApplicationContext()).thenReturn(mContext);
         when(mFragment.getContext()).thenReturn(mShadowContext);
         mLayoutInflater = LayoutInflater.from(mShadowContext);
@@ -87,7 +86,7 @@
 
     @Test
     public void testBuildView_constructedWithoutView_shouldCreateNewView() {
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, null);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
         View view = mController.done(mActivity);
 
         assertThat(view).isNotNull();
@@ -95,7 +94,7 @@
 
     @Test
     public void testBuildView_withContext_shouldBuildPreference() {
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, null);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
         Preference preference = mController.done(mActivity, mShadowContext);
 
         assertThat(preference instanceof LayoutPreference).isTrue();
@@ -104,7 +103,7 @@
     @Test
     public void testBuildView_constructedWithView_shouldReturnSameView() {
         View inputView = mLayoutInflater.inflate(R.layout.settings_entity_header, null /* root */);
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, inputView);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, inputView);
         View view = mController.done(mActivity);
 
         assertThat(view).isSameAs(inputView);
@@ -118,7 +117,7 @@
         final TextView label = header.findViewById(R.id.entity_header_title);
         final TextView version = header.findViewById(R.id.entity_header_summary);
 
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, header);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
         mController.setLabel(testString);
         mController.setSummary(testString);
         mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
@@ -136,10 +135,11 @@
         info.activityInfo.name = "321";
         final View appLinks = mLayoutInflater
                 .inflate(R.layout.settings_entity_header, null /* root */);
+        when(mActivity.getApplicationContext()).thenReturn(mContext);
         when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
                 .thenReturn(info);
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setButtonActions(
                 EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
                 EntityHeaderController.ActionType.ACTION_NONE);
@@ -164,7 +164,7 @@
         when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
                 .thenReturn(null);
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setButtonActions(
                 EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
                 EntityHeaderController.ActionType.ACTION_NONE);
@@ -181,7 +181,7 @@
         final View appLinks = mLayoutInflater
                 .inflate(R.layout.settings_entity_header, null /* root */);
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setPackageName(null)
                 .setButtonActions(
                         EntityHeaderController.ActionType.ACTION_APP_INFO,
@@ -200,7 +200,7 @@
                 .inflate(R.layout.settings_entity_header, null /* root */);
         when(mFragment.getActivity()).thenReturn(mock(Activity.class));
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setPackageName("123")
                 .setUid(UserHandle.USER_SYSTEM)
                 .setButtonActions(
@@ -221,7 +221,7 @@
         when(mFragment.getActivity()).thenReturn(mock(Activity.class));
         when(mContext.getString(eq(R.string.application_info_label))).thenReturn("App Info");
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setPackageName("123")
                 .setUid(UserHandle.USER_SYSTEM)
                 .setButtonActions(
@@ -229,8 +229,8 @@
                         EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
         mController.done(mActivity);
 
-        assertThat(appLinks.findViewById(android.R.id.button1).getContentDescription())
-                .isEqualTo("App Info");
+        assertThat(appLinks.findViewById(android.R.id.button1).getContentDescription().toString())
+                .isEqualTo("App info");
     }
 
     @Test
@@ -238,7 +238,7 @@
         final View appLinks = mLayoutInflater
                 .inflate(R.layout.settings_entity_header, null /* root */);
 
-        mController = EntityHeaderController.newInstance(mContext, mFragment, appLinks);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
         mController.setAppNotifPrefIntent(new Intent())
                 .setButtonActions(
                         EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
@@ -257,7 +257,7 @@
     public void instantApps_normalAppsDontGetLabel() {
         final View header = mLayoutInflater.inflate(
                 R.layout.settings_entity_header, null /* root */);
-        mController = EntityHeaderController.newInstance(mContext, mFragment, header);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
         mController.done(mActivity);
 
         assertThat(header.findViewById(R.id.install_type).getVisibility())
@@ -269,7 +269,7 @@
     public void instantApps_expectedHeaderItem() {
         final View header = mLayoutInflater.inflate(
                 R.layout.settings_entity_header, null /* root */);
-        mController = EntityHeaderController.newInstance(mContext, mFragment, header);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
         mController.setIsInstantApp(true);
         mController.done(mActivity);
         TextView label = header.findViewById(R.id.install_type);
@@ -283,7 +283,7 @@
 
     @Test
     public void styleActionBar_invalidObjects_shouldNotCrash() {
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, null);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
         mController.styleActionBar(null);
 
         when(mActivity.getActionBar()).thenReturn(null);
@@ -296,7 +296,7 @@
     public void styleActionBar_setElevationAndBackground() {
         final ActionBar actionBar = mActivity.getActionBar();
 
-        mController = EntityHeaderController.newInstance(mShadowContext, mFragment, null);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
         mController.styleActionBar(mActivity);
 
         verify(actionBar).setElevation(0);
@@ -307,7 +307,7 @@
 
     @Test
     public void initAppHeaderController_appHeaderNull_useFragmentContext() {
-        mController = EntityHeaderController.newInstance(mContext, mFragment, null);
+        mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
 
         // Fragment.getContext() is invoked to inflate the view
         verify(mFragment).getContext();