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            RawData.PAYLOAD_TYPE,                   // 14
112            RawData.PAYLOAD                         // 15
113    };
114
115    /**
116     * Indexable raw data columns indices.
117     */
118    public static final int COLUMN_INDEX_RAW_RANK = 0;
119    public static final int COLUMN_INDEX_RAW_TITLE = 1;
120    public static final int COLUMN_INDEX_RAW_SUMMARY_ON = 2;
121    public static final int COLUMN_INDEX_RAW_SUMMARY_OFF = 3;
122    public static final int COLUMN_INDEX_RAW_ENTRIES = 4;
123    public static final int COLUMN_INDEX_RAW_KEYWORDS = 5;
124    public static final int COLUMN_INDEX_RAW_SCREEN_TITLE = 6;
125    public static final int COLUMN_INDEX_RAW_CLASS_NAME = 7;
126    public static final int COLUMN_INDEX_RAW_ICON_RESID = 8;
127    public static final int COLUMN_INDEX_RAW_INTENT_ACTION = 9;
128    public static final int COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE = 10;
129    public static final int COLUMN_INDEX_RAW_INTENT_TARGET_CLASS = 11;
130    public static final int COLUMN_INDEX_RAW_KEY = 12;
131    public static final int COLUMN_INDEX_RAW_USER_ID = 13;
132    /**
133     * @hide
134     */
135    public static final int COLUMN_INDEX_RAW_PAYLOAD_TYPE = 14;
136    /**
137     * @hide
138     */
139    public static final int COLUMN_INDEX_RAW_PAYLOAD = 15;
140
141    /**
142     * Indexable raw data columns.
143     */
144    public static final String[] NON_INDEXABLES_KEYS_COLUMNS = new String[] {
145            NonIndexableKey.COLUMN_KEY_VALUE      // 0
146    };
147
148    /**
149     * Non indexable data keys columns indices.
150     */
151    public static final int COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE = 0;
152
153    /**
154     * Constants related to a {@link SearchIndexableResource}.
155     *
156     * This is a description of
157     */
158    public static final class XmlResource extends BaseColumns {
159        private XmlResource() {
160        }
161
162        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
163                "/" + INDEXABLES_XML_RES;
164
165        /**
166         * XML resource ID for the {@link android.preference.PreferenceScreen} to load and index.
167         */
168        public static final String COLUMN_XML_RESID = "xmlResId";
169    }
170
171    /**
172     * Constants related to a {@link SearchIndexableData}.
173     *
174     * This is the raw data that is stored into an Index. This is related to
175     * {@link android.preference.Preference} and its attributes like
176     * {@link android.preference.Preference#getTitle()},
177     * {@link android.preference.Preference#getSummary()}, etc.
178     *
179     */
180    public static final class RawData extends BaseColumns {
181        private RawData() {
182        }
183
184        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
185                "/" + INDEXABLES_RAW;
186
187        /**
188         * Title's raw data.
189         */
190        public static final String COLUMN_TITLE = "title";
191
192        /**
193         * Summary's raw data when the data is "ON".
194         */
195        public static final String COLUMN_SUMMARY_ON = "summaryOn";
196
197        /**
198         * Summary's raw data when the data is "OFF".
199         */
200        public static final String COLUMN_SUMMARY_OFF = "summaryOff";
201
202        /**
203         * Entries associated with the raw data (when the data can have several values).
204         */
205        public static final String COLUMN_ENTRIES = "entries";
206
207        /**
208         * Keywords' raw data.
209         */
210        public static final String COLUMN_KEYWORDS = "keywords";
211
212        /**
213         * Fragment or Activity title associated with the raw data.
214         */
215        public static final String COLUMN_SCREEN_TITLE = "screenTitle";
216
217        /**
218         * Key associated with the raw data. The key needs to be unique.
219         */
220        public static final String COLUMN_KEY = "key";
221
222        /**
223         * UserId associated with the raw data.
224         */
225        public static final String COLUMN_USER_ID = "user_id";
226
227        /**
228         * Identifier for the Payload object type.
229         * @hide
230         */
231        public static final String PAYLOAD_TYPE = "payload_type";
232
233        /**
234         * Generic payload for improving Search result expressiveness.
235         * @hide
236         */
237        public static final String PAYLOAD = "payload";
238    }
239
240    /**
241     * Constants related to a {@link SearchIndexableResource} and {@link SearchIndexableData}.
242     *
243     * This is a description of a data (thru its unique key) that cannot be indexed.
244     */
245    public static final class NonIndexableKey extends BaseColumns {
246        private NonIndexableKey() {
247        }
248
249        public static final String MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
250                "/" + NON_INDEXABLES_KEYS;
251
252        /**
253         * Key for the non indexable data.
254         */
255        public static final String COLUMN_KEY_VALUE = "key";
256    }
257
258    /**
259     * The base columns.
260     */
261    public static class BaseColumns {
262        private BaseColumns() {
263        }
264
265        /**
266         * Rank of the data. This is an integer used for ranking the search results. This is
267         * application specific.
268         */
269        public static final String COLUMN_RANK = "rank";
270
271        /**
272         * Class name associated with the data (usually a Fragment class name).
273         */
274        public static final String COLUMN_CLASS_NAME = "className";
275
276        /**
277         * Icon resource ID for the data.
278         */
279        public static final String COLUMN_ICON_RESID = "iconResId";
280
281        /**
282         * Intent action associated with the data.
283         */
284        public static final String COLUMN_INTENT_ACTION = "intentAction";
285
286        /**
287         * Intent target package associated with the data.
288         */
289        public static final String COLUMN_INTENT_TARGET_PACKAGE = "intentTargetPackage";
290
291        /**
292         * Intent target class associated with the data.
293         */
294        public static final String COLUMN_INTENT_TARGET_CLASS = "intentTargetClass";
295    }
296}
297