mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-28 05:35:44 +00:00
Only deprecate client on 499s from chat service.
This commit is contained in:
committed by
Greyson Parrelli
parent
2f4669d7eb
commit
b8032378f6
@@ -1,31 +0,0 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Marks the client as remotely-deprecated when it receives a 499 response.
|
||||
*/
|
||||
public final class RemoteDeprecationDetectorInterceptor implements Interceptor {
|
||||
|
||||
private static final String TAG = Log.tag(RemoteDeprecationDetectorInterceptor.class);
|
||||
|
||||
@Override
|
||||
public @NonNull Response intercept(@NonNull Chain chain) throws IOException {
|
||||
Response response = chain.proceed(chain.request());
|
||||
|
||||
if (response.code() == 499 && !SignalStore.misc().isClientDeprecated()) {
|
||||
Log.w(TAG, "Received 499. Client version is deprecated.", true);
|
||||
SignalStore.misc().setClientDeprecated(true);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.thoughtcrime.securesms.net
|
||||
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.logging.Log.tag
|
||||
import org.signal.core.util.orNull
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore.Companion.misc
|
||||
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Marks the client as remotely-deprecated when it receives a 499 response.
|
||||
*/
|
||||
class RemoteDeprecationDetectorInterceptor(private val getConfiguration: () -> SignalServiceConfiguration) : Interceptor {
|
||||
|
||||
companion object {
|
||||
private val TAG = tag(RemoteDeprecationDetectorInterceptor::class.java)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
|
||||
if (response.code == 499 && !misc.isClientDeprecated && getConfiguration().signalServiceUrls.any { request.url.toString().startsWith(it.url) && it.hostHeader.orNull() == request.header("host") }) {
|
||||
Log.w(TAG, "Received 499. Client version is deprecated.", true)
|
||||
misc.isClientDeprecated = true
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class SignalServiceNetworkAccess(context: Context) {
|
||||
|
||||
private val interceptors: List<Interceptor> = listOf(
|
||||
StandardUserAgentInterceptor(),
|
||||
RemoteDeprecationDetectorInterceptor(),
|
||||
RemoteDeprecationDetectorInterceptor(this::getConfiguration),
|
||||
DeprecatedClientPreventionInterceptor(),
|
||||
DeviceTransferBlockingInterceptor.getInstance()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user