diff options
-rw-r--r-- | src/com/android/dialer/compat/telecom/TelecomManagerCompat.java | 85 | ||||
-rw-r--r-- | src/com/android/dialer/util/DialerUtils.java | 3 | ||||
-rw-r--r-- | src/com/android/dialer/util/TelecomUtil.java | 12 |
3 files changed, 93 insertions, 7 deletions
diff --git a/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java b/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java new file mode 100644 index 000000000..05055a45e --- /dev/null +++ b/src/com/android/dialer/compat/telecom/TelecomManagerCompat.java @@ -0,0 +1,85 @@ +/* + * 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.compat.telecom; + +import android.app.Activity; +import android.content.Intent; +import android.support.annotation.Nullable; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telephony.PhoneNumberUtils; +import android.telephony.TelephonyManager; + +import com.android.contacts.common.compat.CompatUtils; + +/** + * Compatibility class for {@link android.telecom.TelecomManager} + */ +public class TelecomManagerCompat { + + /** + * Places a new outgoing call to the provided address using the system telecom service with + * the specified intent. + * + * @param activity {@link Activity} used to start another activity for the given intent + * @param telecomManager the {@link TelecomManager} used to place a call, if possible + * @param intent the intent for the call + * @throws NullPointerException if activity, telecomManager, or intent are null + */ + public static void placeCall(Activity activity, TelecomManager telecomManager, Intent intent) { + if (CompatUtils.isMarshmallowCompatible()) { + telecomManager.placeCall(intent.getData(), intent.getExtras()); + return; + } + activity.startActivityForResult(intent, 0); + } + + /** + * Return the line 1 phone number for given phone account. + * + * @param telecomManager the {@link TelecomManager} to use in the event that + * {@link TelecomManager#getLine1Number(PhoneAccountHandle)} is available + * @param telephonyManager the {@link TelephonyManager} to use if TelecomManager#getLine1Number + * is unavailable + * @param phoneAccountHandle the phoneAccountHandle upon which to check the line one number + * @return the line one number + * @throws NullPointerException if telecomManager or telephonyManager are null + */ + public static String getLine1Number(TelecomManager telecomManager, + TelephonyManager telephonyManager, @Nullable PhoneAccountHandle phoneAccountHandle) { + if (CompatUtils.isMarshmallowCompatible()) { + return telecomManager.getLine1Number(phoneAccountHandle); + } + return telephonyManager.getLine1Number(); + } + + /** + * Return whether a given phone number is the configured voicemail number for a + * particular phone account. + * + * @param telecomManager the {@link TelecomManager} to use + * @param accountHandle The handle for the account to check the voicemail number against + * @param number The number to look up. + * @throws NullPointerException if telecomManager is null + */ + public static boolean isVoiceMailNumber(TelecomManager telecomManager, + @Nullable PhoneAccountHandle accountHandle, @Nullable String number) { + if (CompatUtils.isMarshmallowCompatible()) { + return telecomManager.isVoiceMailNumber(accountHandle, number); + } + return PhoneNumberUtils.isVoiceMailNumber(number); + } +} diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java index 3d5c257ea..95d6a81b6 100644 --- a/src/com/android/dialer/util/DialerUtils.java +++ b/src/com/android/dialer/util/DialerUtils.java @@ -87,8 +87,7 @@ public class DialerUtils { intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); } - final boolean hasCallPermission = TelecomUtil.placeCall(context, intent.getData(), - intent.getExtras()); + final boolean hasCallPermission = TelecomUtil.placeCall((Activity) context, intent); if (!hasCallPermission) { // TODO: Make calling activity show request permission dialog and handle // callback results appropriately. diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java index a617af6d2..bc6b32d6e 100644 --- a/src/com/android/dialer/util/TelecomUtil.java +++ b/src/com/android/dialer/util/TelecomUtil.java @@ -17,10 +17,11 @@ package com.android.dialer.util; import android.Manifest; +import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; -import android.os.Bundle; import android.provider.CallLog.Calls; import android.support.v4.content.ContextCompat; import android.telecom.PhoneAccountHandle; @@ -32,6 +33,7 @@ import android.util.Log; import com.android.contacts.common.compat.CompatUtils; import com.android.dialer.compat.DialerCompatUtils; +import com.android.dialer.compat.telecom.TelecomManagerCompat; import java.util.ArrayList; import java.util.List; @@ -153,16 +155,16 @@ public class TelecomUtil { /** * Tries to place a call using the {@link TelecomManager}. * - * @param context a valid context. + * @param activity a valid activity. * @param address Handle to call. * @param extras Bundle of extras to attach to the call intent. * * @return {@code true} if we successfully attempted to place the call, {@code false} if it * failed due to a permission check. */ - public static boolean placeCall(Context context, Uri address, Bundle extras) { - if (hasCallPhonePermission(context)) { - getTelecomManager(context).placeCall(address, extras); + public static boolean placeCall(Activity activity, Intent intent) { + if (hasCallPhonePermission(activity)) { + TelecomManagerCompat.placeCall(activity, getTelecomManager(activity), intent); return true; } return false; |