Loading src/java/com/android/internal/telephony/imsphone/ImsRttTextHandler.java +24 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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(); } Loading tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRttTextHandlerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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."; Loading Loading @@ -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(); Loading Loading
src/java/com/android/internal/telephony/imsphone/ImsRttTextHandler.java +24 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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(); } Loading
tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRttTextHandlerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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."; Loading Loading @@ -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(); Loading