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

Commit 7e9c92ee authored by Thomas Stuart's avatar Thomas Stuart
Browse files

SEND_TO_INCALL null pointer exception fix

A bug was filed on ImsRttTextHandler#handleMessage(Message).
User encountered a null pointer exception in SEND_TO_INCALL case.
2 new conditionals were added to avoid 2 potential null pointer
exceptions and prevent this bug from recurring.

bug: 215215955
Test: 2 Unit tests
Change-Id: I6433b69556b1a913d97db507c17d14a596b4d884
(cherry picked from commit 06dbc439)
parent 7146156b
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -128,7 +128,16 @@ public class ImsRttTextHandler extends Handler {
                mReaderThread.start();
                break;
            case SEND_TO_INCALL:
                if (msg.obj == null) {
                    Rlog.e(LOG_TAG, "RTT msg.obj is null. Ignoring.");
                    return;
                }
                String messageToIncall = (String) msg.obj;
                if (mRttTextStream == null) {
                    Rlog.e(LOG_TAG, "RTT text stream is null. Writing to in-call buffer.");
                    mBufferedTextToIncall.append(messageToIncall);
                    return;
                }
                try {
                    mRttTextStream.write(messageToIncall);
                } catch (IOException e) {
@@ -216,6 +225,21 @@ public class ImsRttTextHandler extends Handler {
        mReadNotifier = latch;
    }

    @VisibleForTesting
    public StringBuffer getBufferedTextToIncall() {
        return mBufferedTextToIncall;
    }

    @VisibleForTesting
    public void setRttTextStream(Connection.RttTextStream rttTextStream) {
        mRttTextStream = rttTextStream;
    }

    @VisibleForTesting
    public int getSendToIncall() {
        return SEND_TO_INCALL;
    }

    public String getNetworkBufferText() {
        return mBufferedTextToNetwork.toString();
    }
+38 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony.imsphone;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import android.os.HandlerThread;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.telecom.Connection;

@@ -41,6 +42,7 @@ import java.util.concurrent.TimeUnit;
public class ImsRttTextHandlerTest extends TelephonyTest {
    private static final int TEST_TIMEOUT = 1000;
    private static final int READ_BUFFER_SIZE = 1000;
    private static final String SHORT_TEXT = "Hello, World!";
    private static final String LONG_TEXT = "No Soldier shall, in time of peace be quartered in " +
            "any house, without the consent of the Owner, nor in time of war, but in a manner to " +
            "be prescribed by law.";
@@ -223,6 +225,42 @@ public class ImsRttTextHandlerTest extends TelephonyTest {
        Assert.assertEquals(LONG_TEXT, readAll(mPipeFromHandler));
    }

    /**
     * Test {@link ImsRttTextHandler#handleMessage(Message)} SEND_TO_INCALL case.  Specifically,
     * test SEND_IN_CALL does not throw an exception when given a null msg.obj.
     */
    @Test
    public void testHandleMessageCaseSendToInCallWithNullMsgObj() {
        // Create a Message object
        Message msg = new Message();
        // Set the message what to SEND_TO_INCALL
        msg.setWhat(mRttTextHandler.getSendToIncall());
        // Set the message object to null
        msg.obj = null;
        // Call handleMessage with the null msg and ensure no Exception is thrown
        mRttTextHandler.handleMessage(msg);
    }

    /**
     * Test {@link ImsRttTextHandler#handleMessage(Message)} SEND_TO_INCALL case.  If
     * mRttTextStream is null, then text should be written to mBufferedTextToIncall.
     */
    @Test
    public void testHandleMessageWithRttTextStreamNull() {
        // Ensure the buffer is empty
        Assert.assertEquals("", mRttTextHandler.getBufferedTextToIncall().toString());
        // Simulate the stream was never initialized or null
        mRttTextHandler.setRttTextStream(null);
        // Wait for change to take action
        waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT);
        // Send text to In Call
        mRttTextHandler.sendToInCall(SHORT_TEXT);
        // Wait for change to take action
        waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT);
        // Assert the text was written to the buffer
        Assert.assertEquals(SHORT_TEXT, mRttTextHandler.getBufferedTextToIncall().toString());
    }

    @After
    public void tearDown() throws Exception {
        mPipeFromHandler.close();