diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ade2ef0a6e..b806c9eff1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -179,6 +179,7 @@ greenrobot-eventbus = "org.greenrobot:eventbus:3.0.0" jackson-core = "com.fasterxml.jackson.core:jackson-databind:2.12.0" jackson-module-kotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:2.12.0" square-okhttp3 = "com.squareup.okhttp3:okhttp:5.3.2" +square-okhttp3-coroutines = "com.squareup.okhttp3:okhttp-coroutines:5.3.2" square-okio = "com.squareup.okio:okio:3.17.0" square-leakcanary = "com.squareup.leakcanary:leakcanary-android:2.14" rxjava3-rxjava = "io.reactivex.rxjava3:rxjava:3.1.12" diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 63da0a5269..61fae2950f 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -5515,6 +5515,14 @@ https://docs.gradle.org/current/userguide/dependency_verification.html + + + + + + + + diff --git a/lib/network/build.gradle.kts b/lib/network/build.gradle.kts index fd7c5687c5..7579b0beca 100644 --- a/lib/network/build.gradle.kts +++ b/lib/network/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation(libs.libsignal.client) api(libs.square.okio) + implementation(libs.square.okhttp3.coroutines) api(libs.rxjava3.rxjava) diff --git a/lib/network/src/main/java/org/signal/network/rest/SignalRestClient.kt b/lib/network/src/main/java/org/signal/network/rest/SignalRestClient.kt index 34bde942a8..25d175be0c 100644 --- a/lib/network/src/main/java/org/signal/network/rest/SignalRestClient.kt +++ b/lib/network/src/main/java/org/signal/network/rest/SignalRestClient.kt @@ -5,9 +5,7 @@ package org.signal.network.rest -import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.Call -import okhttp3.Callback import okhttp3.ConnectionPool import okhttp3.ConnectionSpec import okhttp3.Credentials @@ -20,6 +18,7 @@ import okhttp3.Request import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response +import okhttp3.coroutines.executeAsync import okio.Buffer import okio.BufferedSink import okio.ByteString @@ -50,7 +49,6 @@ import java.util.Random import java.util.concurrent.TimeUnit import javax.net.ssl.SSLContext import javax.net.ssl.X509TrustManager -import kotlin.coroutines.resume import kotlin.jvm.Throws import kotlin.reflect.KClass @@ -260,7 +258,7 @@ class SignalRestClient @JvmOverloads constructor( } val httpRequest = buildHttpRequest(spec, holder, effectiveBody, extraHeaders = emptyMap()) val client = newCallClient(holder) - val response = client.newCall(httpRequest).await() + val response = client.newCall(httpRequest).executeAsync() response.use { resp -> val body = resp.body.bytes() @@ -297,7 +295,7 @@ class SignalRestClient @JvmOverloads constructor( val httpRequest = buildHttpRequest(spec, holder, body = spec.body, extraHeaders = rangeHeader) val client = newCallClient(holder) val call = client.newCall(httpRequest) - val response = call.await() + val response = call.executeAsync() response.use { resp -> val code = resp.code @@ -494,19 +492,6 @@ class SignalRestClient @JvmOverloads constructor( return map } - private suspend fun Call.await(): Response = suspendCancellableCoroutine { cont -> - cont.invokeOnCancellation { runCatching { cancel() } } - enqueue(object : Callback { - override fun onFailure(call: Call, e: IOException) { - if (!cont.isCancelled) cont.resumeWith(Result.failure(e)) - } - - override fun onResponse(call: Call, response: Response) { - cont.resume(response) - } - }) - } - private data class ConnectionHolder( val client: OkHttpClient, val url: String,