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

Commit 15cc4653 authored by donaldahn's avatar donaldahn Committed by Sungcheol Ahn
Browse files

Add support for message in KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY

For TMO case, "510|Call completed elsewhere|1014" is configured as one item in the PARIS key "ims_reasoninfo_mapping_string_array". This purpose is to not show the missed call notification since the other device of the twinning account has answered the call.
However, when the twin device answers the call, the reason text in SIP CANCEL sent to the phone device includes imei information after text "call completed elsewhere" Since the reason text is not fully matched, the reason code is not remapped.
ImsReasonInfoKeyPair, which was created by overriding the Pair, was supported the partial match by using startsWith for extramessage.

Test: atest ImsPhoneCallTrackertest
Bug: b/249606161
Change-Id: Ica8c4fffbd4ac178ef4883626e072de04ea94bf6
parent e50fd722
Loading
Loading
Loading
Loading
+57 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIV
import static com.android.internal.telephony.Phone.CS_FALLBACK;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.usage.NetworkStatsManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
@@ -925,8 +926,10 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
     * {@code ImsReasonInfo#CODE_*} value.
     *
     * See {@link CarrierConfigManager#KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY}.
     * This ImsReasonInfoKeyPair with this key stating will consider getExtraMessage a match
     * if the carrier config messages starts with getExtraMessage result.
     */
    private Map<Pair<Integer, String>, Integer> mImsReasonCodeMap = new ArrayMap<>();
    private Map<ImsReasonInfoKeyPair, Integer> mImsReasonCodeMap = new ArrayMap<>();


    /**
@@ -985,6 +988,54 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    // Used for important operational related events for logging.
    private final LocalLog mOperationLocalLog = new LocalLog(64);

    /**
     * Container to ease passing around a tuple of two objects. This object provides a sensible
     * implementation of equals(), returning true/false using equals() for one object (Integer)
     * and startsWith() for another object (String). Also the startsWith() in this equals() method
     * will return true for A.startsWith(B) if B.second starts with A.second.
     */
    private static class ImsReasonInfoKeyPair extends Pair<Integer, String> {

        /**
         * Constructor for a ImsReasonInfoKeyPair.
         *
         * @param first Integer in the ImsReasonInfoKeyPair
         * @param second String in the ImsReasonInfoKeyPair
         */
        private ImsReasonInfoKeyPair(Integer first, String second) {
            super(first, second);
        }

        /**
         * Checks the two objects for equality by delegating to their respective
         * {@link Object#equals(Object)} methods.
         *
         * @param o the {@link com.android.internal.telephony.imsphone.ImsReasonInfoKeyPair} to
         *         which this one is to be checked for equality
         * @return true if the underlying objects of the ImsReasonInfoKeyPair are
         * considered equal and startsWith
         */
        @Override
        public boolean equals(@Nullable Object o) {
            if (!(o instanceof ImsReasonInfoKeyPair)) {
                return false;
            }
            ImsReasonInfoKeyPair p = (ImsReasonInfoKeyPair) o;

            return Objects.equals(p.first, first)
                    && Objects.toString(second).startsWith(Objects.toString(p.second));
        }

        /**
         * Compute a hash code using the hash code of the Integer key
         *
         * @return a hashcode of the first
         */
        @Override
        public int hashCode() {
            return (first == null ? 0 : first.hashCode());
        }
    }
    //***** Events


@@ -2826,7 +2877,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        if (message != null) {
            message = message.toLowerCase();
        }
        mImsReasonCodeMap.put(new Pair<>(fromCode, message), toCode);
        mImsReasonCodeMap.put(new ImsReasonInfoKeyPair(fromCode, message), toCode);
    }

    /**
@@ -2849,9 +2900,10 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        }
        log("maybeRemapReasonCode : fromCode = " + reasonInfo.getCode() + " ; message = "
                + reason);
        Pair<Integer, String> toCheck = new Pair<>(code, reason);
        Pair<Integer, String> wildcardToCheck = new Pair<>(null, reason);
        Pair<Integer, String> wildcardMessageToCheck = new Pair<>(code, null);
        ImsReasonInfoKeyPair toCheck = new ImsReasonInfoKeyPair(code, reason);
        ImsReasonInfoKeyPair wildcardToCheck = new ImsReasonInfoKeyPair(null, reason);
        ImsReasonInfoKeyPair wildcardMessageToCheck = new ImsReasonInfoKeyPair(code, null);

        if (mImsReasonCodeMap.containsKey(toCheck)) {
            int toCode = mImsReasonCodeMap.get(toCheck);

+5 −0
Original line number Diff line number Diff line
@@ -1006,7 +1006,9 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        PersistableBundle bundle = new PersistableBundle();
        String[] mappings = new String[]{
                "1014|call completed elsewhere|1014",
                "1014|Call Rejected By User|510",
                "1014|*|510",
                "510|Call completed elsewhere|1014",
                };
        bundle.putStringArray(CarrierConfigManager.KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY,
                mappings);
@@ -1024,6 +1026,9 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
                new ImsReasonInfo(1014, 200, "Call Rejected By User"))); // 1014 -> 510
        assertEquals(ImsReasonInfo.CODE_ANSWERED_ELSEWHERE, mCTUT.maybeRemapReasonCode(
                new ImsReasonInfo(1014, 200, "Call completed elsewhere"))); // 1014 -> 1014
        assertEquals(ImsReasonInfo.CODE_ANSWERED_ELSEWHERE, mCTUT.maybeRemapReasonCode(
                new ImsReasonInfo(510, 200,
                        "Call completed elsewhere by instance urn:gsma:imei:xxx"))); // 510 -> 1014

        // Simulate that after SIM swap the new carrier config doesn't have the mapping for 1014
        loadReasonCodeRemapCarrierConfig();