Skip to content
Snippets Groups Projects
Commit 5a42ab81 authored by clairehurst's avatar clairehurst Committed by Pier Angelo Vendrame
Browse files

fixup! TB 42247: Android helpers for the TorProvider

Bug 41188: Wire up stages to UI
parent ec26bc8b
No related branches found
No related tags found
1 merge request!1500TB 43415: Rebased onto 134.0a1
......@@ -53,8 +53,10 @@ public class TorAndroidIntegration implements BundleEventListener {
private static final String EVENT_BOOTSTRAP_BEGIN_AUTO = "GeckoView:Tor:BootstrapBeginAuto";
private static final String EVENT_BOOTSTRAP_CANCEL = "GeckoView:Tor:BootstrapCancel";
private static final String EVENT_BOOTSTRAP_GET_STATE = "GeckoView:Tor:BootstrapGetState";
private static final String EVENT_START_AGAIN = "GeckoView:Tor:StartAgain";
private static final String EVENT_QUICKSTART_GET = "GeckoView:Tor:QuickstartGet";
private static final String EVENT_QUICKSTART_SET = "GeckoView:Tor:QuickstartSet";
private static final String EVENT_COUNTRY_NAMES_GET = "GeckoView:Tor:CountryNamesGet";
private static final String CONTROL_PORT_FILE = "/control-ipc";
private static final String SOCKS_FILE = "/socks-ipc";
......@@ -693,6 +695,10 @@ public class TorAndroidIntegration implements BundleEventListener {
return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_SET, bundle);
}
public @NonNull GeckoResult<Void> startAgain() {
return EventDispatcher.getInstance().queryVoid(EVENT_START_AGAIN);
}
public interface QuickstartGetter {
void onValue(boolean enabled);
}
......@@ -710,6 +716,27 @@ public class TorAndroidIntegration implements BundleEventListener {
return EventDispatcher.getInstance().queryVoid(EVENT_QUICKSTART_SET, bundle);
}
public interface CountryNamesGetter {
void onValue(Map<String, String> regions);
}
public void countryNamesGet(CountryNamesGetter countryNamesGetter) {
EventDispatcher.getInstance().queryBundle(EVENT_COUNTRY_NAMES_GET).then(countryNames -> {
if (countryNames != null) {
String[] codes = countryNames.keys();
Map<String, String> regions = new HashMap<>(codes.length);
for (String code : codes) {
regions.put(code, countryNames.getString(code));
}
countryNamesGetter.onValue(regions);
} else {
Log.e(TAG, "countryNames was null");
countryNamesGetter.onValue(null);
}
return new GeckoResult<Void>();
});
}
public @NonNull GeckoResult<Void> beginBootstrap() {
return EventDispatcher.getInstance().queryVoid(EVENT_BOOTSTRAP_BEGIN);
}
......
......
......@@ -42,8 +42,10 @@ const ListenedEvents = Object.freeze({
bootstrapBeginAuto: "GeckoView:Tor:BootstrapBeginAuto",
bootstrapCancel: "GeckoView:Tor:BootstrapCancel",
bootstrapGetState: "GeckoView:Tor:BootstrapGetState",
startAgain: "GeckoView:Tor:StartAgain",
quickstartGet: "GeckoView:Tor:QuickstartGet",
quickstartSet: "GeckoView:Tor:QuickstartSet",
countryNamesGet: "GeckoView:Tor:CountryNamesGet",
});
class TorAndroidIntegrationImpl {
......@@ -190,14 +192,18 @@ class TorAndroidIntegrationImpl {
case ListenedEvents.bootstrapGetState:
callback?.onSuccess(lazy.TorConnect.state);
return;
// TODO: Expose TorConnect.startAgain() to allow users to begin
// from the start again.
case ListenedEvents.startAgain:
lazy.TorConnect.startAgain();
break;
case ListenedEvents.quickstartGet:
callback?.onSuccess(lazy.TorConnect.quickstart);
return;
case ListenedEvents.quickstartSet:
lazy.TorConnect.quickstart = data.enabled;
break;
case ListenedEvents.countryNamesGet:
callback?.onSuccess(lazy.TorConnect.countryNames)
return;
}
callback?.onSuccess();
} catch (e) {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment