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

Commit 5770c9b8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add support for message wildcard in...

Merge "Add support for message wildcard in KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY" am: 27e008ef am: afaaa8ef

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1861453

Change-Id: Id6756d71c50f2770a47575dcacf5ba789752123d
parents 6d5b9d90 afaaa8ef
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -1542,6 +1542,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            mUssdMethod = carrierConfig.getInt(CarrierConfigManager.KEY_CARRIER_USSD_METHOD_INT);
        }

        if (!mImsReasonCodeMap.isEmpty()) {
            mImsReasonCodeMap.clear();
        }
        String[] mappings = carrierConfig
                .getStringArray(CarrierConfigManager.KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY);
        if (mappings != null && mappings.length > 0) {
@@ -1562,21 +1565,22 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    if (message == null) {
                        message = "";
                    }
                    else if (message.equals("*")) {
                        message = null;
                    }
                    int toCode = Integer.parseInt(values[2]);

                    addReasonCodeRemapping(fromCode, message, toCode);
                    log("Loaded ImsReasonInfo mapping : fromCode = " +
                            fromCode == null ? "any" : fromCode + " ; message = " +
                            message + " ; toCode = " + toCode);
                    log("Loaded ImsReasonInfo mapping :" +
                            " fromCode = " + (fromCode == null ? "any" : fromCode) +
                            " ; message = " + (message == null ? "any" : message) +
                            " ; toCode = " + toCode);
                } catch (NumberFormatException nfe) {
                    loge("Invalid ImsReasonInfo mapping found: " + mapping);
                }
            }
        } else {
            log("No carrier ImsReasonInfo mappings defined.");
            if (!mImsReasonCodeMap.isEmpty()) {
                mImsReasonCodeMap.clear();
            }
        }
    }

@@ -2665,6 +2669,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                + 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);
        if (mImsReasonCodeMap.containsKey(toCheck)) {
            int toCode = mImsReasonCodeMap.get(toCheck);

@@ -2682,6 +2687,19 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    " ; message = " + reason + " ; toCode = " + toCode);
            return toCode;
        }
        else if (mImsReasonCodeMap.containsKey(wildcardMessageToCheck)) {
            // Handle the case where a wildcard is specified for the reason.
            // For example, we can set these two strings in
            // CarrierConfigManager.KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY:
            //   - "1014|call completed elsewhere|1014"
            //   - "1014|*|510"
            // to remap CODE_ANSWERED_ELSEWHERE to CODE_USER_TERMINATED_BY_REMOTE
            // when reason is NOT "call completed elsewhere".
            int toCode = mImsReasonCodeMap.get(wildcardMessageToCheck);
            log("maybeRemapReasonCode : fromCode = " + reasonInfo.getCode() +
                    " ; message(wildcard) = " + reason + " ; toCode = " + toCode);
            return toCode;
        }
        return code;
    }

@@ -3128,7 +3146,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    getNetworkCountryIso(), emergencyNumberTracker != null
                    ? emergencyNumberTracker.getEmergencyNumberDbVersion()
                    : TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION);
            mPhone.getVoiceCallSessionStats().onImsCallTerminated(conn, reasonInfo);
            mPhone.getVoiceCallSessionStats().onImsCallTerminated(conn, new ImsReasonInfo(
                    maybeRemapReasonCode(reasonInfo),
                    reasonInfo.mExtraCode, reasonInfo.mExtraMessage));
            // Remove info for the callId from the current calls and add it to the history
            CallQualityMetrics lastCallMetrics = mCallQualityMetrics.remove(callId);
            if (lastCallMetrics != null) {
+65 −0
Original line number Diff line number Diff line
@@ -770,6 +770,71 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
                "Call answered elsewhere.")));
    }

    private void clearCarrierConfig() {
        PersistableBundle bundle = new PersistableBundle();
        mCTUT.updateCarrierConfigCache(bundle);
    }

    private void loadReasonCodeRemapCarrierConfig() {
        PersistableBundle bundle = new PersistableBundle();
        String[] mappings = new String[] {
                // These shall be equivalent to the remappings added in setUp():
                "*|Wifi signal lost.|1407",
                "501|Call answered elsewhere.|1014",
                "510|Call answered elsewhere.|1014",
                "510||332",
                "352|emergency calls over wifi not allowed in this location|1622",
                "332|service not allowed in this location|1623",
                };
        bundle.putStringArray(CarrierConfigManager.KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY,
                mappings);
        mCTUT.updateCarrierConfigCache(bundle);
    }

    @Test
    @SmallTest
    public void testReasonCodeRemapCarrierConfig() {
        clearCarrierConfig();
        // The map shall become empty now

        assertEquals(510, // ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE
                mCTUT.maybeRemapReasonCode(new ImsReasonInfo(510, 1, "Call answered elsewhere.")));

        loadReasonCodeRemapCarrierConfig();
        testReasonCodeRemap();
        testNumericOnlyRemap();
        testRemapEmergencyCallsOverWfc();
        testRemapWfcNotAvailable();
    }

    private void loadReasonCodeRemapCarrierConfigWithWildcardMessage() {
        PersistableBundle bundle = new PersistableBundle();
        String[] mappings = new String[]{
                "1014|call completed elsewhere|1014",
                "1014|*|510",
                };
        bundle.putStringArray(CarrierConfigManager.KEY_IMS_REASONINFO_MAPPING_STRING_ARRAY,
                mappings);
        mCTUT.updateCarrierConfigCache(bundle);
    }

    @Test
    @SmallTest
    public void testReasonCodeRemapCarrierConfigWithWildcardMessage() {
        clearCarrierConfig();
        // The map shall become empty now

        loadReasonCodeRemapCarrierConfigWithWildcardMessage();
        assertEquals(ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE, mCTUT.maybeRemapReasonCode(
                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

        // Simulate that after SIM swap the new carrier config doesn't have the mapping for 1014
        loadReasonCodeRemapCarrierConfig();
        assertEquals(ImsReasonInfo.CODE_ANSWERED_ELSEWHERE, mCTUT.maybeRemapReasonCode(
                new ImsReasonInfo(1014, 200, "Call Rejected By User"))); // 1014 -> 1014
    }

    @Test
    @SmallTest