From 00623aa60a7908b0709df38632cfa576cb15e33e Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 10 Oct 2017 12:15:08 -0700 Subject: Implement SIM swapping When the call is still ringing, a new button is added to allow to user to call with the other SIM. A background worker will be created to hang up the phone and redial with the other SIM. The in call UI will be prevented from ending during the process. Video: https://drive.google.com/a/google.com/file/d/0B2eYBUUznfyTSl9MdXQ0V1ZzQkE/view?usp=sharing UX has not been finalized, the icon and position are just placeholder. Bug: 64215256 Test: SwapSimWorkerTest PiperOrigin-RevId: 171715715 Change-Id: Idb3f486e9fc9a45d4c5e244af2d7d91b075bf0f2 --- java/com/android/dialer/telecom/TelecomUtil.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'java/com/android/dialer/telecom') diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java index 8ff4b3967..3bf9b4666 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -17,6 +17,7 @@ package com.android.dialer.telecom; import android.Manifest; +import android.Manifest.permission; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -24,7 +25,9 @@ import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.provider.CallLog.Calls; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.RequiresPermission; import android.support.annotation.VisibleForTesting; import android.support.v4.content.ContextCompat; import android.telecom.PhoneAccount; @@ -234,6 +237,26 @@ public abstract class TelecomUtil { return instance.isDefaultDialer(context); } + /** @return the other SIM based PhoneAccountHandle that is not {@code currentAccount} */ + @Nullable + @RequiresPermission(permission.READ_PHONE_STATE) + @SuppressWarnings("MissingPermission") + public static PhoneAccountHandle getOtherAccount( + @NonNull Context context, @Nullable PhoneAccountHandle currentAccount) { + if (currentAccount == null) { + return null; + } + TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + for (PhoneAccountHandle phoneAccountHandle : telecomManager.getCallCapablePhoneAccounts()) { + PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); + if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION) + && !phoneAccountHandle.equals(currentAccount)) { + return phoneAccountHandle; + } + } + return null; + } + /** Contains an implementation for {@link TelecomUtil} methods */ @VisibleForTesting() public static class TelecomUtilImpl { -- cgit v1.2.3