From 730a25995efb2b5646a5d42ce83cfc3dbef6ee74 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Mon, 25 Jun 2018 19:48:33 -0700 Subject: [PATCH] Make RttTextStream's read interruptible Wrap the FileInputStream in a java.nio.Channel so that sending a Thread.interrupt() to the thread blocked on the read will actually do something. Change-Id: Icc11ba69167f448e2b33d9a1a13a1dfa5e5d0d58 Fixes: 110570772 Test: manual (follow repro steps in bug, but type really fast),treehugger --- telecomm/java/android/telecom/Connection.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java index 3bf951d4d8caf..3e97c8f40bf82 100644 --- a/telecomm/java/android/telecom/Connection.java +++ b/telecomm/java/android/telecom/Connection.java @@ -45,6 +45,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.nio.channels.Channels; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -861,8 +862,11 @@ public abstract class Connection extends Conferenceable { public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) { mFdFromInCall = fromInCall; mFdToInCall = toInCall; + + // Wrap the FileInputStream in a Channel so that it's interruptible. mPipeFromInCall = new InputStreamReader( - new FileInputStream(fromInCall.getFileDescriptor())); + Channels.newInputStream(Channels.newChannel( + new FileInputStream(fromInCall.getFileDescriptor())))); mPipeToInCall = new OutputStreamWriter( new FileOutputStream(toInCall.getFileDescriptor())); }