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

Commit 8d05907a authored by Tyler Gunn's avatar Tyler Gunn Committed by Android Git Automerger
Browse files

am 746b6b52: Merge "Escape carrier-specified characters with backslash for...

am 746b6b52: Merge "Escape carrier-specified characters with backslash for call subject." into mnc-dr-dev

* commit '746b6b52':
  Escape carrier-specified characters with backslash for call subject.
parents 014e3a92 746b6b52
Loading
Loading
Loading
Loading
+46 −22
Original line number Original line Diff line number Diff line
@@ -40,9 +40,10 @@ import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.widget.Toast;
import android.widget.Toast;
import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
import android.preference.PreferenceManager;
import android.preference.PreferenceManager;
import android.telecom.ConferenceParticipant;
import android.telecom.ConferenceParticipant;
import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneNumberUtils;
import android.telephony.Rlog;
import android.telephony.Rlog;
@@ -443,7 +444,7 @@ public final class ImsPhoneCallTracker extends CallTracker {
            if (intentExtras != null) {
            if (intentExtras != null) {
                if (intentExtras.containsKey(android.telecom.TelecomManager.EXTRA_CALL_SUBJECT)) {
                if (intentExtras.containsKey(android.telecom.TelecomManager.EXTRA_CALL_SUBJECT)) {
                    intentExtras.putString(ImsCallProfile.EXTRA_DISPLAY_TEXT,
                    intentExtras.putString(ImsCallProfile.EXTRA_DISPLAY_TEXT,
                            removeInstantLetteringInvalidCharacters(intentExtras.getString(
                            cleanseInstantLetteringMessage(intentExtras.getString(
                                    android.telecom.TelecomManager.EXTRA_CALL_SUBJECT))
                                    android.telecom.TelecomManager.EXTRA_CALL_SUBJECT))
                    );
                    );
                }
                }
@@ -1829,37 +1830,60 @@ public final class ImsPhoneCallTracker extends CallTracker {


    /**
    /**
     * Given a call subject, removes any characters considered by the current carrier to be
     * Given a call subject, removes any characters considered by the current carrier to be
     * invalid.
     * invalid, as well as escaping (using \) any characters which the carrier requires to be
     * escaped.
     *
     *
     * @param callSubject The call subject.
     * @param callSubject The call subject.
     * @return The call subject with invalid characters removed.
     * @return The call subject with invalid characters removed and escaping applied as required.
     */
     */
    private String removeInstantLetteringInvalidCharacters(String callSubject) {
    private String cleanseInstantLetteringMessage(String callSubject) {
        String invalidCharacters = getInstantLetteringInvalidCharacters();
        // Get the carrier config for the current sub.
        if (TextUtils.isEmpty(invalidCharacters)) {
        CarrierConfigManager configMgr = (CarrierConfigManager)
                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        // Bail if we can't find the carrier config service.
        if (configMgr == null) {
            return callSubject;
            return callSubject;
        }
        }


        return callSubject.replaceAll(invalidCharacters, "");
        PersistableBundle carrierConfig = configMgr.getConfigForSubId(mPhone.getSubId());
        // Bail if no carrier config found.
        if (carrierConfig == null) {
            return callSubject;
        }

        // Try to replace invalid characters
        String invalidCharacters = carrierConfig.getString(
                CarrierConfigManager.KEY_CARRIER_INSTANT_LETTERING_INVALID_CHARS_STRING);
        if (!TextUtils.isEmpty(invalidCharacters)) {
            callSubject = callSubject.replaceAll(invalidCharacters, "");
        }

        // Try to escape characters which need to be escaped.
        String escapedCharacters = carrierConfig.getString(
                CarrierConfigManager.KEY_CARRIER_INSTANT_LETTERING_ESCAPED_CHARS_STRING);
        if (!TextUtils.isEmpty(escapedCharacters)) {
            callSubject = escapeChars(escapedCharacters, callSubject);
        }
        return callSubject;
    }
    }


    /**
    /**
     * Determines from carrier config the regular expression specifying which characters are not
     * Given a source string, return a string where a set of characters are escaped using the
     * allowed in instant lettering messages.
     * backslash character.
     *
     *
     * @return Regular expression defining the invalid characters, or empty string if none.
     * @param toEscape The characters to escape with a backslash.
     * @param source The source string.
     * @return The source string with characters escaped.
     */
     */
    private String getInstantLetteringInvalidCharacters() {
    private String escapeChars(String toEscape, String source) {
        CarrierConfigManager configMgr = (CarrierConfigManager)
        StringBuilder escaped = new StringBuilder();
                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        for (char c : source.toCharArray()) {
        if (configMgr == null) {
            if (toEscape.contains(Character.toString(c))) {
            return "";
                escaped.append("\\");
            }
            }
        PersistableBundle b = configMgr.getConfigForSubId(mPhone.getSubId());
            escaped.append(c);
        if (b != null) {
            return b.getString(
                    CarrierConfigManager.KEY_CARRIER_INSTANT_LETTERING_INVALID_CHARS_STRING);
        }
        }
        return "";

        return escaped.toString();
    }
    }
}
}