From 4798621c9bf0fd612b6d724a4d246b13409a5e48 Mon Sep 17 00:00:00 2001 From: Erica Chang Date: Tue, 26 Apr 2016 22:34:32 -0700 Subject: [1/2] Contacts : fix InCall plugin related PendingIntent -Have to make CallMethodInfo cloneable so the returned HashMap holds a new instance and so comparison is valid (in order to detect plugin state/auth state change) CD-550 Change-Id: I5eaa99f46681e85aa9e0f49bb0914e195a111223 --- .../common/incall/ContactsDataSubscription.java | 78 ++++++++++++++++++++-- 1 file changed, 72 insertions(+), 6 deletions(-) (limited to 'src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java') diff --git a/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java b/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java index 2b38b1e..e93a72c 100644 --- a/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java +++ b/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java @@ -18,14 +18,20 @@ package com.android.phone.common.incall; import android.content.ComponentName; import android.content.Context; +import android.util.Log; import com.android.phone.common.ambient.SingletonHolder; import com.android.phone.common.ambient.TypedPendingResult; import com.android.phone.common.incall.api.InCallListeners; import com.android.phone.common.incall.api.InCallQueries; +import com.android.phone.common.incall.api.InCallResults; import com.android.phone.common.nudge.api.NudgeQueries; +import com.cyanogen.ambient.common.api.PendingResult; +import com.cyanogen.ambient.common.api.Result; +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.results.PendingIntentResult; import java.util.ArrayList; import java.util.HashMap; @@ -63,7 +69,7 @@ public class ContactsDataSubscription extends DialerDataSubscription { @Override public void onDynamicRefreshRequested(ArrayList queries, - ComponentName componentName) { + ComponentName componentName) { queries.add(InCallQueries.getCallMethodAuthenticated(mClient, componentName)); queries.add(InCallQueries.getCallMethodAccountHandle(mClient, componentName)); } @@ -108,10 +114,6 @@ public class ContactsDataSubscription extends DialerDataSubscription { } } - public static void refreshPendingIntents(InCallContactInfo contactInfo) { - // TODO: implement - } - public Set getAllPluginComponentNames() { Set names = new HashSet(); HashMap plugins = this.getPluginInfo(); @@ -120,4 +122,68 @@ public class ContactsDataSubscription extends DialerDataSubscription { } return names; } -} + + public void updatePendingIntents(final HashMap map, + InCallContactInfo contactInfo) { + HashMap plugins = this.getPluginInfo(); + for (ComponentName cn : plugins.keySet()) { + ArrayList queries = new ArrayList<>(); + queries.add(InCallQueries.getDirectorySearchIntent(mClient, cn, contactInfo)); + queries.add(InCallQueries.getInviteIntent(mClient, cn, contactInfo)); + executeAllPendingIntentQueries(queries, cn, map); + } + } + + private void executeAllPendingIntentQueries(final ArrayList apiCallbacks, + final ComponentName componentName, + final HashMap map) { + final ArrayList pendingResults = new ArrayList<>(); + + for (final TypedPendingResult pendingResult : apiCallbacks) { + pendingResult.setResultCallback(new ResultCallback() { + @Override + public void onResult(Result result) { + pendingResults.remove(pendingResult.getPendingResult()); + if (result == null) { + // Our plugin failed to make this call, log out what and why + Log.e(TAG, "Result from: " + componentName.getPackageName() + " failed"); + } else { + if (result.getStatus().isSuccess()) { + // check to see if our onPostResult removed the plugin. + if (!getPluginInfo().containsKey(componentName)) { + // Our plugin no longer exists, clear other callbacks + for (PendingResult pr : pendingResults) { + pr.cancel(); + } + pendingResults.clear(); + } else { + ContactsPendingIntents intentInfo = map.get(componentName); + if (intentInfo == null) { + intentInfo = new ContactsPendingIntents(); + map.put(componentName, intentInfo); + } + InCallResults.gotContactsIntent(intentInfo, + (PendingIntentResult) result, + pendingResult + .getType()); + } + } else if (result.getStatus().isCanceled()) { + // Our plugin was found invalid or no longer exists. + Log.e(TAG, "Queries to: " + componentName.getPackageName() + + " are cancelled"); + } else { + Log.e(TAG, "Query to: " + componentName.getPackageName() + " " + + result.getClass().getSimpleName() + " failed. Code: " + + result.getStatus().getStatusMessage()); + } + } + } + }); + + // Add items that we've already added to our queue for so we can cancel them if + // need be. Set resultcallback will return instantly but onResult will not. + // So we can use this as our "counter" to determine if we should broadcast + pendingResults.add(pendingResult.getPendingResult()); + } + } +} \ No newline at end of file -- cgit v1.2.3