summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErica Chang <echang@cyngn.com>2016-03-07 17:57:39 -0800
committerErica Chang <echang@cyngn.com>2016-04-07 12:05:49 -0700
commit00120c2802ae5aa6cec947b5a6ac1c8eb37e52fa (patch)
tree6517d124e30cb0e0b35404fb6c1768ac66570170
parent4f95d89bfb5dd9a46c2ba0914465383822bf0f5b (diff)
downloadandroid_packages_apps_Contacts-00120c2802ae5aa6cec947b5a6ac1c8eb37e52fa.tar.gz
android_packages_apps_Contacts-00120c2802ae5aa6cec947b5a6ac1c8eb37e52fa.tar.bz2
android_packages_apps_Contacts-00120c2802ae5aa6cec947b5a6ac1c8eb37e52fa.zip
(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
-rw-r--r--src/com/android/contacts/activities/PeopleActivity.java23
-rw-r--r--src/com/android/contacts/incall/InCallPluginHelper.java44
-rw-r--r--src/com/android/contacts/list/PluginContactBrowseListFragment.java110
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<ComponentName, CallMethodInfo>
callMethodInfo) {
HashMap<ComponentName, CallMethodInfo> newCmMap = (HashMap<ComponentName,
- CallMethodInfo>) 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<ResultCallback, PendingResult> apiCallbacks = new HashMap<ResultCallback,
+ PendingResult>();
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<ResultCallback, PendingResult> apiCallbacks =
+ new HashMap<ResultCallback, PendingResult>();
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<Co
implements View.OnClickListener {
private static final String TAG = PluginContactBrowseListFragment.class.getSimpleName();
private boolean DEBUG = false;
- private Context mContext;
private InCallPluginInfo mInCallPluginInfo;
private View mLayout;
private View mListView;
@@ -96,6 +95,10 @@ public class PluginContactBrowseListFragment extends ContactEntryListFragment<Co
private int mLastSelectedPosition = -1;
private boolean mRefreshingContactUri;
private ContactListFilter mFilter;
+ private boolean mInitialized = false;
+ private boolean mAuthenticated = false;
+ private String mAccountType = "";
+ private String mAccountHandle = "";
private String mPersistentSelectionPrefix = PERSISTENT_SELECTION_PREFIX;
protected OnContactBrowserActionListener mListener;
@@ -202,7 +205,9 @@ public class PluginContactBrowseListFragment extends ContactEntryListFragment<Co
super.onActivityCreated(savedInstanceState);
mPrefs = getActivity().getSharedPreferences(mPrefsFileName, Context.MODE_PRIVATE);
updatePluginView(); // this is execute again reflect change in plugin info
- restoreFilter();
+ if (savedInstanceState != null) {
+ restoreFilter();
+ }
restoreSelectedUri(false);
}
@@ -665,49 +670,54 @@ public class PluginContactBrowseListFragment extends ContactEntryListFragment<Co
if (mInCallPluginInfo != null) {
if (DEBUG) Log.d(TAG, "updatePluginView: " + mInCallPluginInfo.mCallMethodInfo.mName);
if (mListView != null && mLoginView != null) {
- if (mInCallPluginInfo.mCallMethodInfo.mIsAuthenticated) {
- // Show list view
- mLoginView.setVisibility(View.GONE);
- mListView.setVisibility(View.VISIBLE);
- if (mEmptyView != null) {
- mEmptyView.setVisibility(View.VISIBLE);
- ((ListView) mListView).setEmptyView(mEmptyView);
- initEmptyView();
- }
- } else {
- // Show login view
- ((ListView)mListView).setEmptyView(null);
- mListView.setVisibility(View.GONE);
- if (mEmptyView != null) {
- mEmptyView.setVisibility(View.GONE);
- }
- mLoginView.setVisibility(View.VISIBLE);
- if (mLoginIconView != null) {
- if (mInCallPluginInfo.mCallMethodInfo.mLoginIconId == 0) {
- // plugin does not provide a valid icon
- mLoginIconView.setVisibility(View.GONE);
- } else {
- // plugin provides a valid icon, this method is called from the main
- // thread so needs to start an AsyncTask to look up the Drawable from
- // resource Id
- if (mInCallPluginInfo.mCallMethodInfo.mLoginIcon != null) {
- // TODO: may need to self load in the case of restore before plugin
- // update
- mLoginIconView.setImageDrawable(
- mInCallPluginInfo.mCallMethodInfo.mLoginIcon);
+ // if the UI auth state is initialized the first time or the auth state has changed
+ if (!mInitialized || mInCallPluginInfo.mCallMethodInfo.mIsAuthenticated !=
+ mAuthenticated) {
+ mInitialized = true;
+ mAuthenticated = mInCallPluginInfo.mCallMethodInfo.mIsAuthenticated;
+ if (mInCallPluginInfo.mCallMethodInfo.mIsAuthenticated) {
+ // Show list view
+ mLoginView.setVisibility(View.GONE);
+ mListView.setVisibility(View.VISIBLE);
+ if (mEmptyView != null) {
+ mEmptyView.setVisibility(View.VISIBLE);
+ ((ListView) mListView).setEmptyView(mEmptyView);
+ initEmptyView();
+ }
+ } else {
+ // Show login view
+ ((ListView) mListView).setEmptyView(null);
+ mListView.setVisibility(View.GONE);
+ if (mEmptyView != null) {
+ mEmptyView.setVisibility(View.GONE);
+ }
+ mLoginView.setVisibility(View.VISIBLE);
+ if (mLoginIconView != null) {
+ if (mInCallPluginInfo.mCallMethodInfo.mLoginIconId == 0) {
+ // plugin does not provide a valid icon
+ mLoginIconView.setVisibility(View.GONE);
} else {
- if (mInCallPluginInfo.mCallMethodInfo.mLoginIconId != 0) {
- new GetDrawableAsyncTask().execute();
+ if (mInCallPluginInfo.mCallMethodInfo.mLoginIcon != null) {
+ mLoginIconView.setImageDrawable(
+ mInCallPluginInfo.mCallMethodInfo.mLoginIcon);
+ } else {
+ // The fragment has been restored so only the icon id is
+ // a valid value, need to manually load
+ if (mInCallPluginInfo.mCallMethodInfo.mLoginIconId != 0) {
+ new GetDrawableAsyncTask().execute();
+ }
}
}
}
- }
- if (mLoginMsg != null) {
- if (!TextUtils.isEmpty(mInCallPluginInfo.mCallMethodInfo.mLoginSubtitle)) {
- mLoginMsg.setText(mInCallPluginInfo.mCallMethodInfo.mLoginSubtitle);
- } else {
- mLoginMsg.setText(getResources().getString(R.string.plugin_login_msg,
- mInCallPluginInfo.mCallMethodInfo.mName));
+ if (mLoginMsg != null) {
+ if (!TextUtils
+ .isEmpty(mInCallPluginInfo.mCallMethodInfo.mLoginSubtitle)) {
+ mLoginMsg.setText(mInCallPluginInfo.mCallMethodInfo.mLoginSubtitle);
+ } else {
+ mLoginMsg
+ .setText(getResources().getString(R.string.plugin_login_msg,
+ mInCallPluginInfo.mCallMethodInfo.mName));
+ }
}
}
}
@@ -715,11 +725,19 @@ public class PluginContactBrowseListFragment extends ContactEntryListFragment<Co
mPrefsFileName = PREFS_FILE_PREFIX +
mInCallPluginInfo.mCallMethodInfo.mComponent.getClassName();
if (mPrefs != null) {
- setFilter(ContactListFilter.createAccountFilter(
- mInCallPluginInfo.mCallMethodInfo.mAccountType,
- mInCallPluginInfo.mCallMethodInfo.mAccountHandle,
- null,
- null));
+ // Account filter should be updated
+ if (mInCallPluginInfo.mCallMethodInfo.mIsAuthenticated && (!TextUtils.equals
+ (mAccountType, mInCallPluginInfo.mCallMethodInfo.mAccountType) ||
+ TextUtils.equals(mAccountHandle,
+ mInCallPluginInfo.mCallMethodInfo.mAccountHandle))) {
+ mAccountType = mInCallPluginInfo.mCallMethodInfo.mAccountType;
+ mAccountHandle = mInCallPluginInfo.mCallMethodInfo.mAccountHandle;
+ setFilter(ContactListFilter.createAccountFilter(
+ mInCallPluginInfo.mCallMethodInfo.mAccountType,
+ mInCallPluginInfo.mCallMethodInfo.mAccountHandle,
+ null,
+ null));
+ }
}
}
}