diff options
Diffstat (limited to 'src-ambient/incall/CallMethodUtils.java')
-rw-r--r-- | src-ambient/incall/CallMethodUtils.java | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src-ambient/incall/CallMethodUtils.java b/src-ambient/incall/CallMethodUtils.java index 2d2d86f..87a2348 100644 --- a/src-ambient/incall/CallMethodUtils.java +++ b/src-ambient/incall/CallMethodUtils.java @@ -1,5 +1,6 @@ package com.android.phone.common.incall; +import android.content.ComponentName; import android.content.Context; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; @@ -7,7 +8,13 @@ import android.telecom.TelecomManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; +import android.text.TextUtils; +import android.util.ArrayMap; +import android.util.Log; +import com.android.contacts.common.model.AccountTypeManager; +import com.android.contacts.common.model.account.AccountType; +import com.android.contacts.common.model.account.AccountWithDataSet; import com.android.phone.common.R; import java.util.ArrayList; @@ -19,7 +26,8 @@ import static com.cyanogen.ambient.incall.util.InCallHelper.NO_COLOR; * Basic Utils for call method modifications */ public class CallMethodUtils { - + private final static String TAG = CallMethodUtils.class.getSimpleName(); + private final static boolean DEBUG = false; public final static String PREF_SPINNER_COACHMARK_SHOW = "pref_spinner_coachmark_shown"; public final static String PREF_LAST_ENABLED_PROVIDER = "pref_last_enabled_provider"; public final static String PREF_INTERNATIONAL_CALLS = "pref_international_calls"; @@ -103,4 +111,41 @@ public class CallMethodUtils { return callMethodInfo; } + + /* + * Look up the currently logged in plugin account in case plugin fails to return a valid + * account handle + */ + public static String lookupAccountHandle(Context context, String targetAccountType) { + // Gather account handles logged into the device as a backup, in case + // plugins fail to return the account handle even when it reports its + // state as authenticated + AccountTypeManager accountTypes = AccountTypeManager.getInstance(context); + List<AccountWithDataSet> accounts = accountTypes.getAccounts(false); + ArrayMap<String, String> accountMap = new ArrayMap<String, String>(); + + for (AccountWithDataSet account : accounts) { + AccountType accountType = + accountTypes.getAccountType(account.type, account.dataSet); + if (accountType.isExtension() && !account.hasData(context)) { + // Hide extensions with no raw_contacts. + continue; + } + if (DEBUG) { + Log.d(TAG, "account.type: " + account.type + "account.name: " + account.name); + } + // currently only handle one account per account type use case + accountMap.put(account.type, account.name); + } + return accountMap.containsKey(targetAccountType) ? accountMap.get(targetAccountType) : ""; + } + + /* + * Return if the plugin is a soft logged-out state (authenticated is false and there's still + * an account saved in account manager) + */ + public static boolean isSoftLoggedOut(Context context, CallMethodInfo cmi) { + return (!cmi.mIsAuthenticated && !TextUtils.isEmpty(lookupAccountHandle(context, + cmi.mAccountType))); + } } |