Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: 90f60943 by clairehurst at 2025-01-23T18:07:07+00:00 fixup! TB 40933: Add tor-launcher functionality
Bug 43222: Fix tor logs timestamps
- - - - - a1c22a73 by clairehurst at 2025-01-23T18:07:07+00:00 fixup! TB 42247: Android helpers for the TorProvider
Bug 43222: Fix tor logs timestamps
- - - - - db1d2b30 by clairehurst at 2025-01-23T18:07:07+00:00 fixup! TB 41878: [android] Add standalone Tor Bootstrap
Bug 43222: Fix tor logs timestamps
- - - - - b270a085 by clairehurst at 2025-01-23T18:07:07+00:00 fixup! TB 40041 [android]: Implement Tor Network Settings
Bug 43222: Fix tor logs timestamps
- - - - -
8 changed files:
- mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorController.kt - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorControllerGV.kt - + mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLog.kt - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsComposeFragment.kt - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsViewModel.kt - mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java - toolkit/components/tor-launcher/TorProvider.sys.mjs - toolkit/modules/TorAndroidIntegration.sys.mjs
Changes:
===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorController.kt ===================================== @@ -20,7 +20,7 @@ class TorError( ) { }
interface TorLogs { - fun onLog(type: String?, message: String?) + fun onLog(type: String?, message: String?, timestamp: String?) }
internal enum class TorStatus(val status: String) { @@ -32,7 +32,7 @@ internal enum class TorStatus(val status: String) { }
interface TorController: TorEvents { - val logEntries: MutableList<Pair<String?, String?>> + val logEntries: MutableList<TorLog> val isStarting: Boolean val isRestarting: Boolean val isBootstrapped: Boolean
===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorControllerGV.kt ===================================== @@ -66,7 +66,7 @@ class TorControllerGV( private var isTorBootstrapped = false get() = ((_lastKnownStatus.value.isStarted()) && wasTorBootstrapped)
- private val entries = mutableListOf<Pair<String?, String?>>() + private val entries = mutableListOf<TorLog>() override val logEntries get() = entries override val isStarting get() = _lastKnownStatus.value.isStarting() override val isRestarting get() = isTorRestarting @@ -217,10 +217,10 @@ class TorControllerGV( } }
- override fun onLog(type: String?, message: String?) { + override fun onLog(type: String?, message: String?, timestamp: String?) { synchronized(torLogListeners) { - entries.add(Pair(type, message)) - torLogListeners.toList().forEach { it.onLog(type, message) } + entries.add(TorLog(type ?: "null", message ?: "null", timestamp ?: "null")) + torLogListeners.toList().forEach { it.onLog(type ?: "null", message ?: "null", timestamp) } } }
===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLog.kt ===================================== @@ -0,0 +1,10 @@ +package org.mozilla.fenix.tor + +import androidx.compose.runtime.Stable + +@Stable +data class TorLog( + val type: String, + val text: String, + val timestamp: String, +)
===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsComposeFragment.kt ===================================== @@ -108,16 +108,14 @@ class TorLogsComposeFragment : Fragment() { bottom = 16.dp, ), ) { - DisableSelection { - Text( - text = log.timestamp.toString(), - color = PhotonColors.LightGrey40, - modifier = modifier - .padding(bottom = 4.dp), - ) - } Text( - text = log.text, + text = log.timestamp, + color = PhotonColors.LightGrey40, + modifier = modifier + .padding(bottom = 4.dp), + ) + Text( + text = "[${log.type}] " + log.text, color = PhotonColors.LightGrey05, ) }
===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/tor/TorLogsViewModel.kt ===================================== @@ -10,22 +10,18 @@ import android.content.ClipboardManager import android.content.Context import android.os.Build import android.widget.Toast -import androidx.compose.runtime.Stable import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import org.mozilla.fenix.R import org.mozilla.fenix.ext.components -import java.sql.Timestamp
class TorLogsViewModel(application: Application) : AndroidViewModel(application), TorLogs { private val torController = application.components.torController private val clipboardManager = application.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
- private val _torLogs: MutableLiveData<List<TorLog>> = MutableLiveData( - mutableListOf(TorLog("---------------" + application.getString(R.string.tor_initializing_log) + "---------------")), - ) + private val _torLogs: MutableLiveData<List<TorLog>> = MutableLiveData(mutableListOf())
fun torLogs(): LiveData<List<TorLog>> { return _torLogs @@ -38,20 +34,14 @@ class TorLogsViewModel(application: Application) : AndroidViewModel(application) init { setupClipboardListener() torController.registerTorLogListener(this) - val currentEntries = torController.logEntries.filter { it.second != null } - .filter { !(it.second!!.startsWith("Circuit") && it.first == "ON") } - // Keep synchronized with format in onTorStatusUpdate - .flatMap { listOf(TorLog("[${it.first}] ${it.second}")) } + val currentEntries = torController.logEntries for (log in currentEntries) { addLog(log) } }
- override fun onLog(type: String?, message: String?) { - if (message == null || type == null) return - if (type == "ON" && type.startsWith("Circuit")) return - - addLog(TorLog("[$type] $message")) + override fun onLog(type: String?, message: String?, timestamp: String?) { + addLog(TorLog(type ?: "null", message ?: "null", timestamp ?: "null")) }
override fun onCleared() { @@ -86,14 +76,8 @@ class TorLogsViewModel(application: Application) : AndroidViewModel(application) var ret = "" for (log in torLogs().value ?: return getApplication<Application>().getString(R.string.default_error_msg)) { - ret += log.text + '\n' + ret += "${log.timestamp} [${log.type}] ${log.text}\n" } return ret } } - -@Stable -data class TorLog( - val text: String, - val timestamp: Timestamp = Timestamp(System.currentTimeMillis()), -)
===================================== mobile/android/geckoview/src/main/java/org/mozilla/geckoview/TorIntegrationAndroid.java ===================================== @@ -169,8 +169,9 @@ public class TorIntegrationAndroid implements BundleEventListener { } else if (EVENT_TOR_LOGS.equals(event)) { String msg = message.getString("message"); String type = message.getString("logType"); + String timestamp = message.getString("timestamp"); for (TorLogListener listener : mLogListeners) { - listener.onLog(type, msg); + listener.onLog(type, msg, timestamp); } } } @@ -636,7 +637,7 @@ public class TorIntegrationAndroid implements BundleEventListener { }
public interface TorLogListener { - void onLog(String logType, String message); + void onLog(String logType, String message, String timestamp); }
private @NonNull void reloadSettings() {
===================================== toolkit/components/tor-launcher/TorProvider.sys.mjs ===================================== @@ -47,7 +47,7 @@ const logger = console.createInstance({ */ /** * @typedef {object} LogEntry An object with a log message - * @property {Date} date The date at which we received the message + * @property {string} timestamp The local date-time stamp at which we received the message * @property {string} type The message level * @property {string} msg The message */ @@ -518,13 +518,7 @@ export class TorProvider { */ getLog() { return this.#logs - .map(logObj => { - const timeStr = logObj.date - .toISOString() - .replace("T", " ") - .replace("Z", ""); - return `${timeStr} [${logObj.type}] ${logObj.msg}`; - }) + .map(logObj => `${logObj.timestamp} [${logObj.type}] ${logObj.msg}`) .join(TorLauncherUtil.isWindows ? "\r\n" : "\n"); }
@@ -1031,9 +1025,16 @@ export class TorProvider { Services.obs.notifyObservers(null, TorProviderTopics.HasWarnOrErr); }
- Services.obs.notifyObservers({ type, msg }, TorProviderTopics.TorLog); + const timestamp = new Date() + .toISOString() + .replace("T", " ") + .replace("Z", ""); + + Services.obs.notifyObservers( + { type, msg, timestamp }, + TorProviderTopics.TorLog + );
- const date = new Date(); const maxEntries = Services.prefs.getIntPref( Preferences.MaxLogEntries, 1000 @@ -1042,7 +1043,7 @@ export class TorProvider { this.#logs.splice(0, 1); }
- this.#logs.push({ date, type, msg }); + this.#logs.push({ type, msg, timestamp }); switch (type) { case "ERR": logger.error(`[Tor error] ${msg}`);
===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -136,6 +136,7 @@ class TorAndroidIntegrationImpl { type: EmittedEvents.torLogs, logType: subj.wrappedJSObject.type ?? "", message: subj.wrappedJSObject.msg ?? "", + timestamp: subj.wrappedJSObject.timestamp ?? "", }); break; case lazy.TorSettingsTopics.Ready:
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/ed4f395...
tbb-commits@lists.torproject.org