Loading src/java/com/android/internal/telephony/imsphone/ImsRttTextHandler.java +17 −0 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ import android.os.Message; import android.telecom.Connection; import android.telephony.Rlog; import com.android.internal.annotations.VisibleForTesting; import java.io.IOException; import java.util.concurrent.CountDownLatch; public class ImsRttTextHandler extends Handler { public interface NetworkWriter { Loading Loading @@ -60,6 +63,8 @@ public class ImsRttTextHandler extends Handler { private static final int TEARDOWN = 6; private Connection.RttTextStream mRttTextStream; // For synchronization during testing private CountDownLatch mReadNotifier; private class InCallReaderThread extends Thread { private final Connection.RttTextStream mReaderThreadRttTextStream; Loading Loading @@ -95,6 +100,9 @@ public class ImsRttTextHandler extends Handler { } obtainMessage(APPEND_TO_NETWORK_BUFFER, charsReceived) .sendToTarget(); if (mReadNotifier != null) { mReadNotifier.countDown(); } } } } Loading Loading @@ -200,4 +208,13 @@ public class ImsRttTextHandler extends Handler { public void tearDown() { obtainMessage(TEARDOWN).sendToTarget(); } @VisibleForTesting public void setReadNotifier(CountDownLatch latch) { mReadNotifier = latch; } public String getNetworkBufferText() { return mBufferedTextToNetwork.toString(); } } tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRttTextHandlerTest.java +24 −9 Original line number Diff line number Diff line Loading @@ -25,11 +25,14 @@ import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.ComparisonFailure; import org.junit.Test; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class ImsRttTextHandlerTest extends TelephonyTest { private static final int TEST_TIMEOUT = 1000; Loading Loading @@ -121,29 +124,41 @@ public class ImsRttTextHandlerTest extends TelephonyTest { */ @Test public void testSendAfterEnoughChars() throws Exception { // Register a read notifier CountDownLatch readNotifier = new CountDownLatch(1); mRttTextHandler.setReadNotifier(readNotifier); // Send four characters mPipeToHandler.write("abcd"); mPipeToHandler.flush(); // Wait for the stream to consume the characters readNotifier.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); // make sure at it hasn't been sent. Assert.assertEquals("", mNetworkWriter.getContents()); // Send the second part Thread.sleep(10); // Register a read notifier readNotifier = new CountDownLatch(1); mRttTextHandler.setReadNotifier(readNotifier); // Send four more characters mPipeToHandler.write("efgh"); mPipeToHandler.flush(); // Wait for the stream to consume the characters int count = 0; while (mHandlerSideOfPipeToHandler.ready()) { Thread.sleep(10); count += 1; if (count >= 5) { break; } } boolean res = readNotifier.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); // Wait for the handler to write to the mock network writer waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); // make sure that all characters were sent. try { Assert.assertEquals("abcdefgh", mNetworkWriter.getContents()); } catch (ComparisonFailure e) { throw new ComparisonFailure(e.getMessage() + ", network buffer=" + mRttTextHandler.getNetworkBufferText() + ", res=" + res, e.getExpected(), e.getActual()); } } /** Loading Loading
src/java/com/android/internal/telephony/imsphone/ImsRttTextHandler.java +17 −0 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ import android.os.Message; import android.telecom.Connection; import android.telephony.Rlog; import com.android.internal.annotations.VisibleForTesting; import java.io.IOException; import java.util.concurrent.CountDownLatch; public class ImsRttTextHandler extends Handler { public interface NetworkWriter { Loading Loading @@ -60,6 +63,8 @@ public class ImsRttTextHandler extends Handler { private static final int TEARDOWN = 6; private Connection.RttTextStream mRttTextStream; // For synchronization during testing private CountDownLatch mReadNotifier; private class InCallReaderThread extends Thread { private final Connection.RttTextStream mReaderThreadRttTextStream; Loading Loading @@ -95,6 +100,9 @@ public class ImsRttTextHandler extends Handler { } obtainMessage(APPEND_TO_NETWORK_BUFFER, charsReceived) .sendToTarget(); if (mReadNotifier != null) { mReadNotifier.countDown(); } } } } Loading Loading @@ -200,4 +208,13 @@ public class ImsRttTextHandler extends Handler { public void tearDown() { obtainMessage(TEARDOWN).sendToTarget(); } @VisibleForTesting public void setReadNotifier(CountDownLatch latch) { mReadNotifier = latch; } public String getNetworkBufferText() { return mBufferedTextToNetwork.toString(); } }
tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsRttTextHandlerTest.java +24 −9 Original line number Diff line number Diff line Loading @@ -25,11 +25,14 @@ import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.ComparisonFailure; import org.junit.Test; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class ImsRttTextHandlerTest extends TelephonyTest { private static final int TEST_TIMEOUT = 1000; Loading Loading @@ -121,29 +124,41 @@ public class ImsRttTextHandlerTest extends TelephonyTest { */ @Test public void testSendAfterEnoughChars() throws Exception { // Register a read notifier CountDownLatch readNotifier = new CountDownLatch(1); mRttTextHandler.setReadNotifier(readNotifier); // Send four characters mPipeToHandler.write("abcd"); mPipeToHandler.flush(); // Wait for the stream to consume the characters readNotifier.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); // make sure at it hasn't been sent. Assert.assertEquals("", mNetworkWriter.getContents()); // Send the second part Thread.sleep(10); // Register a read notifier readNotifier = new CountDownLatch(1); mRttTextHandler.setReadNotifier(readNotifier); // Send four more characters mPipeToHandler.write("efgh"); mPipeToHandler.flush(); // Wait for the stream to consume the characters int count = 0; while (mHandlerSideOfPipeToHandler.ready()) { Thread.sleep(10); count += 1; if (count >= 5) { break; } } boolean res = readNotifier.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); // Wait for the handler to write to the mock network writer waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); waitForHandlerAction(mRttTextHandler, TEST_TIMEOUT); // make sure that all characters were sent. try { Assert.assertEquals("abcdefgh", mNetworkWriter.getContents()); } catch (ComparisonFailure e) { throw new ComparisonFailure(e.getMessage() + ", network buffer=" + mRttTextHandler.getNetworkBufferText() + ", res=" + res, e.getExpected(), e.getActual()); } } /** Loading