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; |
Fan Zhang | 414447e | 2017-11-29 17:31:35 -0800 | [diff] [blame] | 34 | import android.os.Binder; |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 35 | import android.os.UserManager; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 36 | import android.provider.SearchIndexableResource; |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 37 | import android.provider.SearchIndexablesContract.RawData; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 38 | import android.provider.SearchIndexablesProvider; |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 39 | import android.telephony.euicc.EuiccManager; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 40 | |
Aravind Sreekumar | afc08c5 | 2018-04-10 15:34:32 -0700 | [diff] [blame] | 41 | import androidx.annotation.VisibleForTesting; |
| 42 | |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 43 | public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider { |
| 44 | private static final String TAG = "PhoneSearchIndexablesProvider"; |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 45 | private UserManager mUserManager; |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 46 | |
| 47 | private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] { |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 48 | new SearchIndexableResource(1, R.xml.network_setting_fragment, |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 49 | MobileNetworkSettings.class.getName(), |
| 50 | R.mipmap.ic_launcher_phone), |
| 51 | }; |
| 52 | |
| 53 | @Override |
| 54 | public boolean onCreate() { |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 55 | mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE); |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 56 | return true; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public Cursor queryXmlResources(String[] projection) { |
| 61 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); |
| 62 | final int count = INDEXABLE_RES.length; |
| 63 | for (int n = 0; n < count; n++) { |
| 64 | Object[] ref = new Object[7]; |
Fabrice Di Meglio | 2a52761 | 2014-04-09 19:35:24 -0700 | [diff] [blame] | 65 | ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank; |
| 66 | ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId; |
| 67 | ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null; |
| 68 | ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId; |
| 69 | ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN"; |
| 70 | ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone"; |
| 71 | 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] | 72 | cursor.addRow(ref); |
| 73 | } |
| 74 | return cursor; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public Cursor queryRawData(String[] projection) { |
| 79 | MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 80 | Context context = getContext(); |
| 81 | String title = context.getString(R.string.carrier_settings_euicc); |
| 82 | cursor.newRow() |
| 83 | .add(RawData.COLUMN_RANK, 0) |
| 84 | .add(RawData.COLUMN_TITLE, title) |
| 85 | .add( |
| 86 | RawData.COLUMN_KEYWORDS, |
| 87 | context.getString(R.string.keywords_carrier_settings_euicc)) |
| 88 | .add(RawData.COLUMN_SCREEN_TITLE, title) |
| 89 | .add(RawData.COLUMN_KEY, "esim_list_profile") |
| 90 | .add( |
| 91 | RawData.COLUMN_INTENT_ACTION, |
| 92 | EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS) |
| 93 | .add( |
| 94 | RawData.COLUMN_INTENT_TARGET_PACKAGE, |
| 95 | context.getPackageName()); |
Fabrice Di Meglio | e5ee4a3 | 2014-03-14 19:04:10 -0700 | [diff] [blame] | 96 | return cursor; |
| 97 | } |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 98 | |
Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 99 | @Override |
| 100 | public Cursor queryNonIndexableKeys(String[] projection) { |
Fan Zhang | 414447e | 2017-11-29 17:31:35 -0800 | [diff] [blame] | 101 | final long uidToken = Binder.clearCallingIdentity(); |
| 102 | try { |
| 103 | MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); |
qingxi | 2f7afb3 | 2017-06-28 17:13:21 -0700 | [diff] [blame] | 104 | |
Fan Zhang | 414447e | 2017-11-29 17:31:35 -0800 | [diff] [blame] | 105 | if (!mUserManager.isAdminUser()) { |
| 106 | final String[] values = new String[]{"preferred_network_mode_key", |
Malcolm Chen | 9ee7546 | 2018-03-12 13:29:03 -0700 | [diff] [blame] | 107 | "button_roaming_key", "cdma_lte_data_service_key", "enhanced_4g_lte", |
Fan Zhang | 414447e | 2017-11-29 17:31:35 -0800 | [diff] [blame] | 108 | "button_apn_key", "button_carrier_sel_key", "carrier_settings_key", |
| 109 | "cdma_system_select_key", "esim_list_profile", "mobile_data_enable", |
| 110 | "data_usage_summary", "wifi_calling_key", "video_calling_key"}; |
| 111 | for (String nik : values) { |
| 112 | cursor.addRow(createNonIndexableRow(nik)); |
| 113 | } |
| 114 | } else { |
| 115 | if (isEuiccSettingsHidden()) { |
| 116 | cursor.addRow(createNonIndexableRow("esim_list_profile" /* key */)); |
| 117 | } |
| 118 | if (isEnhanced4gLteHidden()) { |
| 119 | cursor.addRow(createNonIndexableRow("enhanced_4g_lte" /* key */)); |
| 120 | } |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 121 | } |
Malcolm Chen | 9ee7546 | 2018-03-12 13:29:03 -0700 | [diff] [blame] | 122 | |
| 123 | // enabled_networks button and preferred_network_mode button share the same title |
| 124 | // "Preferred network type"and are mutual exclusive. Thus we remove one from search |
| 125 | // result to avoid duplicate search result. |
| 126 | // TODO: b/63381516 all hidden buttons should dynamically be removed from search result. |
| 127 | cursor.addRow(createNonIndexableRow("enabled_networks_key" /* key */)); |
Fan Zhang | 414447e | 2017-11-29 17:31:35 -0800 | [diff] [blame] | 128 | cursor.addRow(createNonIndexableRow("carrier_settings_euicc_key" /* key */)); |
| 129 | cursor.addRow(createNonIndexableRow("advanced_options" /* key */)); |
| 130 | return cursor; |
| 131 | } finally { |
| 132 | Binder.restoreCallingIdentity(uidToken); |
Sanket Padawe | 4cf8211 | 2017-04-14 17:02:07 -0700 | [diff] [blame] | 133 | } |
Fabrice Di Meglio | 7b18c72 | 2014-04-11 18:52:00 -0700 | [diff] [blame] | 134 | } |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 135 | |
| 136 | @VisibleForTesting boolean isEuiccSettingsHidden() { |
| 137 | return !MobileNetworkSettings.showEuiccSettings(getContext()); |
| 138 | } |
| 139 | |
qingxi | 2f7afb3 | 2017-06-28 17:13:21 -0700 | [diff] [blame] | 140 | @VisibleForTesting boolean isEnhanced4gLteHidden() { |
Malcolm Chen | fbf4771 | 2017-12-12 18:19:27 -0800 | [diff] [blame] | 141 | return MobileNetworkSettings.hideEnhanced4gLteSettings(getContext()); |
qingxi | 2f7afb3 | 2017-06-28 17:13:21 -0700 | [diff] [blame] | 142 | } |
| 143 | |
qingxi | 272b117 | 2017-06-23 14:00:34 -0700 | [diff] [blame] | 144 | private Object[] createNonIndexableRow(String key) { |
| 145 | final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length]; |
| 146 | ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = key; |
| 147 | return ref; |
| 148 | } |
Santos Cordon | 7debf01 | 2014-07-18 14:29:07 -0700 | [diff] [blame] | 149 | } |