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

Commit 98399f06 authored by ashastry's avatar ashastry Committed by Gerrit Code Review
Browse files

Merge "Permit privileged system apps to send SMS without persisting."

parents 9ca49a5d a700124b
Loading
Loading
Loading
Loading
+27 −18
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.telephony;

import android.annotation.SystemApi;
import android.app.ActivityThread;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
@@ -298,13 +299,13 @@ public final class SmsManager {
    public void sendTextMessage(
            String destinationAddress, String scAddress, String text,
            PendingIntent sentIntent, PendingIntent deliveryIntent) {
        sendTextMessageInternal(destinationAddress, scAddress, text,
            sentIntent, deliveryIntent, true /* persistMessageForCarrierApp*/);
        sendTextMessageInternal(destinationAddress, scAddress, text, sentIntent, deliveryIntent,
                true /* persistMessage*/);
    }

    private void sendTextMessageInternal(String destinationAddress, String scAddress,
            String text, PendingIntent sentIntent, PendingIntent deliveryIntent,
            boolean persistMessageForCarrierApp) {
            boolean persistMessage) {
        if (TextUtils.isEmpty(destinationAddress)) {
            throw new IllegalArgumentException("Invalid destinationAddress");
        }
@@ -318,7 +319,7 @@ public final class SmsManager {
            iccISms.sendTextForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
                    destinationAddress,
                    scAddress, text, sentIntent, deliveryIntent,
                    persistMessageForCarrierApp);
                    persistMessage);
        } catch (RemoteException ex) {
            // ignore it
        }
@@ -327,16 +328,20 @@ public final class SmsManager {
    /**
     * Send a text based SMS without writing it into the SMS Provider.
     *
     * <p>Only the carrier app can call this method.</p>
     * <p>Requires Permission:
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or the calling app has carrier
     * privileges.
     * </p>
     *
     * @see #sendTextMessage(String, String, String, PendingIntent, PendingIntent)
     * @hide
     */
    @SystemApi
    public void sendTextMessageWithoutPersisting(
            String destinationAddress, String scAddress, String text,
            PendingIntent sentIntent, PendingIntent deliveryIntent) {
        sendTextMessageInternal(destinationAddress, scAddress, text,
            sentIntent, deliveryIntent, false /* persistMessageForCarrierApp*/);
        sendTextMessageInternal(destinationAddress, scAddress, text, sentIntent, deliveryIntent,
                false /* persistMessage */);
    }

    /**
@@ -465,14 +470,14 @@ public final class SmsManager {
    public void sendMultipartTextMessage(
            String destinationAddress, String scAddress, ArrayList<String> parts,
            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts,
              sentIntents, deliveryIntents, true /* persistMessageForCarrierApp*/);
        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
                deliveryIntents, true /* persistMessage*/);
    }

    private void sendMultipartTextMessageInternal(
            String destinationAddress, String scAddress, ArrayList<String> parts,
            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents,
            boolean persistMessageForCarrierApp) {
            String destinationAddress, String scAddress, List<String> parts,
            List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents,
            boolean persistMessage) {
        if (TextUtils.isEmpty(destinationAddress)) {
            throw new IllegalArgumentException("Invalid destinationAddress");
        }
@@ -486,7 +491,7 @@ public final class SmsManager {
                iccISms.sendMultipartTextForSubscriber(getSubscriptionId(),
                        ActivityThread.currentPackageName(),
                        destinationAddress, scAddress, parts,
                        sentIntents, deliveryIntents, persistMessageForCarrierApp);
                        sentIntents, deliveryIntents, persistMessage);
            } catch (RemoteException ex) {
                // ignore it
            }
@@ -507,16 +512,20 @@ public final class SmsManager {
    /**
     * Send a multi-part text based SMS without writing it into the SMS Provider.
     *
     * <p>Only the carrier app can call this method.</p>
     * <p>Requires Permission:
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or the calling app has carrier
     * privileges.
     * </p>
     *
     * @see #sendMultipartTextMessage(String, String, ArrayList, ArrayList, ArrayList)
     * @hide
     **/
    @SystemApi
    public void sendMultipartTextMessageWithoutPersisting(
            String destinationAddress, String scAddress, ArrayList<String> parts,
            ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts,
            sentIntents, deliveryIntents, false /* persistMessageForCarrierApp*/);
            String destinationAddress, String scAddress, List<String> parts,
            List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) {
        sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
                deliveryIntents, false /* persistMessage*/);
    }

    /**
+6 −6
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.os.AsyncResult;
import android.os.Binder;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.os.UserManager;
import android.provider.Telephony;
import android.service.carrier.CarrierMessagingService;
@@ -1118,20 +1117,20 @@ public class IccSmsInterfaceManager {
    }

    /**
     * Enforces that the caller is one of the following:
     * Enforces that the caller has {@link android.Manifest.permission#MODIFY_PHONE_STATE}
     * permission or is one of the following apps:
     * <ul>
     *     <li> Phone process
     *     <li> IMS App
     *     <li> Carrier App
     * </ul>
     */
    private void enforcePrivilegedAppPermissions() {
        int callingUid = Binder.getCallingUid();
        // Allow the phone process itself to send, inject messages.
        if (callingUid == Process.PHONE_UID) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
                == PackageManager.PERMISSION_GRANTED) {
            return;
        }

        int callingUid = Binder.getCallingUid();
        String carrierImsPackage = CarrierSmsUtils.getCarrierImsPackageForIntent(mContext, mPhone,
                new Intent(CarrierMessagingService.SERVICE_INTERFACE));
        try {
@@ -1145,6 +1144,7 @@ public class IccSmsInterfaceManager {
                log("Cannot find configured carrier ims package");
            }
        }

        enforceCarrierPrivilege();
    }