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

Commit 0ef782f7 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

Sms: Fix appOps checks for app-sent text messages

The CM SMS Send broadcast introduced at I063288461161979f951932f32ade2cfbd72f8b73
makes all messages go through a broadcast loop inside the telephony stack
before being sent to the actual interface manager. Calling context is
preserved, down to the calling package, but the actual text is sent by
the framework itself, under the radio UID, resulting in a mismatch vs
the calling app's that makes AppOps reject the operation:

W/AppOps  (  422): Bad call: specified package com.android.mms under uid 1001 but it is really 10030

Instead of rewriting the callingPackage name to the true sender (telephony),
which would break AppOps' ability to block text messages from apps, preserve
the UID of the original app and use that when checking.

Change-Id: I62a4a55567b10252bc37388f233e6fb83282bb1d
parent ed914089
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -350,6 +350,14 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
    @Override
    public void sendText(String callingPackage, String destAddr, String scAddr,
            String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {
        int callingUid = Binder.getCallingUid();

        String[] callingParts = callingPackage.split("\\\\");
        if (callingUid == android.os.Process.PHONE_UID &&
                                         callingParts.length > 1) {
            callingUid = Integer.parseInt(callingParts[1]);
        }

        if (Binder.getCallingPid() != android.os.Process.myPid()) {
            mPhone.getContext().enforceCallingPermission(
                    Manifest.permission.SEND_SMS,
@@ -360,8 +368,8 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
                " text='"+ text + "' sentIntent=" +
                sentIntent + " deliveryIntent=" + deliveryIntent);
        }
        if (mAppOps.noteOp(AppOpsManager.OP_SEND_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
        if (mAppOps.noteOp(AppOpsManager.OP_SEND_SMS, callingUid,
                callingParts[0]) != AppOpsManager.MODE_ALLOWED) {
            return;
        }
        mDispatcher.sendText(destAddr, scAddr, text, sentIntent, deliveryIntent);
@@ -396,6 +404,14 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
    public void sendMultipartText(String callingPackage, String destAddr, String scAddr,
            List<String> parts, List<PendingIntent> sentIntents,
            List<PendingIntent> deliveryIntents) {
        int callingUid = Binder.getCallingUid();

        String[] callingParts = callingPackage.split("\\\\");
        if (callingUid == android.os.Process.PHONE_UID &&
                                         callingParts.length > 1) {
            callingUid = Integer.parseInt(callingParts[1]);
        }

        if (Binder.getCallingPid() != android.os.Process.myPid()) {
            mPhone.getContext().enforceCallingPermission(
                    Manifest.permission.SEND_SMS,
@@ -408,8 +424,8 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
                        ", part[" + (i++) + "]=" + part);
            }
        }
        if (mAppOps.noteOp(AppOpsManager.OP_SEND_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
        if (mAppOps.noteOp(AppOpsManager.OP_SEND_SMS, callingUid,
                callingParts[0]) != AppOpsManager.MODE_ALLOWED) {
            return;
        }
        mDispatcher.sendMultipartText(destAddr, scAddr, (ArrayList<String>) parts,
+5 −0
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
            ArrayList<PendingIntent> sentIntents = intent.getParcelableArrayListExtra("sentIntents");
            ArrayList<PendingIntent> deliveryIntents = intent.getParcelableArrayListExtra("deliveryIntents");

            if (intent.getIntExtra("callingUid", 0) != 0) {
                callingPackage = callingPackage + "\\" + intent.getIntExtra("callingUid", 0);
            }

            if (intent.getBooleanExtra("multipart", false)) {
                mIccSmsInterfaceManager.sendMultipartText(callingPackage, destAddr, scAddr,
                        parts, sentIntents, deliveryIntents);
@@ -151,6 +155,7 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
        broadcast.putExtra("scAddr", scAddr);
        broadcast.putExtra("multipart", multipart);
        broadcast.putExtra("callingPackage", callingPackage);
        broadcast.putExtra("callingUid", android.os.Binder.getCallingUid());
        broadcast.putStringArrayListExtra("parts", parts);
        broadcast.putParcelableArrayListExtra("sentIntents", sentIntents);
        broadcast.putParcelableArrayListExtra("deliveryIntents", deliveryIntents);