blob: 209d100a37f0b7be817a0bcb1891bb776b5b70c6 [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
qingxi272b1172017-06-23 14:00:34 -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;
qingxi272b1172017-06-23 14:00:34 -070036import android.provider.SearchIndexablesContract.RawData;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070037import android.provider.SearchIndexablesProvider;
qingxi272b1172017-06-23 14:00:34 -070038import android.support.annotation.VisibleForTesting;
39import android.telephony.euicc.EuiccManager;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070040
41public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider {
42 private static final String TAG = "PhoneSearchIndexablesProvider";
qingxi272b1172017-06-23 14:00:34 -070043 private UserManager mUserManager;
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070044
45 private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] {
pkanward702e542017-02-08 15:44:54 -080046 new SearchIndexableResource(1, R.xml.network_setting_fragment,
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070047 MobileNetworkSettings.class.getName(),
48 R.mipmap.ic_launcher_phone),
49 };
50
51 @Override
52 public boolean onCreate() {
qingxi272b1172017-06-23 14:00:34 -070053 mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
Fabrice Di Meglioe5ee4a32014-03-14 19:04:10 -070054 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 Meglio2a527612014-04-09 19:35:24 -070063 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 Meglioe5ee4a32014-03-14 19:04:10 -070070 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);
qingxi272b1172017-06-23 14:00:34 -070078 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 Meglioe5ee4a32014-03-14 19:04:10 -070094 return cursor;
95 }
Sanket Padawe4cf82112017-04-14 17:02:07 -070096
Fabrice Di Meglio7b18c722014-04-11 18:52:00 -070097 @Override
98 public Cursor queryNonIndexableKeys(String[] projection) {
99 MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
qingxi272b1172017-06-23 14:00:34 -0700100 if (!mUserManager.isAdminUser()) {
Sanket Padawe4cf82112017-04-14 17:02:07 -0700101 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",
qingxi272b1172017-06-23 14:00:34 -0700104 "cdma_system_select_key", "esim_list_profile"};
Sanket Padawe4cf82112017-04-14 17:02:07 -0700105 for (String nik : values) {
qingxi272b1172017-06-23 14:00:34 -0700106 cursor.addRow(createNonIndexableRow(nik));
Sanket Padawe4cf82112017-04-14 17:02:07 -0700107 }
qingxi272b1172017-06-23 14:00:34 -0700108 } else if (isEuiccSettingsHidden()) {
109 cursor.addRow(createNonIndexableRow("esim_list_profile" /* key */));
Sanket Padawe4cf82112017-04-14 17:02:07 -0700110 }
qingxi272b1172017-06-23 14:00:34 -0700111 cursor.addRow(createNonIndexableRow("carrier_settings_euicc_key" /* key */));
Fabrice Di Meglio7b18c722014-04-11 18:52:00 -0700112 return cursor;
113 }
qingxi272b1172017-06-23 14:00:34 -0700114
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 Cordon7debf012014-07-18 14:29:07 -0700124}