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

Commit feff28f0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Drop SMS that starts with VVM prefix even if the filter is not activated"

parents 34372aca 1a463e27
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -124,6 +124,15 @@ public class VisualVoicemailSmsFilter {
        settings = telephonyManager.getActiveVisualVoicemailSmsFilterSettings(subId);

        if (settings == null) {
            FullMessage fullMessage = getFullMessage(pdus, format);
            if (fullMessage != null) {
                // This is special case that voice mail SMS received before the filter has been
                // set. To drop the SMS unconditionally.
                if (messageBodyMatchesVvmPattern(context, subId, fullMessage.fullMessageBody)) {
                    Log.e(TAG, "SMS matching VVM format received but the filter not been set yet");
                    return true;
                }
            }
            return false;
        }

@@ -182,8 +191,19 @@ public class VisualVoicemailSmsFilter {
            return true;
        }

        if (messageBodyMatchesVvmPattern(context, subId, messageBody)) {
            Log.w(TAG,
                    "SMS matches pattern but has illegal format, still dropping as VVM SMS");
            sendVvmSmsBroadcast(context, settings, phoneAccountHandle, null, messageBody);
            return true;
        }
        return false;
    }

    private static boolean messageBodyMatchesVvmPattern(Context context, int subId,
            String messageBody) {
        buildPatternsMap(context);
        String mccMnc = telephonyManager.getSimOperator(subId);
        String mccMnc = context.getSystemService(TelephonyManager.class).getSimOperator(subId);

        List<Pattern> patterns = sPatterns.get(mccMnc);
        if (patterns == null || patterns.isEmpty()) {
@@ -192,9 +212,7 @@ public class VisualVoicemailSmsFilter {

        for (Pattern pattern : patterns) {
            if (pattern.matcher(messageBody).matches()) {
                Log.w(TAG, "Incoming SMS matches pattern " + pattern + " but has illegal format, "
                        + "still dropping as VVM SMS");
                sendVvmSmsBroadcast(context, settings, phoneAccountHandle, null, messageBody);
                Log.w(TAG, "Incoming SMS matches pattern " + pattern);
                return true;
            }
        }
+32 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.when;

import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
import android.telephony.VisualVoicemailSmsFilterSettings;
@@ -61,6 +62,22 @@ public class VisualVoicemailSmsFilterTest extends TestCase {
            (byte) 0xE9, (byte) 0x62, (byte) 0x37, (byte) 0x50, (byte) 0x0B, (byte) 0x86,
            (byte) 0x83, (byte) 0xC1, (byte) 0x76, (byte) 0xEC, (byte) 0x1E, (byte) 0x0D}};

    /**
     * PDU for the following message:
     * <p>originating number: 129
     * <p>message: //VZWVVM
     */
    private static final byte[][] VZWVVM_PDU = {{
            (byte) 0x07, (byte) 0x91, (byte) 0x41, (byte) 0x50, (byte) 0x74, (byte) 0x02,
            (byte) 0x50, (byte) 0xF5, (byte) 0x04, (byte) 0x03, (byte) 0xC9, (byte) 0x21,
            (byte) 0xF9, (byte) 0x00, (byte) 0x00, (byte) 0x71, (byte) 0x30, (byte) 0x70,
            (byte) 0x81, (byte) 0x71, (byte) 0x81, (byte) 0x2B, (byte) 0x08, (byte) 0xAF,
            (byte) 0x97, (byte) 0x55, (byte) 0x7B, (byte) 0xB5, (byte) 0x5A, (byte) 0x9B}};

    private static final String SIM_MCC_MNC = "001002";

    private static final String[] VVM_PATTERN_REGEXP = {SIM_MCC_MNC + ";^//VZWVVM.*"};

    private Context mContext;
    private TelephonyManager mTelephonyManager;

@@ -109,6 +126,21 @@ public class VisualVoicemailSmsFilterTest extends TestCase {
                VisualVoicemailSmsFilter.filter(mContext, pdus, SmsConstants.FORMAT_3GPP, 0, 0));
    }

    public void testFilterNotSet_matchesVvmPattern_filtered() {
        setSettings(null);
        Resources resources = Mockito.mock(Resources.class);
        when(mTelephonyManager.getSimOperator(anyInt()))
                .thenReturn(SIM_MCC_MNC);
        when(mContext.getResources())
                .thenReturn(resources);
        when(resources.getStringArray(com.android.internal.R.array.config_vvmSmsFilterRegexes))
                .thenReturn(VVM_PATTERN_REGEXP);

        assertTrue(
                VisualVoicemailSmsFilter.filter(mContext, VZWVVM_PDU, SmsConstants.FORMAT_3GPP, 0,
                        0));
    }

    public void testOriginatingNumber_unspecified_filtered() {
        setSettings(new VisualVoicemailSmsFilterSettings.Builder().build());
        assertTrue(VisualVoicemailSmsFilter