From 89e55274354e5c1ba727574da3e81e1451c01a02 Mon Sep 17 00:00:00 2001 From: Erica Chang Date: Fri, 18 Mar 2016 12:19:31 -0700 Subject: [1/2]Contacts : handle soft logged out state Rearranged util function checkUserHandle which queries plugin account from Account Manager to check if we're in a soft logged out state CD-450 Change-Id: I4cb6b7555a4cd6c91ae9155d29863ec3154945ed --- src-ambient/incall/CallMethodHelper.java | 40 ++++----------------------- src-ambient/incall/CallMethodUtils.java | 47 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src-ambient/incall/CallMethodHelper.java b/src-ambient/incall/CallMethodHelper.java index c96fad7..623a9e2 100644 --- a/src-ambient/incall/CallMethodHelper.java +++ b/src-ambient/incall/CallMethodHelper.java @@ -29,13 +29,9 @@ import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; import android.text.TextUtils; -import android.util.ArrayMap; import android.util.Log; import android.widget.Toast; -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 com.android.phone.common.ambient.AmbientConnection; import com.android.phone.common.util.StartInCallCallReceiver; @@ -568,35 +564,6 @@ public class CallMethodHelper { } } - /* - * Look up the currently logged in plugin account in case plugin fails to return a valid - * account handle - */ - private static String lookupAccountHandle(ComponentName cn, 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(getInstance().mContext); - List accounts = accountTypes.getAccounts(false); - ArrayMap accountMap = new ArrayMap(); - - for (AccountWithDataSet account : accounts) { - AccountType accountType = - accountTypes.getAccountType(account.type, account.dataSet); - if (accountType.isExtension() && - !account.hasData(getInstance().mContext)) { - // 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) : ""; - } - /** * Get the plugin info * @param cn @@ -680,7 +647,8 @@ public class CallMethodHelper { cmi.mAccountType = icpi.getAccountType(); cmi.mAccountHandle = icpi.getAccountHandle(); if (TextUtils.isEmpty(cmi.mAccountHandle)) { - cmi.mAccountHandle = lookupAccountHandle(cn, cmi.mAccountType); + cmi.mAccountHandle = CallMethodUtils.lookupAccountHandle( + getInstance().mContext, cmi.mAccountType); } cmi.mBrandIconId = icpi.getBrandIcon(); cmi.mLoginIconId = icpi.getLoginIcon(); @@ -858,7 +826,9 @@ public class CallMethodHelper { if (cmi != null) { cmi.mAccountHandle = result.accountHandle; if (TextUtils.isEmpty(cmi.mAccountHandle)) { - cmi.mAccountHandle = lookupAccountHandle(cn, cmi.mAccountType); + cmi.mAccountHandle = + CallMethodUtils.lookupAccountHandle( + getInstance().mContext, cmi.mAccountType); } mCallMethodInfos.put(cn, cmi); maybeBroadcastToSubscribers(this, apiCallbacks); 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 accounts = accountTypes.getAccounts(false); + ArrayMap accountMap = new ArrayMap(); + + 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))); + } } -- cgit v1.2.3