diff options
Diffstat (limited to 'java/com')
-rw-r--r-- | java/com/android/dialer/phonenumbercache/ContactInfoHelper.java | 30 | ||||
-rw-r--r-- | java/com/android/dialer/telecom/TelecomCallUtil.java | 106 | ||||
-rw-r--r-- | java/com/android/incallui/CallerInfo.java | 238 | ||||
-rw-r--r-- | java/com/android/incallui/ExternalCallNotifier.java | 2 | ||||
-rw-r--r-- | java/com/android/incallui/InCallPresenter.java | 4 | ||||
-rw-r--r-- | java/com/android/incallui/PhoneLookupHistoryRecorder.java | 35 | ||||
-rw-r--r-- | java/com/android/incallui/call/CallList.java | 2 | ||||
-rw-r--r-- | java/com/android/incallui/call/DialerCall.java | 2 | ||||
-rw-r--r-- | java/com/android/incallui/util/TelecomCallUtil.java | 51 |
9 files changed, 246 insertions, 224 deletions
diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java index c3f5b692f..39e3866cf 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -337,30 +337,28 @@ public class ContactInfoHelper { return ContactInfo.EMPTY; } - Cursor phoneLookupCursor = null; - try { - String[] projection = PhoneQuery.getPhoneLookupProjection(uri); - phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null); - } catch (NullPointerException e) { - LogUtil.e("ContactInfoHelper.lookupContactFromUri", "phone lookup", e); - // Trap NPE from pre-N CP2 - return null; - } - if (phoneLookupCursor == null) { - LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null"); - return null; - } + try (Cursor phoneLookupCursor = + mContext + .getContentResolver() + .query( + uri, + PhoneQuery.getPhoneLookupProjection(uri), + null /* selection */, + null /* selectionArgs */, + null /* sortOrder */)) { + if (phoneLookupCursor == null) { + LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null"); + return null; + } - try { if (!phoneLookupCursor.moveToFirst()) { return ContactInfo.EMPTY; } + String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY); ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey); fillAdditionalContactInfo(mContext, contactInfo); return contactInfo; - } finally { - phoneLookupCursor.close(); } } 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<String> getNormalizedNumber(Context appContext, Call call) { + Assert.isWorkerThread(); + PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); + Optional<SubscriptionInfo> 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/CallerInfo.java b/java/com/android/incallui/CallerInfo.java index 6f8d1921e..5c43b4f39 100644 --- a/java/com/android/incallui/CallerInfo.java +++ b/java/com/android/incallui/CallerInfo.java @@ -198,135 +198,133 @@ public class CallerInfo { */ public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) { CallerInfo info = new CallerInfo(); - info.photoResource = 0; - info.phoneLabel = null; - info.numberType = 0; - info.numberLabel = null; info.cachedPhoto = null; - info.isCachedPhotoCurrent = false; info.contactExists = false; + info.contactRefUri = contactRef; + info.isCachedPhotoCurrent = false; + info.name = null; + info.needUpdate = false; + info.numberLabel = null; + info.numberType = 0; + info.phoneLabel = null; + info.photoResource = 0; info.userType = ContactsUtils.USER_TYPE_CURRENT; Log.v(TAG, "getCallerInfo() based on cursor..."); - if (cursor != null) { - if (cursor.moveToFirst()) { - // TODO: photo_id is always available but not taken - // care of here. Maybe we should store it in the - // CallerInfo object as well. - - long contactId = 0L; - int columnIndex; - - // Look for the name - columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); - if (columnIndex != -1) { - info.name = cursor.getString(columnIndex); - } - - // Look for the number - columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER); - if (columnIndex != -1) { - info.phoneNumber = cursor.getString(columnIndex); - } - - // Look for the normalized number - columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER); - if (columnIndex != -1) { - info.normalizedNumber = cursor.getString(columnIndex); - } - - // Look for the label/type combo - columnIndex = cursor.getColumnIndex(PhoneLookup.LABEL); - if (columnIndex != -1) { - int typeColumnIndex = cursor.getColumnIndex(PhoneLookup.TYPE); - if (typeColumnIndex != -1) { - info.numberType = cursor.getInt(typeColumnIndex); - info.numberLabel = cursor.getString(columnIndex); - info.phoneLabel = - Phone.getTypeLabel(context.getResources(), info.numberType, info.numberLabel) - .toString(); - } - } - - // cache the lookup key for later use to create lookup URIs - columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY); - if (columnIndex != -1) { - info.lookupKeyOrNull = cursor.getString(columnIndex); - } - - // Look for the person_id. - columnIndex = getColumnIndexForPersonId(contactRef, cursor); - if (columnIndex != -1) { - contactId = cursor.getLong(columnIndex); - // QuickContacts in M doesn't support enterprise contact id - if (contactId != 0 - && (VERSION.SDK_INT >= VERSION_CODES.N - || !Contacts.isEnterpriseContactId(contactId))) { - info.contactIdOrZero = contactId; - Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero); - } - } else { - // No valid columnIndex, so we can't look up person_id. - Log.v(TAG, "Couldn't find contactId column for " + contactRef); - // Watch out: this means that anything that depends on - // person_id will be broken (like contact photo lookups in - // the in-call UI, for example.) - } - - // Display photo URI. - columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI); - if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { - info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex)); - } else { - info.contactDisplayPhotoUri = null; - } - - // look for the custom ringtone, create from the string stored - // in the database. - columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE); - if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { - if (TextUtils.isEmpty(cursor.getString(columnIndex))) { - // make it consistent with frameworks/base/.../CallerInfo.java - info.contactRingtoneUri = Uri.EMPTY; - } else { - info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex)); - } - } else { - info.contactRingtoneUri = null; - } - - // look for the send to voicemail flag, set it to true only - // under certain circumstances. - columnIndex = cursor.getColumnIndex(PhoneLookup.SEND_TO_VOICEMAIL); - info.shouldSendToVoicemail = (columnIndex != -1) && ((cursor.getInt(columnIndex)) == 1); - info.contactExists = true; - - // Determine userType by directoryId and contactId - final String directory = - contactRef == null - ? null - : contactRef.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); - Long directoryId = null; - if (directory != null) { - try { - directoryId = Long.parseLong(directory); - } catch (NumberFormatException e) { - // do nothing - } - } - info.userType = ContactsUtils.determineUserType(directoryId, contactId); - - info.nameAlternative = - ContactInfoHelper.lookUpDisplayNameAlternative( - context, info.lookupKeyOrNull, info.userType, directoryId); + if (cursor == null || !cursor.moveToFirst()) { + return info; + } + + // TODO: photo_id is always available but not taken + // care of here. Maybe we should store it in the + // CallerInfo object as well. + + long contactId = 0L; + int columnIndex; + + // Look for the name + columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); + if (columnIndex != -1) { + info.name = normalize(cursor.getString(columnIndex)); + } + + // Look for the number + columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER); + if (columnIndex != -1) { + info.phoneNumber = cursor.getString(columnIndex); + } + + // Look for the normalized number + columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER); + if (columnIndex != -1) { + info.normalizedNumber = cursor.getString(columnIndex); + } + + // Look for the label/type combo + columnIndex = cursor.getColumnIndex(PhoneLookup.LABEL); + if (columnIndex != -1) { + int typeColumnIndex = cursor.getColumnIndex(PhoneLookup.TYPE); + if (typeColumnIndex != -1) { + info.numberType = cursor.getInt(typeColumnIndex); + info.numberLabel = cursor.getString(columnIndex); + info.phoneLabel = + Phone.getTypeLabel(context.getResources(), info.numberType, info.numberLabel) + .toString(); } - cursor.close(); } - info.needUpdate = false; - info.name = normalize(info.name); - info.contactRefUri = contactRef; + // cache the lookup key for later use to create lookup URIs + columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY); + if (columnIndex != -1) { + info.lookupKeyOrNull = cursor.getString(columnIndex); + } + + // Look for the person_id. + columnIndex = getColumnIndexForPersonId(contactRef, cursor); + if (columnIndex != -1) { + contactId = cursor.getLong(columnIndex); + // QuickContacts in M doesn't support enterprise contact id + if (contactId != 0 + && (VERSION.SDK_INT >= VERSION_CODES.N || !Contacts.isEnterpriseContactId(contactId))) { + info.contactIdOrZero = contactId; + Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero); + } + } else { + // No valid columnIndex, so we can't look up person_id. + Log.v(TAG, "Couldn't find contactId column for " + contactRef); + // Watch out: this means that anything that depends on + // person_id will be broken (like contact photo lookups in + // the in-call UI, for example.) + } + + // Display photo URI. + columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI); + if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { + info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex)); + } else { + info.contactDisplayPhotoUri = null; + } + + // look for the custom ringtone, create from the string stored + // in the database. + columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE); + if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { + if (TextUtils.isEmpty(cursor.getString(columnIndex))) { + // make it consistent with frameworks/base/.../CallerInfo.java + info.contactRingtoneUri = Uri.EMPTY; + } else { + info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex)); + } + } else { + info.contactRingtoneUri = null; + } + + // look for the send to voicemail flag, set it to true only + // under certain circumstances. + columnIndex = cursor.getColumnIndex(PhoneLookup.SEND_TO_VOICEMAIL); + info.shouldSendToVoicemail = (columnIndex != -1) && ((cursor.getInt(columnIndex)) == 1); + info.contactExists = true; + + // Determine userType by directoryId and contactId + final String directory = + contactRef == null + ? null + : contactRef.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); + Long directoryId = null; + if (directory != null) { + try { + directoryId = Long.parseLong(directory); + } catch (NumberFormatException e) { + // do nothing + } + } + info.userType = ContactsUtils.determineUserType(directoryId, contactId); + + info.nameAlternative = + ContactInfoHelper.lookUpDisplayNameAlternative( + context, info.lookupKeyOrNull, info.userType, directoryId); + cursor.close(); return info; } 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<String> normalizedNumber = getNormalizedNumber(appContext, call); + Optional<String> 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<String> getNormalizedNumber(Context appContext, Call call) { - PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); - Optional<SubscriptionInfo> 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(); - } -} |