From a4745bddb3a012c826225df313820ccd8a68455d Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 12 Dec 2017 18:40:11 -0800 Subject: Move TelecomCallUtil to com.android.dialer Since PhoneLookup exposes Call, more common access to the utility is required. Bug: 70355819 Test: TelecomCallUtilTest PiperOrigin-RevId: 178847628 Change-Id: I6cf55ad4e3566596b7b2e8cffb5a1614e6640a8b --- .../android/dialer/telecom/TelecomCallUtil.java | 106 +++++++++++++++++++++ .../com/android/incallui/ExternalCallNotifier.java | 2 +- java/com/android/incallui/InCallPresenter.java | 4 +- .../incallui/PhoneLookupHistoryRecorder.java | 35 +------ java/com/android/incallui/call/CallList.java | 2 +- java/com/android/incallui/call/DialerCall.java | 2 +- .../com/android/incallui/util/TelecomCallUtil.java | 51 ---------- 7 files changed, 114 insertions(+), 88 deletions(-) create mode 100644 java/com/android/dialer/telecom/TelecomCallUtil.java delete mode 100644 java/com/android/incallui/util/TelecomCallUtil.java diff --git a/java/com/android/dialer/telecom/TelecomCallUtil.java b/java/com/android/dialer/telecom/TelecomCallUtil.java new file mode 100644 index 000000000..acec49851 --- /dev/null +++ b/java/com/android/dialer/telecom/TelecomCallUtil.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2015 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.telecom; + +import android.content.Context; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.WorkerThread; +import android.telecom.Call; +import android.telecom.PhoneAccountHandle; +import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionInfo; +import android.text.TextUtils; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.google.common.base.Optional; +import java.util.Locale; + +/** + * Class to provide a standard interface for obtaining information from the underlying + * android.telecom.Call. Much of this should be obtained through the incall.Call, but on occasion we + * need to interact with the telecom.Call directly (eg. call blocking, before the incall.Call has + * been created). + */ +public class TelecomCallUtil { + + /** Returns Whether the call handle is an emergency number. */ + public static boolean isEmergencyCall(@NonNull Call call) { + Assert.isNotNull(call); + Uri handle = call.getDetails().getHandle(); + return PhoneNumberUtils.isEmergencyNumber(handle == null ? "" : handle.getSchemeSpecificPart()); + } + + /** + * Returns The phone number which the {@code Call} is currently connected, or {@code null} if the + * number is not available. + */ + @Nullable + public static String getNumber(@Nullable Call call) { + if (call == null) { + return null; + } + if (call.getDetails().getGatewayInfo() != null) { + return call.getDetails().getGatewayInfo().getOriginalAddress().getSchemeSpecificPart(); + } + Uri handle = getHandle(call); + return handle == null ? null : handle.getSchemeSpecificPart(); + } + + /** + * Returns The handle (e.g., phone number) to which the {@code Call} is currently connected, or + * {@code null} if the number is not available. + */ + @Nullable + public static Uri getHandle(@Nullable Call call) { + return call == null ? null : call.getDetails().getHandle(); + } + + /** + * Normalizes the number of the {@code call} to E.164. If the country code is missing in the + * number the SIM's country will be used. Only removes non-dialable digits if the country code is + * missing. + */ + @WorkerThread + public static Optional getNormalizedNumber(Context appContext, Call call) { + Assert.isWorkerThread(); + PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); + Optional subscriptionInfo = + TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle); + String rawNumber = getNumber(call); + if (TextUtils.isEmpty(rawNumber)) { + return Optional.absent(); + } + String normalizedNumber = PhoneNumberUtils.normalizeNumber(rawNumber); + if (TextUtils.isEmpty(normalizedNumber)) { + return Optional.absent(); + } + String countryCode = + subscriptionInfo.isPresent() ? subscriptionInfo.get().getCountryIso() : null; + if (countryCode == null) { + LogUtil.w( + "PhoneLookupHistoryRecorder.getNormalizedNumber", + "couldn't find a country code for call"); + return Optional.of(normalizedNumber); + } + + String e164Number = + PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US)); + return e164Number == null ? Optional.of(normalizedNumber) : Optional.of(e164Number); + } +} diff --git a/java/com/android/incallui/ExternalCallNotifier.java b/java/com/android/incallui/ExternalCallNotifier.java index 9e7805236..7915b85af 100644 --- a/java/com/android/incallui/ExternalCallNotifier.java +++ b/java/com/android/incallui/ExternalCallNotifier.java @@ -44,11 +44,11 @@ import com.android.dialer.common.Assert; import com.android.dialer.contactphoto.BitmapUtil; import com.android.dialer.notification.DialerNotificationManager; import com.android.dialer.notification.NotificationChannelId; +import com.android.dialer.telecom.TelecomCallUtil; import com.android.incallui.call.DialerCall; import com.android.incallui.call.DialerCallDelegate; import com.android.incallui.call.ExternalCallList; import com.android.incallui.latencyreport.LatencyReport; -import com.android.incallui.util.TelecomCallUtil; import java.util.Map; /** diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java index f8605ae7c..3debd704e 100644 --- a/java/com/android/incallui/InCallPresenter.java +++ b/java/com/android/incallui/InCallPresenter.java @@ -52,6 +52,7 @@ import com.android.dialer.location.GeoUtil; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.postcall.PostCall; +import com.android.dialer.telecom.TelecomCallUtil; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.TouchPointManager; import com.android.incallui.InCallOrientationEventListener.ScreenOrientation; @@ -66,7 +67,6 @@ import com.android.incallui.incalluilock.InCallUiLock; import com.android.incallui.latencyreport.LatencyReport; import com.android.incallui.legacyblocking.BlockedNumberContentObserver; import com.android.incallui.spam.SpamCallListListener; -import com.android.incallui.util.TelecomCallUtil; import com.android.incallui.videosurface.bindings.VideoSurfaceBindings; import com.android.incallui.videosurface.protocol.VideoSurfaceTexture; import com.android.incallui.videotech.utils.VideoUtils; @@ -213,7 +213,7 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud } } }; - + /** Whether or not InCallService is bound to Telecom. */ private boolean mServiceBound = false; diff --git a/java/com/android/incallui/PhoneLookupHistoryRecorder.java b/java/com/android/incallui/PhoneLookupHistoryRecorder.java index 2632e6515..667c0d1cc 100644 --- a/java/com/android/incallui/PhoneLookupHistoryRecorder.java +++ b/java/com/android/incallui/PhoneLookupHistoryRecorder.java @@ -19,25 +19,18 @@ import android.content.ContentValues; import android.content.Context; import android.support.annotation.Nullable; import android.telecom.Call; -import android.telecom.PhoneAccountHandle; -import android.telephony.PhoneNumberUtils; -import android.telephony.SubscriptionInfo; -import android.text.TextUtils; import com.android.dialer.buildtype.BuildType; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutors; -import com.android.dialer.location.CountryDetector; import com.android.dialer.phonelookup.PhoneLookupComponent; import com.android.dialer.phonelookup.PhoneLookupInfo; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory; -import com.android.dialer.telecom.TelecomUtil; -import com.android.incallui.util.TelecomCallUtil; +import com.android.dialer.telecom.TelecomCallUtil; import com.google.common.base.Optional; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.util.Locale; /** * Fetches the current {@link PhoneLookupInfo} for the provided call and writes it to the @@ -61,7 +54,8 @@ final class PhoneLookupHistoryRecorder { @Override public void onSuccess(@Nullable PhoneLookupInfo result) { Assert.checkArgument(result != null); - Optional normalizedNumber = getNormalizedNumber(appContext, call); + Optional normalizedNumber = + TelecomCallUtil.getNormalizedNumber(appContext, call); if (!normalizedNumber.isPresent()) { LogUtil.w("PhoneLookupHistoryRecorder.onSuccess", "couldn't get a number"); return; @@ -90,27 +84,4 @@ final class PhoneLookupHistoryRecorder { }, DialerExecutors.getLowPriorityThreadPool(appContext)); } - - private static Optional getNormalizedNumber(Context appContext, Call call) { - PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); - Optional subscriptionInfo = - TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle); - String countryCode = - subscriptionInfo.isPresent() - ? subscriptionInfo.get().getCountryIso() - : CountryDetector.getInstance(appContext).getCurrentCountryIso(); - if (countryCode == null) { - LogUtil.w( - "PhoneLookupHistoryRecorder.getNormalizedNumber", - "couldn't find a country code for call"); - countryCode = "US"; - } - String rawNumber = TelecomCallUtil.getNumber(call); - if (TextUtils.isEmpty(rawNumber)) { - return Optional.absent(); - } - String normalizedNumber = - PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US)); - return normalizedNumber == null ? Optional.of(rawNumber) : Optional.of(normalizedNumber); - } } diff --git a/java/com/android/incallui/call/CallList.java b/java/com/android/incallui/call/CallList.java index d2ac483a7..150b20e28 100644 --- a/java/com/android/incallui/call/CallList.java +++ b/java/com/android/incallui/call/CallList.java @@ -40,9 +40,9 @@ import com.android.dialer.logging.LoggingBindings; import com.android.dialer.shortcuts.ShortcutUsageReporter; import com.android.dialer.spam.Spam; import com.android.dialer.spam.SpamComponent; +import com.android.dialer.telecom.TelecomCallUtil; import com.android.incallui.call.DialerCall.State; import com.android.incallui.latencyreport.LatencyReport; -import com.android.incallui.util.TelecomCallUtil; import com.android.incallui.videotech.utils.SessionModificationState; import java.util.Collection; import java.util.Collections; diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java index e8523d650..812024904 100644 --- a/java/com/android/incallui/call/DialerCall.java +++ b/java/com/android/incallui/call/DialerCall.java @@ -64,12 +64,12 @@ import com.android.dialer.logging.ContactLookupResult; import com.android.dialer.logging.ContactLookupResult.Type; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.telecom.TelecomCallUtil; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.theme.R; import com.android.dialer.util.PermissionsUtil; import com.android.incallui.audiomode.AudioModeProvider; import com.android.incallui.latencyreport.LatencyReport; -import com.android.incallui.util.TelecomCallUtil; import com.android.incallui.videotech.VideoTech; import com.android.incallui.videotech.VideoTech.VideoTechListener; import com.android.incallui.videotech.duo.DuoVideoTech; diff --git a/java/com/android/incallui/util/TelecomCallUtil.java b/java/com/android/incallui/util/TelecomCallUtil.java deleted file mode 100644 index 8855543b1..000000000 --- a/java/com/android/incallui/util/TelecomCallUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2015 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.incallui.util; - -import android.net.Uri; -import android.telecom.Call; -import android.telephony.PhoneNumberUtils; - -/** - * Class to provide a standard interface for obtaining information from the underlying - * android.telecom.Call. Much of this should be obtained through the incall.Call, but on occasion we - * need to interact with the telecom.Call directly (eg. call blocking, before the incall.Call has - * been created). - */ -public class TelecomCallUtil { - - // Whether the call handle is an emergency number. - public static boolean isEmergencyCall(Call call) { - Uri handle = call.getDetails().getHandle(); - return PhoneNumberUtils.isEmergencyNumber(handle == null ? "" : handle.getSchemeSpecificPart()); - } - - public static String getNumber(Call call) { - if (call == null) { - return null; - } - if (call.getDetails().getGatewayInfo() != null) { - return call.getDetails().getGatewayInfo().getOriginalAddress().getSchemeSpecificPart(); - } - Uri handle = getHandle(call); - return handle == null ? null : handle.getSchemeSpecificPart(); - } - - public static Uri getHandle(Call call) { - return call == null ? null : call.getDetails().getHandle(); - } -} -- cgit v1.2.3