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