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

Commit 058f5401 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Add null check to avoid exception.

Code was already added for b/28614514; moving it to check a little
earlier. Also adding another null pointer check.

This takes care of b/28842442 too.

Bug: 28883656
Change-Id: Ib8e29a7cc18bffa45a361c27a640fef791d6cafa
parent 673a8e3d
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -780,6 +780,14 @@ public abstract class InboundSmsHandler extends StateMachine {
            }
        }

        // Do not process null pdu(s). Check for that and return false in that case.
        List<byte[]> pduList = Arrays.asList(pdus);
        if (pduList.size() == 0 || pduList.contains(null)) {
            loge("processMessagePart: returning false due to " +
                    (pduList.size() == 0 ? "pduList.size() == 0" : "pduList.contains(null)"));
            return false;
        }

        if (!mUserManager.isUserUnlocked()) {
            return processMessagePartWithUserLocked(tracker, pdus, destPort);
        }
@@ -793,7 +801,12 @@ public abstract class InboundSmsHandler extends StateMachine {
                // 3GPP needs to extract the User Data from the PDU; 3GPP2 has already done this
                if (!tracker.is3gpp2()) {
                    SmsMessage msg = SmsMessage.createFromPdu(pdu, SmsConstants.FORMAT_3GPP);
                    if (msg != null) {
                        pdu = msg.getUserData();
                    } else {
                        loge("processMessagePart: SmsMessage.createFromPdu returned null");
                        return false;
                    }
                }
                output.write(pdu, 0, pdu.length);
            }
@@ -880,15 +893,6 @@ public abstract class InboundSmsHandler extends StateMachine {
     */
    private boolean filterSmsWithCarrierOrSystemApp(byte[][] pdus, int destPort,
        InboundSmsTracker tracker, SmsBroadcastReceiver resultReceiver, boolean userUnlocked) {
        // Do not send null pdu(s) to CarrierSmsFilter. Check for that and return false in that case
        List<byte[]> pduList = Arrays.asList(pdus);
        if (pduList == null || pduList.size() == 0 || pduList.contains(null)) {
            loge("filterSmsWithCarrierOrSystemApp: Bypassing carrier/system sms filter due to " +
                    (pduList == null ? "pduList == null" : (pduList.size() == 0 ?
                            "pduList.size() == 0" : "pduList.contains(null)")));
            return false;
        }

        List<String> carrierPackages = null;
        UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
        if (card != null) {
+40 −0
Original line number Diff line number Diff line
@@ -594,6 +594,46 @@ public class GsmInboundSmsHandlerTest extends TelephonyTest {
        assertEquals("IdleState", getCurrentState().getName());
    }

    @Test
    @MediumTest
    public void testMultiPartIncompleteSms() {
        /**
         * Test scenario: 2 messages are received with same address, ref number, count, and
         * seqNumber, with count = 2 and seqNumber = 1. We should not try to merge these.
         */
        transitionFromStartupToIdle();

        // prepare SMS part 1 and part 2
        prepareMultiPartSms();
        // change seqNumber in part 2 to 1
        mInboundSmsTrackerCVPart2.put("sequence", 1);

        mSmsHeader.concatRef = new SmsHeader.ConcatRef();
        doReturn(mSmsHeader).when(mGsmSmsMessage).getUserDataHeader();

        doReturn(mInboundSmsTrackerPart1).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(byte[].class), anyLong(), anyInt(), anyBoolean(),
                        anyString(), anyInt(), anyInt(), anyInt(), anyBoolean(), anyString());
        mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null,
                mSmsMessage, null));
        waitForMs(100);

        // State machine should go back to idle and wait for second part
        assertEquals("IdleState", getCurrentState().getName());

        doReturn(mInboundSmsTrackerPart2).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(byte[].class), anyLong(), anyInt(), anyBoolean(),
                        anyString(), anyInt(), anyInt(), anyInt(), anyBoolean(), anyString());
        mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null,
                mSmsMessage, null));
        waitForMs(100);

        // verify no broadcasts sent
        verify(mContext, never()).sendBroadcast(any(Intent.class));
        // State machine should go back to idle
        assertEquals("IdleState", getCurrentState().getName());
    }

    @Test
    @MediumTest
    public void testMultipartSmsFromBlockedNumber_noBroadcastsSent() {