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 
17 package com.android.phone;
18 
19 import android.database.Cursor;
20 import android.database.MatrixCursor;
21 import android.provider.SearchIndexableResource;
22 import android.provider.SearchIndexablesProvider;
23 
24 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK;
25 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID;
26 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME;
27 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID;
28 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION;
29 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE;
30 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS;
31 
32 import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
33 import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS;
34 import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS;
35 
36 public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider {
37     private static final String TAG = "PhoneSearchIndexablesProvider";
38 
39     private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] {
40             new SearchIndexableResource(1, R.xml.network_setting,
41                     MobileNetworkSettings.class.getName(),
42                     R.mipmap.ic_launcher_phone),
43     };
44 
45     @Override
onCreate()46     public boolean onCreate() {
47         return true;
48     }
49 
50     @Override
queryXmlResources(String[] projection)51     public Cursor queryXmlResources(String[] projection) {
52         MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS);
53         final int count = INDEXABLE_RES.length;
54         for (int n = 0; n < count; n++) {
55             Object[] ref = new Object[7];
56             ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank;
57             ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId;
58             ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null;
59             ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId;
60             ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN";
61             ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone";
62             ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = INDEXABLE_RES[n].className;
63             cursor.addRow(ref);
64         }
65         return cursor;
66     }
67 
68     @Override
queryRawData(String[] projection)69     public Cursor queryRawData(String[] projection) {
70         MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
71         return cursor;
72     }
73     @Override
queryNonIndexableKeys(String[] projection)74     public Cursor queryNonIndexableKeys(String[] projection) {
75         MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
76         return cursor;
77     }
78 }
79