Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.dialer; |
| 18 | |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 20 | import android.app.AlertDialog; |
Jay Shrauner | 384eaad | 2015-04-03 16:03:41 -0700 | [diff] [blame] | 21 | import android.app.DialogFragment; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 22 | import android.app.KeyguardManager; |
| 23 | import android.app.ProgressDialog; |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.DialogInterface; |
| 28 | import android.content.Intent; |
| 29 | import android.database.Cursor; |
| 30 | import android.net.Uri; |
| 31 | import android.os.Looper; |
Jeff Sharkey | f4f4766 | 2014-04-16 17:21:12 -0700 | [diff] [blame] | 32 | import android.provider.Settings; |
Yorke Lee | 3af7e56 | 2015-04-15 11:05:54 -0700 | [diff] [blame] | 33 | import android.telecom.PhoneAccount; |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 34 | import android.telecom.PhoneAccountHandle; |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 35 | import android.telecom.TelecomManager; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 36 | import android.telephony.PhoneNumberUtils; |
| 37 | import android.telephony.TelephonyManager; |
Nancy Chen | 0f4ec2a | 2015-03-23 15:03:03 -0700 | [diff] [blame] | 38 | import android.text.TextUtils; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 39 | import android.util.Log; |
| 40 | import android.view.WindowManager; |
| 41 | import android.widget.EditText; |
| 42 | import android.widget.Toast; |
| 43 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 44 | import com.android.common.io.MoreCloseables; |
Chiao Cheng | 07af764 | 2012-09-14 12:05:14 -0700 | [diff] [blame] | 45 | import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 46 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; |
| 47 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; |
| 48 | import com.android.dialer.calllog.PhoneAccountUtils; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 49 | |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 50 | import java.util.Arrays; |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 51 | import java.util.ArrayList; |
| 52 | import java.util.List; |
| 53 | |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Helper class to listen for some magic character sequences |
| 56 | * that are handled specially by the dialer. |
| 57 | * |
| 58 | * Note the Phone app also handles these sequences too (in a couple of |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 59 | * relatively obscure places in the UI), so there's a separate version of |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 60 | * this class under apps/Phone. |
| 61 | * |
| 62 | * TODO: there's lots of duplicated code between this class and the |
| 63 | * corresponding class under apps/Phone. Let's figure out a way to |
| 64 | * unify these two classes (in the framework? in a common shared library?) |
| 65 | */ |
| 66 | public class SpecialCharSequenceMgr { |
| 67 | private static final String TAG = "SpecialCharSequenceMgr"; |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 68 | |
Jay Shrauner | 384eaad | 2015-04-03 16:03:41 -0700 | [diff] [blame] | 69 | private static final String TAG_SELECT_ACCT_FRAGMENT = "tag_select_acct_fragment"; |
| 70 | |
Yorke Lee | f90dada | 2013-12-09 11:50:28 -0800 | [diff] [blame] | 71 | private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE"; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 72 | private static final String MMI_IMEI_DISPLAY = "*#06#"; |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 73 | private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#"; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Remembers the previous {@link QueryHandler} and cancel the operation when needed, to |
| 77 | * prevent possible crash. |
| 78 | * |
| 79 | * QueryHandler may call {@link ProgressDialog#dismiss()} when the screen is already gone, |
| 80 | * which will cause the app crash. This variable enables the class to prevent the crash |
| 81 | * on {@link #cleanup()}. |
| 82 | * |
| 83 | * TODO: Remove this and replace it (and {@link #cleanup()}) with better implementation. |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 84 | * One complication is that we have SpecialCharSequenceMgr in Phone package too, which has |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 85 | * *slightly* different implementation. Note that Phone package doesn't have this problem, |
| 86 | * so the class on Phone side doesn't have this functionality. |
| 87 | * Fundamental fix would be to have one shared implementation and resolve this corner case more |
| 88 | * gracefully. |
| 89 | */ |
| 90 | private static QueryHandler sPreviousAdnQueryHandler; |
| 91 | |
| 92 | /** This class is never instantiated. */ |
| 93 | private SpecialCharSequenceMgr() { |
| 94 | } |
| 95 | |
| 96 | public static boolean handleChars(Context context, String input, EditText textField) { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 97 | //get rid of the separators so that the string gets parsed correctly |
| 98 | String dialString = PhoneNumberUtils.stripSeparators(input); |
| 99 | |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 100 | if (handleDeviceIdDisplay(context, dialString) |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 101 | || handleRegulatoryInfoDisplay(context, dialString) |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 102 | || handlePinEntry(context, dialString) |
| 103 | || handleAdnEntry(context, dialString, textField) |
| 104 | || handleSecretCode(context, dialString)) { |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Cleanup everything around this class. Must be run inside the main thread. |
| 113 | * |
| 114 | * This should be called when the screen becomes background. |
| 115 | */ |
| 116 | public static void cleanup() { |
| 117 | if (Looper.myLooper() != Looper.getMainLooper()) { |
| 118 | Log.wtf(TAG, "cleanup() is called outside the main thread"); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if (sPreviousAdnQueryHandler != null) { |
| 123 | sPreviousAdnQueryHandler.cancel(); |
| 124 | sPreviousAdnQueryHandler = null; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*. |
| 130 | * If a secret code is encountered an Intent is started with the android_secret_code://<code> |
| 131 | * URI. |
| 132 | * |
| 133 | * @param context the context to use |
| 134 | * @param input the text to check for a secret code in |
| 135 | * @return true if a secret code was encountered |
| 136 | */ |
| 137 | static boolean handleSecretCode(Context context, String input) { |
| 138 | // Secret codes are in the form *#*#<code>#*#* |
| 139 | int len = input.length(); |
| 140 | if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) { |
Yorke Lee | f90dada | 2013-12-09 11:50:28 -0800 | [diff] [blame] | 141 | final Intent intent = new Intent(SECRET_CODE_ACTION, |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 142 | Uri.parse("android_secret_code://" + input.substring(4, len - 4))); |
| 143 | context.sendBroadcast(intent); |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Handle ADN requests by filling in the SIM contact number into the requested |
| 152 | * EditText. |
| 153 | * |
| 154 | * This code works alongside the Asynchronous query handler {@link QueryHandler} |
| 155 | * and query cancel handler implemented in {@link SimContactQueryCookie}. |
| 156 | */ |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 157 | static boolean handleAdnEntry(final Context context, String input, EditText textField) { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 158 | /* ADN entries are of the form "N(N)(N)#" */ |
| 159 | |
| 160 | TelephonyManager telephonyManager = |
| 161 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
| 162 | if (telephonyManager == null |
Yorke Lee | 62280c7 | 2013-11-22 18:24:59 -0800 | [diff] [blame] | 163 | || telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| 167 | // if the phone is keyguard-restricted, then just ignore this |
| 168 | // input. We want to make sure that sim card contacts are NOT |
| 169 | // exposed unless the phone is unlocked, and this code can be |
| 170 | // accessed from the emergency dialer. |
| 171 | KeyguardManager keyguardManager = |
| 172 | (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); |
| 173 | if (keyguardManager.inKeyguardRestrictedInputMode()) { |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | int len = input.length(); |
| 178 | if ((len > 1) && (len < 5) && (input.endsWith("#"))) { |
| 179 | try { |
| 180 | // get the ordinal number of the sim contact |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 181 | final int index = Integer.parseInt(input.substring(0, len-1)); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 182 | |
| 183 | // The original code that navigated to a SIM Contacts list view did not |
| 184 | // highlight the requested contact correctly, a requirement for PTCRB |
| 185 | // certification. This behaviour is consistent with the UI paradigm |
| 186 | // for touch-enabled lists, so it does not make sense to try to work |
| 187 | // around it. Instead we fill in the the requested phone number into |
| 188 | // the dialer text field. |
| 189 | |
| 190 | // create the async query handler |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 191 | final QueryHandler handler = new QueryHandler (context.getContentResolver()); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 192 | |
| 193 | // create the cookie object |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 194 | final SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler, |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 195 | ADN_QUERY_TOKEN); |
| 196 | |
| 197 | // setup the cookie fields |
| 198 | sc.contactNum = index - 1; |
| 199 | sc.setTextField(textField); |
| 200 | |
| 201 | // create the progress dialog |
| 202 | sc.progressDialog = new ProgressDialog(context); |
| 203 | sc.progressDialog.setTitle(R.string.simContacts_title); |
| 204 | sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading)); |
| 205 | sc.progressDialog.setIndeterminate(true); |
| 206 | sc.progressDialog.setCancelable(true); |
| 207 | sc.progressDialog.setOnCancelListener(sc); |
| 208 | sc.progressDialog.getWindow().addFlags( |
| 209 | WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 210 | |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 211 | final TelecomManager telecomManager = |
| 212 | (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 213 | List<PhoneAccountHandle> subscriptionAccountHandles = |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 214 | PhoneAccountUtils.getSubscriptionPhoneAccounts(context); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 215 | |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 216 | boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( |
Yorke Lee | 3af7e56 | 2015-04-15 11:05:54 -0700 | [diff] [blame] | 217 | telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 218 | |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 219 | if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) { |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 220 | Uri uri = telecomManager.getAdnUriForPhoneAccount(null); |
| 221 | handleAdnQuery(handler, sc, uri); |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 222 | } else if (subscriptionAccountHandles.size() > 1){ |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 223 | SelectPhoneAccountListener listener = new SelectPhoneAccountListener() { |
| 224 | @Override |
| 225 | public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, |
| 226 | boolean setDefault) { |
| 227 | Uri uri = |
| 228 | telecomManager.getAdnUriForPhoneAccount(selectedAccountHandle); |
| 229 | handleAdnQuery(handler, sc, uri); |
| 230 | //TODO: show error dialog if result isn't valid |
| 231 | } |
| 232 | @Override |
| 233 | public void onDialogDismissed() {} |
| 234 | }; |
| 235 | |
Jay Shrauner | 384eaad | 2015-04-03 16:03:41 -0700 | [diff] [blame] | 236 | // NOTE: If you want to support rotation of this dialog need |
| 237 | // to refactor the listener and set it in DialpadFragment.onCreate() |
| 238 | DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance( |
| 239 | subscriptionAccountHandles, listener); |
| 240 | dialogFragment.show(((Activity) context).getFragmentManager(), |
| 241 | TAG_SELECT_ACCT_FRAGMENT); |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 242 | } else { |
| 243 | return false; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 244 | } |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 245 | |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 246 | return true; |
| 247 | } catch (NumberFormatException ex) { |
| 248 | // Ignore |
| 249 | } |
| 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 254 | private static void handleAdnQuery(QueryHandler handler, SimContactQueryCookie cookie, |
| 255 | Uri uri) { |
| 256 | if (handler == null || cookie == null || uri == null) { |
| 257 | Log.w(TAG, "queryAdn parameters incorrect"); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | // display the progress dialog |
| 262 | cookie.progressDialog.show(); |
| 263 | |
| 264 | // run the query. |
| 265 | handler.startQuery(ADN_QUERY_TOKEN, cookie, uri, new String[]{ADN_PHONE_NUMBER_COLUMN_NAME}, |
| 266 | null, null, null); |
| 267 | |
| 268 | if (sPreviousAdnQueryHandler != null) { |
| 269 | // It is harmless to call cancel() even after the handler's gone. |
| 270 | sPreviousAdnQueryHandler.cancel(); |
| 271 | } |
| 272 | sPreviousAdnQueryHandler = handler; |
| 273 | } |
| 274 | |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 275 | static boolean handlePinEntry(Context context, final String input) { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 276 | if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) { |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 277 | final TelecomManager telecomManager = |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 278 | (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 279 | List<PhoneAccountHandle> subscriptionAccountHandles = |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 280 | PhoneAccountUtils.getSubscriptionPhoneAccounts(context); |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 281 | boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( |
Yorke Lee | 3af7e56 | 2015-04-15 11:05:54 -0700 | [diff] [blame] | 282 | telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)); |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 283 | |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 284 | if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) { |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 285 | // Don't bring up the dialog for single-SIM or if the default outgoing account is |
| 286 | // a subscription account. |
| 287 | return telecomManager.handleMmi(input); |
Nancy Chen | 39c18f2 | 2014-12-03 16:37:45 -0800 | [diff] [blame] | 288 | } else if (subscriptionAccountHandles.size() > 1){ |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 289 | SelectPhoneAccountListener listener = new SelectPhoneAccountListener() { |
| 290 | @Override |
| 291 | public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, |
| 292 | boolean setDefault) { |
Yorke Lee | 4015d9e | 2015-04-14 14:30:19 -0700 | [diff] [blame] | 293 | telecomManager.handleMmi(input, selectedAccountHandle); |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 294 | //TODO: show error dialog if result isn't valid |
| 295 | } |
| 296 | @Override |
| 297 | public void onDialogDismissed() {} |
| 298 | }; |
| 299 | |
Jay Shrauner | 384eaad | 2015-04-03 16:03:41 -0700 | [diff] [blame] | 300 | // NOTE: If you want to support rotation of this dialog need |
| 301 | // to refactor the listener and set it in DialpadFragment.onCreate() |
| 302 | DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance( |
| 303 | subscriptionAccountHandles, listener); |
| 304 | dialogFragment.show(((Activity) context).getFragmentManager(), |
| 305 | TAG_SELECT_ACCT_FRAGMENT); |
Nancy Chen | 675af1f | 2014-10-16 18:33:51 -0700 | [diff] [blame] | 306 | } |
| 307 | return true; |
| 308 | } |
| 309 | return false; |
| 310 | } |
| 311 | |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 312 | // TODO: Use TelephonyCapabilities.getDeviceIdLabel() to get the device id label instead of a |
| 313 | // hard-coded string. |
| 314 | static boolean handleDeviceIdDisplay(Context context, String input) { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 315 | TelephonyManager telephonyManager = |
| 316 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 317 | |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 318 | if (telephonyManager != null && input.equals(MMI_IMEI_DISPLAY)) { |
| 319 | int labelResId = (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) ? |
| 320 | R.string.imei : R.string.meid; |
| 321 | |
| 322 | List<String> deviceIds = new ArrayList<String>(); |
| 323 | for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) { |
Nancy Chen | 0f4ec2a | 2015-03-23 15:03:03 -0700 | [diff] [blame] | 324 | String deviceId = telephonyManager.getDeviceId(slot); |
| 325 | if (!TextUtils.isEmpty(deviceId)) { |
| 326 | deviceIds.add(deviceId); |
| 327 | } |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | AlertDialog alert = new AlertDialog.Builder(context) |
| 331 | .setTitle(labelResId) |
| 332 | .setItems(deviceIds.toArray(new String[deviceIds.size()]), null) |
Nancy Chen | 0f4ec2a | 2015-03-23 15:03:03 -0700 | [diff] [blame] | 333 | .setPositiveButton(android.R.string.ok, null) |
Nancy Chen | 8c258ac | 2014-10-20 19:33:55 -0700 | [diff] [blame] | 334 | .setCancelable(false) |
| 335 | .show(); |
| 336 | return true; |
| 337 | } |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 341 | private static boolean handleRegulatoryInfoDisplay(Context context, String input) { |
| 342 | if (input.equals(MMI_REGULATORY_INFO_DISPLAY)) { |
| 343 | Log.d(TAG, "handleRegulatoryInfoDisplay() sending intent to settings app"); |
Jeff Sharkey | f4f4766 | 2014-04-16 17:21:12 -0700 | [diff] [blame] | 344 | Intent showRegInfoIntent = new Intent(Settings.ACTION_SHOW_REGULATORY_INFO); |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 345 | try { |
| 346 | context.startActivity(showRegInfoIntent); |
| 347 | } catch (ActivityNotFoundException e) { |
| 348 | Log.e(TAG, "startActivity() failed: " + e); |
| 349 | } |
| 350 | return true; |
| 351 | } |
| 352 | return false; |
| 353 | } |
| 354 | |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 355 | /******* |
| 356 | * This code is used to handle SIM Contact queries |
| 357 | *******/ |
| 358 | private static final String ADN_PHONE_NUMBER_COLUMN_NAME = "number"; |
| 359 | private static final String ADN_NAME_COLUMN_NAME = "name"; |
| 360 | private static final int ADN_QUERY_TOKEN = -1; |
| 361 | |
| 362 | /** |
| 363 | * Cookie object that contains everything we need to communicate to the |
| 364 | * handler's onQuery Complete, as well as what we need in order to cancel |
| 365 | * the query (if requested). |
| 366 | * |
| 367 | * Note, access to the textField field is going to be synchronized, because |
| 368 | * the user can request a cancel at any time through the UI. |
| 369 | */ |
| 370 | private static class SimContactQueryCookie implements DialogInterface.OnCancelListener{ |
| 371 | public ProgressDialog progressDialog; |
| 372 | public int contactNum; |
| 373 | |
| 374 | // Used to identify the query request. |
| 375 | private int mToken; |
| 376 | private QueryHandler mHandler; |
| 377 | |
| 378 | // The text field we're going to update |
| 379 | private EditText textField; |
| 380 | |
| 381 | public SimContactQueryCookie(int number, QueryHandler handler, int token) { |
| 382 | contactNum = number; |
| 383 | mHandler = handler; |
| 384 | mToken = token; |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Synchronized getter for the EditText. |
| 389 | */ |
| 390 | public synchronized EditText getTextField() { |
| 391 | return textField; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Synchronized setter for the EditText. |
| 396 | */ |
| 397 | public synchronized void setTextField(EditText text) { |
| 398 | textField = text; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Cancel the ADN query by stopping the operation and signaling |
| 403 | * the cookie that a cancel request is made. |
| 404 | */ |
| 405 | public synchronized void onCancel(DialogInterface dialog) { |
| 406 | // close the progress dialog |
| 407 | if (progressDialog != null) { |
| 408 | progressDialog.dismiss(); |
| 409 | } |
| 410 | |
| 411 | // setting the textfield to null ensures that the UI does NOT get |
| 412 | // updated. |
| 413 | textField = null; |
| 414 | |
| 415 | // Cancel the operation if possible. |
| 416 | mHandler.cancelOperation(mToken); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Asynchronous query handler that services requests to look up ADNs |
| 422 | * |
Jake Hamby | 1d6fb57 | 2013-04-09 15:49:56 -0700 | [diff] [blame] | 423 | * Queries originate from {@link #handleAdnEntry}. |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 424 | */ |
Chiao Cheng | 07af764 | 2012-09-14 12:05:14 -0700 | [diff] [blame] | 425 | private static class QueryHandler extends NoNullCursorAsyncQueryHandler { |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 426 | |
| 427 | private boolean mCanceled; |
| 428 | |
| 429 | public QueryHandler(ContentResolver cr) { |
| 430 | super(cr); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Override basic onQueryComplete to fill in the textfield when |
| 435 | * we're handed the ADN cursor. |
| 436 | */ |
| 437 | @Override |
Chiao Cheng | 07af764 | 2012-09-14 12:05:14 -0700 | [diff] [blame] | 438 | protected void onNotNullableQueryComplete(int token, Object cookie, Cursor c) { |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 439 | try { |
| 440 | sPreviousAdnQueryHandler = null; |
| 441 | if (mCanceled) { |
| 442 | return; |
| 443 | } |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 444 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 445 | SimContactQueryCookie sc = (SimContactQueryCookie) cookie; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 446 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 447 | // close the progress dialog. |
| 448 | sc.progressDialog.dismiss(); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 449 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 450 | // get the EditText to update or see if the request was cancelled. |
| 451 | EditText text = sc.getTextField(); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 452 | |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 453 | // if the TextView is valid, and the cursor is valid and positionable on the |
| 454 | // Nth number, then we update the text field and display a toast indicating the |
| 455 | // caller name. |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 456 | if ((c != null) && (text != null) && (c.moveToPosition(sc.contactNum))) { |
| 457 | String name = c.getString(c.getColumnIndexOrThrow(ADN_NAME_COLUMN_NAME)); |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 458 | String number = |
| 459 | c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME)); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 460 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 461 | // fill the text in. |
| 462 | text.getText().replace(0, 0, number); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 463 | |
Jay Shrauner | ede67ec | 2014-09-11 15:03:36 -0700 | [diff] [blame] | 464 | // display the name as a toast |
| 465 | Context context = sc.progressDialog.getContext(); |
| 466 | name = context.getString(R.string.menu_callNumber, name); |
| 467 | Toast.makeText(context, name, Toast.LENGTH_SHORT) |
| 468 | .show(); |
| 469 | } |
| 470 | } finally { |
| 471 | MoreCloseables.closeQuietly(c); |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
| 475 | public void cancel() { |
| 476 | mCanceled = true; |
Nancy Chen | 18c52ff | 2014-10-30 10:25:00 -0700 | [diff] [blame] | 477 | // Ask AsyncQueryHandler to cancel the whole request. This will fail when the query is |
| 478 | // already started. |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 479 | cancelOperation(ADN_QUERY_TOKEN); |
| 480 | } |
| 481 | } |
| 482 | } |