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

Commit 6a03323d authored by Hyunho's avatar Hyunho Committed by Automerger Merge Worker
Browse files

add use_tel_uri_for_pidf_xml field for ATT-UCE 430 am: cac5e221 am: e7393c8d am: d1f45509

parents 0f097791 d1f45509
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.telephony.ims.RcsContactUceCapability.SOURCE_TYPE_CACHED;

import android.content.Context;
import android.net.Uri;
import android.telecom.PhoneAccount;
import android.telecom.TelecomManager;
import android.telephony.AccessNetworkConstants;
import android.telephony.ims.ImsRegistrationAttributes;
@@ -276,7 +277,8 @@ public class DeviceCapabilityInfo {
     * Get the IMS associated URI. It will first get the uri of MMTEL if it is not empty, otherwise
     * it will try to get the uri of RCS. The null will be returned if both MMTEL and RCS are empty.
     */
    public synchronized Uri getImsAssociatedUri() {
    public synchronized Uri getImsAssociatedUri(boolean perferTelUri) {
        if (perferTelUri == false) {
            if (!mRcsAssociatedUris.isEmpty()) {
                return mRcsAssociatedUris.get(0);
            } else if (!mMmtelAssociatedUris.isEmpty()) {
@@ -284,6 +286,23 @@ public class DeviceCapabilityInfo {
            } else {
                return null;
            }
        } else {
            if (!mRcsAssociatedUris.isEmpty()) {
                for (Uri rcsAssociatedUri : mRcsAssociatedUris) {
                    if (PhoneAccount.SCHEME_TEL.equalsIgnoreCase(rcsAssociatedUri.getScheme())) {
                        return rcsAssociatedUri;
                    }
                }
            }
            if (!mMmtelAssociatedUris.isEmpty()) {
                for (Uri mmtelAssociatedUri : mMmtelAssociatedUris) {
                    if (PhoneAccount.SCHEME_TEL.equalsIgnoreCase(mmtelAssociatedUri.getScheme())) {
                        return mmtelAssociatedUri;
                    }
                }
            }
            return null;
        }
    }

    public synchronized boolean addRegistrationOverrideCapabilities(Set<String> featureTags) {
@@ -473,7 +492,7 @@ public class DeviceCapabilityInfo {

    // Get the device's capabilities with the PRESENCE mechanism.
    private RcsContactUceCapability getPresenceCapabilities(Context context) {
        Uri uri = PublishUtils.getDeviceContactUri(context, mSubId, this);
        Uri uri = PublishUtils.getDeviceContactUri(context, mSubId, this, true);
        if (uri == null) {
            logw("getPresenceCapabilities: uri is empty");
            return null;
@@ -534,7 +553,7 @@ public class DeviceCapabilityInfo {

    // Get the device's capabilities with the OPTIONS mechanism.
    private RcsContactUceCapability getOptionsCapabilities(Context context) {
        Uri uri = PublishUtils.getDeviceContactUri(context, mSubId, this);
        Uri uri = PublishUtils.getDeviceContactUri(context, mSubId, this, false);
        if (uri == null) {
            logw("getOptionsCapabilities: uri is empty");
            return null;
+51 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.ims.rcs.uce.presence.publish;

import android.content.Context;
import android.net.Uri;
import android.telecom.PhoneAccount;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.telephony.ims.feature.RcsFeature.RcsImsCapabilities;
@@ -25,6 +26,9 @@ import android.telephony.ims.feature.RcsFeature.RcsImsCapabilities.RcsImsCapabil
import android.text.TextUtils;
import android.util.Log;

import com.android.i18n.phonenumbers.NumberParseException;
import com.android.i18n.phonenumbers.PhoneNumberUtil;
import com.android.i18n.phonenumbers.Phonenumber;
import com.android.ims.rcs.uce.util.UceUtils;

import java.util.Arrays;
@@ -40,9 +44,13 @@ public class PublishUtils {
    private static final String DOMAIN_SEPARATOR = "@";

    public static Uri getDeviceContactUri(Context context, int subId,
            DeviceCapabilityInfo deviceCap) {
            DeviceCapabilityInfo deviceCap, boolean isForPresence) {
        boolean preferTelUri = false;
        if (isForPresence) {
            preferTelUri = UceUtils.isTelUriForPidfXmlEnabled(context, subId);
        }
        // Get the uri from the IMS associated URI which is provided by the IMS service.
        Uri contactUri = deviceCap.getImsAssociatedUri();
        Uri contactUri = deviceCap.getImsAssociatedUri(preferTelUri);
        if (contactUri != null) {
            Log.d(LOG_TAG, "getDeviceContactUri: ims associated uri");
            return contactUri;
@@ -58,12 +66,20 @@ public class PublishUtils {
        contactUri = getContactUriFromIsim(telephonyManager);
        if (contactUri != null) {
            Log.d(LOG_TAG, "getDeviceContactUri: impu");
            if (preferTelUri) {
                return getConvertedTelUri(context, contactUri);
            } else {
                return contactUri;
            }
        } else {
            Log.d(LOG_TAG, "getDeviceContactUri: line number");
            if (preferTelUri) {
                return getConvertedTelUri(context, getContactUriFromLine1Number(telephonyManager));
            } else {
                return getContactUriFromLine1Number(telephonyManager);
            }
        }
    }

    /**
     * Find all instances of sip/sips/tel URIs containing PII and replace them.
@@ -136,6 +152,37 @@ public class PublishUtils {
        }
    }

    private static Uri getConvertedTelUri(Context context, Uri contactUri) {
        if (contactUri == null) {
            return null;
        }
        if (contactUri.getScheme().equalsIgnoreCase(SCHEME_SIP)) {
            TelephonyManager manager = context.getSystemService(TelephonyManager.class);
            if (manager.getIsimDomain() == null) {
                return contactUri;
            }

            String numbers = contactUri.getSchemeSpecificPart();
            String[] numberParts = numbers.split("[@;:]");
            String number = numberParts[0];

            String simCountryIso = manager.getSimCountryIso();
            if (!TextUtils.isEmpty(simCountryIso)) {
                simCountryIso = simCountryIso.toUpperCase();
                PhoneNumberUtil util = PhoneNumberUtil.getInstance();
                try {
                    Phonenumber.PhoneNumber phoneNumber = util.parse(number, simCountryIso);
                    number = util.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
                    String telUri = SCHEME_TEL + ":" + number;
                    contactUri = Uri.parse(telUri);
                } catch (NumberParseException e) {
                    Log.w(LOG_TAG, "formatNumber: could not format " + number + ", error: " + e);
                }
            }
        }
        return contactUri;
    }

    static @RcsImsCapabilityFlag int getCapabilityType(Context context, int subId) {
        boolean isPresenceSupported = UceUtils.isPresenceSupported(context, subId);
        boolean isSipOptionsSupported = UceUtils.isSipOptionsSupported(context, subId);
+16 −0
Original line number Diff line number Diff line
@@ -209,6 +209,22 @@ public class UceUtils {
                CarrierConfigManager.Ims.KEY_USE_SIP_URI_FOR_PRESENCE_SUBSCRIBE_BOOL);
    }

    /**
     * Check whether tel uri should be used for pidf xml
     */
    public static boolean isTelUriForPidfXmlEnabled(Context context, int subId) {
        CarrierConfigManager configManager = context.getSystemService(CarrierConfigManager.class);
        if (configManager == null) {
            return false;
        }
        PersistableBundle config = configManager.getConfigForSubId(subId);
        if (config == null) {
            return false;
        }
        return config.getBoolean(
                CarrierConfigManager.Ims.KEY_USE_TEL_URI_FOR_PIDF_XML_BOOL);
    }

    /**
     * Get the minimum time that allow two PUBLISH requests can be executed continuously.
     *
+143 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source 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.ims.rcs.uce.presence.publish;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import android.net.Uri;
import android.telecom.PhoneAccount;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.ims.ImsTestBase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

@RunWith(AndroidJUnit4.class)
public class DeviceCapabilityInfoTest extends ImsTestBase {

    int mSubId = 1;

    String sipNumber = "123456789";
    String telNumber = "987654321";

    @Before
    public void setUp() throws Exception {
        super.setUp();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test
    @SmallTest
    public void testGetImsAssociatedUriWithoutPreferTelUri() throws Exception {
        DeviceCapabilityInfo deviceCapInfo = createDeviceCapabilityInfo();

        Uri[] uris = new Uri[2];
        uris[0] = Uri.fromParts(PhoneAccount.SCHEME_SIP, sipNumber, null);
        uris[1] = Uri.fromParts(PhoneAccount.SCHEME_TEL, telNumber, null);

        // When stored in the order of SIP, TEL URI, check whether the SIP URI saved at
        // the beginning is retrieved.
        deviceCapInfo.updateRcsAssociatedUri(uris);
        Uri outUri = deviceCapInfo.getImsAssociatedUri(false);

        String numbers = outUri.getSchemeSpecificPart();
        String[] numberParts = numbers.split("[@;:]");
        String number = numberParts[0];

        assertEquals(number, sipNumber);

        // When stored in the order of TEL, SIP URI, check whether the TEL URI saved at
        // the beginning is retrieved.
        deviceCapInfo = createDeviceCapabilityInfo();

        uris[0] = Uri.fromParts(PhoneAccount.SCHEME_TEL, telNumber, null);
        uris[1] = Uri.fromParts(PhoneAccount.SCHEME_SIP, sipNumber, null);

        deviceCapInfo.updateRcsAssociatedUri(uris);
        outUri = deviceCapInfo.getImsAssociatedUri(false);

        numbers = outUri.getSchemeSpecificPart();
        numberParts = numbers.split("[@;:]");
        number = numberParts[0];

        assertEquals(number, telNumber);
    }

    @Test
    @SmallTest
    public void testGetImsAssociatedUriWithPreferTelUri() throws Exception {
        DeviceCapabilityInfo deviceCapInfo = createDeviceCapabilityInfo();

        Uri[] uris = new Uri[2];
        uris[0] = Uri.fromParts(PhoneAccount.SCHEME_SIP, sipNumber, null);
        uris[1] = Uri.fromParts(PhoneAccount.SCHEME_TEL, telNumber, null);

        // Check whether TEL URI is returned when preferTelUri is true even if SIP and TEL URI
        // are in the order.
        deviceCapInfo.updateRcsAssociatedUri(uris);
        Uri outUri = deviceCapInfo.getImsAssociatedUri(true);

        String numbers = outUri.getSchemeSpecificPart();
        String[] numberParts = numbers.split("[@;:]");
        String number = numberParts[0];

        assertEquals(number, telNumber);

        // If preferTelUri is true, check if a TEL URI is returned.
        deviceCapInfo = createDeviceCapabilityInfo();

        uris[0] = Uri.fromParts(PhoneAccount.SCHEME_TEL, telNumber, null);
        uris[1] = Uri.fromParts(PhoneAccount.SCHEME_SIP, sipNumber, null);

        deviceCapInfo.updateRcsAssociatedUri(uris);
        outUri = deviceCapInfo.getImsAssociatedUri(true);

        numbers = outUri.getSchemeSpecificPart();
        numberParts = numbers.split("[@;:]");
        number = numberParts[0];

        assertEquals(number, telNumber);

        //If there is only SIP URI, check the return uri is null if preferTelUir is true.
        deviceCapInfo = createDeviceCapabilityInfo();

        uris[0] = Uri.fromParts(PhoneAccount.SCHEME_SIP, telNumber, null);
        uris[1] = Uri.fromParts(PhoneAccount.SCHEME_SIP, sipNumber, null);

        deviceCapInfo.updateRcsAssociatedUri(uris);
        outUri = deviceCapInfo.getImsAssociatedUri(true);

        assertNull(outUri);
    }

    private DeviceCapabilityInfo createDeviceCapabilityInfo() {
        DeviceCapabilityInfo deviceCapInfo = new DeviceCapabilityInfo(mSubId, null);
        return deviceCapInfo;
    }

}
 No newline at end of file