summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaiyiz <kaiyiz@codeaurora.org>2014-10-22 14:09:50 +0800
committerXiaojing Zhang <zhangx@codeaurora.org>2014-11-04 20:34:54 -0800
commitadab5d2339ae3f2bea73e3b71d5bbb89f9ea1c46 (patch)
treeefb9a8af6c5c4706b7f44432255d75b2136ab72f
parent42b46deb38c2f5fe5f423d5c8de401cf92fae27f (diff)
downloadandroid_packages_apps_ContactsCommon-adab5d2339ae3f2bea73e3b71d5bbb89f9ea1c46.tar.gz
android_packages_apps_ContactsCommon-adab5d2339ae3f2bea73e3b71d5bbb89f9ea1c46.tar.bz2
android_packages_apps_ContactsCommon-adab5d2339ae3f2bea73e3b71d5bbb89f9ea1c46.zip
ContactsCommon: Add sim indicator in contacts history.
Add sim indicator in contacts history of contact detail. Change-Id: I7359300fb8b262b97d3562e51d2b9f1ea2fd09ba
-rw-r--r--src/com/android/contacts/common/util/TelephonyManagerUtils.java70
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);
+ }
}