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

Commit 01245270 authored by Adnan's avatar Adnan
Browse files

Telephony: Add PROTECTED_SMS_RECEIVED_ACTION.

  - If an address matches against a whitelist for known reg/auth,
  broadcast it as a protected sms received action. Not for third
  party applications.

Change-Id: Ibc62b5bb0110192620ef35f197553065a8c5345f
parent 44f20f98
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ LOCAL_SRC_FILES += $(call find-other-java-files,$(BOARD_RIL_CLASS))
endif

LOCAL_JAVA_LIBRARIES := voip-common
LOCAL_STATIC_JAVA_LIBRARIES := libphonenumbergoogle
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := telephony-common

+50 −0
Original line number Diff line number Diff line
@@ -36,9 +36,13 @@ import android.util.Patterns;

import com.android.internal.telephony.MSimConstants;
import com.android.internal.telephony.SmsApplication;
import com.google.i18n.phonenumbers.PhoneNumberUtil;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -834,6 +838,30 @@ public final class Telephony {
             */
            public static final int RESULT_SMS_BLACKLISTED_REGEX = 8;

            /**
             * Used internally:
             * Broadcast Action: A new protected text-based SMS message has been received
             * by the device. This intent will be delivered to all registered
             * receivers who possess {@link android.Manifest.permission#RECEIVE_PROTECTED_SMS}.
             * These apps SHOULD NOT write the message or notify the user.
             * The intent will have the following extra values:
             * </p>
             *
             * <ul>
             *   <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs
             *   that make up the message.</li>
             * </ul>
             *
             * <p>The extra values can be extracted using
             * {@link #getMessagesFromIntent(Intent)}.</p>
             *
             * <p>If a BroadcastReceiver encounters an error while processing
             * this intent it should set the result code appropriately.</p>
             * @hide
             */
            public static final String PROTECTED_SMS_RECEIVED_ACTION =
                    "android.provider.Telephony.ACTION_PROTECTED_SMS_RECEIVED";

            /**
             * Activity action: Ask the user to change the default
             * SMS application. This will show a dialog that asks the
@@ -1120,6 +1148,28 @@ public final class Telephony {
                }
                return msgs;
            }

            /**
             * Read the normalized addresses out of PDUs
             * @param pdus bytes for PDUs
             * @param format the format of the message
             * @return a list of Addresses for the PDUs
             */
            public static List<String> getNormalizedAddressesFromPdus(byte[][] pdus,
                    String format) {
                int pduCount = pdus.length;
                SmsMessage[] msgs = new SmsMessage[pduCount];
                List<String> addresses = new ArrayList<String>();

                for (int i = 0; i < pduCount; i++) {
                    byte[] pdu = (byte[]) pdus[i];
                    msgs[i] = SmsMessage.createFromPdu(pdu, format);
                    String normalized = PhoneNumberUtil
                            .normalizeDigitsOnly(msgs[i].getOriginatingAddress());
                    addresses.add(normalized);
                }
                return addresses;
            }
        }
    }

+21 −1
Original line number Diff line number Diff line
@@ -37,20 +37,27 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.provider.Telephony;
import android.provider.Telephony.Sms.Intents;
import android.telephony.Rlog;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;

import android.text.TextUtils;
import com.android.internal.telephony.util.BlacklistUtils;
import com.android.internal.telephony.PhoneBase;
import com.android.internal.util.HexDump;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.google.i18n.phonenumbers.PhoneNumberUtil;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;

@@ -730,7 +737,20 @@ public abstract class InboundSmsHandler extends StateMachine {
        }

        Intent intent;
        if (destPort == -1) {
        List<String> regAddresses = Settings.Secure.getDelimitedStringAsList(mContext.getContentResolver(),
                Settings.Secure.PROTECTED_SMS_ADDRESSES , "\\|");

        List<String> allAddresses = Intents
                .getNormalizedAddressesFromPdus(pdus, tracker.getFormat());

        if (!Collections.disjoint(regAddresses, allAddresses)) {
            intent = new Intent(Intents.PROTECTED_SMS_RECEIVED_ACTION);
            intent.putExtra("pdus", pdus);
            intent.putExtra("format", tracker.getFormat());
            dispatchIntent(intent, android.Manifest.permission.RECEIVE_PROTECTED_SMS,
                    AppOpsManager.OP_RECEIVE_SMS, resultReceiver);
            return true;
        } else if (destPort == -1) {
            intent = new Intent(Intents.SMS_DELIVER_ACTION);

            // Direct the intent to only the default SMS app. If we can't find a default SMS app