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/dataconnection/DcNetworkAgentTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.Mock; import java.lang.reflect.Field; Loading @@ -51,8 +51,11 @@ public class DcNetworkAgentTest extends TelephonyTest { private DcController mDcc; private DcFailBringUp mDcFailBringUp; @Mock private DataServiceManager mDataServiceManager; @Mock private DcTesterFailBringUpAll mDcTesterFailBringUpAll; @Mock private NetworkProvider mNetworkProvider; @Before Loading @@ -63,11 +66,6 @@ public class DcNetworkAgentTest extends TelephonyTest { Looper.prepare(); } doReturn(false).when(mPhone).isUsingNewDataStack(); mDataServiceManager = Mockito.mock(DataServiceManager.class); mDcTesterFailBringUpAll = Mockito.mock(DcTesterFailBringUpAll.class); mNetworkProvider = Mockito.mock(NetworkProvider.class); final NetworkAgentConfig.Builder configBuilder = new NetworkAgentConfig.Builder(); configBuilder.setLegacyType(ConnectivityManager.TYPE_MOBILE); configBuilder.setLegacyTypeName("MOBILE"); Loading Loading @@ -112,7 +110,9 @@ public class DcNetworkAgentTest extends TelephonyTest { public void testUnwantedTimeout() throws Exception { mDcNetworkAgent.markConnected(); mDcNetworkAgent.onNetworkUnwanted(); processAllFutureMessages(); processAllMessages(); moveTimeForward(60000); processAllMessages(); verifyDisconnected(); } } 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 @@ -43,6 +44,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 @@ -225,6 +227,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/dataconnection/DcNetworkAgentTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.Mock; import java.lang.reflect.Field; Loading @@ -51,8 +51,11 @@ public class DcNetworkAgentTest extends TelephonyTest { private DcController mDcc; private DcFailBringUp mDcFailBringUp; @Mock private DataServiceManager mDataServiceManager; @Mock private DcTesterFailBringUpAll mDcTesterFailBringUpAll; @Mock private NetworkProvider mNetworkProvider; @Before Loading @@ -63,11 +66,6 @@ public class DcNetworkAgentTest extends TelephonyTest { Looper.prepare(); } doReturn(false).when(mPhone).isUsingNewDataStack(); mDataServiceManager = Mockito.mock(DataServiceManager.class); mDcTesterFailBringUpAll = Mockito.mock(DcTesterFailBringUpAll.class); mNetworkProvider = Mockito.mock(NetworkProvider.class); final NetworkAgentConfig.Builder configBuilder = new NetworkAgentConfig.Builder(); configBuilder.setLegacyType(ConnectivityManager.TYPE_MOBILE); configBuilder.setLegacyTypeName("MOBILE"); Loading Loading @@ -112,7 +110,9 @@ public class DcNetworkAgentTest extends TelephonyTest { public void testUnwantedTimeout() throws Exception { mDcNetworkAgent.markConnected(); mDcNetworkAgent.onNetworkUnwanted(); processAllFutureMessages(); processAllMessages(); moveTimeForward(60000); processAllMessages(); verifyDisconnected(); } }
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 @@ -43,6 +44,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 @@ -225,6 +227,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