Remove unnecessary okhttp close when canceling.
Canceling should handle closing stuff now. And if we close from a different thread than the calling thread, okhttp will crash.
This commit is contained in:
parent
453996c374
commit
e3ea36c76f
2 changed files with 9 additions and 14 deletions
|
@ -13,6 +13,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketException;
|
||||
|
||||
public class EncryptedCacheEncoder extends EncryptedCoder implements Encoder<InputStream> {
|
||||
|
||||
|
@ -42,12 +43,14 @@ public class EncryptedCacheEncoder extends EncryptedCoder implements Encoder<Inp
|
|||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
if (e instanceof SocketException) {
|
||||
Log.d(TAG, "Socket exception. Likely a cancellation.");
|
||||
} else {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
byteArrayPool.put(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.os.AsyncTask;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
|
@ -27,24 +28,15 @@ public class CallRequestController implements RequestController {
|
|||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||
synchronized (CallRequestController.this) {
|
||||
if (canceled) return;
|
||||
|
||||
|
||||
call.cancel();
|
||||
|
||||
if (stream != null) {
|
||||
Util.close(stream);
|
||||
}
|
||||
|
||||
canceled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void setStream(@NonNull InputStream stream) {
|
||||
if (canceled) {
|
||||
Util.close(stream);
|
||||
} else {
|
||||
this.stream = stream;
|
||||
}
|
||||
this.stream = stream;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue