summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/telecom/TelecomUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/telecom/TelecomUtil.java')
-rw-r--r--java/com/android/dialer/telecom/TelecomUtil.java23
1 files changed, 23 insertions, 0 deletions
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 {