blob: fe9d214480b749cbbbfce93307817d831dd49b3a [file] [log] [blame]
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -07001/*
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 com.android.phone;
18
Malcolm Chen34d4fa52017-06-05 19:02:16 -070019import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
20import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME;
21import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID;
22import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION;
23import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS;
24import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE;
25import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK;
26import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID;
27import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
28import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS;
29import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS;
30
Sanket Padawe4cf82112017-04-14 17:02:07 -070031import android.content.Context;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070032import android.database.Cursor;
33import android.database.MatrixCursor;
Sanket Padawe4cf82112017-04-14 17:02:07 -070034import android.os.UserManager;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070035import android.provider.SearchIndexableResource;
36import android.provider.SearchIndexablesProvider;
37
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070038public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider {
39 private static final String TAG = "PhoneSearchIndexablesProvider";
40
41 private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] {
pkanward702e542017-02-08 15:44:54 -080042 new SearchIndexableResource(1, R.xml.network_setting_fragment,
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070043 MobileNetworkSettings.class.getName(),
44 R.mipmap.ic_launcher_phone),
45 };
46
47 @Override
48 public boolean onCreate() {
49 return true;
50 }
51
52 @Override
53 public Cursor queryXmlResources(String[] projection) {
54 MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS);
55 final int count = INDEXABLE_RES.length;
56 for (int n = 0; n < count; n++) {
57 Object[] ref = new Object[7];
Fabrice Di Meglio2a527612014-04-09 19:35:24 -070058 ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank;
59 ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId;
60 ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null;
61 ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId;
62 ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN";
63 ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone";
64 ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = INDEXABLE_RES[n].className;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070065 cursor.addRow(ref);
66 }
67 return cursor;
68 }
69
70 @Override
71 public Cursor queryRawData(String[] projection) {
72 MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
73 return cursor;
74 }
Sanket Padawe4cf82112017-04-14 17:02:07 -070075
Fabrice Di Meglio7b18c722014-04-11 18:52:00 -070076 @Override
77 public Cursor queryNonIndexableKeys(String[] projection) {
78 MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
Sanket Padawe4cf82112017-04-14 17:02:07 -070079 final UserManager userManager = (UserManager) getContext().getSystemService(
80 Context.USER_SERVICE);
81 if (!userManager.isAdminUser()) {
82 final String[] values = new String[]{"preferred_network_mode_key", "button_roaming_key",
83 "cdma_lte_data_service_key", "enabled_networks_key", "enhanced_4g_lte",
Malcolm Chen34d4fa52017-06-05 19:02:16 -070084 "button_apn_key", "button_network_select_key", "carrier_settings_key",
Sanket Padawe4cf82112017-04-14 17:02:07 -070085 "cdma_system_select_key", "carrier_settings_euicc_key"};
86 for (String nik : values) {
87 final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length];
88 ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = nik;
89 cursor.addRow(ref);
90 }
91 }
Fabrice Di Meglio7b18c722014-04-11 18:52:00 -070092 return cursor;
93 }
Santos Cordon7debf012014-07-18 14:29:07 -070094}