Add UI support for configuring a proxy.

This commit is contained in:
Greyson Parrelli
2021-02-02 16:42:47 -05:00
committed by GitHub
parent 0d215d609b
commit 46344776a4
37 changed files with 1217 additions and 55 deletions

View File

@@ -0,0 +1,70 @@
package org.thoughtcrime.securesms.keyvalue;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
public final class ProxyValues extends SignalStoreValues {
private static final String KEY_PROXY_ENABLED = "proxy.enabled";
private static final String KEY_HOST = "proxy.host";
private static final String KEY_PORT = "proxy.port";
ProxyValues(@NonNull KeyValueStore store) {
super(store);
}
@Override
void onFirstEverAppLaunch() {
}
public void enableProxy(@NonNull SignalProxy proxy) {
getStore().beginWrite()
.putBoolean(KEY_PROXY_ENABLED, true)
.putString(KEY_HOST, proxy.getHost())
.putInteger(KEY_PORT, proxy.getPort())
.apply();
}
/**
* Disables the proxy, but does not clear out the last-chosen host.
*/
public void disableProxy() {
putBoolean(KEY_PROXY_ENABLED, false);
}
public boolean isProxyEnabled() {
return getBoolean(KEY_PROXY_ENABLED, false);
}
/**
* Sets the proxy. This does not *enable* the proxy. This is because the user may want to set a
* proxy and then enabled it and disable it at will.
*/
public void setProxy(@Nullable SignalProxy proxy) {
if (proxy != null) {
getStore().beginWrite()
.putString(KEY_HOST, proxy.getHost())
.putInteger(KEY_PORT, proxy.getPort())
.apply();
} else {
getStore().beginWrite()
.remove(KEY_HOST)
.remove(KEY_PORT)
.apply();
}
}
public @Nullable SignalProxy getProxy() {
String host = getString(KEY_HOST, null);
int port = getInteger(KEY_PORT, 0);
if (host != null) {
return new SignalProxy(host, port);
} else {
return null;
}
}
}

View File

@@ -30,6 +30,7 @@ public final class SignalStore {
private final PhoneNumberPrivacyValues phoneNumberPrivacyValues;
private final OnboardingValues onboardingValues;
private final WallpaperValues wallpaperValues;
private final ProxyValues proxyValues;
private SignalStore() {
this.store = new KeyValueStore(ApplicationDependencies.getApplication());
@@ -48,6 +49,7 @@ public final class SignalStore {
this.phoneNumberPrivacyValues = new PhoneNumberPrivacyValues(store);
this.onboardingValues = new OnboardingValues(store);
this.wallpaperValues = new WallpaperValues(store);
this.proxyValues = new ProxyValues(store);
}
public static void onFirstEverAppLaunch() {
@@ -65,6 +67,7 @@ public final class SignalStore {
phoneNumberPrivacy().onFirstEverAppLaunch();
onboarding().onFirstEverAppLaunch();
wallpaper().onFirstEverAppLaunch();
proxy().onFirstEverAppLaunch();
}
public static @NonNull KbsValues kbsValues() {
@@ -127,6 +130,10 @@ public final class SignalStore {
return INSTANCE.wallpaperValues;
}
public static @NonNull ProxyValues proxy() {
return INSTANCE.proxyValues;
}
public static @NonNull GroupsV2AuthorizationSignalStoreCache groupsV2AuthorizationCache() {
return new GroupsV2AuthorizationSignalStoreCache(getStore());
}