Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 687964cf authored by Lei Yu's avatar Lei Yu
Browse files

Add search index provider for bt page

1. Implement the search index provider for
ConnectedDeviceDashboardFragment.
2. Since in SEARCH_INDEX_DATA_PROVIDER fragment is null,
so we need to pass in context to all components
instead of getting it from fragment.
3. Update test for it as well as creating new shadow.

Change-Id: If0aa67d5b6ca207c6b728c8355581bf414577091
Fixes: 69333961
Test: RunSettingsRoboTests
parent 048b71a6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="connected_devices_screen"
    android:key="connected_devices_advanced_screen"
    android:title="@string/connected_device_connections_title">

    <SwitchPreference
+2 −2
Original line number Diff line number Diff line
@@ -93,9 +93,9 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
        }
    }

    public BluetoothDeviceUpdater(DashboardFragment fragment,
    public BluetoothDeviceUpdater(Context context, DashboardFragment fragment,
            DevicePreferenceCallback devicePreferenceCallback) {
        this(fragment, devicePreferenceCallback, Utils.getLocalBtManager(fragment.getContext()));
        this(fragment, devicePreferenceCallback, Utils.getLocalBtManager(context));
    }

    @VisibleForTesting
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.settings.bluetooth;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.annotation.VisibleForTesting;

import com.android.settings.connecteddevice.DevicePreferenceCallback;
@@ -29,9 +30,9 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
 */
public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {

    public ConnectedBluetoothDeviceUpdater(DashboardFragment fragment,
    public ConnectedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
            DevicePreferenceCallback devicePreferenceCallback) {
        super(fragment, devicePreferenceCallback);
        super(context, fragment, devicePreferenceCallback);
    }

    @VisibleForTesting
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.settings.bluetooth;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.annotation.VisibleForTesting;

import com.android.settings.connecteddevice.DevicePreferenceCallback;
@@ -29,9 +30,9 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
 */
public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {

    public SavedBluetoothDeviceUpdater(DashboardFragment fragment,
    public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
            DevicePreferenceCallback devicePreferenceCallback) {
        super(fragment, devicePreferenceCallback);
        super(context, fragment, devicePreferenceCallback);
    }

    @VisibleForTesting
+29 −9
Original line number Diff line number Diff line
@@ -26,17 +26,22 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ConnectedDeviceDashboardFragment extends DashboardFragment {

    private static final String TAG = "ConnectedDeviceFrag";

    @VisibleForTesting
    static final String KEY_CONNECTED_DEVICES = "connected_device_list";
    @VisibleForTesting
    static final String KEY_SAVED_DEVICES = "saved_device_list";

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY;
@@ -59,11 +64,14 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final Lifecycle lifecycle = getLifecycle();
        return buildPreferenceControllers(context, getLifecycle(), this);
    }

        controllers.add(new ConnectedDeviceGroupController(this, lifecycle));
        controllers.add(new SavedDeviceGroupController(this, lifecycle));
    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
            Lifecycle lifecycle, DashboardFragment dashboardFragment) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(new ConnectedDeviceGroupController(context, dashboardFragment, lifecycle));
        controllers.add(new SavedDeviceGroupController(context, dashboardFragment, lifecycle));

        return controllers;
    }
@@ -108,18 +116,30 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
    /**
     * For Search.
     */
    //TODO(b/69333961): update the index for this new fragment
    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(
                        Context context, boolean enabled) {
                    return new ArrayList<>();
                    final SearchIndexableResource sir = new SearchIndexableResource(context);
                    sir.xmlResId = R.xml.connected_devices;
                    return Arrays.asList(sir);
                }

                @Override
                public List<AbstractPreferenceController> createPreferenceControllers(Context
                        context) {
                    return buildPreferenceControllers(context, null /* lifecycle */,
                            null /* dashboardFragment */);
                }

                @Override
                public List<String> getNonIndexableKeys(Context context) {
                    return new ArrayList<>();
                    List<String> keys = super.getNonIndexableKeys(context);
                    // Disable because they show dynamic data
                    keys.add(KEY_CONNECTED_DEVICES);
                    keys.add(KEY_SAVED_DEVICES);
                    return keys;
                }
            };
}
Loading