summaryrefslogtreecommitdiffstats
path: root/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java
diff options
context:
space:
mode:
Diffstat (limited to 'src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java')
-rw-r--r--src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java78
1 files changed, 72 insertions, 6 deletions
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<TypedPendingResult> 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<String> getAllPluginComponentNames() {
Set<String> names = new HashSet<String>();
HashMap<ComponentName, CallMethodInfo> plugins = this.getPluginInfo();
@@ -120,4 +122,68 @@ public class ContactsDataSubscription extends DialerDataSubscription {
}
return names;
}
-}
+
+ public void updatePendingIntents(final HashMap<ComponentName, ContactsPendingIntents> map,
+ InCallContactInfo contactInfo) {
+ HashMap<ComponentName, CallMethodInfo> plugins = this.getPluginInfo();
+ for (ComponentName cn : plugins.keySet()) {
+ ArrayList<TypedPendingResult> 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<TypedPendingResult> apiCallbacks,
+ final ComponentName componentName,
+ final HashMap<ComponentName, ContactsPendingIntents> map) {
+ final ArrayList<PendingResult> 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