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

Commit c607acbd authored by Arc Wang's avatar Arc Wang Committed by Gerrit Code Review
Browse files

Merge "Gracefully handle pdu null case in SMSDispatcher.sendMultipartText"

parents 877bf6fd 3f4d2e08
Loading
Loading
Loading
Loading
+26 −22
Original line number Diff line number Diff line
@@ -967,14 +967,19 @@ public abstract class SMSDispatcher extends Handler {
     *  Validity Period(Maximum) -> 635040 mins(i.e.63 weeks).
     *  Any Other values included Negative considered as Invalid Validity Period of the message.
     */
    protected void sendMultipartText(String destAddr, String scAddr,
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
    public void sendMultipartText(String destAddr, String scAddr,
            ArrayList<String> parts, ArrayList<PendingIntent> sentIntents,
            ArrayList<PendingIntent> deliveryIntents, Uri messageUri, String callingPkg,
            boolean persistMessage, int priority, boolean expectMore, int validityPeriod) {
        final String fullMessageText = getMultipartMessageText(parts);
        int refNumber = getNextConcatenatedRef() & 0x00FF;
        int msgCount = parts.size();
        int encoding = SmsConstants.ENCODING_UNKNOWN;
        int msgCount = parts.size();
        if (msgCount < 1) {
            triggerSentIntentForFailure(sentIntents);
            return;
        }

        TextEncodingDetails[] encodingForParts = new TextEncodingDetails[msgCount];
        for (int i = 0; i < msgCount; i++) {
@@ -1029,15 +1034,12 @@ public abstract class SMSDispatcher extends Handler {
                        sentIntent, deliveryIntent, (i == (msgCount - 1)),
                        unsentPartCount, anyPartFailed, messageUri,
                        fullMessageText, priority, expectMore, validityPeriod);
            trackers[i].mPersistMessage = persistMessage;
        }

        if (parts == null || trackers == null || trackers.length == 0
                || trackers[0] == null) {
            Rlog.e(TAG, "Cannot send multipart text. parts=" + parts + " trackers=" + trackers);
            if (trackers[i] == null) {
                triggerSentIntentForFailure(sentIntents);
                return;
            }
            trackers[i].mPersistMessage = persistMessage;
        }

        String carrierPackage = getCarrierAppPackageName();
        if (carrierPackage != null) {
@@ -1048,11 +1050,7 @@ public abstract class SMSDispatcher extends Handler {
        } else {
            Rlog.v(TAG, "No carrier package.");
            for (SmsTracker tracker : trackers) {
                if (tracker != null) {
                sendSubmitPdu(tracker);
                } else {
                    Rlog.e(TAG, "Null tracker.");
                }
            }
        }
    }
@@ -1085,13 +1083,18 @@ public abstract class SMSDispatcher extends Handler {
                    com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(destinationAddress,
                            uData, (deliveryIntent != null) && lastPart, priority);

            if (submitPdu != null) {
                HashMap map = getSmsTrackerMap(destinationAddress, scAddress,
                        message, submitPdu);
                return getSmsTracker(map, sentIntent, deliveryIntent,
                        getFormat(), unsentPartCount, anyPartFailed, messageUri, smsHeader,
                        (!lastPart || expectMore), fullMessageText, true /*isText*/,
                        true /*persistMessage*/, priority, validityPeriod);

            } else {
                Rlog.e(TAG, "CdmaSMSDispatcher.getNewSubmitPduTracker(): getSubmitPdu() returned "
                        + "null");
                return null;
            }
        } else {
            SmsMessageBase.SubmitPduBase pdu =
                    com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
@@ -1106,7 +1109,8 @@ public abstract class SMSDispatcher extends Handler {
                        smsHeader, (!lastPart || expectMore), fullMessageText, true /*isText*/,
                        false /*persistMessage*/, priority, validityPeriod);
            } else {
                Rlog.e(TAG, "GsmSMSDispatcher.sendNewSubmitPdu(): getSubmitPdu() returned null");
                Rlog.e(TAG, "GsmSMSDispatcher.getNewSubmitPduTracker(): getSubmitPdu() returned "
                        + "null");
                return null;
            }
        }
+38 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.HashMap;

public class GsmSmsDispatcherTest extends TelephonyTest {
@@ -86,7 +87,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
    @Mock
    private ISub.Stub mISubStub;
    private Object mLock = new Object();
    private boolean mReceivedTestIntent = false;
    private boolean mReceivedTestIntent;
    private static final String TEST_INTENT = "com.android.internal.telephony.TEST_INTENT";
    private BroadcastReceiver mTestReceiver = new BroadcastReceiver() {
        @Override
@@ -215,6 +216,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(realContext, 0,
                new Intent(TEST_INTENT), 0);
        // send invalid dest address: +
        mReceivedTestIntent = false;
        mGsmSmsDispatcher.sendText("+", "222" /*scAddr*/, TAG,
                pendingIntent, null, null, null, false, -1, false, -1);
        waitForMs(500);
@@ -257,4 +259,39 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        verify(mSmsTracker, times(1)).onFailed(any(), argumentCaptor.capture(), anyInt());
        assertEquals(RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED, (int) argumentCaptor.getValue());
    }

    @Test @SmallTest
    public void testSendMultipartTextWithInvalidText() throws Exception {
        // unmock ActivityManager to be able to register receiver, create real PendingIntent and
        // receive TEST_INTENT
        restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton);
        restoreInstance(ActivityManager.class, "IActivityManagerSingleton", null);

        Context realContext = TestApplication.getAppContext();
        realContext.registerReceiver(mTestReceiver, new IntentFilter(TEST_INTENT));

        // initiate parameters for an invalid text MO SMS (the 2nd segmeant has 161 characters)
        ArrayList<String> parts = new ArrayList<>();
        parts.add("valid segment1");
        parts.add("too long segment2 12345678912345678912345678912345678912345678912345678912345678"
                + "91234567891234567891234567891234567891234567891234567891234567891234567891234567"
                + "8");

        ArrayList<PendingIntent> sentIntents = new ArrayList<>();
        PendingIntent sentIntent = PendingIntent.getBroadcast(realContext, 0,
                new Intent(TEST_INTENT), 0);
        sentIntents.add(sentIntent);
        sentIntents.add(sentIntent);

        // send SMS and check sentIntent
        mReceivedTestIntent = false;
        mGsmSmsDispatcher.sendMultipartText("+123" /*destAddr*/, "222" /*scAddr*/, parts,
                sentIntents, null, null, null, false, -1, false, -1);

        waitForMs(500);
        synchronized (mLock) {
            assertEquals(true, mReceivedTestIntent);
            assertEquals(SmsManager.RESULT_ERROR_GENERIC_FAILURE, mTestReceiver.getResultCode());
        }
    }
}