Use a simple check to verify proxies during registration.

This commit is contained in:
Greyson Parrelli 2021-02-03 14:55:05 -05:00
parent 51879a9c46
commit af7e736de9
4 changed files with 39 additions and 2 deletions

View file

@ -148,6 +148,7 @@ public class EditProxyFragment extends Fragment {
requireActivity().onBackPressed();
})
.show();
requireActivity().onBackPressed();
break;
case PROXY_FAILURE:
proxyStatus.setVisibility(View.INVISIBLE);

View file

@ -6,12 +6,16 @@ import androidx.annotation.WorkerThread;
import androidx.lifecycle.Observer;
import org.conscrypt.Conscrypt;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.net.PipeConnectivityListener;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
@ -69,8 +73,8 @@ public final class SignalProxyUtil {
startListeningToWebsocket();
if (TextSecurePreferences.getLocalNumber(ApplicationDependencies.getApplication()) == null) {
Log.i(TAG, "User is unregistered! Assuming success.");
return true;
Log.i(TAG, "User is unregistered! Doing simple check.");
return testWebsocketConnectionUnregistered(timeout);
}
CountDownLatch latch = new CountDownLatch(1);
@ -156,4 +160,28 @@ public final class SignalProxyUtil {
return "https://" + PROXY_LINK_HOST + "/#" + host;
}
private static boolean testWebsocketConnectionUnregistered(long timeout) {
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean success = new AtomicBoolean(false);
SignalServiceAccountManager accountManager = AccountManagerFactory.createUnauthenticated(ApplicationDependencies.getApplication(), "", "");
SignalExecutors.UNBOUNDED.execute(() -> {
try {
accountManager.checkNetworkConnection();
success.set(true);
latch.countDown();
} catch (IOException e) {
latch.countDown();
}
});
try {
latch.await(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Log.w(TAG, "Interrupted!", e);
}
return success.get();
}
}

View file

@ -632,6 +632,10 @@ public class SignalServiceAccountManager {
return this.pushServiceSocket.getTurnServerInfo();
}
public void checkNetworkConnection() throws IOException {
this.pushServiceSocket.pingStorageService();
}
/**
* @return The avatar URL path, if one was written.
*/

View file

@ -885,6 +885,10 @@ public class PushServiceSocket {
}
}
public void pingStorageService() throws IOException {
makeStorageRequest(null, "/ping", "GET", null);
}
public RemoteConfigResponse getRemoteConfig() throws IOException {
String response = makeServiceRequest("/v1/config", "GET", null);
return JsonUtil.fromJson(response, RemoteConfigResponse.class);