summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErica Chang <echang@cyngn.com>2016-04-26 22:34:32 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-04-28 11:18:28 -0700
commit4798621c9bf0fd612b6d724a4d246b13409a5e48 (patch)
treec75e7e86315211ef5eeacc75f646d5ea98b2e052
parentdea0bdd78ec5f3b632a380093ff4dc216d809407 (diff)
downloadandroid_packages_apps_PhoneCommon-4798621c9bf0fd612b6d724a4d246b13409a5e48.tar.gz
android_packages_apps_PhoneCommon-4798621c9bf0fd612b6d724a4d246b13409a5e48.tar.bz2
android_packages_apps_PhoneCommon-4798621c9bf0fd612b6d724a4d246b13409a5e48.zip
[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
-rw-r--r--src-ambient/com/android/phone/common/ambient/TypedPendingResult.java16
-rw-r--r--src-ambient/com/android/phone/common/incall/CallMethodInfo.java14
-rw-r--r--src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java78
-rw-r--r--src-ambient/com/android/phone/common/incall/ContactsPendingIntents.java23
-rw-r--r--src-ambient/com/android/phone/common/incall/api/InCallQueries.java13
-rw-r--r--src-ambient/com/android/phone/common/incall/api/InCallResults.java13
-rw-r--r--src-ambient/com/android/phone/common/incall/utils/CallMethodFilters.java3
7 files changed, 149 insertions, 11 deletions
diff --git a/src-ambient/com/android/phone/common/ambient/TypedPendingResult.java b/src-ambient/com/android/phone/common/ambient/TypedPendingResult.java
index 783b519..95ee5b2 100644
--- a/src-ambient/com/android/phone/common/ambient/TypedPendingResult.java
+++ b/src-ambient/com/android/phone/common/ambient/TypedPendingResult.java
@@ -42,6 +42,10 @@ public class TypedPendingResult {
public static final int INCALL_CONTACT_CARD_DOWNLOAD = 1003;
public static final int INCALL_CONTACT_FRAGMENT_LOGIN = 1004;
+ // 2000 - 3000 Reserved for invite intents
+ public static final int DIRECTORY_SEARCH_INTENT = 2000;
+ public static final int INVITE_INTENT = 2001;
+
public TypedPendingResult(PendingResult pendingResult, int type) {
this.mPendingResult = pendingResult;
this.mType = type;
@@ -50,4 +54,16 @@ public class TypedPendingResult {
public void setResultCallback(ResultCallback resultCallback, long length, TimeUnit unit) {
this.mPendingResult.setResultCallback(resultCallback, length, unit);
}
+
+ public void setResultCallback(ResultCallback resultCallback) {
+ this.mPendingResult.setResultCallback(resultCallback);
+ }
+
+ public PendingResult getPendingResult() {
+ return mPendingResult;
+ }
+
+ public int getType() {
+ return mType;
+ }
}
diff --git a/src-ambient/com/android/phone/common/incall/CallMethodInfo.java b/src-ambient/com/android/phone/common/incall/CallMethodInfo.java
index cbc5242..0fd90d1 100644
--- a/src-ambient/com/android/phone/common/incall/CallMethodInfo.java
+++ b/src-ambient/com/android/phone/common/incall/CallMethodInfo.java
@@ -44,7 +44,7 @@ import java.math.BigDecimal;
import java.util.Currency;
import java.util.List;
-public class CallMethodInfo {
+public class CallMethodInfo implements Cloneable {
public String mId;
public UserHandle mUserHandle;
@@ -105,8 +105,6 @@ public class CallMethodInfo {
public PendingIntent mManageCreditIntent;
public PendingIntent mLoginIntent;
public PendingIntent mDefaultDirectorySearchIntent; // empty contact Uri
- public PendingIntent mDirectorySearchIntent;
- public PendingIntent mInviteIntent;
public PendingIntent mSettingsIntent;
private static CallMethodInfo sEmergencyCallMethod;
private AuthenticationListenerImpl mAuthListener;
@@ -148,6 +146,16 @@ public class CallMethodInfo {
return false;
}
+ @Override
+ public CallMethodInfo clone() {
+ // we only need Immutable types to be cloned
+ try {
+ return (CallMethodInfo) super.clone();
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+
/**
* return empty mock call method that represents emergency call only mode
*/
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
diff --git a/src-ambient/com/android/phone/common/incall/ContactsPendingIntents.java b/src-ambient/com/android/phone/common/incall/ContactsPendingIntents.java
new file mode 100644
index 0000000..da49f9e
--- /dev/null
+++ b/src-ambient/com/android/phone/common/incall/ContactsPendingIntents.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.phone.common.incall;
+
+import android.app.PendingIntent;
+
+public class ContactsPendingIntents {
+ public PendingIntent mDirectorySearchIntent;
+ public PendingIntent mInviteIntent;
+}
diff --git a/src-ambient/com/android/phone/common/incall/api/InCallQueries.java b/src-ambient/com/android/phone/common/incall/api/InCallQueries.java
index 384cfdb..67dd1d7 100644
--- a/src-ambient/com/android/phone/common/incall/api/InCallQueries.java
+++ b/src-ambient/com/android/phone/common/incall/api/InCallQueries.java
@@ -28,6 +28,7 @@ import com.cyanogen.ambient.analytics.Event;
import com.cyanogen.ambient.common.api.AmbientApiClient;
import com.cyanogen.ambient.common.api.Result;
import com.cyanogen.ambient.common.api.ResultCallback;
+import com.cyanogen.ambient.incall.extension.InCallContactInfo;
/**
* Queries for incall plugins
@@ -227,4 +228,16 @@ public class InCallQueries extends ApiHelper {
}
});
}
+
+ public static TypedPendingResult getDirectorySearchIntent(AmbientApiClient client,
+ ComponentName componentName, InCallContactInfo contactInfo) {
+ return new TypedPendingResult(thisApi().getDirectorySearchIntent(client, componentName,
+ contactInfo.mLookupUri), TypedPendingResult.DIRECTORY_SEARCH_INTENT);
+ }
+
+ public static TypedPendingResult getInviteIntent(AmbientApiClient client,
+ ComponentName componentName, InCallContactInfo contactInfo) {
+ return new TypedPendingResult(thisApi().getInviteIntent(client, componentName,
+ contactInfo), TypedPendingResult.INVITE_INTENT);
+ }
}
diff --git a/src-ambient/com/android/phone/common/incall/api/InCallResults.java b/src-ambient/com/android/phone/common/incall/api/InCallResults.java
index 8e0064e..63655c3 100644
--- a/src-ambient/com/android/phone/common/incall/api/InCallResults.java
+++ b/src-ambient/com/android/phone/common/incall/api/InCallResults.java
@@ -27,6 +27,7 @@ import android.util.Log;
import com.android.phone.common.ambient.AmbientDataSubscription;
import com.android.phone.common.ambient.TypedPendingResult;
import com.android.phone.common.incall.CallMethodInfo;
+import com.android.phone.common.incall.ContactsPendingIntents;
import com.android.phone.common.incall.utils.CallMethodUtils;
import com.android.phone.common.ambient.utils.PluginUtils;
import com.android.phone.common.nudge.api.NudgeTypedResult;
@@ -280,4 +281,16 @@ public class InCallResults extends ApiHelper {
private static String getKey(String key, CallMethodInfo cmi) {
return cmi.mComponent.getClassName() + "." + key;
}
+
+ public static void gotContactsIntent(ContactsPendingIntents intents, PendingIntentResult result,
+ int type) {
+ switch(type) {
+ case TypedPendingResult.DIRECTORY_SEARCH_INTENT:
+ intents.mDirectorySearchIntent = result.intent;
+ break;
+ case TypedPendingResult.INVITE_INTENT:
+ intents.mInviteIntent = result.intent;
+ break;
+ }
+ }
}
diff --git a/src-ambient/com/android/phone/common/incall/utils/CallMethodFilters.java b/src-ambient/com/android/phone/common/incall/utils/CallMethodFilters.java
index 9a576b7..f83204d 100644
--- a/src-ambient/com/android/phone/common/incall/utils/CallMethodFilters.java
+++ b/src-ambient/com/android/phone/common/incall/utils/CallMethodFilters.java
@@ -62,7 +62,7 @@ public class CallMethodFilters extends ApiHelper {
HashMap<ComponentName, CallMethodInfo> cmi = new HashMap<>();
for (Map.Entry<ComponentName, CallMethodInfo> entry : instance.getPluginInfo().entrySet()) {
ComponentName key = entry.getKey();
- CallMethodInfo value = entry.getValue();
+ CallMethodInfo value = entry.getValue().clone();
if (value.mStatus == PluginStatus.ENABLED || value.mStatus == PluginStatus.HIDDEN) {
cmi.put(key, value);
@@ -90,5 +90,4 @@ public class CallMethodFilters extends ApiHelper {
}
return targetEntry;
}
-
}