diff options
-rw-r--r-- | src/com/android/contacts/common/util/TelephonyManagerUtils.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/android/contacts/common/util/TelephonyManagerUtils.java b/src/com/android/contacts/common/util/TelephonyManagerUtils.java index 7c322ca0..01232859 100644 --- a/src/com/android/contacts/common/util/TelephonyManagerUtils.java +++ b/src/com/android/contacts/common/util/TelephonyManagerUtils.java @@ -15,12 +15,19 @@ */ package com.android.contacts.common.util; +import android.content.ComponentName; import android.content.Context; +import android.graphics.drawable.Drawable; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; +import java.util.List; import java.util.Locale; /** @@ -70,4 +77,67 @@ public class TelephonyManagerUtils { // TODO: Check the telephony manager's subscriptions to see if any support video calls. return true; } + + /** + * Retrieve the account metadata, but if the account does not exist or the device has only a + * single registered and enabled account, return null. + */ + private static PhoneAccount getAccountOrNull(Context context, + PhoneAccountHandle phoneAccount) { + final TelecomManager telecomManager = + (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); + final PhoneAccount account = telecomManager.getPhoneAccount(phoneAccount); + if (account == null || !telecomManager.hasMultipleCallCapableAccounts()) { + return null; + } + return account; + } + + /** + * Generate account info from data in Telecomm database + */ + public static PhoneAccountHandle getAccount(String componentString, + String accountId) { + if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { + return null; + } + final ComponentName componentName = ComponentName.unflattenFromString(componentString); + return new PhoneAccountHandle(componentName, accountId); + } + + /** + * Generate account icon from data in Telecomm database + */ + public static Drawable getAccountIcon(Context context, PhoneAccountHandle phoneAccount) { + final PhoneAccount account = getAccountOrNull(context, phoneAccount); + if (account == null) { + return null; + } + return account.getIcon(context); + } + + public static Drawable getMultiSimIcon(Context context, int subscription) { + if (context == null) { + // If the context is null, return 0 as no resource found. + return null; + } + + long subId[] = SubscriptionManager.getSubId(subscription); + final TelecomManager telecomManager = (TelecomManager) context + .getSystemService(Context.TELECOM_SERVICE); + List<PhoneAccountHandle> pHandles = telecomManager.getCallCapablePhoneAccounts(); + PhoneAccountHandle phoneAccountHandle = null; + for (PhoneAccountHandle itorator : pHandles) { + if (String.valueOf(subId[0]).equals(itorator.getId())) { + phoneAccountHandle = itorator; + } + } + + if (phoneAccountHandle == null) { + return null; + } + final PhoneAccount account = telecomManager + .getPhoneAccount(phoneAccountHandle); + return account.getIcon(context); + } } |