From 9779f967ebb9512e5b19090b071572c9c4f0f2a6 Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Mon, 27 Mar 2017 12:31:48 -0700 Subject: Update AOSP Dialer source from internal google3 repository at cl/151342913. Test: make, treehugger This CL updates the AOSP Dialer source with all the changes that have gone into the private google3 repository. This includes all the changes from cl/151128062 (3/24/2017) to cl/151342913 (3/27/2017). This goal of these drops is to keep the AOSP source in sync with the internal google3 repository. Currently these sync are done by hand with very minor modifications to the internal source code. See the Android.mk file for list of modifications. Our current goal is to do frequent drops (daily if possible) and eventually switched to an automated process. Change-Id: I8d4855628b62e9067e71f32ed40317617a1e3b02 --- .../android/dialer/app/calllog/CallLogAdapter.java | 19 +- .../dialer/app/calllog/CallLogAsyncTaskUtil.java | 4 +- .../dialer/app/contactinfo/ContactInfoCache.java | 34 +-- .../android/dialer/app/res/values-ne/strings.xml | 2 +- .../android/dialer/app/res/values-uz/strings.xml | 4 +- .../app/voicemail/VoicemailPlaybackPresenter.java | 4 +- .../callcomposer/camera/ImagePersistTask.java | 2 +- .../callcomposer/util/CopyAndResizeImageTask.java | 2 +- .../dialer/calldetails/CallDetailsActivity.java | 2 +- .../android/dialer/common/AsyncTaskExecutor.java | 51 ---- .../android/dialer/common/AsyncTaskExecutors.java | 91 ------- .../android/dialer/common/FallibleAsyncTask.java | 94 ------- .../common/concurrent/AsyncTaskExecutor.java | 51 ++++ .../common/concurrent/AsyncTaskExecutors.java | 92 +++++++ .../common/concurrent/DialerAsyncTaskHelper.java | 2 - .../common/concurrent/FallibleAsyncTask.java | 94 +++++++ .../dialer/enrichedcall/RcsVideoShareFactory.java | 1 + java/com/android/dialer/oem/AndroidManifest.xml | 15 ++ .../android/dialer/oem/CequintCallerIdManager.java | 297 +++++++++++++++++++++ .../dialer/phonenumbercache/ContactInfo.java | 11 +- .../dialer/phonenumbercache/ContactInfoHelper.java | 38 ++- .../dialer/shortcuts/ShortcutRefresher.java | 6 +- .../dialer/shortcuts/ShortcutUsageReporter.java | 4 +- 23 files changed, 644 insertions(+), 276 deletions(-) delete mode 100644 java/com/android/dialer/common/AsyncTaskExecutor.java delete mode 100644 java/com/android/dialer/common/AsyncTaskExecutors.java delete mode 100644 java/com/android/dialer/common/FallibleAsyncTask.java create mode 100644 java/com/android/dialer/common/concurrent/AsyncTaskExecutor.java create mode 100644 java/com/android/dialer/common/concurrent/AsyncTaskExecutors.java create mode 100644 java/com/android/dialer/common/concurrent/FallibleAsyncTask.java create mode 100644 java/com/android/dialer/oem/CequintCallerIdManager.java (limited to 'java/com/android/dialer') diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java index b23e18d6b..301fc009e 100644 --- a/java/com/android/dialer/app/calllog/CallLogAdapter.java +++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java @@ -58,9 +58,9 @@ import com.android.dialer.calldetails.nano.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.calllogutils.PhoneCallDetails; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.AsyncTaskExecutor; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; import com.android.dialer.enrichedcall.EnrichedCallCapabilities; import com.android.dialer.enrichedcall.EnrichedCallComponent; import com.android.dialer.enrichedcall.EnrichedCallManager; @@ -457,6 +457,7 @@ public class CallLogAdapter extends GroupingListAdapter final long rowId, final PhoneCallDetails details, final CallDetailsEntries callDetailsEntries) { + LogUtil.d("CallLogAdapter.loadAndRender", "position: %d", views.getAdapterPosition()); // Reset block and spam information since this view could be reused which may contain // outdated data. views.isSpam = false; @@ -667,12 +668,13 @@ public class CallLogAdapter extends GroupingListAdapter && !isVoicemailNumber) { // Lookup contacts with this number // Only do remote lookup in first 5 rows. + int position = views.getAdapterPosition(); info = mContactInfoCache.getValue( details.number + details.postDialDigits, details.countryIso, details.cachedContactInfo, - rowId + position < Bindings.get(mActivity) .getConfigProvider() .getLong("number_of_call_to_do_remote_lookup", 5L)); @@ -699,6 +701,17 @@ public class CallLogAdapter extends GroupingListAdapter details.objectId = info.objectId; details.contactUserType = info.userType; } + LogUtil.d( + "CallLogAdapter.loadData", + "position:%d, update geo info: %s, cequint caller id geo: %s, photo uri: %s <- %s", + views.getAdapterPosition(), + details.geocode, + info.geoDescription, + details.photoUri, + info.photoUri); + if (!TextUtils.isEmpty(info.geoDescription)) { + details.geocode = info.geoDescription; + } views.info = info; views.numberType = diff --git a/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java b/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java index 2198626d6..2aedb6f17 100644 --- a/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java +++ b/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java @@ -28,8 +28,8 @@ import android.provider.VoicemailContract.Voicemails; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; +import com.android.dialer.common.concurrent.AsyncTaskExecutor; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; import com.android.dialer.util.PermissionsUtil; import com.android.voicemail.VoicemailClient; diff --git a/java/com/android/dialer/app/contactinfo/ContactInfoCache.java b/java/com/android/dialer/app/contactinfo/ContactInfoCache.java index 6c35711a8..ab5541b6f 100644 --- a/java/com/android/dialer/app/contactinfo/ContactInfoCache.java +++ b/java/com/android/dialer/app/contactinfo/ContactInfoCache.java @@ -18,9 +18,11 @@ package com.android.dialer.app.contactinfo; import android.os.Handler; import android.os.Message; +import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; +import com.android.dialer.common.LogUtil; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.util.ExpirableCache; @@ -97,39 +99,29 @@ public class ContactInfoCache { NumberWithCountryIso numberCountryIso = new NumberWithCountryIso(number, countryIso); ExpirableCache.CachedValue cachedInfo = mCache.getCachedValue(numberCountryIso); ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue(); + int requestType = + remoteLookupIfNotFoundLocally + ? ContactInfoRequest.TYPE_LOCAL_AND_REMOTE + : ContactInfoRequest.TYPE_LOCAL; if (cachedInfo == null) { mCache.put(numberCountryIso, ContactInfo.EMPTY); // Use the cached contact info from the call log. info = callLogContactInfo; // The db request should happen on a non-UI thread. // Request the contact details immediately since they are currently missing. - int requestType = - remoteLookupIfNotFoundLocally - ? ContactInfoRequest.TYPE_LOCAL_AND_REMOTE - : ContactInfoRequest.TYPE_LOCAL; enqueueRequest(number, countryIso, callLogContactInfo, /* immediate */ true, requestType); // We will format the phone number when we make the background request. } else { if (cachedInfo.isExpired()) { // The contact info is no longer up to date, we should request it. However, we // do not need to request them immediately. - enqueueRequest( - number, - countryIso, - callLogContactInfo, /* immediate */ - false, - ContactInfoRequest.TYPE_LOCAL); + enqueueRequest(number, countryIso, callLogContactInfo, /* immediate */ false, requestType); } else if (!callLogInfoMatches(callLogContactInfo, info)) { // The call log information does not match the one we have, look it up again. // We could simply update the call log directly, but that needs to be done in a // background thread, so it is easier to simply request a new lookup, which will, as // a side-effect, update the call log. - enqueueRequest( - number, - countryIso, - callLogContactInfo, /* immediate */ - false, - ContactInfoRequest.TYPE_LOCAL); + enqueueRequest(number, countryIso, callLogContactInfo, /* immediate */ false, requestType); } if (info == ContactInfo.EMPTY) { @@ -152,9 +144,19 @@ public class ContactInfoCache { * to update its content. */ private boolean queryContactInfo(ContactInfoRequest request) { + LogUtil.d( + "ContactInfoCache.queryContactInfo", + "request number: %s, type: %d", + LogUtil.sanitizePhoneNumber(request.number), + request.type); ContactInfo info; if (request.isLocalRequest()) { info = mContactInfoHelper.lookupNumber(request.number, request.countryIso); + // TODO: Maybe skip look up if it's already available in cached number lookup service. + long start = SystemClock.uptimeMillis(); + mContactInfoHelper.updateFromCequintCallerId(info, request.number); + long time = SystemClock.uptimeMillis() - start; + LogUtil.d("ContactInfoCache.queryContactInfo", "Cequint Caller Id look up takes %d ms", time); if (request.type == ContactInfoRequest.TYPE_LOCAL_AND_REMOTE) { if (!mContactInfoHelper.hasName(info)) { enqueueRequest( diff --git a/java/com/android/dialer/app/res/values-ne/strings.xml b/java/com/android/dialer/app/res/values-ne/strings.xml index 29eaccdb5..33989648e 100644 --- a/java/com/android/dialer/app/res/values-ne/strings.xml +++ b/java/com/android/dialer/app/res/values-ne/strings.xml @@ -193,7 +193,7 @@ "कल रोक्दै" "भ्वाइस मेल" "कल अवरुद्ध अस्थायी रुपमा निष्क्रिय" - "कल अवरुद्ध अस्थायी रुपमा असक्षम गरिएको छ किनभने तपाईँले अन्तिम ४८ घण्टा भित्र यस फोनबाट आपत्कालीन सेवाहरू सम्पर्क गर्नुभयो। एकपटक ४८ घण्टा अवधि समाप्त भएपछि यो स्वचालित रूपले पुनः सक्रिय हुनेछ।" + "कल अवरुद्ध अस्थायी रुपमा असक्षम गरिएको छ किनभने तपाईँले अन्तिम ४८ घन्टा भित्र यस फोनबाट आपत्कालीन सेवाहरू सम्पर्क गर्नुभयो। एकपटक ४८ घन्टा अवधि समाप्त भएपछि यो स्वचालित रूपले पुनः सक्रिय हुनेछ।" "नम्बरहरू आयात गर्नुहोस्" "तपाईँले पहिल्यै केही कल गर्ने व्यक्तिहरूलाई अन्य अनुप्रयोगहरू मार्फत स्वत: रूपमा भ्वाइस मेल पठाउन नै चिन्ह लगाउनु भएको थियो।" "नम्बरहरू हेर्नुहोस्" diff --git a/java/com/android/dialer/app/res/values-uz/strings.xml b/java/com/android/dialer/app/res/values-uz/strings.xml index d26c53cf4..11befbc51 100644 --- a/java/com/android/dialer/app/res/values-uz/strings.xml +++ b/java/com/android/dialer/app/res/values-uz/strings.xml @@ -40,7 +40,7 @@ "Javobsiz chaqiruvlar" "%d ta javobsiz chaqiruv" "Telefon" - "SMS yuborish" + "SMS yozish" "%1$s: %2$s" %1$d ta ovozli xabar @@ -143,7 +143,7 @@ "Barcha raqamlarni ko‘rish uchun rasm ustiga bosing yoki joyini o‘zgartirish uchun rasmni bosib turing." "O‘chirish" "Video qo‘ng‘iroq" - "SMS yuborish" + "Xabar yuborish" "Chaqiruv tafsilotlari" "Yuborish:" "Qo‘ng‘iroq qilish: ^1" diff --git a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java index 994160ff9..492f2088b 100644 --- a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java +++ b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java @@ -46,10 +46,10 @@ import com.android.common.io.MoreCloseables; import com.android.dialer.app.R; import com.android.dialer.app.calllog.CallLogListItemViewHolder; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; import com.android.dialer.common.ConfigProviderBindings; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.AsyncTaskExecutor; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; import com.android.dialer.constants.Constants; import com.android.dialer.logging.Logger; import com.android.dialer.logging.nano.DialerImpression; diff --git a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java index a23014bf0..80921cdd8 100644 --- a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java +++ b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java @@ -29,7 +29,7 @@ import com.android.dialer.callcomposer.camera.exif.ExifInterface; import com.android.dialer.callcomposer.camera.exif.ExifTag; import com.android.dialer.callcomposer.util.CopyAndResizeImageTask; import com.android.dialer.common.Assert; -import com.android.dialer.common.FallibleAsyncTask; +import com.android.dialer.common.concurrent.FallibleAsyncTask; import com.android.dialer.constants.Constants; import com.android.dialer.util.DialerUtils; import java.io.File; diff --git a/java/com/android/dialer/callcomposer/util/CopyAndResizeImageTask.java b/java/com/android/dialer/callcomposer/util/CopyAndResizeImageTask.java index 83580fd38..be08555f9 100644 --- a/java/com/android/dialer/callcomposer/util/CopyAndResizeImageTask.java +++ b/java/com/android/dialer/callcomposer/util/CopyAndResizeImageTask.java @@ -26,8 +26,8 @@ import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.android.dialer.common.Assert; -import com.android.dialer.common.FallibleAsyncTask; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.FallibleAsyncTask; import com.android.dialer.util.DialerUtils; import java.io.File; import java.io.FileOutputStream; diff --git a/java/com/android/dialer/calldetails/CallDetailsActivity.java b/java/com/android/dialer/calldetails/CallDetailsActivity.java index 6070640a0..bb2f58083 100644 --- a/java/com/android/dialer/calldetails/CallDetailsActivity.java +++ b/java/com/android/dialer/calldetails/CallDetailsActivity.java @@ -32,7 +32,7 @@ import com.android.dialer.callcomposer.nano.CallComposerContact; import com.android.dialer.calldetails.nano.CallDetailsEntries; import com.android.dialer.calldetails.nano.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutors; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; import com.android.dialer.logging.Logger; import com.android.dialer.logging.nano.DialerImpression; import com.android.dialer.protos.ProtoParsers; diff --git a/java/com/android/dialer/common/AsyncTaskExecutor.java b/java/com/android/dialer/common/AsyncTaskExecutor.java deleted file mode 100644 index caadfe7ce..000000000 --- a/java/com/android/dialer/common/AsyncTaskExecutor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.common; - -import android.os.AsyncTask; -import android.support.annotation.MainThread; -import java.util.concurrent.Executor; - -/** - * Interface used to submit {@link AsyncTask} objects to run in the background. - * - *

This interface has a direct parallel with the {@link Executor} interface. It exists to - * decouple the mechanics of AsyncTask submission from the description of how that AsyncTask will - * execute. - * - *

One immediate benefit of this approach is that testing becomes much easier, since it is easy - * to introduce a mock or fake AsyncTaskExecutor in unit/integration tests, and thus inspect which - * tasks have been submitted and control their execution in an orderly manner. - * - *

Another benefit in due course will be the management of the submitted tasks. An extension to - * this interface is planned to allow Activities to easily cancel all the submitted tasks that are - * still pending in the onDestroy() method of the Activity. - */ -public interface AsyncTaskExecutor { - - /** - * Executes the given AsyncTask with the default Executor. - * - *

This method must only be called from the ui thread. - * - *

The identifier supplied is any Object that can be used to identify the task later. Most - * commonly this will be an enum which the tests can also refer to. {@code null} is also accepted, - * though of course this won't help in identifying the task later. - */ - @MainThread - AsyncTask submit(Object identifier, AsyncTask task, T... params); -} diff --git a/java/com/android/dialer/common/AsyncTaskExecutors.java b/java/com/android/dialer/common/AsyncTaskExecutors.java deleted file mode 100644 index 77bebdb36..000000000 --- a/java/com/android/dialer/common/AsyncTaskExecutors.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.common; - -import android.os.AsyncTask; -import android.support.annotation.MainThread; -import java.util.concurrent.Executor; - -/** - * Factory methods for creating AsyncTaskExecutors. - * - *

All of the factory methods on this class check first to see if you have set a static {@link - * AsyncTaskExecutorFactory} set through the {@link #setFactoryForTest(AsyncTaskExecutorFactory)} - * method, and if so delegate to that instead, which is one way of injecting dependencies for - * testing classes whose construction cannot be controlled such as {@link android.app.Activity}. - */ -public final class AsyncTaskExecutors { - - /** - * A single instance of the {@link AsyncTaskExecutorFactory}, to which we delegate if it is - * non-null, for injecting when testing. - */ - private static AsyncTaskExecutorFactory mInjectedAsyncTaskExecutorFactory = null; - - /** - * Creates an AsyncTaskExecutor that submits tasks to run with {@link AsyncTask#SERIAL_EXECUTOR}. - */ - public static AsyncTaskExecutor createAsyncTaskExecutor() { - synchronized (AsyncTaskExecutors.class) { - if (mInjectedAsyncTaskExecutorFactory != null) { - return mInjectedAsyncTaskExecutorFactory.createAsyncTaskExeuctor(); - } - return new SimpleAsyncTaskExecutor(AsyncTask.SERIAL_EXECUTOR); - } - } - - /** - * Creates an AsyncTaskExecutor that submits tasks to run with {@link - * AsyncTask#THREAD_POOL_EXECUTOR}. - */ - public static AsyncTaskExecutor createThreadPoolExecutor() { - synchronized (AsyncTaskExecutors.class) { - if (mInjectedAsyncTaskExecutorFactory != null) { - return mInjectedAsyncTaskExecutorFactory.createAsyncTaskExeuctor(); - } - return new SimpleAsyncTaskExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - - public static void setFactoryForTest(AsyncTaskExecutorFactory factory) { - synchronized (AsyncTaskExecutors.class) { - mInjectedAsyncTaskExecutorFactory = factory; - } - } - - /** Interface for creating AsyncTaskExecutor objects. */ - public interface AsyncTaskExecutorFactory { - - AsyncTaskExecutor createAsyncTaskExeuctor(); - } - - private static class SimpleAsyncTaskExecutor implements AsyncTaskExecutor { - - private final Executor mExecutor; - - public SimpleAsyncTaskExecutor(Executor executor) { - mExecutor = executor; - } - - @Override - @MainThread - public AsyncTask submit(Object identifer, AsyncTask task, T... params) { - Assert.isMainThread(); - return task.executeOnExecutor(mExecutor, params); - } - } -} diff --git a/java/com/android/dialer/common/FallibleAsyncTask.java b/java/com/android/dialer/common/FallibleAsyncTask.java deleted file mode 100644 index f3abace1a..000000000 --- a/java/com/android/dialer/common/FallibleAsyncTask.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.common; - -import android.os.AsyncTask; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import com.android.dialer.common.FallibleAsyncTask.FallibleTaskResult; -import com.google.auto.value.AutoValue; - -/** - * A task that runs work in the background, passing Throwables from {@link - * #doInBackground(Object[])} to {@link #onPostExecute(Object)} through a {@link - * FallibleTaskResult}. - * - * @param the type of the parameters sent to the task upon execution - * @param the type of the progress units published during the background computation - * @param the type of the result of the background computation - */ -public abstract class FallibleAsyncTask - extends AsyncTask> { - - @Override - protected final FallibleTaskResult doInBackground(ParamsT... params) { - try { - return FallibleTaskResult.createSuccessResult(doInBackgroundFallible(params)); - } catch (Throwable t) { - return FallibleTaskResult.createFailureResult(t); - } - } - - /** Performs background work that may result in a Throwable. */ - @Nullable - protected abstract ResultT doInBackgroundFallible(ParamsT... params) throws Throwable; - - /** - * Holds the result of processing from {@link #doInBackground(Object[])}. - * - * @param the type of the result of the background computation - */ - @AutoValue - public abstract static class FallibleTaskResult { - - /** Creates an instance of FallibleTaskResult for the given throwable. */ - private static FallibleTaskResult createFailureResult(@NonNull Throwable t) { - return new AutoValue_FallibleAsyncTask_FallibleTaskResult<>(t, null); - } - - /** Creates an instance of FallibleTaskResult for the given result. */ - private static FallibleTaskResult createSuccessResult( - @Nullable ResultT result) { - return new AutoValue_FallibleAsyncTask_FallibleTaskResult<>(null, result); - } - - /** - * Returns the Throwable thrown in {@link #doInBackground(Object[])}, or {@code null} if - * background work completed without throwing. - */ - @Nullable - public abstract Throwable getThrowable(); - - /** - * Returns the result of {@link #doInBackground(Object[])}, which may be {@code null}, or {@code - * null} if the background work threw a Throwable. - * - *

Use {@link #isFailure()} to determine if a {@code null} return is the result of a - * Throwable from the background work. - */ - @Nullable - public abstract ResultT getResult(); - - /** - * Returns {@code true} if this object is the result of background work that threw a Throwable. - */ - public boolean isFailure() { - //noinspection ThrowableResultOfMethodCallIgnored - return getThrowable() != null; - } - } -} diff --git a/java/com/android/dialer/common/concurrent/AsyncTaskExecutor.java b/java/com/android/dialer/common/concurrent/AsyncTaskExecutor.java new file mode 100644 index 000000000..3bdcd035b --- /dev/null +++ b/java/com/android/dialer/common/concurrent/AsyncTaskExecutor.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.common.concurrent; + +import android.os.AsyncTask; +import android.support.annotation.MainThread; +import java.util.concurrent.Executor; + +/** + * Interface used to submit {@link AsyncTask} objects to run in the background. + * + *

This interface has a direct parallel with the {@link Executor} interface. It exists to + * decouple the mechanics of AsyncTask submission from the description of how that AsyncTask will + * execute. + * + *

One immediate benefit of this approach is that testing becomes much easier, since it is easy + * to introduce a mock or fake AsyncTaskExecutor in unit/integration tests, and thus inspect which + * tasks have been submitted and control their execution in an orderly manner. + * + *

Another benefit in due course will be the management of the submitted tasks. An extension to + * this interface is planned to allow Activities to easily cancel all the submitted tasks that are + * still pending in the onDestroy() method of the Activity. + */ +public interface AsyncTaskExecutor { + + /** + * Executes the given AsyncTask with the default Executor. + * + *

This method must only be called from the ui thread. + * + *

The identifier supplied is any Object that can be used to identify the task later. Most + * commonly this will be an enum which the tests can also refer to. {@code null} is also accepted, + * though of course this won't help in identifying the task later. + */ + @MainThread + AsyncTask submit(Object identifier, AsyncTask task, T... params); +} diff --git a/java/com/android/dialer/common/concurrent/AsyncTaskExecutors.java b/java/com/android/dialer/common/concurrent/AsyncTaskExecutors.java new file mode 100644 index 000000000..fd358328e --- /dev/null +++ b/java/com/android/dialer/common/concurrent/AsyncTaskExecutors.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.common.concurrent; + +import android.os.AsyncTask; +import android.support.annotation.MainThread; +import com.android.dialer.common.Assert; +import java.util.concurrent.Executor; + +/** + * Factory methods for creating AsyncTaskExecutors. + * + *

All of the factory methods on this class check first to see if you have set a static {@link + * AsyncTaskExecutorFactory} set through the {@link #setFactoryForTest(AsyncTaskExecutorFactory)} + * method, and if so delegate to that instead, which is one way of injecting dependencies for + * testing classes whose construction cannot be controlled such as {@link android.app.Activity}. + */ +public final class AsyncTaskExecutors { + + /** + * A single instance of the {@link AsyncTaskExecutorFactory}, to which we delegate if it is + * non-null, for injecting when testing. + */ + private static AsyncTaskExecutorFactory mInjectedAsyncTaskExecutorFactory = null; + + /** + * Creates an AsyncTaskExecutor that submits tasks to run with {@link AsyncTask#SERIAL_EXECUTOR}. + */ + public static AsyncTaskExecutor createAsyncTaskExecutor() { + synchronized (AsyncTaskExecutors.class) { + if (mInjectedAsyncTaskExecutorFactory != null) { + return mInjectedAsyncTaskExecutorFactory.createAsyncTaskExeuctor(); + } + return new SimpleAsyncTaskExecutor(AsyncTask.SERIAL_EXECUTOR); + } + } + + /** + * Creates an AsyncTaskExecutor that submits tasks to run with {@link + * AsyncTask#THREAD_POOL_EXECUTOR}. + */ + public static AsyncTaskExecutor createThreadPoolExecutor() { + synchronized (AsyncTaskExecutors.class) { + if (mInjectedAsyncTaskExecutorFactory != null) { + return mInjectedAsyncTaskExecutorFactory.createAsyncTaskExeuctor(); + } + return new SimpleAsyncTaskExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + + public static void setFactoryForTest(AsyncTaskExecutorFactory factory) { + synchronized (AsyncTaskExecutors.class) { + mInjectedAsyncTaskExecutorFactory = factory; + } + } + + /** Interface for creating AsyncTaskExecutor objects. */ + public interface AsyncTaskExecutorFactory { + + AsyncTaskExecutor createAsyncTaskExeuctor(); + } + + private static class SimpleAsyncTaskExecutor implements AsyncTaskExecutor { + + private final Executor mExecutor; + + public SimpleAsyncTaskExecutor(Executor executor) { + mExecutor = executor; + } + + @Override + @MainThread + public AsyncTask submit(Object identifer, AsyncTask task, T... params) { + Assert.isMainThread(); + return task.executeOnExecutor(mExecutor, params); + } + } +} diff --git a/java/com/android/dialer/common/concurrent/DialerAsyncTaskHelper.java b/java/com/android/dialer/common/concurrent/DialerAsyncTaskHelper.java index acfcda7f6..65b408094 100644 --- a/java/com/android/dialer/common/concurrent/DialerAsyncTaskHelper.java +++ b/java/com/android/dialer/common/concurrent/DialerAsyncTaskHelper.java @@ -23,8 +23,6 @@ import android.os.Bundle; import android.support.annotation.MainThread; import android.support.annotation.WorkerThread; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; import com.android.dialer.common.LogUtil; /** diff --git a/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java b/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java new file mode 100644 index 000000000..6d02fe67f --- /dev/null +++ b/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.common.concurrent; + +import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.android.dialer.common.concurrent.FallibleAsyncTask.FallibleTaskResult; +import com.google.auto.value.AutoValue; + +/** + * A task that runs work in the background, passing Throwables from {@link + * #doInBackground(Object[])} to {@link #onPostExecute(Object)} through a {@link + * FallibleTaskResult}. + * + * @param the type of the parameters sent to the task upon execution + * @param the type of the progress units published during the background computation + * @param the type of the result of the background computation + */ +public abstract class FallibleAsyncTask + extends AsyncTask> { + + @Override + protected final FallibleTaskResult doInBackground(ParamsT... params) { + try { + return FallibleTaskResult.createSuccessResult(doInBackgroundFallible(params)); + } catch (Throwable t) { + return FallibleTaskResult.createFailureResult(t); + } + } + + /** Performs background work that may result in a Throwable. */ + @Nullable + protected abstract ResultT doInBackgroundFallible(ParamsT... params) throws Throwable; + + /** + * Holds the result of processing from {@link #doInBackground(Object[])}. + * + * @param the type of the result of the background computation + */ + @AutoValue + public abstract static class FallibleTaskResult { + + /** Creates an instance of FallibleTaskResult for the given throwable. */ + private static FallibleTaskResult createFailureResult(@NonNull Throwable t) { + return new AutoValue_FallibleAsyncTask_FallibleTaskResult<>(t, null); + } + + /** Creates an instance of FallibleTaskResult for the given result. */ + private static FallibleTaskResult createSuccessResult( + @Nullable ResultT result) { + return new AutoValue_FallibleAsyncTask_FallibleTaskResult<>(null, result); + } + + /** + * Returns the Throwable thrown in {@link #doInBackground(Object[])}, or {@code null} if + * background work completed without throwing. + */ + @Nullable + public abstract Throwable getThrowable(); + + /** + * Returns the result of {@link #doInBackground(Object[])}, which may be {@code null}, or {@code + * null} if the background work threw a Throwable. + * + *

Use {@link #isFailure()} to determine if a {@code null} return is the result of a + * Throwable from the background work. + */ + @Nullable + public abstract ResultT getResult(); + + /** + * Returns {@code true} if this object is the result of background work that threw a Throwable. + */ + public boolean isFailure() { + //noinspection ThrowableResultOfMethodCallIgnored + return getThrowable() != null; + } + } +} diff --git a/java/com/android/dialer/enrichedcall/RcsVideoShareFactory.java b/java/com/android/dialer/enrichedcall/RcsVideoShareFactory.java index 566d9f339..38f91da7d 100644 --- a/java/com/android/dialer/enrichedcall/RcsVideoShareFactory.java +++ b/java/com/android/dialer/enrichedcall/RcsVideoShareFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License */ + package com.android.dialer.enrichedcall; import android.support.annotation.NonNull; diff --git a/java/com/android/dialer/oem/AndroidManifest.xml b/java/com/android/dialer/oem/AndroidManifest.xml index e161a6d14..685bc3d20 100644 --- a/java/com/android/dialer/oem/AndroidManifest.xml +++ b/java/com/android/dialer/oem/AndroidManifest.xml @@ -1,3 +1,18 @@ + + \ No newline at end of file diff --git a/java/com/android/dialer/oem/CequintCallerIdManager.java b/java/com/android/dialer/oem/CequintCallerIdManager.java new file mode 100644 index 000000000..094cc842d --- /dev/null +++ b/java/com/android/dialer/oem/CequintCallerIdManager.java @@ -0,0 +1,297 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.dialer.oem; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.pm.PackageManager; +import android.database.ContentObserver; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build.VERSION_CODES; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.WorkerThread; +import android.telephony.PhoneNumberUtils; +import android.text.TextUtils; +import com.android.dialer.common.Assert; +import com.android.dialer.common.ConfigProviderBindings; +import com.android.dialer.common.LogUtil; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Cequint Caller ID manager to provide caller information. + * + *

This is only enabled on Motorola devices for Sprint. + * + *

If it's enabled, this class will be called by call log and incall to get caller info from + * Cequint Caller ID. It also caches any information fetched in static map, which lives through + * whole application lifecycle. + */ +@TargetApi(VERSION_CODES.M) +public class CequintCallerIdManager { + + private static final String CONFIG_CALLER_ID_ENABLED = "config_caller_id_enabled"; + + private static final String PROVIDER_NAME = "com.cequint.ecid"; + + private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/lookup"); + + private static final int CALLER_ID_LOOKUP_USER_PROVIDED_CID = 0x0001; + private static final int CALLER_ID_LOOKUP_SYSTEM_PROVIDED_CID = 0x0002; + private static final int CALLER_ID_LOOKUP_INCOMING_CALL = 0x0020; + + private static final Uri CONTENT_URI_FOR_INCALL = + Uri.parse("content://" + PROVIDER_NAME + "/incalllookup"); + + // Column names in Cequint provider. + private static final String CITY_NAME = "cid_pCityName"; + private static final String STATE_NAME = "cid_pStateName"; + private static final String STATE_ABBR = "cid_pStateAbbr"; + private static final String COUNTRY_NAME = "cid_pCountryName"; + private static final String COMPANY = "cid_pCompany"; + private static final String NAME = "cid_pName"; + private static final String FIRST_NAME = "cid_pFirstName"; + private static final String LAST_NAME = "cid_pLastName"; + private static final String IMAGE = "cid_pImage"; + private static final String DISPLAY_NAME = "cid_pDisplayName"; + + // TODO: Revisit it and maybe remove it if it's not necessary. + private static final ConcurrentHashMap callLogCache = + new ConcurrentHashMap<>(); + // Cache for incall lookup. Key is phone number + "i" for incoming call or "o" for outgoing call. + // TODO: Revisit it and maybe remove it if it's not necessary. + private static final ConcurrentHashMap incallCache = + new ConcurrentHashMap<>(); + private static boolean hasRegisteredContentObserver; + private static boolean hasAlreadyCheckedCequintCallerIdPackage; + private static boolean isCequintCallerIdEnabled; + + /** Cequint caller id contact information. */ + public static class CequintCallerIdContact { + public final String name; + public final String geoDescription; + public final String imageUrl; + + private CequintCallerIdContact(String name, String geoDescription, String imageUrl) { + this.name = name; + this.geoDescription = geoDescription; + this.imageUrl = imageUrl; + } + } + + /** Check whether Cequint Caller Id provider package is available and enabled. */ + public static synchronized boolean isCequintCallerIdEnabled(@NonNull Context context) { + if (!ConfigProviderBindings.get(context).getBoolean(CONFIG_CALLER_ID_ENABLED, true)) { + return false; + } + if (!hasAlreadyCheckedCequintCallerIdPackage) { + hasAlreadyCheckedCequintCallerIdPackage = true; + isCequintCallerIdEnabled = false; + + try { + context.getPackageManager().getPackageInfo(PROVIDER_NAME, 0); + isCequintCallerIdEnabled = true; + } catch (PackageManager.NameNotFoundException e) { + isCequintCallerIdEnabled = false; + } + } + return isCequintCallerIdEnabled; + } + + @WorkerThread + public static CequintCallerIdContact getCequintCallerIdContact(Context context, String number) { + Assert.isWorkerThread(); + LogUtil.d( + "CequintCallerIdManager.getCequintCallerIdContact", + "number: %s", + LogUtil.sanitizePhoneNumber(number)); + registerContentObserver(context); + if (callLogCache.containsKey(number)) { + return callLogCache.get(number); + } + CequintCallerIdContact cequintCallerIdContact = + lookup( + context, + CONTENT_URI, + PhoneNumberUtils.stripSeparators(number), + new String[] {"system"}); + if (cequintCallerIdContact != null) { + callLogCache.put(number, cequintCallerIdContact); + } + return cequintCallerIdContact; + } + + @WorkerThread + public static CequintCallerIdContact getCequintCallerIdContactForInCall( + Context context, String number, String cnapName, boolean isIncoming) { + Assert.isWorkerThread(); + LogUtil.d( + "CequintCallerIdManager.getCequintCallerIdContactForInCall", + "number: %s, cnapName: %s, isIncoming: %b", + LogUtil.sanitizePhoneNumber(number), + LogUtil.sanitizePii(cnapName), + isIncoming); + registerContentObserver(context); + String key = number + (isIncoming ? "i" : "o"); + if (incallCache.containsKey(key)) { + return incallCache.get(key); + } + int flag = 0; + if (isIncoming) { + flag |= CALLER_ID_LOOKUP_INCOMING_CALL; + flag |= CALLER_ID_LOOKUP_SYSTEM_PROVIDED_CID; + } else { + flag |= CALLER_ID_LOOKUP_USER_PROVIDED_CID; + } + String[] flags = {cnapName, String.valueOf(flag)}; + CequintCallerIdContact cequintCallerIdContact = + lookup(context, CONTENT_URI_FOR_INCALL, number, flags); + if (cequintCallerIdContact != null) { + incallCache.put(key, cequintCallerIdContact); + } + return cequintCallerIdContact; + } + + @WorkerThread + @Nullable + private static CequintCallerIdContact lookup( + Context context, Uri uri, String number, String[] flags) { + Assert.isWorkerThread(); + + // Cequint is using custom arguments for content provider. See more details in b/35766080. + try (Cursor cursor = context.getContentResolver().query(uri, null, number, flags, null)) { + if (cursor != null && cursor.moveToFirst()) { + String city = getString(cursor, cursor.getColumnIndex(CITY_NAME)); + String state = getString(cursor, cursor.getColumnIndex(STATE_NAME)); + String stateAbbr = getString(cursor, cursor.getColumnIndex(STATE_ABBR)); + String country = getString(cursor, cursor.getColumnIndex(COUNTRY_NAME)); + String company = getString(cursor, cursor.getColumnIndex(COMPANY)); + String name = getString(cursor, cursor.getColumnIndex(NAME)); + String firstName = getString(cursor, cursor.getColumnIndex(FIRST_NAME)); + String lastName = getString(cursor, cursor.getColumnIndex(LAST_NAME)); + String imageUrl = getString(cursor, cursor.getColumnIndex(IMAGE)); + String displayName = getString(cursor, cursor.getColumnIndex(DISPLAY_NAME)); + + String contactName = + TextUtils.isEmpty(displayName) + ? generateDisplayName(firstName, lastName, company, name) + : displayName; + String geoDescription = getGeoDescription(city, state, stateAbbr, country); + LogUtil.d( + "CequintCallerIdManager.lookup", + "number: %s, contact name: %s, geo: %s, photo url: %s", + LogUtil.sanitizePhoneNumber(number), + LogUtil.sanitizePii(contactName), + LogUtil.sanitizePii(geoDescription), + imageUrl); + return new CequintCallerIdContact(contactName, geoDescription, imageUrl); + } else { + LogUtil.d("CequintCallerIdManager.lookup", "No CequintCallerIdContact found"); + return null; + } + } + } + + private static String getString(Cursor cursor, int columnIndex) { + if (!cursor.isNull(columnIndex)) { + String string = cursor.getString(columnIndex); + if (!TextUtils.isEmpty(string)) { + return string; + } + } + return null; + } + + /** + * Returns generated name from other names, e.g. first name, last name etc. Returns null if there + * is no other names. + */ + @Nullable + private static String generateDisplayName( + String firstName, String lastName, String company, String name) { + boolean hasFirstName = !TextUtils.isEmpty(firstName); + boolean hasLastName = !TextUtils.isEmpty(lastName); + boolean hasCompanyName = !TextUtils.isEmpty(company); + boolean hasName = !TextUtils.isEmpty(name); + + StringBuilder stringBuilder = new StringBuilder(); + + if (hasFirstName || hasLastName) { + if (hasFirstName) { + stringBuilder.append(firstName); + if (hasLastName) { + stringBuilder.append(" "); + } + } + if (hasLastName) { + stringBuilder.append(lastName); + } + } else if (hasCompanyName) { + stringBuilder.append(company); + } else if (hasName) { + stringBuilder.append(name); + } else { + return null; + } + + if (stringBuilder.length() > 0) { + return stringBuilder.toString(); + } + return null; + } + + /** Returns geo location information. e.g. Mountain View, CA. */ + private static String getGeoDescription( + String city, String state, String stateAbbr, String country) { + String geoDescription = null; + + if (TextUtils.isEmpty(city) && !TextUtils.isEmpty(state)) { + geoDescription = state; + } else if (!TextUtils.isEmpty(city) && !TextUtils.isEmpty(stateAbbr)) { + geoDescription = city + ", " + stateAbbr; + } else if (!TextUtils.isEmpty(country)) { + geoDescription = country; + } + return geoDescription; + } + + private static void registerContentObserver(Context context) { + if (hasRegisteredContentObserver) { + return; + } + ContentObserver contentObserver = + new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + invalidateCache(); + } + }; + + context.getContentResolver().registerContentObserver(CONTENT_URI, true, contentObserver); + context + .getContentResolver() + .registerContentObserver(CONTENT_URI_FOR_INCALL, true, contentObserver); + hasRegisteredContentObserver = true; + } + + private static void invalidateCache() { + callLogCache.clear(); + incallCache.clear(); + } + + private CequintCallerIdManager() {} +} diff --git a/java/com/android/dialer/phonenumbercache/ContactInfo.java b/java/com/android/dialer/phonenumbercache/ContactInfo.java index d7a75c34f..03240cc62 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfo.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfo.java @@ -38,6 +38,7 @@ public class ContactInfo { public String label; public String number; public String formattedNumber; + public String geoDescription; /* * ContactInfo.normalizedNumber is a column value returned by PhoneLookup query. By definition, * it's E164 representation. @@ -121,7 +122,13 @@ public class ContactInfo { if (userType != other.userType) { return false; } - return carrierPresence == other.carrierPresence; + if (carrierPresence != other.carrierPresence) { + return false; + } + if (!TextUtils.equals(geoDescription, other.geoDescription)) { + return false; + } + return true; } @Override @@ -160,6 +167,8 @@ public class ContactInfo { + userType + ", carrierPresence=" + carrierPresence + + ", geoDescription=" + + geoDescription + '}'; } } diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java index 6a5e2e6b4..66ddd06fd 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -33,12 +33,14 @@ import android.provider.ContactsContract.PhoneLookup; import android.support.annotation.Nullable; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; -import android.util.Log; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.ContactsUtils.UserType; import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.UriUtils; +import com.android.dialer.common.LogUtil; +import com.android.dialer.oem.CequintCallerIdManager; +import com.android.dialer.oem.CequintCallerIdManager.CequintCallerIdContact; import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.telecom.TelecomUtil; @@ -131,7 +133,7 @@ public class ContactInfoHelper { } } catch (IllegalArgumentException e) { // Avoid dialer crash when lookup key is not valid - Log.e(TAG, "IllegalArgumentException in lookUpDisplayNameAlternative", e); + LogUtil.e(TAG, "IllegalArgumentException in lookUpDisplayNameAlternative", e); } finally { if (cursor != null) { cursor.close(); @@ -508,6 +510,11 @@ public class ContactInfoHelper { values.put(Calls.CACHED_FORMATTED_NUMBER, updatedInfo.formattedNumber); needsUpdate = true; } + + if (!TextUtils.equals(updatedInfo.geoDescription, callLogInfo.geoDescription)) { + values.put(Calls.GEOCODED_LOCATION, updatedInfo.geoDescription); + needsUpdate = true; + } } else { // No previous values, store all of them. values.put(Calls.CACHED_NAME, updatedInfo.name); @@ -521,6 +528,7 @@ public class ContactInfoHelper { Calls.CACHED_PHOTO_URI, UriUtils.uriToString(UriUtils.nullForNonContactsUri(updatedInfo.photoUri))); values.put(Calls.CACHED_FORMATTED_NUMBER, updatedInfo.formattedNumber); + values.put(Calls.GEOCODED_LOCATION, updatedInfo.geoDescription); needsUpdate = true; } @@ -547,7 +555,7 @@ public class ContactInfoHelper { new String[] {number, countryIso}); } } catch (SQLiteFullException e) { - Log.e(TAG, "Unable to update contact info in call log db", e); + LogUtil.e(TAG, "Unable to update contact info in call log db", e); } } @@ -583,4 +591,28 @@ public class ContactInfoHelper { return mCachedNumberLookupService != null && mCachedNumberLookupService.canReportAsInvalid(sourceType, objectId); } + + /** + * Update ContactInfo by querying to Cequint Caller ID. Only name, geoDescription and photo uri + * will be updated if available. + */ + public void updateFromCequintCallerId(ContactInfo info, String number) { + if (!CequintCallerIdManager.isCequintCallerIdEnabled(mContext)) { + return; + } + CequintCallerIdContact cequintCallerIdContact = + CequintCallerIdManager.getCequintCallerIdContact(mContext, number); + if (cequintCallerIdContact == null) { + return; + } + if (!TextUtils.isEmpty(cequintCallerIdContact.name)) { + info.name = cequintCallerIdContact.name; + } + if (!TextUtils.isEmpty(cequintCallerIdContact.geoDescription)) { + info.geoDescription = cequintCallerIdContact.geoDescription; + } + if (cequintCallerIdContact.imageUrl != null) { + info.photoUri = UriUtils.parseUriOrNull(cequintCallerIdContact.imageUrl); + } + } } diff --git a/java/com/android/dialer/shortcuts/ShortcutRefresher.java b/java/com/android/dialer/shortcuts/ShortcutRefresher.java index f5ff64874..120382dc5 100644 --- a/java/com/android/dialer/shortcuts/ShortcutRefresher.java +++ b/java/com/android/dialer/shortcuts/ShortcutRefresher.java @@ -23,10 +23,10 @@ import android.support.annotation.NonNull; import android.support.annotation.WorkerThread; import com.android.contacts.common.list.ContactEntry; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; -import com.android.dialer.common.FallibleAsyncTask; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.AsyncTaskExecutor; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; +import com.android.dialer.common.concurrent.FallibleAsyncTask; import java.util.ArrayList; import java.util.List; diff --git a/java/com/android/dialer/shortcuts/ShortcutUsageReporter.java b/java/com/android/dialer/shortcuts/ShortcutUsageReporter.java index 50130fc49..3f0b2a632 100644 --- a/java/com/android/dialer/shortcuts/ShortcutUsageReporter.java +++ b/java/com/android/dialer/shortcuts/ShortcutUsageReporter.java @@ -35,9 +35,9 @@ import android.support.annotation.WorkerThread; import android.support.v4.content.ContextCompat; import android.text.TextUtils; import com.android.dialer.common.Assert; -import com.android.dialer.common.AsyncTaskExecutor; -import com.android.dialer.common.AsyncTaskExecutors; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.AsyncTaskExecutor; +import com.android.dialer.common.concurrent.AsyncTaskExecutors; /** * Reports outgoing calls as shortcut usage. -- cgit v1.2.3