Home | History | Annotate | Download | only in indexing
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  */
     17 
     18 package com.android.settings.search.indexing;
     19 
     20 import android.content.Context;
     21 import android.provider.SearchIndexableResource;
     22 
     23 import com.android.internal.logging.nano.MetricsProto;
     24 import com.android.settings.dashboard.DashboardFragment;
     25 import com.android.settings.search.BaseSearchIndexProvider;
     26 import com.android.settings.search.SearchIndexableRaw;
     27 import com.android.settingslib.core.AbstractPreferenceController;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 /**
     33  * Test class for Settings Search Indexing.
     34  * If you change this class, please run robotests to make sure they still pass.
     35  */
     36 public class FakeSettingsFragment extends DashboardFragment {
     37 
     38     public static final String TITLE = "raw title";
     39     public static final String SUMMARY_ON = "raw summary on";
     40     public static final String SUMMARY_OFF = "raw summary off";
     41     public static final String ENTRIES = "rawentries";
     42     public static final String KEYWORDS = "keywords, keywordss, keywordsss";
     43     public static final String SPACE_KEYWORDS = "keywords keywordss keywordsss";
     44     public static final String SCREEN_TITLE = "raw screen title";
     45     public static final String CLASS_NAME = FakeSettingsFragment.class.getName();
     46     public static final int ICON = 0xff;
     47     public static final String INTENT_ACTION = "raw action";
     48     public static final String PACKAGE_NAME = "raw target package";
     49     public static final String TARGET_CLASS = "raw target class";
     50     public static final String TARGET_PACKAGE = "raw package name";
     51     public static final String KEY = "raw key";
     52     public static final boolean ENABLED = true;
     53 
     54 
     55     @Override
     56     public int getMetricsCategory() {
     57         return MetricsProto.MetricsEvent.DISPLAY;
     58     }
     59 
     60     @Override
     61     protected String getLogTag() {
     62         return "";
     63     }
     64 
     65     @Override
     66     protected int getPreferenceScreenResId() {
     67         return com.android.settings.R.xml.display_settings;
     68     }
     69 
     70     @Override
     71     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     72         return null;
     73     }
     74 
     75     /** Index provider used to expose this fragment in search. */
     76     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     77             new BaseSearchIndexProvider() {
     78                 @Override
     79                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
     80                         boolean enabled) {
     81                     final SearchIndexableRaw data = new SearchIndexableRaw(context);
     82                     data.title = TITLE;
     83                     data.summaryOn = SUMMARY_ON;
     84                     data.summaryOff = SUMMARY_OFF;
     85                     data.entries = ENTRIES;
     86                     data.keywords = KEYWORDS;
     87                     data.screenTitle = SCREEN_TITLE;
     88                     data.packageName = PACKAGE_NAME;
     89                     data.intentAction = INTENT_ACTION;
     90                     data.intentTargetClass = TARGET_CLASS;
     91                     data.intentTargetPackage = TARGET_PACKAGE;
     92                     data.key = KEY;
     93                     data.iconResId = ICON;
     94                     data.enabled = ENABLED;
     95 
     96                     final List<SearchIndexableRaw> result = new ArrayList<>(1);
     97                     result.add(data);
     98                     return result;
     99                 }
    100 
    101                 @Override
    102                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
    103                         boolean enabled) {
    104                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
    105 
    106                     final SearchIndexableResource sir = new SearchIndexableResource(context);
    107                     sir.xmlResId = com.android.settings.R.xml.display_settings;
    108                     result.add(sir);
    109                     return result;
    110                 }
    111 
    112                 @Override
    113                 public List<String> getNonIndexableKeys(Context context) {
    114                     List<String> keys = super.getNonIndexableKeys(context);
    115                     keys.add("pref_key_1");
    116                     keys.add("pref_key_3");
    117                     return keys;
    118                 }
    119             };
    120 }