| 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 |  | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 19 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE; | 
|  | 20 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME; | 
|  | 21 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID; | 
|  | 22 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION; | 
|  | 23 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS; | 
|  | 24 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE; | 
|  | 25 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK; | 
|  | 26 | import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID; | 
|  | 27 | import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; | 
|  | 28 | import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; | 
|  | 29 | import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; | 
|  | 30 |  | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 31 | import android.content.Context; | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 32 | import android.database.Cursor; | 
|  | 33 | import android.database.MatrixCursor; | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 34 | import android.os.UserManager; | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 35 | import android.provider.SearchIndexableResource; | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 36 | import android.provider.SearchIndexablesContract.RawData; | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 37 | import android.provider.SearchIndexablesProvider; | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 38 | import android.support.annotation.VisibleForTesting; | 
|  | 39 | import android.telephony.euicc.EuiccManager; | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 40 |  | 
|  | 41 | public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider { | 
|  | 42 | private static final String TAG = "PhoneSearchIndexablesProvider"; | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 43 | private UserManager mUserManager; | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] { | 
| pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 46 | new SearchIndexableResource(1, R.xml.network_setting_fragment, | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 47 | MobileNetworkSettings.class.getName(), | 
|  | 48 | R.mipmap.ic_launcher_phone), | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | @Override | 
|  | 52 | public boolean onCreate() { | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 53 | mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE); | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 54 | return true; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | @Override | 
|  | 58 | public Cursor queryXmlResources(String[] projection) { | 
|  | 59 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); | 
|  | 60 | final int count = INDEXABLE_RES.length; | 
|  | 61 | for (int n = 0; n < count; n++) { | 
|  | 62 | Object[] ref = new Object[7]; | 
| Fabrice Di Meglio | 2a52761 | 2014-04-09 19:35:24 -0700 | [diff] [blame] | 63 | ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank; | 
|  | 64 | ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId; | 
|  | 65 | ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null; | 
|  | 66 | ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId; | 
|  | 67 | ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN"; | 
|  | 68 | ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone"; | 
|  | 69 | 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] | 70 | cursor.addRow(ref); | 
|  | 71 | } | 
|  | 72 | return cursor; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | @Override | 
|  | 76 | public Cursor queryRawData(String[] projection) { | 
|  | 77 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 78 | Context context = getContext(); | 
|  | 79 | String title = context.getString(R.string.carrier_settings_euicc); | 
|  | 80 | cursor.newRow() | 
|  | 81 | .add(RawData.COLUMN_RANK, 0) | 
|  | 82 | .add(RawData.COLUMN_TITLE, title) | 
|  | 83 | .add( | 
|  | 84 | RawData.COLUMN_KEYWORDS, | 
|  | 85 | context.getString(R.string.keywords_carrier_settings_euicc)) | 
|  | 86 | .add(RawData.COLUMN_SCREEN_TITLE, title) | 
|  | 87 | .add(RawData.COLUMN_KEY, "esim_list_profile") | 
|  | 88 | .add( | 
|  | 89 | RawData.COLUMN_INTENT_ACTION, | 
|  | 90 | EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS) | 
|  | 91 | .add( | 
|  | 92 | RawData.COLUMN_INTENT_TARGET_PACKAGE, | 
|  | 93 | context.getPackageName()); | 
| Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 94 | return cursor; | 
|  | 95 | } | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 96 |  | 
| Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 97 | @Override | 
|  | 98 | public Cursor queryNonIndexableKeys(String[] projection) { | 
|  | 99 | MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 100 | if (!mUserManager.isAdminUser()) { | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 101 | final String[] values = new String[]{"preferred_network_mode_key", "button_roaming_key", | 
|  | 102 | "cdma_lte_data_service_key", "enabled_networks_key", "enhanced_4g_lte", | 
|  | 103 | "button_apn_key", "button_carrier_sel_key", "carrier_settings_key", | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 104 | "cdma_system_select_key", "esim_list_profile"}; | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 105 | for (String nik : values) { | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 106 | cursor.addRow(createNonIndexableRow(nik)); | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 107 | } | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 108 | } else if (isEuiccSettingsHidden()) { | 
|  | 109 | cursor.addRow(createNonIndexableRow("esim_list_profile" /* key */)); | 
| Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 110 | } | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 111 | cursor.addRow(createNonIndexableRow("carrier_settings_euicc_key" /* key */)); | 
| Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 112 | return cursor; | 
|  | 113 | } | 
| qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 114 |  | 
|  | 115 | @VisibleForTesting boolean isEuiccSettingsHidden() { | 
|  | 116 | return !MobileNetworkSettings.showEuiccSettings(getContext()); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | private Object[] createNonIndexableRow(String key) { | 
|  | 120 | final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length]; | 
|  | 121 | ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = key; | 
|  | 122 | return ref; | 
|  | 123 | } | 
| Santos Cordon | 7debf01 | 2014-07-18 14:29:07 -0700 | [diff] [blame] | 124 | } |