blob: 858d0f4b75af892714df1e1722522b3d58c02a15 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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.incallui;
18
19import android.Manifest;
20import android.annotation.TargetApi;
21import android.content.AsyncQueryHandler;
22import android.content.ContentResolver;
23import android.content.Context;
24import android.database.Cursor;
25import android.database.SQLException;
26import android.net.Uri;
27import android.os.Build.VERSION;
28import android.os.Build.VERSION_CODES;
29import android.os.Handler;
30import android.os.Looper;
31import android.os.Message;
32import android.provider.ContactsContract;
33import android.provider.ContactsContract.Directory;
34import android.support.annotation.MainThread;
35import android.support.annotation.RequiresPermission;
36import android.support.annotation.WorkerThread;
37import android.telephony.PhoneNumberUtils;
38import android.text.TextUtils;
39import com.android.contacts.common.compat.DirectoryCompat;
40import com.android.dialer.phonenumbercache.CachedNumberLookupService;
41import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo;
42import com.android.dialer.phonenumbercache.ContactInfoHelper;
43import com.android.dialer.phonenumbercache.PhoneNumberCache;
Eric Erfanian2ca43182017-08-31 06:57:16 -070044import com.android.dialer.strictmode.DialerStrictMode;
Eric Erfanianccca3152017-02-22 16:32:36 -080045import java.io.IOException;
46import java.io.InputStream;
47import java.util.ArrayList;
48import java.util.Arrays;
49
50/**
51 * Helper class to make it easier to run asynchronous caller-id lookup queries.
52 *
53 * @see CallerInfo
54 */
55@TargetApi(VERSION_CODES.M)
56public class CallerInfoAsyncQuery {
57
58 /** Interface for a CallerInfoAsyncQueryHandler result return. */
Eric Erfaniand5e47f62017-03-15 14:41:07 -070059 interface OnQueryCompleteListener {
Eric Erfanianccca3152017-02-22 16:32:36 -080060
61 /** Called when the query is complete. */
62 @MainThread
63 void onQueryComplete(int token, Object cookie, CallerInfo ci);
64
65 /** Called when data is loaded. Must be called in worker thread. */
66 @WorkerThread
67 void onDataLoaded(int token, Object cookie, CallerInfo ci);
68 }
69
70 private static final boolean DBG = false;
71 private static final String LOG_TAG = "CallerInfoAsyncQuery";
72
73 private static final int EVENT_NEW_QUERY = 1;
74 private static final int EVENT_ADD_LISTENER = 2;
75 private static final int EVENT_EMERGENCY_NUMBER = 3;
76 private static final int EVENT_VOICEMAIL_NUMBER = 4;
77 // If the CallerInfo query finds no contacts, should we use the
78 // PhoneNumberOfflineGeocoder to look up a "geo description"?
79 // (TODO: This could become a flag in config.xml if it ever needs to be
80 // configured on a per-product basis.)
81 private static final boolean ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION = true;
82 /* Directory lookup related code - START */
83 private static final String[] DIRECTORY_PROJECTION = new String[] {Directory._ID};
84
85 /** Private constructor for factory methods. */
86 private CallerInfoAsyncQuery() {}
87
88 @RequiresPermission(Manifest.permission.READ_CONTACTS)
Eric Erfaniand5e47f62017-03-15 14:41:07 -070089 static void startQuery(
Eric Erfanianccca3152017-02-22 16:32:36 -080090 final int token,
91 final Context context,
92 final CallerInfo info,
93 final OnQueryCompleteListener listener,
94 final Object cookie) {
95 Log.d(LOG_TAG, "##### CallerInfoAsyncQuery startContactProviderQuery()... #####");
96 Log.d(LOG_TAG, "- number: " + info.phoneNumber);
97 Log.d(LOG_TAG, "- cookie: " + cookie);
98
99 OnQueryCompleteListener contactsProviderQueryCompleteListener =
100 new OnQueryCompleteListener() {
101 @Override
102 public void onQueryComplete(int token, Object cookie, CallerInfo ci) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700103 Log.d(LOG_TAG, "contactsProviderQueryCompleteListener onQueryComplete");
Eric Erfanianccca3152017-02-22 16:32:36 -0800104 // If there are no other directory queries, make sure that the listener is
105 // notified of this result. see b/27621628
106 if ((ci != null && ci.contactExists)
107 || !startOtherDirectoriesQuery(token, context, info, listener, cookie)) {
108 if (listener != null && ci != null) {
109 listener.onQueryComplete(token, cookie, ci);
110 }
111 }
112 }
113
114 @Override
115 public void onDataLoaded(int token, Object cookie, CallerInfo ci) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700116 Log.d(LOG_TAG, "contactsProviderQueryCompleteListener onDataLoaded");
Eric Erfanianccca3152017-02-22 16:32:36 -0800117 listener.onDataLoaded(token, cookie, ci);
118 }
119 };
120 startDefaultDirectoryQuery(token, context, info, contactsProviderQueryCompleteListener, cookie);
121 }
122
123 // Private methods
124 private static void startDefaultDirectoryQuery(
125 int token,
126 Context context,
127 CallerInfo info,
128 OnQueryCompleteListener listener,
129 Object cookie) {
130 // Construct the URI object and query params, and start the query.
131 Uri uri = ContactInfoHelper.getContactInfoLookupUri(info.phoneNumber);
132 startQueryInternal(token, context, info, listener, cookie, uri);
133 }
134
135 /**
136 * Factory method to start the query based on a CallerInfo object.
137 *
138 * <p>Note: if the number contains an "@" character we treat it as a SIP address, and look it up
139 * directly in the Data table rather than using the PhoneLookup table. TODO: But eventually we
140 * should expose two separate methods, one for numbers and one for SIP addresses, and then have
141 * PhoneUtils.startGetCallerInfo() decide which one to call based on the phone type of the
142 * incoming connection.
143 */
144 private static void startQueryInternal(
145 int token,
146 Context context,
147 CallerInfo info,
148 OnQueryCompleteListener listener,
149 Object cookie,
150 Uri contactRef) {
151 if (DBG) {
152 Log.d(LOG_TAG, "==> contactRef: " + sanitizeUriToString(contactRef));
153 }
154
155 if ((context == null) || (contactRef == null)) {
156 throw new QueryPoolException("Bad context or query uri.");
157 }
158 CallerInfoAsyncQueryHandler handler = new CallerInfoAsyncQueryHandler(context, contactRef);
159
160 //create cookieWrapper, start query
161 CookieWrapper cw = new CookieWrapper();
162 cw.listener = listener;
163 cw.cookie = cookie;
164 cw.number = info.phoneNumber;
165
166 // check to see if these are recognized numbers, and use shortcuts if we can.
167 if (PhoneNumberUtils.isLocalEmergencyNumber(context, info.phoneNumber)) {
168 cw.event = EVENT_EMERGENCY_NUMBER;
169 } else if (info.isVoiceMailNumber()) {
170 cw.event = EVENT_VOICEMAIL_NUMBER;
171 } else {
172 cw.event = EVENT_NEW_QUERY;
173 }
174
175 String[] proejection = CallerInfo.getDefaultPhoneLookupProjection(contactRef);
176 handler.startQuery(
177 token,
178 cw, // cookie
179 contactRef, // uri
180 proejection, // projection
181 null, // selection
182 null, // selectionArgs
183 null); // orderBy
184 }
185
186 // Return value indicates if listener was notified.
187 private static boolean startOtherDirectoriesQuery(
188 int token,
189 Context context,
190 CallerInfo info,
191 OnQueryCompleteListener listener,
192 Object cookie) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700193 long[] directoryIds = DialerStrictMode.bypass(() -> getDirectoryIds(context));
Eric Erfanianccca3152017-02-22 16:32:36 -0800194 int size = directoryIds.length;
195 if (size == 0) {
196 return false;
197 }
198
199 DirectoryQueryCompleteListenerFactory listenerFactory =
200 new DirectoryQueryCompleteListenerFactory(context, size, listener);
201
202 // The current implementation of multiple async query runs in single handler thread
203 // in AsyncQueryHandler.
204 // intermediateListener.onQueryComplete is also called from the same caller thread.
205 // TODO(b/26019872): use thread pool instead of single thread.
206 for (int i = 0; i < size; i++) {
207 long directoryId = directoryIds[i];
208 Uri uri = ContactInfoHelper.getContactInfoLookupUri(info.phoneNumber, directoryId);
209 if (DBG) {
210 Log.d(LOG_TAG, "directoryId: " + directoryId + " uri: " + uri);
211 }
212 OnQueryCompleteListener intermediateListener = listenerFactory.newListener(directoryId);
213 startQueryInternal(token, context, info, intermediateListener, cookie, uri);
214 }
215 return true;
216 }
217
218 private static long[] getDirectoryIds(Context context) {
219 ArrayList<Long> results = new ArrayList<>();
220
221 Uri uri = Directory.CONTENT_URI;
222 if (VERSION.SDK_INT >= VERSION_CODES.N) {
223 uri = Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, "directories_enterprise");
224 }
225
226 ContentResolver cr = context.getContentResolver();
227 Cursor cursor = cr.query(uri, DIRECTORY_PROJECTION, null, null, null);
228 addDirectoryIdsFromCursor(cursor, results);
229
230 long[] result = new long[results.size()];
231 for (int i = 0; i < results.size(); i++) {
232 result[i] = results.get(i);
233 }
234 return result;
235 }
236
237 private static void addDirectoryIdsFromCursor(Cursor cursor, ArrayList<Long> results) {
238 if (cursor != null) {
239 int idIndex = cursor.getColumnIndex(Directory._ID);
240 while (cursor.moveToNext()) {
241 long id = cursor.getLong(idIndex);
242 if (DirectoryCompat.isRemoteDirectoryId(id)) {
243 results.add(id);
244 }
245 }
246 cursor.close();
247 }
248 }
249
250 private static String sanitizeUriToString(Uri uri) {
251 if (uri != null) {
252 String uriString = uri.toString();
253 int indexOfLastSlash = uriString.lastIndexOf('/');
254 if (indexOfLastSlash > 0) {
255 return uriString.substring(0, indexOfLastSlash) + "/xxxxxxx";
256 } else {
257 return uriString;
258 }
259 } else {
260 return "";
261 }
262 }
263
264 /** Wrap the cookie from the WorkerArgs with additional information needed by our classes. */
265 private static final class CookieWrapper {
266
267 public OnQueryCompleteListener listener;
268 public Object cookie;
269 public int event;
270 public String number;
271 }
272 /* Directory lookup related code - END */
273
274 /** Simple exception used to communicate problems with the query pool. */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700275 private static class QueryPoolException extends SQLException {
Eric Erfanianccca3152017-02-22 16:32:36 -0800276
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700277 QueryPoolException(String error) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800278 super(error);
279 }
280 }
281
282 private static final class DirectoryQueryCompleteListenerFactory {
283
284 private final OnQueryCompleteListener mListener;
285 private final Context mContext;
286 // Make sure listener to be called once and only once
287 private int mCount;
288 private boolean mIsListenerCalled;
289
290 DirectoryQueryCompleteListenerFactory(
291 Context context, int size, OnQueryCompleteListener listener) {
292 mCount = size;
293 mListener = listener;
294 mIsListenerCalled = false;
295 mContext = context;
296 }
297
298 private void onDirectoryQueryComplete(
299 int token, Object cookie, CallerInfo ci, long directoryId) {
300 boolean shouldCallListener = false;
301 synchronized (this) {
302 mCount = mCount - 1;
303 if (!mIsListenerCalled && (ci.contactExists || mCount == 0)) {
304 mIsListenerCalled = true;
305 shouldCallListener = true;
306 }
307 }
308
309 // Don't call callback in synchronized block because mListener.onQueryComplete may
310 // take long time to complete
311 if (shouldCallListener && mListener != null) {
312 addCallerInfoIntoCache(ci, directoryId);
313 mListener.onQueryComplete(token, cookie, ci);
314 }
315 }
316
317 private void addCallerInfoIntoCache(CallerInfo ci, long directoryId) {
318 CachedNumberLookupService cachedNumberLookupService =
319 PhoneNumberCache.get(mContext).getCachedNumberLookupService();
320 if (ci.contactExists && cachedNumberLookupService != null) {
321 // 1. Cache caller info
322 CachedContactInfo cachedContactInfo =
323 CallerInfoUtils.buildCachedContactInfo(cachedNumberLookupService, ci);
324 String directoryLabel = mContext.getString(R.string.directory_search_label);
325 cachedContactInfo.setDirectorySource(directoryLabel, directoryId);
326 cachedNumberLookupService.addContact(mContext, cachedContactInfo);
327
328 // 2. Cache photo
329 if (ci.contactDisplayPhotoUri != null && ci.normalizedNumber != null) {
330 try (InputStream in =
331 mContext.getContentResolver().openInputStream(ci.contactDisplayPhotoUri)) {
332 if (in != null) {
333 cachedNumberLookupService.addPhoto(mContext, ci.normalizedNumber, in);
334 }
335 } catch (IOException e) {
336 Log.e(LOG_TAG, "failed to fetch directory contact photo", e);
337 }
338 }
339 }
340 }
341
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700342 OnQueryCompleteListener newListener(long directoryId) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800343 return new DirectoryQueryCompleteListener(directoryId);
344 }
345
346 private class DirectoryQueryCompleteListener implements OnQueryCompleteListener {
347
348 private final long mDirectoryId;
349
350 DirectoryQueryCompleteListener(long directoryId) {
351 mDirectoryId = directoryId;
352 }
353
354 @Override
355 public void onDataLoaded(int token, Object cookie, CallerInfo ci) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700356 Log.d(LOG_TAG, "DirectoryQueryCompleteListener.onDataLoaded");
Eric Erfanianccca3152017-02-22 16:32:36 -0800357 mListener.onDataLoaded(token, cookie, ci);
358 }
359
360 @Override
361 public void onQueryComplete(int token, Object cookie, CallerInfo ci) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700362 Log.d(LOG_TAG, "DirectoryQueryCompleteListener.onQueryComplete");
Eric Erfanianccca3152017-02-22 16:32:36 -0800363 onDirectoryQueryComplete(token, cookie, ci, mDirectoryId);
364 }
365 }
366 }
367
368 /** Our own implementation of the AsyncQueryHandler. */
369 private static class CallerInfoAsyncQueryHandler extends AsyncQueryHandler {
370
371 /**
372 * The information relevant to each CallerInfo query. Each query may have multiple listeners, so
373 * each AsyncCursorInfo is associated with 2 or more CookieWrapper objects in the queue (one
374 * with a new query event, and one with a end event, with 0 or more additional listeners in
375 * between).
376 */
377 private Context mQueryContext;
378
379 private Uri mQueryUri;
380 private CallerInfo mCallerInfo;
381
382 /** Asynchronous query handler class for the contact / callerinfo object. */
383 private CallerInfoAsyncQueryHandler(Context context, Uri contactRef) {
384 super(context.getContentResolver());
385 this.mQueryContext = context;
386 this.mQueryUri = contactRef;
387 }
388
389 @Override
390 public void startQuery(
391 int token,
392 Object cookie,
393 Uri uri,
394 String[] projection,
395 String selection,
396 String[] selectionArgs,
397 String orderBy) {
398 if (DBG) {
399 // Show stack trace with the arguments.
400 Log.d(
401 LOG_TAG,
402 "InCall: startQuery: url="
403 + uri
404 + " projection=["
405 + Arrays.toString(projection)
406 + "]"
407 + " selection="
408 + selection
409 + " "
410 + " args=["
411 + Arrays.toString(selectionArgs)
412 + "]",
413 new RuntimeException("STACKTRACE"));
414 }
415 super.startQuery(token, cookie, uri, projection, selection, selectionArgs, orderBy);
416 }
417
418 @Override
419 protected Handler createHandler(Looper looper) {
420 return new CallerInfoWorkerHandler(looper);
421 }
422
423 /**
424 * Overrides onQueryComplete from AsyncQueryHandler.
425 *
426 * <p>This method takes into account the state of this class; we construct the CallerInfo object
427 * only once for each set of listeners. When the query thread has done its work and calls this
428 * method, we inform the remaining listeners in the queue, until we're out of listeners. Once we
429 * get the message indicating that we should expect no new listeners for this CallerInfo object,
430 * we release the AsyncCursorInfo back into the pool.
431 */
432 @Override
433 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
434 Log.d(this, "##### onQueryComplete() ##### query complete for token: " + token);
435
436 CookieWrapper cw = (CookieWrapper) cookie;
437
438 if (cw.listener != null) {
439 Log.d(
440 this,
441 "notifying listener: "
442 + cw.listener.getClass().toString()
443 + " for token: "
444 + token
445 + mCallerInfo);
446 cw.listener.onQueryComplete(token, cw.cookie, mCallerInfo);
447 }
448 mQueryContext = null;
449 mQueryUri = null;
450 mCallerInfo = null;
451 }
452
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700453 void updateData(int token, Object cookie, Cursor cursor) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800454 try {
455 Log.d(this, "##### updateData() ##### for token: " + token);
456
457 //get the cookie and notify the listener.
458 CookieWrapper cw = (CookieWrapper) cookie;
459 if (cw == null) {
460 // Normally, this should never be the case for calls originating
461 // from within this code.
462 // However, if there is any code that calls this method, we should
463 // check the parameters to make sure they're viable.
464 Log.d(this, "Cookie is null, ignoring onQueryComplete() request.");
465 return;
466 }
467
468 // check the token and if needed, create the callerinfo object.
469 if (mCallerInfo == null) {
470 if ((mQueryContext == null) || (mQueryUri == null)) {
471 throw new QueryPoolException(
472 "Bad context or query uri, or CallerInfoAsyncQuery already released.");
473 }
474
475 // adjust the callerInfo data as needed, and only if it was set from the
476 // initial query request.
477 // Change the callerInfo number ONLY if it is an emergency number or the
478 // voicemail number, and adjust other data (including photoResource)
479 // accordingly.
480 if (cw.event == EVENT_EMERGENCY_NUMBER) {
481 // Note we're setting the phone number here (refer to javadoc
482 // comments at the top of CallerInfo class).
483 mCallerInfo = new CallerInfo().markAsEmergency(mQueryContext);
484 } else if (cw.event == EVENT_VOICEMAIL_NUMBER) {
485 mCallerInfo = new CallerInfo().markAsVoiceMail(mQueryContext);
486 } else {
487 mCallerInfo = CallerInfo.getCallerInfo(mQueryContext, mQueryUri, cursor);
488 Log.d(this, "==> Got mCallerInfo: " + mCallerInfo);
489
490 CallerInfo newCallerInfo =
491 CallerInfo.doSecondaryLookupIfNecessary(mQueryContext, cw.number, mCallerInfo);
492 if (newCallerInfo != mCallerInfo) {
493 mCallerInfo = newCallerInfo;
494 Log.d(this, "#####async contact look up with numeric username" + mCallerInfo);
495 }
496
497 // Final step: look up the geocoded description.
498 if (ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION) {
499 // Note we do this only if we *don't* have a valid name (i.e. if
500 // no contacts matched the phone number of the incoming call),
501 // since that's the only case where the incoming-call UI cares
502 // about this field.
503 //
504 // (TODO: But if we ever want the UI to show the geoDescription
505 // even when we *do* match a contact, we'll need to either call
506 // updateGeoDescription() unconditionally here, or possibly add a
507 // new parameter to CallerInfoAsyncQuery.startQuery() to force
508 // the geoDescription field to be populated.)
509
510 if (TextUtils.isEmpty(mCallerInfo.name)) {
511 // Actually when no contacts match the incoming phone number,
512 // the CallerInfo object is totally blank here (i.e. no name
513 // *or* phoneNumber). So we need to pass in cw.number as
514 // a fallback number.
515 mCallerInfo.updateGeoDescription(mQueryContext, cw.number);
516 }
517 }
518
519 // Use the number entered by the user for display.
520 if (!TextUtils.isEmpty(cw.number)) {
521 mCallerInfo.phoneNumber = cw.number;
522 }
523 }
524
525 Log.d(this, "constructing CallerInfo object for token: " + token);
526
527 if (cw.listener != null) {
528 cw.listener.onDataLoaded(token, cw.cookie, mCallerInfo);
529 }
530 }
531
532 } finally {
533 // The cursor may have been closed in CallerInfo.getCallerInfo()
534 if (cursor != null && !cursor.isClosed()) {
535 cursor.close();
536 }
537 }
538 }
539
540 /**
541 * Our own query worker thread.
542 *
543 * <p>This thread handles the messages enqueued in the looper. The normal sequence of events is
544 * that a new query shows up in the looper queue, followed by 0 or more add listener requests,
545 * and then an end request. Of course, these requests can be interlaced with requests from other
546 * tokens, but is irrelevant to this handler since the handler has no state.
547 *
548 * <p>Note that we depend on the queue to keep things in order; in other words, the looper queue
549 * must be FIFO with respect to input from the synchronous startQuery calls and output to this
550 * handleMessage call.
551 *
552 * <p>This use of the queue is required because CallerInfo objects may be accessed multiple
553 * times before the query is complete. All accesses (listeners) must be queued up and informed
554 * in order when the query is complete.
555 */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700556 class CallerInfoWorkerHandler extends WorkerHandler {
Eric Erfanianccca3152017-02-22 16:32:36 -0800557
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700558 CallerInfoWorkerHandler(Looper looper) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800559 super(looper);
560 }
561
562 @Override
563 public void handleMessage(Message msg) {
564 WorkerArgs args = (WorkerArgs) msg.obj;
565 CookieWrapper cw = (CookieWrapper) args.cookie;
566
567 if (cw == null) {
568 // Normally, this should never be the case for calls originating
569 // from within this code.
570 // However, if there is any code that this Handler calls (such as in
571 // super.handleMessage) that DOES place unexpected messages on the
572 // queue, then we need pass these messages on.
573 Log.d(
574 this,
575 "Unexpected command (CookieWrapper is null): "
576 + msg.what
577 + " ignored by CallerInfoWorkerHandler, passing onto parent.");
578
579 super.handleMessage(msg);
580 } else {
581 Log.d(
582 this,
583 "Processing event: "
584 + cw.event
585 + " token (arg1): "
586 + msg.arg1
587 + " command: "
588 + msg.what
589 + " query URI: "
590 + sanitizeUriToString(args.uri));
591
592 switch (cw.event) {
593 case EVENT_NEW_QUERY:
594 final ContentResolver resolver = mQueryContext.getContentResolver();
595
596 // This should never happen.
597 if (resolver == null) {
598 Log.e(this, "Content Resolver is null!");
599 return;
600 }
601 //start the sql command.
602 Cursor cursor;
603 try {
604 cursor =
605 resolver.query(
606 args.uri,
607 args.projection,
608 args.selection,
609 args.selectionArgs,
610 args.orderBy);
611 // Calling getCount() causes the cursor window to be filled,
612 // which will make the first access on the main thread a lot faster.
613 if (cursor != null) {
614 cursor.getCount();
615 }
616 } catch (Exception e) {
617 Log.e(this, "Exception thrown during handling EVENT_ARG_QUERY", e);
618 cursor = null;
619 }
620
621 args.result = cursor;
622 updateData(msg.arg1, cw, cursor);
623 break;
624
625 // shortcuts to avoid query for recognized numbers.
626 case EVENT_EMERGENCY_NUMBER:
627 case EVENT_VOICEMAIL_NUMBER:
628 case EVENT_ADD_LISTENER:
629 updateData(msg.arg1, cw, (Cursor) args.result);
630 break;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700631 default: // fall out
Eric Erfanianccca3152017-02-22 16:32:36 -0800632 }
633 Message reply = args.handler.obtainMessage(msg.what);
634 reply.obj = args;
635 reply.arg1 = msg.arg1;
636
637 reply.sendToTarget();
638 }
639 }
640 }
641 }
642}