Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 736ed110 authored by James.cf Lin's avatar James.cf Lin
Browse files

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
parent 9b1d58ee
Loading
Loading
Loading
Loading
+34 −11
Original line number Diff line number Diff line
@@ -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);
    }

    /*
+23 −0
Original line number Diff line number Diff line
@@ -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];
    }
}