From 00120c2802ae5aa6cec947b5a6ac1c8eb37e52fa Mon Sep 17 00:00:00 2001 From: Erica Chang Date: Mon, 7 Mar 2016 17:57:39 -0800 Subject: (2/2) Contacts: fixed auth state handling and account handle Contacts wasn't able to update the fragment UI properly with the auth state change. Also needed to lookup account handle in the event where the plugin fails to report a valid one. Issue-id: CD-448, CD-449 Change-Id: I118ba8bd152af19fbffee6a218c622d631aaf979 --- .../contacts/activities/PeopleActivity.java | 23 +++-- .../contacts/incall/InCallPluginHelper.java | 44 +++++---- .../list/PluginContactBrowseListFragment.java | 110 ++++++++++++--------- 3 files changed, 102 insertions(+), 75 deletions(-) diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java index f548976eb..665d3cf8f 100644 --- a/src/com/android/contacts/activities/PeopleActivity.java +++ b/src/com/android/contacts/activities/PeopleActivity.java @@ -394,6 +394,8 @@ public class PeopleActivity extends ContactsActivity implements mPluginLength = mPluginTabInfo.size(); for (int i = 0; i < mPluginLength; i++) { InCallPluginInfo pluginInfo = mPluginTabInfo.get(i); + mCallMethodMap.put(pluginInfo.mCallMethodInfo.mComponent, pluginInfo + .mCallMethodInfo); mTabTitles.add(TabState.GROUPS + i, new TabEntry(pluginInfo.mTabTag, pluginInfo.mCallMethodInfo.mName)); pluginInfo.mFragment = (PluginContactBrowseListFragment) fragmentManager @@ -1883,7 +1885,7 @@ public class PeopleActivity extends ContactsActivity implements private synchronized void updatePlugins(HashMap callMethodInfo) { HashMap newCmMap = (HashMap) CallMethodHelper.getAllEnabledCallMethods().clone(); + CallMethodInfo>) CallMethodHelper.getAllEnabledCallMethods(); if (DEBUG) Log.d(TAG, "updatePlugins newCmMap size:" + newCmMap.size()); boolean updateTabs = false; String lastSelectedTabTag = mTabTitles.get(mActionBarAdapter.getCurrentTab()).mTag; @@ -1892,16 +1894,14 @@ public class PeopleActivity extends ContactsActivity implements FragmentManager fragmentManager = getFragmentManager(); for (ComponentName cn : mCallMethodMap.keySet()) { - CallMethodInfo cm = mCallMethodMap.get(cn); if (newCmMap.containsKey(cn)) { - // Check if update needed + // Update plugin info only, the plugin fragment keeps track of its state to + // determine if a UI update is necessary CallMethodInfo newCm = newCmMap.remove(cn); - if (!newCm.equals(cm) || newCm.mIsAuthenticated != cm.mIsAuthenticated) { - InCallPluginInfo pluginInfo = getPluginInfo(cn); - pluginInfo.mCallMethodInfo = newCm; - pluginInfo.mFragment.updateInCallPluginInfo(pluginInfo); - mCallMethodMap.put(cn, newCm); - } + InCallPluginInfo pluginInfo = getPluginInfo(cn); + pluginInfo.mCallMethodInfo = newCm; + pluginInfo.mFragment.updateInCallPluginInfo(pluginInfo); + mCallMethodMap.put(cn, newCm); } else { // Remove the tab associated with a plugin that's no longer available updateTabs = true; @@ -1916,7 +1916,7 @@ public class PeopleActivity extends ContactsActivity implements } } } - // add newly added tab from newCmMap (existing tab already removed in the logic above) + // add newly added tab from newCmMap for (ComponentName cn : newCmMap.keySet()) { InCallPluginInfo newInfo = new InCallPluginInfo(); newInfo.mTabTag = cn.toShortString(); @@ -1940,11 +1940,10 @@ public class PeopleActivity extends ContactsActivity implements executeFragTransact = true; } } - if (executeFragTransact) { fragmentManager.executePendingTransactions(); } - // update holders + // update view pager if (updateTabs) { mPluginLength = mPluginTabInfo.size(); mPageStateCount = TabState.COUNT + mPluginLength; diff --git a/src/com/android/contacts/incall/InCallPluginHelper.java b/src/com/android/contacts/incall/InCallPluginHelper.java index f7fe3b6c7..8c0403df8 100644 --- a/src/com/android/contacts/incall/InCallPluginHelper.java +++ b/src/com/android/contacts/incall/InCallPluginHelper.java @@ -24,17 +24,19 @@ import android.util.Log; import com.android.phone.common.ambient.AmbientConnection; import com.android.phone.common.incall.CallMethodHelper; import com.android.phone.common.incall.CallMethodInfo; +import com.cyanogen.ambient.common.api.PendingResult; import com.cyanogen.ambient.common.api.ResultCallback; import com.cyanogen.ambient.discovery.util.NudgeKey; import com.cyanogen.ambient.incall.extension.InCallContactInfo; +import com.cyanogen.ambient.incall.extension.StatusCodes; import com.cyanogen.ambient.incall.InCallServices; import com.cyanogen.ambient.incall.results.InstalledPluginsResult; +import java.util.HashMap; + public class InCallPluginHelper extends CallMethodHelper { private static final String TAG = InCallPluginHelper.class.getSimpleName(); - private static final int EXPECTED_CALL_BACKS = 11; - protected static synchronized InCallPluginHelper getInstance() { if (sInstance == null) { sInstance = new InCallPluginHelper(); @@ -44,7 +46,6 @@ public class InCallPluginHelper extends CallMethodHelper { public static void init(Context context) { InCallPluginHelper helper = getInstance(); - helper.expectedCallbacks = EXPECTED_CALL_BACKS; helper.mContext = context; helper.mClient = AmbientConnection.CLIENT.get(context); helper.mInCallApi = InCallServices.getInstance(); @@ -58,9 +59,13 @@ public class InCallPluginHelper extends CallMethodHelper { } public static void refreshDynamicItems() { + HashMap apiCallbacks = new HashMap(); for (ComponentName cn : mCallMethodInfos.keySet()) { - getCallMethodAuthenticated(cn, true); + getCallMethodAuthenticated(cn, apiCallbacks); + getCallMethodAccountHandle(cn, apiCallbacks); } + executeAll(apiCallbacks); } public static void refreshPendingIntents(InCallContactInfo contactInfo) { @@ -84,27 +89,32 @@ public class InCallPluginHelper extends CallMethodHelper { } if (mInstalledPlugins.size() == 0) { - broadcast(false); + broadcast(); } - + HashMap apiCallbacks = + new HashMap(); for (ComponentName cn : mInstalledPlugins) { mCallMethodInfos.put(cn, new CallMethodInfo()); - getCallMethodInfo(cn); - getCallMethodMimeType(cn); - getCallMethodStatus(cn); - getCallMethodVideoCallableMimeType(cn); - getCallMethodImMimeType(cn); - getCallMethodAuthenticated(cn, false); - getLoginIntent(cn); - getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_FRAGMENT_LOGIN); - getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_CARD_LOGIN); - getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_CARD_DOWNLOAD); - getDefaultDirectorySearchIntent(cn); + getCallMethodInfo(cn, apiCallbacks); + getCallMethodMimeType(cn, apiCallbacks); + getCallMethodStatus(cn, apiCallbacks); + getCallMethodVideoCallableMimeType(cn, apiCallbacks); + getCallMethodImMimeType(cn, apiCallbacks); + getCallMethodAuthenticated(cn, apiCallbacks); + getLoginIntent(cn, apiCallbacks); + getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_FRAGMENT_LOGIN, + apiCallbacks); + getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_CARD_LOGIN, + apiCallbacks); + getNudgeConfiguration(cn, NudgeKey.INCALL_CONTACT_CARD_DOWNLOAD, + apiCallbacks); + getDefaultDirectorySearchIntent(cn, apiCallbacks); // If you add any more callbacks, be sure to update // EXPECTED_RESULT_CALLBACKS // and EXPECTED_DYNAMIC_RESULT_CALLBACKS if the callback is dynamic // with the proper count. } + executeAll(apiCallbacks); } }); } diff --git a/src/com/android/contacts/list/PluginContactBrowseListFragment.java b/src/com/android/contacts/list/PluginContactBrowseListFragment.java index 3a5aeaa6e..d5a219f0d 100644 --- a/src/com/android/contacts/list/PluginContactBrowseListFragment.java +++ b/src/com/android/contacts/list/PluginContactBrowseListFragment.java @@ -64,7 +64,6 @@ public class PluginContactBrowseListFragment extends ContactEntryListFragment