summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErica Chang <echang@cyngn.com>2016-03-18 12:19:31 -0700
committerRichard MacGregor <rmacgregor@cyngn.com>2016-04-08 10:42:51 -0700
commit89e55274354e5c1ba727574da3e81e1451c01a02 (patch)
treead1f73f5ef2126a02428929eb6272911dc5d245f
parent27e78ce4d5350e006e74966f9dc864ef3401a954 (diff)
downloadandroid_packages_apps_PhoneCommon-89e55274354e5c1ba727574da3e81e1451c01a02.tar.gz
android_packages_apps_PhoneCommon-89e55274354e5c1ba727574da3e81e1451c01a02.tar.bz2
android_packages_apps_PhoneCommon-89e55274354e5c1ba727574da3e81e1451c01a02.zip
[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
-rw-r--r--src-ambient/incall/CallMethodHelper.java40
-rw-r--r--src-ambient/incall/CallMethodUtils.java47
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<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(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<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)));
+ }
}