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

Commit e6de81fd authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Fix NPE in SmsManager and keep existing behavior

The behavior of SmsManager#sendTextMessage changed,
we are blocking the sending of the SMS if there were no
subscriptions (i.e. no SIM scenario). This change
accidently introduced a NPE scenario in some cases.

Fixed NPE and removed SMS blocking code in SmsManager
to keep existing functionality the same.

Bug: 127338050
Test: atest GtsTelephonyTestCases
Change-Id: I71eefbc8e1619701e1b1d7b12c3c080c4ef376ef
parent 8bf13f06
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ public final class SmsManager {
     *  <code>RESULT_ERROR_GENERIC_FAILURE</code><br>
     *  <code>RESULT_ERROR_RADIO_OFF</code><br>
     *  <code>RESULT_ERROR_NULL_PDU</code><br>
     *  <code>RESULT_ERROR_NO_SERVICE</code><br>
     *  For <code>RESULT_ERROR_GENERIC_FAILURE</code> the sentIntent may include
     *  the extra "errorCode" containing a radio technology specific value,
     *  generally only useful for troubleshooting.<br>
@@ -365,19 +366,12 @@ public final class SmsManager {
        if (DBG) {
            Log.d(TAG, "for subId: " + subId + ", subscription-info: " + info);
        }
        if (info == null) {
            // There is no subscription for the given subId. That can only mean one thing:
            // the caller is using a SmsManager instance with an obsolete subscription id.
            // That is most probably because caller didn't invalidate SmsManager instance
            // for an already deleted subscription id.
            Log.e(TAG, "subId: " + subId + " for this SmsManager instance is obsolete.");
            sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_NO_SERVICE);
        }

        /* If the Subscription associated with this SmsManager instance belongs to a remote-sim,
         * then send the message thru the remote-sim subscription.
         */
        if (info.getSubscriptionType() == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM) {
        if (info != null
                && info.getSubscriptionType() == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM) {
            if (DBG) Log.d(TAG, "sending message thru bluetooth");
            sendTextMessageBluetooth(destinationAddress, scAddress, text, sentIntent,
                    deliveryIntent, info);
@@ -385,8 +379,10 @@ public final class SmsManager {
        }

        try {
            // If the subscription is invalid or default, we will use the default phone to send the
            // SMS and possibly fail later in the SMS sending process.
            ISms iccISms = getISmsServiceOrThrow();
            iccISms.sendTextForSubscriber(getSubscriptionId(), ActivityThread.currentPackageName(),
            iccISms.sendTextForSubscriber(subId, ActivityThread.currentPackageName(),
                    destinationAddress,
                    scAddress, text, sentIntent, deliveryIntent,
                    persistMessage);
@@ -459,6 +455,9 @@ public final class SmsManager {
    }

    private void sendErrorInPendingIntent(PendingIntent intent, int errorCode) {
        if (intent == null) {
            return;
        }
        try {
            intent.send(errorCode);
        } catch (PendingIntent.CanceledException e) {