From 2f084815ea44664bebe82c0c98c498b27240a120 Mon Sep 17 00:00:00 2001 From: erfanian Date: Fri, 22 Dec 2017 15:38:57 -0800 Subject: Enable multi-sim support in assisted dialing. * Add a new flag to enable or disable multi-sim support. * Add a new mock method to the ShadowTelephonyMananger to support N+. * Use new O+ API when available. This logic is client specific, and is unecessary in the platform. Bug: 69861007 Test: new unit tests PiperOrigin-RevId: 179970674 Change-Id: Id9889c81e3c196f4a246f0a604d08b81cc906499 --- .../dialer/assisteddialing/ConcreteCreator.java | 2 +- .../dialer/precall/impl/AssistedDialAction.java | 52 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/java/com/android/dialer/assisteddialing/ConcreteCreator.java b/java/com/android/dialer/assisteddialing/ConcreteCreator.java index 5236ea8eb..a3c96dbdc 100644 --- a/java/com/android/dialer/assisteddialing/ConcreteCreator.java +++ b/java/com/android/dialer/assisteddialing/ConcreteCreator.java @@ -39,7 +39,7 @@ import com.android.dialer.configprovider.ConfigProviderBindings; public final class ConcreteCreator { // Floor set at N due to use of Optional. - protected static final int BUILD_CODE_FLOOR = Build.VERSION_CODES.N; + @VisibleForTesting public static final int BUILD_CODE_FLOOR = Build.VERSION_CODES.N; // Ceiling set at O_MR1 because this feature will ship as part of the framework in P. @VisibleForTesting public static final int BUILD_CODE_CEILING = Build.VERSION_CODES.O_MR1; diff --git a/java/com/android/dialer/precall/impl/AssistedDialAction.java b/java/com/android/dialer/precall/impl/AssistedDialAction.java index dc2510960..77c93279b 100644 --- a/java/com/android/dialer/precall/impl/AssistedDialAction.java +++ b/java/com/android/dialer/precall/impl/AssistedDialAction.java @@ -21,19 +21,24 @@ import android.content.Context; import android.os.Build; import android.os.Bundle; import android.telecom.PhoneAccount; +import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; import com.android.dialer.assisteddialing.AssistedDialingMediator; import com.android.dialer.assisteddialing.ConcreteCreator; import com.android.dialer.assisteddialing.TransformationInfo; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; import com.android.dialer.compat.telephony.TelephonyManagerCompat; +import com.android.dialer.configprovider.ConfigProvider; +import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.precall.PreCallAction; import com.android.dialer.precall.PreCallCoordinator; +import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.CallUtil; import java.util.Optional; -/** Rewrites the call URI with country code. TODO(erfanian): use phone account for multi SIM */ +/** Rewrites the call URI with country code. */ public class AssistedDialAction implements PreCallAction { @Override @@ -48,12 +53,14 @@ public class AssistedDialAction implements PreCallAction { if (!builder.isAssistedDialAllowed()) { return; } + AssistedDialingMediator assistedDialingMediator = ConcreteCreator.createNewAssistedDialingMediator( - context.getSystemService(TelephonyManager.class), context); + getAssistedDialingTelephonyManager(context, builder), context); if (Build.VERSION.SDK_INT > ConcreteCreator.BUILD_CODE_CEILING) { builder.getOutgoingCallExtras().putBoolean(TelephonyManagerCompat.USE_ASSISTED_DIALING, true); } + // Checks the platform is N+ and meets other pre-flight checks. if (!assistedDialingMediator.isPlatformEligible()) { return; } @@ -74,6 +81,47 @@ public class AssistedDialAction implements PreCallAction { } } + /** + * A convenience method to return the proper TelephonyManager in possible multi-sim environments. + */ + @SuppressWarnings("AndroidApiChecker") // Use of createForSubscriptionId + @TargetApi(Build.VERSION_CODES.N) + private TelephonyManager getAssistedDialingTelephonyManager( + Context context, CallIntentBuilder builder) { + + ConfigProvider configProvider = ConfigProviderBindings.get(context); + TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); + // None of this will be required in the framework because the PhoneAccountHandle + // is already mapped to the request in the TelecomConnection. + if (builder.getPhoneAccountHandle() == null) { + return telephonyManager; + } + + if (!configProvider.getBoolean("assisted_dialing_dual_sim_enabled", false)) { + return telephonyManager; + } + + com.google.common.base.Optional subscriptionInfo = + TelecomUtil.getSubscriptionInfo(context, builder.getPhoneAccountHandle()); + if (!subscriptionInfo.isPresent()) { + LogUtil.i( + "AssistedDialAction.getAssistedDialingTelephonyManager", "subcriptionInfo was absent."); + return telephonyManager; + } + TelephonyManager pinnedtelephonyManager = + telephonyManager.createForSubscriptionId(subscriptionInfo.get().getSubscriptionId()); + if (pinnedtelephonyManager == null) { + LogUtil.i( + "AssistedDialAction.getAssistedDialingTelephonyManager", + "createForSubscriptionId pinnedtelephonyManager was null."); + return telephonyManager; + } + LogUtil.i( + "AssistedDialAction.getAssistedDialingTelephonyManager", + "createForPhoneAccountHandle using pinnedtelephonyManager from subscription id."); + return pinnedtelephonyManager; + } + @Override public void runWithUi(PreCallCoordinator coordinator) { runWithoutUi(coordinator.getActivity(), coordinator.getBuilder()); -- cgit v1.2.3