blob: 1e686125fd290965defd32dfac8b7bc6b10b45da [file] [log] [blame]
Chiao Cheng91197042012-08-24 14:19:37 -07001/*
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
17package com.android.dialer;
18
Nancy Chen675af1f2014-10-16 18:33:51 -070019import android.app.Activity;
Chiao Cheng91197042012-08-24 14:19:37 -070020import android.app.AlertDialog;
Jay Shrauner384eaad2015-04-03 16:03:41 -070021import android.app.DialogFragment;
Chiao Cheng91197042012-08-24 14:19:37 -070022import android.app.KeyguardManager;
23import android.app.ProgressDialog;
Jake Hamby1d6fb572013-04-09 15:49:56 -070024import android.content.ActivityNotFoundException;
Chiao Cheng91197042012-08-24 14:19:37 -070025import android.content.ContentResolver;
26import android.content.Context;
27import android.content.DialogInterface;
28import android.content.Intent;
29import android.database.Cursor;
30import android.net.Uri;
31import android.os.Looper;
Jeff Sharkeyf4f47662014-04-16 17:21:12 -070032import android.provider.Settings;
Nancy Chen675af1f2014-10-16 18:33:51 -070033import android.telecom.PhoneAccountHandle;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070034import android.telecom.TelecomManager;
Chiao Cheng91197042012-08-24 14:19:37 -070035import android.telephony.PhoneNumberUtils;
36import android.telephony.TelephonyManager;
Nancy Chen0f4ec2a2015-03-23 15:03:03 -070037import android.text.TextUtils;
Chiao Cheng91197042012-08-24 14:19:37 -070038import android.util.Log;
39import android.view.WindowManager;
40import android.widget.EditText;
41import android.widget.Toast;
42
Jay Shraunerede67ec2014-09-11 15:03:36 -070043import com.android.common.io.MoreCloseables;
Chiao Cheng07af7642012-09-14 12:05:14 -070044import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler;
Nancy Chen675af1f2014-10-16 18:33:51 -070045import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
46import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener;
47import com.android.dialer.calllog.PhoneAccountUtils;
Chiao Cheng91197042012-08-24 14:19:37 -070048
Nancy Chen675af1f2014-10-16 18:33:51 -070049import java.util.Arrays;
Nancy Chen8c258ac2014-10-20 19:33:55 -070050import java.util.ArrayList;
51import java.util.List;
52
Chiao Cheng91197042012-08-24 14:19:37 -070053/**
54 * Helper class to listen for some magic character sequences
55 * that are handled specially by the dialer.
56 *
57 * Note the Phone app also handles these sequences too (in a couple of
Jake Hamby1d6fb572013-04-09 15:49:56 -070058 * relatively obscure places in the UI), so there's a separate version of
Chiao Cheng91197042012-08-24 14:19:37 -070059 * this class under apps/Phone.
60 *
61 * TODO: there's lots of duplicated code between this class and the
62 * corresponding class under apps/Phone. Let's figure out a way to
63 * unify these two classes (in the framework? in a common shared library?)
64 */
65public class SpecialCharSequenceMgr {
66 private static final String TAG = "SpecialCharSequenceMgr";
Jake Hamby1d6fb572013-04-09 15:49:56 -070067
Jay Shrauner384eaad2015-04-03 16:03:41 -070068 private static final String TAG_SELECT_ACCT_FRAGMENT = "tag_select_acct_fragment";
69
Yorke Leef90dada2013-12-09 11:50:28 -080070 private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
Chiao Cheng91197042012-08-24 14:19:37 -070071 private static final String MMI_IMEI_DISPLAY = "*#06#";
Jake Hamby1d6fb572013-04-09 15:49:56 -070072 private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#";
Chiao Cheng91197042012-08-24 14:19:37 -070073
74 /**
75 * Remembers the previous {@link QueryHandler} and cancel the operation when needed, to
76 * prevent possible crash.
77 *
78 * QueryHandler may call {@link ProgressDialog#dismiss()} when the screen is already gone,
79 * which will cause the app crash. This variable enables the class to prevent the crash
80 * on {@link #cleanup()}.
81 *
82 * TODO: Remove this and replace it (and {@link #cleanup()}) with better implementation.
Jake Hamby1d6fb572013-04-09 15:49:56 -070083 * One complication is that we have SpecialCharSequenceMgr in Phone package too, which has
Chiao Cheng91197042012-08-24 14:19:37 -070084 * *slightly* different implementation. Note that Phone package doesn't have this problem,
85 * so the class on Phone side doesn't have this functionality.
86 * Fundamental fix would be to have one shared implementation and resolve this corner case more
87 * gracefully.
88 */
89 private static QueryHandler sPreviousAdnQueryHandler;
90
91 /** This class is never instantiated. */
92 private SpecialCharSequenceMgr() {
93 }
94
95 public static boolean handleChars(Context context, String input, EditText textField) {
Chiao Cheng91197042012-08-24 14:19:37 -070096 //get rid of the separators so that the string gets parsed correctly
97 String dialString = PhoneNumberUtils.stripSeparators(input);
98
Nancy Chen8c258ac2014-10-20 19:33:55 -070099 if (handleDeviceIdDisplay(context, dialString)
Jake Hamby1d6fb572013-04-09 15:49:56 -0700100 || handleRegulatoryInfoDisplay(context, dialString)
Chiao Cheng91197042012-08-24 14:19:37 -0700101 || handlePinEntry(context, dialString)
102 || handleAdnEntry(context, dialString, textField)
103 || handleSecretCode(context, dialString)) {
104 return true;
105 }
106
107 return false;
108 }
109
110 /**
111 * Cleanup everything around this class. Must be run inside the main thread.
112 *
113 * This should be called when the screen becomes background.
114 */
115 public static void cleanup() {
116 if (Looper.myLooper() != Looper.getMainLooper()) {
117 Log.wtf(TAG, "cleanup() is called outside the main thread");
118 return;
119 }
120
121 if (sPreviousAdnQueryHandler != null) {
122 sPreviousAdnQueryHandler.cancel();
123 sPreviousAdnQueryHandler = null;
124 }
125 }
126
127 /**
128 * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
129 * If a secret code is encountered an Intent is started with the android_secret_code://<code>
130 * URI.
131 *
132 * @param context the context to use
133 * @param input the text to check for a secret code in
134 * @return true if a secret code was encountered
135 */
136 static boolean handleSecretCode(Context context, String input) {
137 // Secret codes are in the form *#*#<code>#*#*
138 int len = input.length();
139 if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
Yorke Leef90dada2013-12-09 11:50:28 -0800140 final Intent intent = new Intent(SECRET_CODE_ACTION,
Chiao Cheng91197042012-08-24 14:19:37 -0700141 Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
142 context.sendBroadcast(intent);
143 return true;
144 }
145
146 return false;
147 }
148
149 /**
150 * Handle ADN requests by filling in the SIM contact number into the requested
151 * EditText.
152 *
153 * This code works alongside the Asynchronous query handler {@link QueryHandler}
154 * and query cancel handler implemented in {@link SimContactQueryCookie}.
155 */
Nancy Chen18c52ff2014-10-30 10:25:00 -0700156 static boolean handleAdnEntry(final Context context, String input, EditText textField) {
Chiao Cheng91197042012-08-24 14:19:37 -0700157 /* ADN entries are of the form "N(N)(N)#" */
158
159 TelephonyManager telephonyManager =
160 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
161 if (telephonyManager == null
Yorke Lee62280c72013-11-22 18:24:59 -0800162 || telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) {
Chiao Cheng91197042012-08-24 14:19:37 -0700163 return false;
164 }
165
166 // if the phone is keyguard-restricted, then just ignore this
167 // input. We want to make sure that sim card contacts are NOT
168 // exposed unless the phone is unlocked, and this code can be
169 // accessed from the emergency dialer.
170 KeyguardManager keyguardManager =
171 (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
172 if (keyguardManager.inKeyguardRestrictedInputMode()) {
173 return false;
174 }
175
176 int len = input.length();
177 if ((len > 1) && (len < 5) && (input.endsWith("#"))) {
178 try {
179 // get the ordinal number of the sim contact
Nancy Chen18c52ff2014-10-30 10:25:00 -0700180 final int index = Integer.parseInt(input.substring(0, len-1));
Chiao Cheng91197042012-08-24 14:19:37 -0700181
182 // The original code that navigated to a SIM Contacts list view did not
183 // highlight the requested contact correctly, a requirement for PTCRB
184 // certification. This behaviour is consistent with the UI paradigm
185 // for touch-enabled lists, so it does not make sense to try to work
186 // around it. Instead we fill in the the requested phone number into
187 // the dialer text field.
188
189 // create the async query handler
Nancy Chen18c52ff2014-10-30 10:25:00 -0700190 final QueryHandler handler = new QueryHandler (context.getContentResolver());
Chiao Cheng91197042012-08-24 14:19:37 -0700191
192 // create the cookie object
Nancy Chen18c52ff2014-10-30 10:25:00 -0700193 final SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler,
Chiao Cheng91197042012-08-24 14:19:37 -0700194 ADN_QUERY_TOKEN);
195
196 // setup the cookie fields
197 sc.contactNum = index - 1;
198 sc.setTextField(textField);
199
200 // create the progress dialog
201 sc.progressDialog = new ProgressDialog(context);
202 sc.progressDialog.setTitle(R.string.simContacts_title);
203 sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading));
204 sc.progressDialog.setIndeterminate(true);
205 sc.progressDialog.setCancelable(true);
206 sc.progressDialog.setOnCancelListener(sc);
207 sc.progressDialog.getWindow().addFlags(
208 WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
209
Nancy Chen18c52ff2014-10-30 10:25:00 -0700210 final TelecomManager telecomManager =
211 (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Nancy Chen39c18f22014-12-03 16:37:45 -0800212 List<PhoneAccountHandle> subscriptionAccountHandles =
Nancy Chen18c52ff2014-10-30 10:25:00 -0700213 PhoneAccountUtils.getSubscriptionPhoneAccounts(context);
Chiao Cheng91197042012-08-24 14:19:37 -0700214
Nancy Chen39c18f22014-12-03 16:37:45 -0800215 boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
216 telecomManager.getUserSelectedOutgoingPhoneAccount());
Chiao Cheng91197042012-08-24 14:19:37 -0700217
Nancy Chen39c18f22014-12-03 16:37:45 -0800218 if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
Nancy Chen18c52ff2014-10-30 10:25:00 -0700219 Uri uri = telecomManager.getAdnUriForPhoneAccount(null);
220 handleAdnQuery(handler, sc, uri);
Nancy Chen39c18f22014-12-03 16:37:45 -0800221 } else if (subscriptionAccountHandles.size() > 1){
Nancy Chen18c52ff2014-10-30 10:25:00 -0700222 SelectPhoneAccountListener listener = new SelectPhoneAccountListener() {
223 @Override
224 public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle,
225 boolean setDefault) {
226 Uri uri =
227 telecomManager.getAdnUriForPhoneAccount(selectedAccountHandle);
228 handleAdnQuery(handler, sc, uri);
229 //TODO: show error dialog if result isn't valid
230 }
231 @Override
232 public void onDialogDismissed() {}
233 };
234
Jay Shrauner384eaad2015-04-03 16:03:41 -0700235 // NOTE: If you want to support rotation of this dialog need
236 // to refactor the listener and set it in DialpadFragment.onCreate()
237 DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(
238 subscriptionAccountHandles, listener);
239 dialogFragment.show(((Activity) context).getFragmentManager(),
240 TAG_SELECT_ACCT_FRAGMENT);
Nancy Chen18c52ff2014-10-30 10:25:00 -0700241 } else {
242 return false;
Chiao Cheng91197042012-08-24 14:19:37 -0700243 }
Nancy Chen18c52ff2014-10-30 10:25:00 -0700244
Chiao Cheng91197042012-08-24 14:19:37 -0700245 return true;
246 } catch (NumberFormatException ex) {
247 // Ignore
248 }
249 }
250 return false;
251 }
252
Nancy Chen18c52ff2014-10-30 10:25:00 -0700253 private static void handleAdnQuery(QueryHandler handler, SimContactQueryCookie cookie,
254 Uri uri) {
255 if (handler == null || cookie == null || uri == null) {
256 Log.w(TAG, "queryAdn parameters incorrect");
257 return;
258 }
259
260 // display the progress dialog
261 cookie.progressDialog.show();
262
263 // run the query.
264 handler.startQuery(ADN_QUERY_TOKEN, cookie, uri, new String[]{ADN_PHONE_NUMBER_COLUMN_NAME},
265 null, null, null);
266
267 if (sPreviousAdnQueryHandler != null) {
268 // It is harmless to call cancel() even after the handler's gone.
269 sPreviousAdnQueryHandler.cancel();
270 }
271 sPreviousAdnQueryHandler = handler;
272 }
273
Nancy Chen675af1f2014-10-16 18:33:51 -0700274 static boolean handlePinEntry(Context context, final String input) {
Chiao Cheng91197042012-08-24 14:19:37 -0700275 if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) {
Nancy Chen675af1f2014-10-16 18:33:51 -0700276 final TelecomManager telecomManager =
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700277 (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Nancy Chen39c18f22014-12-03 16:37:45 -0800278 List<PhoneAccountHandle> subscriptionAccountHandles =
Nancy Chen675af1f2014-10-16 18:33:51 -0700279 PhoneAccountUtils.getSubscriptionPhoneAccounts(context);
Nancy Chen39c18f22014-12-03 16:37:45 -0800280 boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
281 telecomManager.getUserSelectedOutgoingPhoneAccount());
Nancy Chen675af1f2014-10-16 18:33:51 -0700282
Nancy Chen39c18f22014-12-03 16:37:45 -0800283 if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
Nancy Chen675af1f2014-10-16 18:33:51 -0700284 // Don't bring up the dialog for single-SIM or if the default outgoing account is
285 // a subscription account.
286 return telecomManager.handleMmi(input);
Nancy Chen39c18f22014-12-03 16:37:45 -0800287 } else if (subscriptionAccountHandles.size() > 1){
Nancy Chen675af1f2014-10-16 18:33:51 -0700288 SelectPhoneAccountListener listener = new SelectPhoneAccountListener() {
289 @Override
290 public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle,
291 boolean setDefault) {
292 telecomManager.handleMmi(selectedAccountHandle, input);
293 //TODO: show error dialog if result isn't valid
294 }
295 @Override
296 public void onDialogDismissed() {}
297 };
298
Jay Shrauner384eaad2015-04-03 16:03:41 -0700299 // NOTE: If you want to support rotation of this dialog need
300 // to refactor the listener and set it in DialpadFragment.onCreate()
301 DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(
302 subscriptionAccountHandles, listener);
303 dialogFragment.show(((Activity) context).getFragmentManager(),
304 TAG_SELECT_ACCT_FRAGMENT);
Nancy Chen675af1f2014-10-16 18:33:51 -0700305 }
306 return true;
307 }
308 return false;
309 }
310
Nancy Chen8c258ac2014-10-20 19:33:55 -0700311 // TODO: Use TelephonyCapabilities.getDeviceIdLabel() to get the device id label instead of a
312 // hard-coded string.
313 static boolean handleDeviceIdDisplay(Context context, String input) {
Chiao Cheng91197042012-08-24 14:19:37 -0700314 TelephonyManager telephonyManager =
315 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Chiao Cheng91197042012-08-24 14:19:37 -0700316
Nancy Chen8c258ac2014-10-20 19:33:55 -0700317 if (telephonyManager != null && input.equals(MMI_IMEI_DISPLAY)) {
318 int labelResId = (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) ?
319 R.string.imei : R.string.meid;
320
321 List<String> deviceIds = new ArrayList<String>();
322 for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {
Nancy Chen0f4ec2a2015-03-23 15:03:03 -0700323 String deviceId = telephonyManager.getDeviceId(slot);
324 if (!TextUtils.isEmpty(deviceId)) {
325 deviceIds.add(deviceId);
326 }
Nancy Chen8c258ac2014-10-20 19:33:55 -0700327 }
328
329 AlertDialog alert = new AlertDialog.Builder(context)
330 .setTitle(labelResId)
331 .setItems(deviceIds.toArray(new String[deviceIds.size()]), null)
Nancy Chen0f4ec2a2015-03-23 15:03:03 -0700332 .setPositiveButton(android.R.string.ok, null)
Nancy Chen8c258ac2014-10-20 19:33:55 -0700333 .setCancelable(false)
334 .show();
335 return true;
336 }
Chiao Cheng91197042012-08-24 14:19:37 -0700337 return false;
338 }
339
Jake Hamby1d6fb572013-04-09 15:49:56 -0700340 private static boolean handleRegulatoryInfoDisplay(Context context, String input) {
341 if (input.equals(MMI_REGULATORY_INFO_DISPLAY)) {
342 Log.d(TAG, "handleRegulatoryInfoDisplay() sending intent to settings app");
Jeff Sharkeyf4f47662014-04-16 17:21:12 -0700343 Intent showRegInfoIntent = new Intent(Settings.ACTION_SHOW_REGULATORY_INFO);
Jake Hamby1d6fb572013-04-09 15:49:56 -0700344 try {
345 context.startActivity(showRegInfoIntent);
346 } catch (ActivityNotFoundException e) {
347 Log.e(TAG, "startActivity() failed: " + e);
348 }
349 return true;
350 }
351 return false;
352 }
353
Chiao Cheng91197042012-08-24 14:19:37 -0700354 /*******
355 * This code is used to handle SIM Contact queries
356 *******/
357 private static final String ADN_PHONE_NUMBER_COLUMN_NAME = "number";
358 private static final String ADN_NAME_COLUMN_NAME = "name";
359 private static final int ADN_QUERY_TOKEN = -1;
360
361 /**
362 * Cookie object that contains everything we need to communicate to the
363 * handler's onQuery Complete, as well as what we need in order to cancel
364 * the query (if requested).
365 *
366 * Note, access to the textField field is going to be synchronized, because
367 * the user can request a cancel at any time through the UI.
368 */
369 private static class SimContactQueryCookie implements DialogInterface.OnCancelListener{
370 public ProgressDialog progressDialog;
371 public int contactNum;
372
373 // Used to identify the query request.
374 private int mToken;
375 private QueryHandler mHandler;
376
377 // The text field we're going to update
378 private EditText textField;
379
380 public SimContactQueryCookie(int number, QueryHandler handler, int token) {
381 contactNum = number;
382 mHandler = handler;
383 mToken = token;
384 }
385
386 /**
387 * Synchronized getter for the EditText.
388 */
389 public synchronized EditText getTextField() {
390 return textField;
391 }
392
393 /**
394 * Synchronized setter for the EditText.
395 */
396 public synchronized void setTextField(EditText text) {
397 textField = text;
398 }
399
400 /**
401 * Cancel the ADN query by stopping the operation and signaling
402 * the cookie that a cancel request is made.
403 */
404 public synchronized void onCancel(DialogInterface dialog) {
405 // close the progress dialog
406 if (progressDialog != null) {
407 progressDialog.dismiss();
408 }
409
410 // setting the textfield to null ensures that the UI does NOT get
411 // updated.
412 textField = null;
413
414 // Cancel the operation if possible.
415 mHandler.cancelOperation(mToken);
416 }
417 }
418
419 /**
420 * Asynchronous query handler that services requests to look up ADNs
421 *
Jake Hamby1d6fb572013-04-09 15:49:56 -0700422 * Queries originate from {@link #handleAdnEntry}.
Chiao Cheng91197042012-08-24 14:19:37 -0700423 */
Chiao Cheng07af7642012-09-14 12:05:14 -0700424 private static class QueryHandler extends NoNullCursorAsyncQueryHandler {
Chiao Cheng91197042012-08-24 14:19:37 -0700425
426 private boolean mCanceled;
427
428 public QueryHandler(ContentResolver cr) {
429 super(cr);
430 }
431
432 /**
433 * Override basic onQueryComplete to fill in the textfield when
434 * we're handed the ADN cursor.
435 */
436 @Override
Chiao Cheng07af7642012-09-14 12:05:14 -0700437 protected void onNotNullableQueryComplete(int token, Object cookie, Cursor c) {
Jay Shraunerede67ec2014-09-11 15:03:36 -0700438 try {
439 sPreviousAdnQueryHandler = null;
440 if (mCanceled) {
441 return;
442 }
Chiao Cheng91197042012-08-24 14:19:37 -0700443
Jay Shraunerede67ec2014-09-11 15:03:36 -0700444 SimContactQueryCookie sc = (SimContactQueryCookie) cookie;
Chiao Cheng91197042012-08-24 14:19:37 -0700445
Jay Shraunerede67ec2014-09-11 15:03:36 -0700446 // close the progress dialog.
447 sc.progressDialog.dismiss();
Chiao Cheng91197042012-08-24 14:19:37 -0700448
Jay Shraunerede67ec2014-09-11 15:03:36 -0700449 // get the EditText to update or see if the request was cancelled.
450 EditText text = sc.getTextField();
Chiao Cheng91197042012-08-24 14:19:37 -0700451
Nancy Chen18c52ff2014-10-30 10:25:00 -0700452 // if the TextView is valid, and the cursor is valid and positionable on the
453 // Nth number, then we update the text field and display a toast indicating the
454 // caller name.
Jay Shraunerede67ec2014-09-11 15:03:36 -0700455 if ((c != null) && (text != null) && (c.moveToPosition(sc.contactNum))) {
456 String name = c.getString(c.getColumnIndexOrThrow(ADN_NAME_COLUMN_NAME));
Nancy Chen18c52ff2014-10-30 10:25:00 -0700457 String number =
458 c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME));
Chiao Cheng91197042012-08-24 14:19:37 -0700459
Jay Shraunerede67ec2014-09-11 15:03:36 -0700460 // fill the text in.
461 text.getText().replace(0, 0, number);
Chiao Cheng91197042012-08-24 14:19:37 -0700462
Jay Shraunerede67ec2014-09-11 15:03:36 -0700463 // display the name as a toast
464 Context context = sc.progressDialog.getContext();
465 name = context.getString(R.string.menu_callNumber, name);
466 Toast.makeText(context, name, Toast.LENGTH_SHORT)
467 .show();
468 }
469 } finally {
470 MoreCloseables.closeQuietly(c);
Chiao Cheng91197042012-08-24 14:19:37 -0700471 }
472 }
473
474 public void cancel() {
475 mCanceled = true;
Nancy Chen18c52ff2014-10-30 10:25:00 -0700476 // Ask AsyncQueryHandler to cancel the whole request. This will fail when the query is
477 // already started.
Chiao Cheng91197042012-08-24 14:19:37 -0700478 cancelOperation(ADN_QUERY_TOKEN);
479 }
480 }
481}