From 01245270a394b9b98e56b29b91660adb16b71a50 Mon Sep 17 00:00:00 2001
From: Adnan
Date: Wed, 5 Nov 2014 18:34:02 -0800
Subject: 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
---
Android.mk | 1 +
src/java/android/provider/Telephony.java | 50 ++++++++++++++++++++++
.../internal/telephony/InboundSmsHandler.java | 22 +++++++++-
3 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/Android.mk b/Android.mk
index 5589a3a40..64d69a9a5 100644
--- a/Android.mk
+++ b/Android.mk
@@ -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
diff --git a/src/java/android/provider/Telephony.java b/src/java/android/provider/Telephony.java
index 7332496d2..e8deaa50f 100755
--- a/src/java/android/provider/Telephony.java
+++ b/src/java/android/provider/Telephony.java
@@ -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:
+ *
+ *
+ *
+ * - "pdus" - An Object[] of byte[]s containing the PDUs
+ * that make up the message.
+ *
+ *
+ * The extra values can be extracted using
+ * {@link #getMessagesFromIntent(Intent)}.
+ *
+ * If a BroadcastReceiver encounters an error while processing
+ * this intent it should set the result code appropriately.
+ * @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 getNormalizedAddressesFromPdus(byte[][] pdus,
+ String format) {
+ int pduCount = pdus.length;
+ SmsMessage[] msgs = new SmsMessage[pduCount];
+ List addresses = new ArrayList();
+
+ 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;
+ }
}
}
diff --git a/src/java/com/android/internal/telephony/InboundSmsHandler.java b/src/java/com/android/internal/telephony/InboundSmsHandler.java
index fe29695d7..cbec2b081 100644
--- a/src/java/com/android/internal/telephony/InboundSmsHandler.java
+++ b/src/java/com/android/internal/telephony/InboundSmsHandler.java
@@ -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 regAddresses = Settings.Secure.getDelimitedStringAsList(mContext.getContentResolver(),
+ Settings.Secure.PROTECTED_SMS_ADDRESSES , "\\|");
+
+ List 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
--
cgit v1.2.3