summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2013-07-07 19:13:09 -0700
committerKoushik Dutta <koushd@gmail.com>2013-07-11 09:33:44 -0700
commitaf06916efaf041b02df3233b2bf8eeac62d93ae8 (patch)
treefa950deb6986b90a3a3ed7c1c2e4281b84bd8d05
parentb7abe4eecf521ec79c0797cfa8ea67e4505a97c4 (diff)
downloadframeworks_opt_telephony-af06916efaf041b02df3233b2bf8eeac62d93ae8.zip
frameworks_opt_telephony-af06916efaf041b02df3233b2bf8eeac62d93ae8.tar.gz
frameworks_opt_telephony-af06916efaf041b02df3233b2bf8eeac62d93ae8.tar.bz2
Refactor SMS Middleware and SMS Send path.
Introduce a new Broadcast, ACTION_NEW_OUTGOING_SMS, that is similar to the existing call equivalent ACTION_NEW_OUTGOING_CALL. This allows a receiver to rewrite the intent or cancel it entirely. This removes the need for injecting middleware. Change-Id: I063288461161979f951932f32ade2cfbd72f8b73
-rw-r--r--Android.mk1
-rw-r--r--src/java/com/android/internal/telephony/ISms.aidl2
-rw-r--r--src/java/com/android/internal/telephony/ISmsMiddleware.aidl12
-rw-r--r--src/java/com/android/internal/telephony/IccSmsInterfaceManager.java21
-rw-r--r--src/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java110
5 files changed, 82 insertions, 64 deletions
diff --git a/Android.mk b/Android.mk
index fa7bbeb..9e07849 100644
--- a/Android.mk
+++ b/Android.mk
@@ -19,7 +19,6 @@ include $(CLEAR_VARS)
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/src/java
LOCAL_SRC_FILES := \
src/java/com/android/internal/telephony/ISms.aidl \
- src/java/com/android/internal/telephony/ISmsMiddleware.aidl \
src/java/com/android/internal/telephony/IIccPhoneBook.aidl \
src/java/com/android/internal/telephony/EventLogTags.logtags \
diff --git a/src/java/com/android/internal/telephony/ISms.aidl b/src/java/com/android/internal/telephony/ISms.aidl
index 0f50ff0..88a92df 100644
--- a/src/java/com/android/internal/telephony/ISms.aidl
+++ b/src/java/com/android/internal/telephony/ISms.aidl
@@ -18,7 +18,6 @@ package com.android.internal.telephony;
import android.app.PendingIntent;
import com.android.internal.telephony.SmsRawData;
-import com.android.internal.telephony.ISmsMiddleware;
import java.util.List;
@@ -37,7 +36,6 @@ import java.util.List;
*/
interface ISms {
- void registerSmsMiddleware(String name, ISmsMiddleware middleware);
void synthesizeMessages(String originatingAddress, String scAddress, in List<String> messages, long timestampMillis);
/**
diff --git a/src/java/com/android/internal/telephony/ISmsMiddleware.aidl b/src/java/com/android/internal/telephony/ISmsMiddleware.aidl
deleted file mode 100644
index 1268f2e..0000000
--- a/src/java/com/android/internal/telephony/ISmsMiddleware.aidl
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.android.internal.telephony;
-
-import android.app.PendingIntent;
-
-interface ISmsMiddleware {
- boolean onSendText(in String destAddr, in String scAddr, in String text,
- in PendingIntent sentIntent, in PendingIntent deliveryIntent);
-
- boolean onSendMultipartText(in String destinationAddress, in String scAddress,
- in List<String> parts, in List<PendingIntent> sentIntents,
- in List<PendingIntent> deliveryIntents);
-} \ No newline at end of file
diff --git a/src/java/com/android/internal/telephony/IccSmsInterfaceManager.java b/src/java/com/android/internal/telephony/IccSmsInterfaceManager.java
index b4d13fd..dec58e6 100644
--- a/src/java/com/android/internal/telephony/IccSmsInterfaceManager.java
+++ b/src/java/com/android/internal/telephony/IccSmsInterfaceManager.java
@@ -18,6 +18,7 @@ package com.android.internal.telephony;
import android.app.PendingIntent;
import android.content.Context;
+import android.os.Binder;
import android.os.RemoteException;
import android.util.Log;
@@ -50,10 +51,6 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
}
@Override
- public void registerSmsMiddleware(String name, ISmsMiddleware middleware) throws android.os.RemoteException {
- }
-
- @Override
public void synthesizeMessages(String originatingAddress, String scAddress, List<String> messages, long timestampMillis) throws RemoteException {
}
@@ -121,9 +118,11 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
*/
public void sendText(String destAddr, String scAddr,
String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {
- mPhone.getContext().enforceCallingPermission(
- "android.permission.SEND_SMS",
- "Sending SMS message");
+ if (Binder.getCallingPid() != android.os.Process.myPid()) {
+ mPhone.getContext().enforceCallingPermission(
+ "android.permission.SEND_SMS",
+ "Sending SMS message");
+ }
if (Log.isLoggable("SMS", Log.VERBOSE)) {
log("sendText: destAddr=" + destAddr + " scAddr=" + scAddr +
" text='"+ text + "' sentIntent=" +
@@ -159,9 +158,11 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
*/
public void sendMultipartText(String destAddr, String scAddr, List<String> parts,
List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) {
- mPhone.getContext().enforceCallingPermission(
- "android.permission.SEND_SMS",
- "Sending SMS message");
+ if (Binder.getCallingPid() != android.os.Process.myPid()) {
+ mPhone.getContext().enforceCallingPermission(
+ "android.permission.SEND_SMS",
+ "Sending SMS message");
+ }
if (Log.isLoggable("SMS", Log.VERBOSE)) {
int i = 0;
for (String part : parts) {
diff --git a/src/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java b/src/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
index 44882ef..9572c39 100644
--- a/src/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
+++ b/src/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
@@ -16,23 +16,58 @@
package com.android.internal.telephony;
-import java.util.Hashtable;
+import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.os.SystemProperties;
+import android.os.UserHandle;
import android.provider.Telephony.Sms.Intents;
import android.telephony.SmsMessage;
public class IccSmsInterfaceManagerProxy extends ISms.Stub {
private IccSmsInterfaceManager mIccSmsInterfaceManager;
- private Hashtable<String, ISmsMiddleware> mMiddleware = new Hashtable<String, ISmsMiddleware>();
+
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ public void onReceive(Context context, Intent intent) {
+ // check if the message was aborted
+ if (getResultCode() != Activity.RESULT_OK) {
+ return;
+ }
+ String destAddr = getResultData();
+ String scAddr = intent.getStringExtra("scAddr");
+ ArrayList<String> parts = intent.getStringArrayListExtra("parts");
+ ArrayList<PendingIntent> sentIntents = intent.getParcelableArrayListExtra("sentIntent");
+ ArrayList<PendingIntent> deliveryIntents = intent.getParcelableArrayListExtra("deliveryIntents");
+
+ if (intent.getBooleanExtra("multipart", false)) {
+ mIccSmsInterfaceManager.sendMultipartText(destAddr, scAddr,
+ parts, sentIntents, deliveryIntents);
+ return;
+ }
+
+ PendingIntent sentIntent = null;
+ if (sentIntents != null && sentIntents.size() > 0) {
+ sentIntent = sentIntents.get(0);
+ }
+ PendingIntent deliveryIntent = null;
+ if (deliveryIntents != null && deliveryIntents.size() > 0) {
+ deliveryIntent = deliveryIntents.get(0);
+ }
+ String text = null;
+ if (parts != null && parts.size() > 0) {
+ text = parts.get(0);
+ }
+ mIccSmsInterfaceManager.sendText(destAddr, scAddr, text,
+ sentIntent, deliveryIntent);
+ }
+ };
public IccSmsInterfaceManagerProxy(Context context,
IccSmsInterfaceManager iccSmsInterfaceManager) {
@@ -51,19 +86,10 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
private void createWakelock() {
PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SMSDispatcher");
+ mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IccSmsInterfaceManager");
mWakeLock.setReferenceCounted(true);
}
- @Override
- public void registerSmsMiddleware(String name, ISmsMiddleware middleware) throws android.os.RemoteException {
- if (!"1".equals(SystemProperties.get("persist.sys.sms_debug", "0"))) {
- mContext.enforceCallingPermission(
- "android.permission.INTERCEPT_SMS", "");
- }
- mMiddleware.put(name, middleware);
- }
-
private Context mContext;
private PowerManager.WakeLock mWakeLock;
private static final int WAKE_LOCK_TIMEOUT = 5000;
@@ -83,11 +109,8 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
@Override
public void synthesizeMessages(String originatingAddress, String scAddress, List<String> messages, long timestampMillis) throws RemoteException {
- // if not running in debug mode
- if (!"1".equals(SystemProperties.get("persist.sys.sms_debug", "0"))) {
- mContext.enforceCallingPermission(
- "android.permission.BROADCAST_SMS", "");
- }
+ mContext.enforceCallingPermission(
+ android.Manifest.permission.BROADCAST_SMS, "");
byte[][] pdus = new byte[messages.size()][];
for (int i = 0; i < messages.size(); i++) {
SyntheticSmsMessage message = new SyntheticSmsMessage(originatingAddress, scAddress, messages.get(i), timestampMillis);
@@ -116,34 +139,43 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
sentIntent, deliveryIntent);
}
+ private void broadcastOutgoingSms(String destAddr, String scAddr,
+ boolean multipart, ArrayList<String> parts,
+ ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
+ Intent broadcast = new Intent(Intent.ACTION_NEW_OUTGOING_SMS);
+ broadcast.putExtra("destAddr", destAddr);
+ broadcast.putExtra("scAddr", scAddr);
+ broadcast.putExtra("multipart", multipart);
+ broadcast.putStringArrayListExtra("parts", parts);
+ broadcast.putParcelableArrayListExtra("sentIntents", sentIntents);
+ broadcast.putParcelableArrayListExtra("deliveryIntents", deliveryIntents);
+ mContext.sendOrderedBroadcastAsUser(broadcast, UserHandle.OWNER,
+ android.Manifest.permission.INTERCEPT_SMS,
+ mReceiver, null, Activity.RESULT_OK, destAddr, null);
+ }
+
public void sendText(String destAddr, String scAddr,
String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {
- for (ISmsMiddleware middleware: mMiddleware.values()) {
- try {
- if (middleware.onSendText(destAddr, scAddr, text, sentIntent, deliveryIntent))
- return;
- }
- catch (Exception e) {
- // TOOD: remove the busted middleware?
- }
- }
- mIccSmsInterfaceManager.sendText(destAddr, scAddr, text, sentIntent, deliveryIntent);
+ mContext.enforceCallingPermission(
+ android.Manifest.permission.SEND_SMS,
+ "Sending SMS message");
+ ArrayList<String> parts = new ArrayList<String>();
+ parts.add(text);
+ ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
+ sentIntents.add(sentIntent);
+ ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
+ deliveryIntents.add(deliveryIntent);
+ broadcastOutgoingSms(destAddr, scAddr, false, parts, sentIntents, deliveryIntents);
}
public void sendMultipartText(String destAddr, String scAddr,
List<String> parts, List<PendingIntent> sentIntents,
List<PendingIntent> deliveryIntents) throws android.os.RemoteException {
- for (ISmsMiddleware middleware: mMiddleware.values()) {
- try {
- if (middleware.onSendMultipartText(destAddr, scAddr, parts, sentIntents, deliveryIntents))
- return;
- }
- catch (Exception e) {
- // TOOD: remove the busted middleware?
- }
- }
- mIccSmsInterfaceManager.sendMultipartText(destAddr, scAddr,
- parts, sentIntents, deliveryIntents);
+ mContext.enforceCallingPermission(
+ android.Manifest.permission.SEND_SMS,
+ "Sending SMS message");
+ broadcastOutgoingSms(destAddr, scAddr, true, new ArrayList<String>(parts),
+ new ArrayList<PendingIntent>(sentIntents), new ArrayList<PendingIntent>(deliveryIntents));
}
public boolean enableCellBroadcast(int messageIdentifier) throws android.os.RemoteException {