1 /* 2 * Copyright (C) 2018 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 package com.android.settings.search; 18 19 import android.content.Context; 20 import android.provider.SearchIndexableResource; 21 22 import com.android.internal.logging.nano.MetricsProto; 23 import com.android.settings.dashboard.DashboardFragment; 24 import com.android.settingslib.core.AbstractPreferenceController; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 29 /** 30 * Test class for Settings Search Indexing. 31 * If you change this class, please run robotests to make sure they still pass. 32 */ 33 public class FakeSettingsFragment extends DashboardFragment { 34 35 public static final String TITLE = "raw title"; 36 public static final String SUMMARY_ON = "raw summary on"; 37 public static final String SUMMARY_OFF = "raw summary off"; 38 public static final String ENTRIES = "rawentries"; 39 public static final String KEYWORDS = "keywords, keywordss, keywordsss"; 40 public static final String SPACE_KEYWORDS = "keywords keywordss keywordsss"; 41 public static final String SCREEN_TITLE = "raw screen title"; 42 public static final String CLASS_NAME = FakeSettingsFragment.class.getName(); 43 public static final int ICON = 0xff; 44 public static final String INTENT_ACTION = "raw action"; 45 public static final String PACKAGE_NAME = "raw target package"; 46 public static final String TARGET_CLASS = "raw target class"; 47 public static final String TARGET_PACKAGE = "raw package name"; 48 public static final String KEY = "raw key"; 49 public static final boolean ENABLED = true; 50 51 52 @Override getMetricsCategory()53 public int getMetricsCategory() { 54 return MetricsProto.MetricsEvent.DISPLAY; 55 } 56 57 @Override getLogTag()58 protected String getLogTag() { 59 return ""; 60 } 61 62 @Override getPreferenceScreenResId()63 protected int getPreferenceScreenResId() { 64 return com.android.settings.R.xml.display_settings; 65 } 66 67 @Override createPreferenceControllers(Context context)68 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 69 return null; 70 } 71 72 /** Index provider used to expose this fragment in search. */ 73 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 74 new BaseSearchIndexProvider() { 75 @Override 76 public List<SearchIndexableRaw> getRawDataToIndex(Context context, 77 boolean enabled) { 78 final SearchIndexableRaw data = new SearchIndexableRaw(context); 79 data.title = TITLE; 80 data.summaryOn = SUMMARY_ON; 81 data.summaryOff = SUMMARY_OFF; 82 data.entries = ENTRIES; 83 data.keywords = KEYWORDS; 84 data.screenTitle = SCREEN_TITLE; 85 data.packageName = PACKAGE_NAME; 86 data.intentAction = INTENT_ACTION; 87 data.intentTargetClass = TARGET_CLASS; 88 data.intentTargetPackage = TARGET_PACKAGE; 89 data.key = KEY; 90 data.iconResId = ICON; 91 data.enabled = ENABLED; 92 93 final List<SearchIndexableRaw> result = new ArrayList<>(1); 94 result.add(data); 95 return result; 96 } 97 98 @Override 99 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 100 boolean enabled) { 101 final ArrayList<SearchIndexableResource> result = new ArrayList<>(); 102 103 final SearchIndexableResource sir = new SearchIndexableResource(context); 104 sir.xmlResId = com.android.settings.R.xml.display_settings; 105 result.add(sir); 106 return result; 107 } 108 109 @Override 110 public List<String> getNonIndexableKeys(Context context) { 111 List<String> keys = super.getNonIndexableKeys(context); 112 keys.add("pref_key_1"); 113 keys.add("pref_key_3"); 114 return keys; 115 } 116 }; 117 }