[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-115.6.0esr-13.5-1] fixup! Bug 42247: Android helpers for the TorProvider

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Thu Dec 21 21:56:46 UTC 2023



Pier Angelo Vendrame pushed to branch tor-browser-115.6.0esr-13.5-1 at The Tor Project / Applications / Tor Browser


Commits:
f422c485 by Dan Ballard at 2023-12-21T11:51:26-08:00
fixup! Bug 42247: Android helpers for the TorProvider

Fix settings loading issues and saving

- - - - -


2 changed files:

- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
- toolkit/modules/TorAndroidIntegration.sys.mjs


Changes:

=====================================
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java
=====================================
@@ -7,6 +7,7 @@
 package org.mozilla.geckoview;
 
 import android.content.Context;
+import android.os.AsyncTask;
 import android.util.Log;
 
 import androidx.annotation.AnyThread;
@@ -131,7 +132,11 @@ public class TorIntegrationAndroid implements BundleEventListener {
         } else if (EVENT_MEEK_STOP.equals(event)) {
             stopMeek(message, callback);
         } else if (EVENT_SETTINGS_READY.equals(event)) {
-            loadSettings(message);
+            try {
+                new SettingsLoader().execute(message);
+            } catch(Exception e) {
+                Log.e(TAG, "SettingsLoader error: "+ e.toString());
+            }
         } else if (EVENT_BOOTSTRAP_STATE_CHANGED.equals(event)) {
             String state = message.getString("state");
             for (BootstrapStateChangeListener listener: mBootstrapStateListeners) {
@@ -161,14 +166,24 @@ public class TorIntegrationAndroid implements BundleEventListener {
         }
     }
 
-    private void loadSettings(GeckoBundle message) {
-        if (TorLegacyAndroidSettings.unmigrated()) {
-            mSettings = TorLegacyAndroidSettings.loadTorSettings();
-            setSettings(mSettings);
-            TorLegacyAndroidSettings.setMigrated();
-        } else {
-            GeckoBundle bundle = message.getBundle("settings");
-            mSettings = new TorSettings(bundle);
+    private class SettingsLoader extends AsyncTask<GeckoBundle, Void, TorSettings> {
+        protected TorSettings doInBackground(GeckoBundle... messages) {
+            GeckoBundle message = messages[0];
+            TorSettings settings;
+            if (TorLegacyAndroidSettings.unmigrated()) {
+                settings = TorLegacyAndroidSettings.loadTorSettings();
+                setSettings(settings, true, true);
+                TorLegacyAndroidSettings.setMigrated();
+            } else {
+                GeckoBundle bundle = message.getBundle("settings");
+                settings = new TorSettings(bundle);
+            }
+            return settings;
+        }
+
+        @Override
+        protected void onPostExecute(TorSettings torSettings) {
+            mSettings = torSettings;
         }
     }
 
@@ -515,8 +530,12 @@ public class TorIntegrationAndroid implements BundleEventListener {
         return EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET);
     }
 
-    public @NonNull GeckoResult<Void> setSettings(final TorSettings settings) {
-        return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_SET, settings.asGeckoBundle());
+    public @NonNull GeckoResult<Void> setSettings(final TorSettings settings, boolean save, boolean apply) {
+        GeckoBundle bundle = new GeckoBundle(3);
+        bundle.putBoolean("save", save);
+        bundle.putBoolean("apply", apply);
+        bundle.putBundle("settings", settings.asGeckoBundle());
+        return EventDispatcher.getInstance().queryVoid(EVENT_SETTINGS_SET, bundle);
     }
 
     public @NonNull GeckoResult<Void> applySettings() {


=====================================
toolkit/modules/TorAndroidIntegration.sys.mjs
=====================================
@@ -136,13 +136,19 @@ class TorAndroidIntegrationImpl {
           return;
         case ListenedEvents.settingsSet:
           // This does not throw, so we do not have any way to report the error!
-          lazy.TorSettings.setSettings(data);
+          lazy.TorSettings.setSettings(data.settings);
+          if (data.save) {
+            lazy.TorSettings.saveToPrefs();
+          }
+          if (data.apply) {
+            lazy.TorSettings.applySettings();
+          }
           break;
         case ListenedEvents.settingsApply:
           await lazy.TorSettings.applySettings();
           break;
         case ListenedEvents.settingsSave:
-          await lazy.TorSettings.saveSettings();
+          await lazy.TorSettings.saveToPrefs();
           break;
         case ListenedEvents.bootstrapBegin:
           lazy.TorConnect.beginBootstrap();



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/f422c48575e1b447a2d3d2d46e559ec001e3ecc5

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/f422c48575e1b447a2d3d2d46e559ec001e3ecc5
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20231221/72de7b91/attachment-0001.htm>


More information about the tor-commits mailing list