Pier Angelo Vendrame pushed to branch tor-browser-115.9.0esr-13.5-1 at The Tor Project / Applications / Tor Browser
Commits: 9e01b1a9 by Dan Ballard at 2024-03-26T11:33:26-07:00 fixup! Bug 42247: Android helpers for the TorProvider
Bug 41187: Add support for tor logs in android integration
- - - - -
4 changed files:
- mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java - toolkit/components/tor-launcher/TorProvider.sys.mjs - toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs - toolkit/modules/TorAndroidIntegration.sys.mjs
Changes:
===================================== mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java ===================================== @@ -46,6 +46,7 @@ public class TorIntegrationAndroid implements BundleEventListener { private static final String EVENT_BOOTSTRAP_PROGRESS = "GeckoView:Tor:BootstrapProgress"; private static final String EVENT_BOOTSTRAP_COMPLETE = "GeckoView:Tor:BootstrapComplete"; private static final String EVENT_BOOTSTRAP_ERROR = "GeckoView:Tor:BootstrapError"; + private static final String EVENT_TOR_LOGS = "GeckoView:Tor:Logs"; private static final String EVENT_SETTINGS_READY = "GeckoView:Tor:SettingsReady"; private static final String EVENT_SETTINGS_CHANGED = "GeckoView:Tor:SettingsChanged"; private static final String EVENT_SETTINGS_OPEN = "GeckoView:Tor:OpenSettings"; @@ -118,6 +119,7 @@ public class TorIntegrationAndroid implements BundleEventListener { EVENT_BOOTSTRAP_PROGRESS, EVENT_BOOTSTRAP_COMPLETE, EVENT_BOOTSTRAP_ERROR, + EVENT_TOR_LOGS, EVENT_SETTINGS_OPEN); }
@@ -168,6 +170,12 @@ public class TorIntegrationAndroid implements BundleEventListener { for (BootstrapStateChangeListener listener: mBootstrapStateListeners) { listener.onBootstrapError(msg, details); } + } else if (EVENT_TOR_LOGS.equals(event)) { + String msg = message.getString("message"); + String type = message.getString("logType"); + for (TorLogListener listener: mLogListeners) { + listener.onLog(type, msg); + } } else if (EVENT_SETTINGS_OPEN.equals(event)) { for (BootstrapStateChangeListener listener: mBootstrapStateListeners) { listener.onSettingsRequested(); @@ -573,6 +581,10 @@ public class TorIntegrationAndroid implements BundleEventListener { void onSettingsRequested(); }
+ public interface TorLogListener { + void onLog(String logType, String message); + } + private @NonNull void reloadSettings() { EventDispatcher.getInstance().queryBundle(EVENT_SETTINGS_GET).then( new GeckoResult.OnValueListener<GeckoBundle, Void>() { public GeckoResult<Void> onValue(final GeckoBundle bundle) { @@ -647,4 +659,14 @@ public class TorIntegrationAndroid implements BundleEventListener { }
private final HashSet<BootstrapStateChangeListener> mBootstrapStateListeners = new HashSet<>(); + + public void registerLogListener(TorLogListener listener) { + mLogListeners.add(listener); + } + + public void unregisterLogListener(TorLogListener listener) { + mLogListeners.remove(listener); + } + + private final HashSet<TorLogListener> mLogListeners = new HashSet<>(); }
===================================== toolkit/components/tor-launcher/TorProvider.sys.mjs ===================================== @@ -1002,6 +1002,8 @@ export class TorProvider { Services.obs.notifyObservers(null, TorProviderTopics.HasWarnOrErr); }
+ Services.obs.notifyObservers({ type, msg }, TorProviderTopics.TorLog); + const date = new Date(); const maxEntries = Services.prefs.getIntPref( Preferences.MaxLogEntries,
===================================== toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs ===================================== @@ -12,6 +12,7 @@ export const TorProviderTopics = Object.freeze({ ProcessExited: "TorProcessExited", BootstrapStatus: "TorBootstrapStatus", BootstrapError: "TorBootstrapError", + TorLog: "TorLog", HasWarnOrErr: "TorLogHasWarnOrErr", BridgeChanged: "TorBridgeChanged", CircuitCredentialsMatched: "TorCircuitCredentialsMatched",
===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, { TorConnectTopics: "resource://gre/modules/TorConnect.sys.mjs", TorSettingsTopics: "resource://gre/modules/TorSettings.sys.mjs", TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs", + TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs", TorSettings: "resource://gre/modules/TorSettings.sys.mjs", });
@@ -32,6 +33,7 @@ const EmittedEvents = Object.freeze({ bootstrapProgress: "GeckoView:Tor:BootstrapProgress", bootstrapComplete: "GeckoView:Tor:BootstrapComplete", bootstrapError: "GeckoView:Tor:BootstrapError", + torLogs: "GeckoView:Tor:Logs", });
const ListenedEvents = Object.freeze({ @@ -59,6 +61,8 @@ class TorAndroidIntegrationImpl { this.#bootstrapMethodReset(); Services.prefs.addObserver(Prefs.useNewBootstrap, this);
+ Services.obs.addObserver(this, lazy.TorProviderTopics.TorLog); + for (const topic in lazy.TorConnectTopics) { Services.obs.addObserver(this, lazy.TorConnectTopics[topic]); } @@ -118,6 +122,13 @@ class TorAndroidIntegrationImpl { details: subj.wrappedJSObject.details ?? "", }); break; + case lazy.TorProviderTopics.TorLog: + lazy.EventDispatcher.instance.sendRequest({ + type: EmittedEvents.torLogs, + logType: subj.wrappedJSObject.type ?? "", + message: subj.wrappedJSObject.msg ?? "", + }); + break; case lazy.TorSettingsTopics.Ready: lazy.EventDispatcher.instance.sendRequest({ type: EmittedEvents.settingsReady,
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/9e01b1a9...