Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 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 | |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 20 | import android.database.Cursor; |
| 21 | import android.database.MatrixCursor; |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 22 | import android.os.UserManager; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 23 | import android.provider.SearchIndexableResource; |
| 24 | import android.provider.SearchIndexablesProvider; |
| 25 | |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 26 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE; |
Fabrice Di Meglio | 2a52761 | 2014-04-09 19:35:24 -0700 | [diff] [blame] | 27 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK; |
| 28 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID; |
| 29 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME; |
| 30 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID; |
| 31 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION; |
| 32 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE; |
| 33 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS; |
| 34 | |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 35 | import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; |
| 36 | import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; |
Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 37 | import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 38 | |
| 39 | public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider { |
| 40 | private static final String TAG = "PhoneSearchIndexablesProvider"; |
| 41 | |
| 42 | private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] { |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 43 | new SearchIndexableResource(1, R.xml.network_setting_fragment, |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 44 | MobileNetworkSettings.class.getName(), |
| 45 | R.mipmap.ic_launcher_phone), |
| 46 | }; |
| 47 | |
| 48 | @Override |
| 49 | public boolean onCreate() { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Cursor queryXmlResources(String[] projection) { |
| 55 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); |
| 56 | final int count = INDEXABLE_RES.length; |
| 57 | for (int n = 0; n < count; n++) { |
| 58 | Object[] ref = new Object[7]; |
Fabrice Di Meglio | 2a52761 | 2014-04-09 19:35:24 -0700 | [diff] [blame] | 59 | ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank; |
| 60 | ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId; |
| 61 | ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null; |
| 62 | ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId; |
| 63 | ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN"; |
| 64 | ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone"; |
| 65 | ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = INDEXABLE_RES[n].className; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 66 | cursor.addRow(ref); |
| 67 | } |
| 68 | return cursor; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Cursor queryRawData(String[] projection) { |
| 73 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); |
| 74 | return cursor; |
| 75 | } |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 76 | |
Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 77 | @Override |
| 78 | public Cursor queryNonIndexableKeys(String[] projection) { |
| 79 | MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 80 | final UserManager userManager = (UserManager) getContext().getSystemService( |
| 81 | Context.USER_SERVICE); |
| 82 | if (!userManager.isAdminUser()) { |
| 83 | final String[] values = new String[]{"preferred_network_mode_key", "button_roaming_key", |
| 84 | "cdma_lte_data_service_key", "enabled_networks_key", "enhanced_4g_lte", |
| 85 | "button_apn_key", "button_carrier_sel_key", "carrier_settings_key", |
| 86 | "cdma_system_select_key", "carrier_settings_euicc_key"}; |
| 87 | for (String nik : values) { |
| 88 | final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length]; |
| 89 | ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = nik; |
| 90 | cursor.addRow(ref); |
| 91 | } |
| 92 | } |
Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 93 | return cursor; |
| 94 | } |
Santos Cordon | 7debf01 | 2014-07-18 14:29:07 -0700 | [diff] [blame] | 95 | } |