From c1623fe219f3229bf9191afdcf0667efd0f549b8 Mon Sep 17 00:00:00 2001 From: twyen Date: Thu, 25 Jan 2018 15:54:00 -0800 Subject: Remove non call log dependencies on PhoneAccountUtil Methods moved to TelecomUtils Test: Unit tests PiperOrigin-RevId: 183305626 Change-Id: Idd6604e58c06a36066bd49870849dd71747969c6 --- java/com/android/dialer/telecom/TelecomUtil.java | 30 ++++++++++++++++++++++++ 1 file changed, 30 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 f79ca8607..56349b651 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -18,6 +18,7 @@ package com.android.dialer.telecom; import android.Manifest; import android.Manifest.permission; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -49,6 +50,7 @@ import java.util.concurrent.ConcurrentHashMap; * perform the required check and return the fallback default if the permission is missing, * otherwise return the value from TelecomManager. */ +@SuppressWarnings("MissingPermission") public abstract class TelecomUtil { private static final String TAG = "TelecomUtil"; @@ -148,6 +150,34 @@ public abstract class TelecomUtil { return new ArrayList<>(); } + /** Return a list of phone accounts that are subscription/SIM accounts. */ + public static List getSubscriptionPhoneAccounts(Context context) { + List subscriptionAccountHandles = new ArrayList<>(); + final List accountHandles = + TelecomUtil.getCallCapablePhoneAccounts(context); + for (PhoneAccountHandle accountHandle : accountHandles) { + PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); + if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { + subscriptionAccountHandles.add(accountHandle); + } + } + return subscriptionAccountHandles; + } + + /** Compose {@link PhoneAccountHandle} object from component name and account id. */ + @Nullable + public static PhoneAccountHandle composePhoneAccountHandle( + @Nullable String componentString, @Nullable String accountId) { + if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { + return null; + } + final ComponentName componentName = ComponentName.unflattenFromString(componentString); + if (componentName == null) { + return null; + } + return new PhoneAccountHandle(componentName, accountId); + } + /** * @return the {@link SubscriptionInfo} of the SIM if {@code phoneAccountHandle} corresponds to a * valid SIM. Absent otherwise. -- cgit v1.2.3