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