SearchIndexablesContract.java revision 27e13347344276f337d4289e3197f8ab7d5c74d2
1/*
2 * Copyright (C) 2014 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
17package android.provider;
18
19import android.annotation.SystemApi;
20import android.content.ContentResolver;
21
22/**
23 * Describe the contract for an Indexable data.
24 *
25 * @hide
26 */
27@SystemApi
28public class SearchIndexablesContract {
29
30    /**
31     * Intent action used to identify {@link SearchIndexablesProvider}
32     * instances. This is used in the {@code <intent-filter>} of a {@code <provider>}.
33     */
34    public static final String PROVIDER_INTERFACE =
35            "android.content.action.SEARCH_INDEXABLES_PROVIDER";
36
37    private static final String SETTINGS = "settings";
38
39    /**
40     * Indexable reference names.
41     */
42    public static final String INDEXABLES_XML_RES = "indexables_xml_res";
43
44    /**
45     * ContentProvider path for indexable xml resources.
46     */
47    public static final String INDEXABLES_XML_RES_PATH = SETTINGS + "/" + INDEXABLES_XML_RES;
48
49    /**
50     * Indexable raw data names.
51     */
52    public static final String INDEXABLES_RAW = "indexables_raw";
53
54    /**
55     * ContentProvider path for indexable raw data.
56     */
57    public static final String INDEXABLES_RAW_PATH = SETTINGS + "/" + INDEXABLES_RAW;
58
59    /**
60     * Non indexable data keys.
61     */
62    public static final String NON_INDEXABLES_KEYS = "non_indexables_key";
63
64    /**
65     * ContentProvider path for non indexable data keys.
66     */
67    public static final String NON_INDEXABLES_KEYS_PATH = SETTINGS + "/" + NON_INDEXABLES_KEYS;
68
69    /**
70     * Indexable xml resources columns.
71     */
72    public static final String[] INDEXABLES_XML_RES_COLUMNS = new String[] {
73            XmlResource.COLUMN_RANK,                    // 0
74            XmlResource.COLUMN_XML_RESID,               // 1
75            XmlResource.COLUMN_CLASS_NAME,              // 2
76            XmlResource.COLUMN_ICON_RESID,              // 3
77            XmlResource.COLUMN_INTENT_ACTION,           // 4
78            XmlResource.COLUMN_INTENT_TARGET_PACKAGE,   // 5
79            XmlResource.COLUMN_INTENT_TARGET_CLASS      // 6
80    };
81
82    /**
83     * Indexable xml resources columns indices.
84     */
85    public static final int COLUMN_INDEX_XML_RES_RANK = 0;
86    public static final int COLUMN_INDEX_XML_RES_RESID = 1;
87    public static final int COLUMN_INDEX_XML_RES_CLASS_NAME = 2;
88    public static final int COLUMN_INDEX_XML_RES_ICON_RESID = 3;
89    public static final int COLUMN_INDEX_XML_RES_INTENT_ACTION = 4;
90    public static final int COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE = 5;
91    public static final int COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS = 6;
92
93    /**
94     * Indexable raw data columns.
95     */
96    public static final String[] INDEXABLES_RAW_COLUMNS = new String[] {
97            RawData.COLUMN_RANK,                    // 0
98            RawData.COLUMN_TITLE,                   // 1
99            RawData.COLUMN_SUMMARY_ON,              // 2
100            RawData.COLUMN_SUMMARY_OFF,             // 3
101            RawData.COLUMN_ENTRIES,                 // 4
102            RawData.COLUMN_KEYWORDS,                // 5
103            RawData.COLUMN_SCREEN_TITLE,            // 6
104            RawData.COLUMN_CLASS_NAME,              // 7
105            RawData.COLUMN_ICON_RESID,              // 8
106            RawData.COLUMN_INTENT_ACTION,           // 9
107            RawData.COLUMN_INTENT_TARGET_PACKAGE,   // 10
108            RawData.COLUMN_INTENT_TARGET_CLASS,     // 11
109            RawData.COLUMN_KEY,                     // 12
110            RawData.COLUMN_USER_ID,                 // 13
111    };
112
113    /**
114     * Indexable raw data columns indices.
115     */
116    public static final int COLUMN_INDEX_RAW_RANK = 0;
117    public static final int COLUMN_INDEX_RAW_TITLE = 1;
118    public static final int COLUMN_INDEX_RAW_SUMMARY_ON = 2;
119    public static final int COLUMN_INDEX_RAW_SUMMARY_OFF = 3;
120    public static final int COLUMN_INDEX_RAW_ENTRIES = 4;
121    public static final int COLUMN_INDEX_RAW_KEYWORDS = 5;
122    public static final int COLUMN_INDEX_RAW_SCREEN_TITLE = 6;
123    public static final int COLUMN_INDEX_RAW_CLASS_NAME = 7;
124    public static final int COLUMN_INDEX_RAW_ICON_RESID = 8;
125    public static final int COLUMN_INDEX_RAW_INTENT_ACTION = 9;
126    public static final int COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE = 10;
127    public static final int COLUMN_INDEX_RAW_INTENT_TARGET_CLASS = 11;
128    public static final int COLUMN_INDEX_RAW_KEY = 12;
129    public static final int COLUMN_INDEX_RAW_USER_ID = 13;
130
131    /**
132     * Indexable raw data columns.
133     */
134    public static final String[] NON_INDEXABLES_KEYS_COLUMNS = new String[] {
135            NonIndexableKey.COLUMN_KEY_VALUE      // 0
136    };
137
138    /**
139     * Non indexable data keys columns indices.
140     */
141    public static final int COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE = 0;
142
143    /**
144     * Constants related to a {@link SearchIndexableResource}.
145     *
146     * This is a description of
147     */
148    public static final class XmlResource extends BaseColumns {
149        private XmlResource() {
150        }
151
152        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
153                "/" + INDEXABLES_XML_RES;
154
155        /**
156         * XML resource ID for the {@link android.preference.PreferenceScreen} to load and index.
157         */
158        public static final String COLUMN_XML_RESID = "xmlResId";
159    }
160
161    /**
162     * Constants related to a {@link SearchIndexableData}.
163     *
164     * This is the raw data that is stored into an Index. This is related to
165     * {@link android.preference.Preference} and its attributes like
166     * {@link android.preference.Preference#getTitle()},
167     * {@link android.preference.Preference#getSummary()}, etc.
168     *
169     */
170    public static final class RawData extends BaseColumns {
171        private RawData() {
172        }
173
174        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
175                "/" + INDEXABLES_RAW;
176
177        /**
178         * Title's raw data.
179         */
180        public static final String COLUMN_TITLE = "title";
181
182        /**
183         * Summary's raw data when the data is "ON".
184         */
185        public static final String COLUMN_SUMMARY_ON = "summaryOn";
186
187        /**
188         * Summary's raw data when the data is "OFF".
189         */
190        public static final String COLUMN_SUMMARY_OFF = "summaryOff";
191
192        /**
193         * Entries associated with the raw data (when the data can have several values).
194         */
195        public static final String COLUMN_ENTRIES = "entries";
196
197        /**
198         * Keywords' raw data.
199         */
200        public static final String COLUMN_KEYWORDS = "keywords";
201
202        /**
203         * Fragment or Activity title associated with the raw data.
204         */
205        public static final String COLUMN_SCREEN_TITLE = "screenTitle";
206
207        /**
208         * Key associated with the raw data. The key needs to be unique.
209         */
210        public static final String COLUMN_KEY = "key";
211
212        /**
213         * UserId associated with the raw data.
214         */
215        public static final String COLUMN_USER_ID = "user_id";
216    }
217
218    /**
219     * Constants related to a {@link SearchIndexableResource} and {@link SearchIndexableData}.
220     *
221     * This is a description of a data (thru its unique key) that cannot be indexed.
222     */
223    public static final class NonIndexableKey extends BaseColumns {
224        private NonIndexableKey() {
225        }
226
227        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
228                "/" + NON_INDEXABLES_KEYS;
229
230        /**
231         * Key for the non indexable data.
232         */
233        public static final String COLUMN_KEY_VALUE = "key";
234    }
235
236    /**
237     * The base columns.
238     */
239    private static class BaseColumns {
240        private BaseColumns() {
241        }
242
243        /**
244         * Rank of the data. This is an integer used for ranking the search results. This is
245         * application specific.
246         */
247        public static final String COLUMN_RANK = "rank";
248
249        /**
250         * Class name associated with the data (usually a Fragment class name).
251         */
252        public static final String COLUMN_CLASS_NAME = "className";
253
254        /**
255         * Icon resource ID for the data.
256         */
257        public static final String COLUMN_ICON_RESID = "iconResId";
258
259        /**
260         * Intent action associated with the data.
261         */
262        public static final String COLUMN_INTENT_ACTION = "intentAction";
263
264        /**
265         * Intent target package associated with the data.
266         */
267        public static final String COLUMN_INTENT_TARGET_PACKAGE = "intentTargetPackage";
268
269        /**
270         * Intent target class associated with the data.
271         */
272        public static final String COLUMN_INTENT_TARGET_CLASS = "intentTargetClass";
273    }
274}
275