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

Commit d6345bfe authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Remove carrier-defined invalid characters from call subjects.

1. Look up a regular expression containing carrier-specific invalid
characters for call subjects.
2. If found, use reg exp to cleanse the call subject prior to setting
on the dial intent.

Bug: 22779583
Change-Id: I708468294e94d5959cd2fe0f605ec0515b6e2eaf
parent 2f85930c
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -31,11 +31,14 @@ import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
import android.widget.Toast;
import android.preference.PreferenceManager;
import android.telecom.ConferenceParticipant;
@@ -439,8 +442,9 @@ public final class ImsPhoneCallTracker extends CallTracker {
            if (intentExtras != null) {
                if (intentExtras.containsKey(android.telecom.TelecomManager.EXTRA_CALL_SUBJECT)) {
                    intentExtras.putString(ImsCallProfile.EXTRA_DISPLAY_TEXT,
                            intentExtras.getString(
                                    android.telecom.TelecomManager.EXTRA_CALL_SUBJECT));
                            removeInstantLetteringInvalidCharacters(intentExtras.getString(
                                    android.telecom.TelecomManager.EXTRA_CALL_SUBJECT))
                    );
                }

                // Pack the OEM-specific call extras.
@@ -1804,4 +1808,40 @@ public final class ImsPhoneCallTracker extends CallTracker {
        return (mImsFeatureEnabled[ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_LTE]
            || mImsFeatureEnabled[ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_WIFI]);
    }

    /**
     * Given a call subject, removes any characters considered by the current carrier to be
     * invalid.
     *
     * @param callSubject The call subject.
     * @return The call subject with invalid characters removed.
     */
    private String removeInstantLetteringInvalidCharacters(String callSubject) {
        String invalidCharacters = getInstantLetteringInvalidCharacters();
        if (TextUtils.isEmpty(invalidCharacters)) {
            return callSubject;
        }

        return callSubject.replaceAll(invalidCharacters, "");
    }

    /**
     * Determines from carrier config the regular expression specifying which characters are not
     * allowed in instant lettering messages.
     *
     * @return Regular expression defining the invalid characters, or empty string if none.
     */
    private String getInstantLetteringInvalidCharacters() {
        CarrierConfigManager configMgr = (CarrierConfigManager)
                mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        if (configMgr == null) {
            return "";
        }
        PersistableBundle b = configMgr.getConfigForSubId(mPhone.getSubId());
        if (b != null) {
            return b.getString(
                    CarrierConfigManager.KEY_CARRIER_INSTANT_LETTERING_INVALID_CHARS_STRING);
        }
        return "";
    }
}