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

Commit 31a28538 authored by Fan Zhang's avatar Fan Zhang
Browse files

Add search provider for storage dashboard.

Bug: 31800690
Test: manual
Change-Id: Icb906bf3b3698c1379e10cf6e346d489675ad940
parent 1d4495f9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/storage_settings">
    <com.android.settings.dashboard.DashboardTilePreference
        android:key="pref_manage_storage"
        android:title="@string/storage_menu_manage"
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import java.util.List;

/**
 * A controller that manages event for preference.
 */
@@ -43,6 +45,12 @@ public abstract class PreferenceController {
     */
    public abstract boolean handlePreferenceTreeClick(Preference preference);

    /**
     * Updates non-indexable keys for search provider.
     *
     * Called by SearchIndexProvider#getNonIndexableKeys
     */
    public abstract void updateNonIndexableKeys(List<String> keys);

    /**
     * Removes preference from screen.
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;

import java.util.List;

public class ManageStoragePreferenceController extends PreferenceController {

    public static final String KEY_MANAGE_STORAGE = "pref_manage_storage";
@@ -37,6 +39,13 @@ public class ManageStoragePreferenceController extends PreferenceController {
        }
    }

    @Override
    public void updateNonIndexableKeys(List<String> keys) {
        if (!isAvailable()) {
            keys.add(KEY_MANAGE_STORAGE);
        }
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        return false;
+40 −0
Original line number Diff line number Diff line
@@ -18,10 +18,19 @@ package com.android.settings.deviceinfo;

import android.content.Context;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;

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

public class StorageDashboardFragment extends DashboardFragment {

@@ -62,4 +71,35 @@ public class StorageDashboardFragment extends DashboardFragment {
        displayTilesAsPreference(TAG, getPreferenceScreen(),
                mDashboardFeatureProvider.getTilesForStorageCategory());
    }

    /**
     * For Search.
     */
    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(
                        Context context, boolean enabled) {
                    if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
                            .isEnabled()) {
                        return null;
                    }
                    final SearchIndexableResource sir = new SearchIndexableResource(context);
                    sir.xmlResId = R.xml.storage_dashboard_fragment;
                    return Arrays.asList(sir);
                }

                @Override
                public List<String> getNonIndexableKeys(Context context) {
                    if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
                            .isEnabled()) {
                        return null;
                    }
                    final ManageStoragePreferenceController controller =
                            new ManageStoragePreferenceController(context);
                    final List<String> keys = new ArrayList<>();
                    controller.updateNonIndexableKeys(keys);
                    return keys;
                }
            };
}
+1 −5
Original line number Diff line number Diff line
@@ -62,11 +62,7 @@ public class SystemUpdatePreferenceController extends PreferenceController {
        }
    }

    /**
     * Updates non-indexable keys for search provider.
     *
     * Called by SearchIndexProvider#getNonIndexableKeys
     */
    @Override
    public void updateNonIndexableKeys(List<String> keys) {
        // TODO: system update needs to be fixed for non-owner user b/22760654
        if (!isAvailable(mContext, KEY_SYSTEM_UPDATE_SETTINGS)) {
Loading