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

Commit 441f248c authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Replace callers of SmsApplication with user-aware

methods.

Bug: 250617029
Test: Sending and receiving SMS,
      atest FrameworkTelephonyTests,
      atest CtsTelephonyTestCases
Change-Id: I6d360254db1b9b989b28138da74d05b2ad477e1c
parent 594dbf64
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1436,12 +1436,14 @@ public abstract class InboundSmsHandler extends StateMachine {
            intent.putExtra("messageId", messageId);
        }

        UserHandle userHandle = null;
        if (destPort == -1) {
            intent.setAction(Intents.SMS_DELIVER_ACTION);
            // Direct the intent to only the default SMS app. If we can't find a default SMS app
            // then sent it to all broadcast receivers.
            // We are deliberately delivering to the primary user's default SMS App.
            ComponentName componentName = SmsApplication.getDefaultSmsApplication(mContext, true);
            userHandle = TelephonyUtils.getSubscriptionUserHandle(mContext, subId);
            ComponentName componentName = SmsApplication.getDefaultSmsApplicationAsUser(mContext,
                    true, userHandle);
            if (componentName != null) {
                // Deliver SMS message only to this receiver.
                intent.setComponent(componentName);
@@ -1465,9 +1467,12 @@ public abstract class InboundSmsHandler extends StateMachine {
            intent.setComponent(null);
        }

        if (userHandle == null) {
            userHandle = UserHandle.SYSTEM;
        }
        Bundle options = handleSmsWhitelisting(intent.getComponent(), isClass0);
        dispatchIntent(intent, android.Manifest.permission.RECEIVE_SMS,
                AppOpsManager.OPSTR_RECEIVE_SMS, options, resultReceiver, UserHandle.SYSTEM, subId);
                AppOpsManager.OPSTR_RECEIVE_SMS, options, resultReceiver, userHandle, subId);
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails;
import com.android.internal.telephony.cdma.sms.UserData;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

import java.io.FileDescriptor;
@@ -2401,9 +2402,10 @@ public abstract class SMSDispatcher extends Handler {
        /** Return if the SMS was originated from the default SMS application. */
        public boolean isFromDefaultSmsApplication(Context context) {
            if (mIsFromDefaultSmsApplication == null) {
                UserHandle userHandle = TelephonyUtils.getSubscriptionUserHandle(context, mSubId);
                // Perform a lazy initialization, due to the cost of the operation.
                mIsFromDefaultSmsApplication =
                        SmsApplication.isDefaultSmsApplication(context, getAppPackageName());
                mIsFromDefaultSmsApplication = SmsApplication.isDefaultSmsApplicationAsUser(context,
                                    getAppPackageName(), userHandle);
            }
            return mIsFromDefaultSmsApplication;
        }
+5 −1
Original line number Diff line number Diff line
@@ -23,9 +23,11 @@ import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Build;
import android.os.UserHandle;
import android.service.carrier.CarrierMessagingService;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

/**
@@ -163,7 +165,9 @@ public class SmsPermissions {
    @VisibleForTesting
    public boolean isCallerDefaultSmsPackage(String packageName) {
        if (packageNameMatchesCallingUid(packageName)) {
            return SmsApplication.isDefaultSmsApplication(mContext, packageName);
            UserHandle userHandle = TelephonyUtils.getSubscriptionUserHandle(mContext,
                    mPhone.getSubId());
            return SmsApplication.isDefaultSmsApplicationAsUser(mContext, packageName, userHandle);
        }
        return false;
    }
+9 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony;

import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -26,10 +27,12 @@ import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.UserHandle;
import android.provider.Telephony.Sms.Intents;
import android.telephony.SubscriptionManager;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

/**
@@ -223,9 +226,14 @@ public class SmsStorageMonitor extends Handler {
     * that SIM storage for SMS messages is full.
     */
    private void handleIccFull() {
        UserHandle userHandle = TelephonyUtils.getSubscriptionUserHandle(mContext,
                mPhone.getSubId());
        ComponentName componentName = SmsApplication.getDefaultSimFullApplicationAsUser(mContext,
                false, userHandle);

        // broadcast SIM_FULL intent
        Intent intent = new Intent(Intents.SIM_FULL_ACTION);
        intent.setComponent(SmsApplication.getDefaultSimFullApplication(mContext, false));
        intent.setComponent(componentName);
        mWakeLock.acquire(WAKE_LOCK_TIMEOUT);
        SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
        mContext.sendBroadcast(intent, android.Manifest.permission.RECEIVE_SMS);
+9 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.telephony.SubscriptionManager;
import android.text.TextUtils;

import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

import com.google.android.mms.pdu.GenericPdu;
@@ -391,7 +392,10 @@ public class WapPushOverSms implements ServiceConnection {

        // Direct the intent to only the default MMS app. If we can't find a default MMS app
        // then sent it to all broadcast receivers.
        ComponentName componentName = SmsApplication.getDefaultMmsApplication(mContext, true);
        UserHandle userHandle = TelephonyUtils.getSubscriptionUserHandle(mContext, subId);
        ComponentName componentName = SmsApplication.getDefaultMmsApplicationAsUser(mContext,
                true, userHandle);

        Bundle options = null;
        if (componentName != null) {
            // Deliver MMS message only to this receiver
@@ -409,9 +413,12 @@ public class WapPushOverSms implements ServiceConnection {
            options = bopts.toBundle();
        }

        if (userHandle == null) {
            userHandle = UserHandle.SYSTEM;
        }
        handler.dispatchIntent(intent, getPermissionForType(result.mimeType),
                getAppOpsStringPermissionForIntent(result.mimeType), options, receiver,
                UserHandle.SYSTEM, subId);
                userHandle, subId);
        return Activity.RESULT_OK;
    }