Add Device to Device Transfer UI.

This commit is contained in:
Cody Henthorne
2021-03-11 13:27:25 -05:00
committed by Greyson Parrelli
parent 6f8be3260c
commit 75aab4c031
75 changed files with 3494 additions and 200 deletions

View File

@@ -0,0 +1,55 @@
package org.thoughtcrime.securesms.net;
import androidx.annotation.NonNull;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Protocol;
import okhttp3.Response;
import okhttp3.ResponseBody;
/**
* Provide a way to block network access while performing a device transfer.
*/
public final class DeviceTransferBlockingInterceptor implements Interceptor {
private static final String TAG = Log.tag(DeviceTransferBlockingInterceptor.class);
private static final DeviceTransferBlockingInterceptor INSTANCE = new DeviceTransferBlockingInterceptor();
private volatile boolean blockNetworking = false;
public static DeviceTransferBlockingInterceptor getInstance() {
return INSTANCE;
}
@Override
public @NonNull Response intercept(@NonNull Chain chain) throws IOException {
if (!blockNetworking) {
return chain.proceed(chain.request());
}
Log.w(TAG, "Preventing request because in transfer mode.");
return new Response.Builder().request(chain.request())
.protocol(Protocol.HTTP_1_1)
.receivedResponseAtMillis(System.currentTimeMillis())
.message("")
.body(ResponseBody.create(null, ""))
.code(500)
.build();
}
public void blockNetwork() {
blockNetworking = true;
ApplicationDependencies.closeConnections();
}
public void unblockNetwork() {
blockNetworking = false;
ApplicationDependencies.getIncomingMessageObserver();
}
}

View File

@@ -68,7 +68,7 @@ public class PipeConnectivityListener implements ConnectivityListener {
if (SignalStore.proxy().isProxyEnabled()) {
Log.w(TAG, "Encountered an error while we had a proxy set! Terminating the connection to prevent retry spam.");
ApplicationDependencies.closeConnectionsAfterProxyFailure();
ApplicationDependencies.closeConnections();
return false;
} else {
return true;