aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames.cf Lin <jamescflin@google.com>2021-06-10 20:24:53 +0800
committerJames.cf Lin <jamescflin@google.com>2021-06-10 20:24:53 +0800
commit736ed1104bdb1b18f49c2c9defb240402beb00bc (patch)
tree8c9771b14649868a626517d4a4739cae769483b8
parent9b1d58ee558119b3f97f5f46b80f2c5a457aab8d (diff)
downloadims-736ed1104bdb1b18f49c2c9defb240402beb00bc.tar.gz
Fix The callback "onError" may be called with the error TIMEOUT when request capabilities
The contact uri format has changed when receive the capabilities updated. It causes that the result of the contact uri comparison is failed and the framework determined that there are still capabilities have not been received. Bug: 190669410 Test: atest RcsUceAdapterTest; ImsServiceTest Change-Id: Ic40e63d1b0af978f15bf78827de597c64644c4f3
-rw-r--r--src/java/com/android/ims/rcs/uce/request/CapabilityRequestResponse.java45
-rw-r--r--src/java/com/android/ims/rcs/uce/util/UceUtils.java23
2 files changed, 57 insertions, 11 deletions
diff --git a/src/java/com/android/ims/rcs/uce/request/CapabilityRequestResponse.java b/src/java/com/android/ims/rcs/uce/request/CapabilityRequestResponse.java
index cd4b6e21..1ac46a7a 100644
--- a/src/java/com/android/ims/rcs/uce/request/CapabilityRequestResponse.java
+++ b/src/java/com/android/ims/rcs/uce/request/CapabilityRequestResponse.java
@@ -82,7 +82,7 @@ public class CapabilityRequestResponse {
private Set<String> mRemoteCaps;
// The collection to record whether the request contacts have received the capabilities updated.
- private Map<Uri, Boolean> mContactCapsReceived;
+ private Map<String, Boolean> mContactCapsReceived;
public CapabilityRequestResponse() {
mRequestInternalError = Optional.empty();
@@ -104,7 +104,15 @@ public class CapabilityRequestResponse {
* Set the request contacts which is expected to receive the capabilities updated.
*/
public synchronized void setRequestContacts(List<Uri> contactUris) {
- contactUris.stream().forEach(contact -> mContactCapsReceived.put(contact, Boolean.FALSE));
+ // Convert the given contact uris to the contact numbers.
+ List<String> numbers = contactUris.stream()
+ .map(UceUtils::getContactNumber)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ // Initialize the default value to FALSE. All the numbers have not received the
+ // capabilities updated.
+ numbers.stream().forEach(contact -> mContactCapsReceived.put(contact, Boolean.FALSE));
Log.d(LOG_TAG, "setRequestContacts: size=" + mContactCapsReceived.size());
}
@@ -230,9 +238,26 @@ public class CapabilityRequestResponse {
public synchronized void addCachedCapabilities(List<RcsContactUceCapability> capabilityList) {
mCachedCapabilityList.addAll(capabilityList);
- // Record which contact has received the capabilities updated.
- capabilityList.stream().forEach(cap ->
- mContactCapsReceived.computeIfPresent(cap.getContactUri(), (k, v) -> Boolean.TRUE));
+ // Update the flag to indicate that these contacts have received the capabilities updated.
+ updateCapsReceivedFlag(capabilityList);
+ }
+
+ /**
+ * Update the flag to indicate that the given contacts have received the capabilities updated.
+ */
+ private synchronized void updateCapsReceivedFlag(List<RcsContactUceCapability> updatedCapList) {
+ for (RcsContactUceCapability updatedCap : updatedCapList) {
+ Uri updatedUri = updatedCap.getContactUri();
+ if (updatedUri == null) continue;
+ String updatedUriStr = updatedUri.toString();
+
+ for (Map.Entry<String, Boolean> contactCapEntry : mContactCapsReceived.entrySet()) {
+ if (updatedUriStr.contains(contactCapEntry.getKey())) {
+ // Set the flag that this contact has received the capability updated.
+ contactCapEntry.setValue(true);
+ }
+ }
+ }
}
/**
@@ -255,9 +280,8 @@ public class CapabilityRequestResponse {
public synchronized void addUpdatedCapabilities(List<RcsContactUceCapability> capabilityList) {
mUpdatedCapabilityList.addAll(capabilityList);
- // Record which contact has received the capabilities updated.
- capabilityList.stream().forEach(cap ->
- mContactCapsReceived.computeIfPresent(cap.getContactUri(), (k, v) -> Boolean.TRUE));
+ // Update the flag to indicate that these contacts have received the capabilities updated.
+ updateCapsReceivedFlag(capabilityList);
}
/**
@@ -288,9 +312,8 @@ public class CapabilityRequestResponse {
// Save the terminated resource.
mTerminatedResource.addAll(capabilityList);
- // Record which contact has received the capabilities updated.
- capabilityList.stream().forEach(cap ->
- mContactCapsReceived.computeIfPresent(cap.getContactUri(), (k, v) -> Boolean.TRUE));
+ // Update the flag to indicate that these contacts have received the capabilities updated.
+ updateCapsReceivedFlag(capabilityList);
}
/*
diff --git a/src/java/com/android/ims/rcs/uce/util/UceUtils.java b/src/java/com/android/ims/rcs/uce/util/UceUtils.java
index 6db0d23e..e5ba6a96 100644
--- a/src/java/com/android/ims/rcs/uce/util/UceUtils.java
+++ b/src/java/com/android/ims/rcs/uce/util/UceUtils.java
@@ -18,6 +18,7 @@ package com.android.ims.rcs.uce.util;
import android.content.Context;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.PersistableBundle;
import android.preference.PreferenceManager;
import android.provider.BlockedNumberContract;
@@ -376,4 +377,26 @@ public class UceUtils {
return DEFAULT_CAP_REQUEST_TIMEOUT_AFTER_MS;
}
}
+
+ /**
+ * Get the contact number from the given URI.
+ * @param contactUri The contact uri of the capabilities to request for.
+ * @return The number of the contact uri. NULL if the number cannot be retrieved.
+ */
+ public static String getContactNumber(Uri contactUri) {
+ if (contactUri == null) {
+ return null;
+ }
+ String number = contactUri.getSchemeSpecificPart();
+ if (TextUtils.isEmpty(number)) {
+ return null;
+ }
+
+ String numberParts[] = number.split("[@;:]");
+ if (numberParts.length == 0) {
+ Log.d(LOG_TAG, "getContactNumber: the length of numberPars is 0");
+ return contactUri.toString();
+ }
+ return numberParts[0];
+ }
}