diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-12-23 01:33:12 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-12-23 01:33:12 +0000 |
commit | 0e130eb65c12f52417c731e28330f96b8f71521d (patch) | |
tree | d4e7ce266ed0add41dac2b5fd7a08a3e696beeb0 /java/com/android/dialer/precall/impl | |
parent | 40795d57a3e0d2147bd3db694f3f585602b78a8f (diff) | |
parent | 2f084815ea44664bebe82c0c98c498b27240a120 (diff) |
Merge "Enable multi-sim support in assisted dialing."
Diffstat (limited to 'java/com/android/dialer/precall/impl')
-rw-r--r-- | java/com/android/dialer/precall/impl/AssistedDialAction.java | 52 |
1 files changed, 50 insertions, 2 deletions
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> 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()); |