aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan <adnan@cyngn.com>2014-11-05 18:34:02 -0800
committerAdnan <adnan@cyngn.com>2014-11-06 16:06:18 -0800
commit01245270a394b9b98e56b29b91660adb16b71a50 (patch)
tree0f8d2a38fc06dfa39fb63f93c475aa974e406c71
parent44f20f9880424df2dccd8c5f60e28da9892c86ed (diff)
downloadandroid_frameworks_opt_telephony-01245270a394b9b98e56b29b91660adb16b71a50.tar.gz
android_frameworks_opt_telephony-01245270a394b9b98e56b29b91660adb16b71a50.tar.bz2
android_frameworks_opt_telephony-01245270a394b9b98e56b29b91660adb16b71a50.zip
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
-rw-r--r--Android.mk1
-rwxr-xr-xsrc/java/android/provider/Telephony.java50
-rw-r--r--src/java/com/android/internal/telephony/InboundSmsHandler.java22
3 files changed, 72 insertions, 1 deletions
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;
@@ -835,6 +839,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
* user whether they want to replace the current default
@@ -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;
+ }
}
}
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<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