Verified Commit 7459cd43 authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

fixup! TB 42247: Android helpers for the TorProvider

TB 41921: Only use TorSettings.changeSettings to change the Tor
settings and apply them in one method.

We drop redundant arguments and unused methods from android integration.
parent b5dc5202
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -48,8 +48,6 @@ public class TorIntegrationAndroid implements BundleEventListener {
  // Events we emit
  private static final String EVENT_SETTINGS_GET = "GeckoView:Tor:SettingsGet";
  private static final String EVENT_SETTINGS_SET = "GeckoView:Tor:SettingsSet";
  private static final String EVENT_SETTINGS_APPLY = "GeckoView:Tor:SettingsApply";
  private static final String EVENT_SETTINGS_SAVE = "GeckoView:Tor:SettingsSave";
  private static final String EVENT_BOOTSTRAP_BEGIN = "GeckoView:Tor:BootstrapBegin";
  private static final String EVENT_BOOTSTRAP_BEGIN_AUTO = "GeckoView:Tor:BootstrapBeginAuto";
  private static final String EVENT_BOOTSTRAP_CANCEL = "GeckoView:Tor:BootstrapCancel";
@@ -194,7 +192,7 @@ public class TorIntegrationAndroid implements BundleEventListener {
    protected void onPostExecute(TorSettings torSettings) {
      mSettings = torSettings;
      if (TorLegacyAndroidSettings.unmigrated()) {
        setSettings(mSettings, true, true);
        setSettings(mSettings);
        TorLegacyAndroidSettings.setMigrated();
      }
    }
@@ -657,10 +655,10 @@ public class TorIntegrationAndroid implements BundleEventListener {
    return mSettings;
  }

  public void setSettings(final TorSettings settings, boolean save, boolean apply) {
  public void setSettings(final TorSettings settings) {
    mSettings = settings;

    emitSetSettings(settings, save, apply)
    emitSetSettings(settings)
        .then(
            new GeckoResult.OnValueListener<Void, Void>() {
              public GeckoResult<Void> onValue(Void v) {
@@ -677,22 +675,12 @@ public class TorIntegrationAndroid implements BundleEventListener {
  }

  private @NonNull GeckoResult<Void> emitSetSettings(
      final TorSettings settings, boolean save, boolean apply) {
    GeckoBundle bundle = new GeckoBundle(3);
    bundle.putBoolean("save", save);
    bundle.putBoolean("apply", apply);
      final TorSettings settings) {
    GeckoBundle bundle = new GeckoBundle(1);
    bundle.putBundle("settings", settings.asGeckoBundle());
    return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_SET, bundle);
  }

  public @NonNull GeckoResult<Void> applySettings() {
    return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_APPLY);
  }

  public @NonNull GeckoResult<Void> saveSettings() {
    return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_SAVE);
  }

  public @NonNull GeckoResult<Void> beginBootstrap() {
    return EventDispatcher.getInstance().queryVoid(EVENT_BOOTSTRAP_BEGIN);
  }
+4 −16
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ const ListenedEvents = Object.freeze({
  settingsGet: "GeckoView:Tor:SettingsGet",
  // The data is passed directly to TorSettings.
  settingsSet: "GeckoView:Tor:SettingsSet",
  settingsApply: "GeckoView:Tor:SettingsApply",
  settingsSave: "GeckoView:Tor:SettingsSave",
  bootstrapBegin: "GeckoView:Tor:BootstrapBegin",
  // Optionally takes a countryCode, as data.countryCode.
  bootstrapBeginAuto: "GeckoView:Tor:BootstrapBeginAuto",
@@ -145,20 +143,10 @@ class TorAndroidIntegrationImpl {
          callback?.onSuccess(lazy.TorSettings.getSettings());
          return;
        case ListenedEvents.settingsSet:
          // This does not throw, so we do not have any way to report the error!
          lazy.TorSettings.setSettings(data.settings);
          if (data.save) {
            lazy.TorSettings.saveToPrefs();
          }
          if (data.apply) {
            await lazy.TorSettings.applySettings();
          }
          break;
        case ListenedEvents.settingsApply:
          await lazy.TorSettings.applySettings();
          break;
        case ListenedEvents.settingsSave:
          await lazy.TorSettings.saveToPrefs();
          // TODO: Handle setting throw? This can throw if data.settings is
          // incorrectly formatted, but more like it can throw when the settings
          // fail to be passed onto the TorProvider. tor-browser#43405.
          await lazy.TorSettings.changeSettings(data.settings);
          break;
        case ListenedEvents.bootstrapBegin:
          lazy.TorConnect.beginBootstrapping();