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
-
a1c22a73
by clairehurst at 2025-01-23T18:07:07+00:00
-
db1d2b30
by clairehurst at 2025-01-23T18:07:07+00:00
-
b270a085
by clairehurst at 2025-01-23T18:07:07+00:00
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:
| ... | ... | @@ -20,7 +20,7 @@ class TorError( |
| 20 | 20 | ) { }
|
| 21 | 21 | |
| 22 | 22 | interface TorLogs {
|
| 23 | - fun onLog(type: String?, message: String?)
|
|
| 23 | + fun onLog(type: String?, message: String?, timestamp: String?)
|
|
| 24 | 24 | }
|
| 25 | 25 | |
| 26 | 26 | internal enum class TorStatus(val status: String) {
|
| ... | ... | @@ -32,7 +32,7 @@ internal enum class TorStatus(val status: String) { |
| 32 | 32 | }
|
| 33 | 33 | |
| 34 | 34 | interface TorController: TorEvents {
|
| 35 | - val logEntries: MutableList<Pair<String?, String?>>
|
|
| 35 | + val logEntries: MutableList<TorLog>
|
|
| 36 | 36 | val isStarting: Boolean
|
| 37 | 37 | val isRestarting: Boolean
|
| 38 | 38 | val isBootstrapped: Boolean
|
| ... | ... | @@ -66,7 +66,7 @@ class TorControllerGV( |
| 66 | 66 | private var isTorBootstrapped = false
|
| 67 | 67 | get() = ((_lastKnownStatus.value.isStarted()) && wasTorBootstrapped)
|
| 68 | 68 | |
| 69 | - private val entries = mutableListOf<Pair<String?, String?>>()
|
|
| 69 | + private val entries = mutableListOf<TorLog>()
|
|
| 70 | 70 | override val logEntries get() = entries
|
| 71 | 71 | override val isStarting get() = _lastKnownStatus.value.isStarting()
|
| 72 | 72 | override val isRestarting get() = isTorRestarting
|
| ... | ... | @@ -217,10 +217,10 @@ class TorControllerGV( |
| 217 | 217 | }
|
| 218 | 218 | }
|
| 219 | 219 | |
| 220 | - override fun onLog(type: String?, message: String?) {
|
|
| 220 | + override fun onLog(type: String?, message: String?, timestamp: String?) {
|
|
| 221 | 221 | synchronized(torLogListeners) {
|
| 222 | - entries.add(Pair(type, message))
|
|
| 223 | - torLogListeners.toList().forEach { it.onLog(type, message) }
|
|
| 222 | + entries.add(TorLog(type ?: "null", message ?: "null", timestamp ?: "null"))
|
|
| 223 | + torLogListeners.toList().forEach { it.onLog(type ?: "null", message ?: "null", timestamp) }
|
|
| 224 | 224 | }
|
| 225 | 225 | }
|
| 226 | 226 |
| 1 | +package org.mozilla.fenix.tor
|
|
| 2 | + |
|
| 3 | +import androidx.compose.runtime.Stable
|
|
| 4 | + |
|
| 5 | +@Stable
|
|
| 6 | +data class TorLog(
|
|
| 7 | + val type: String,
|
|
| 8 | + val text: String,
|
|
| 9 | + val timestamp: String,
|
|
| 10 | +) |
| ... | ... | @@ -108,16 +108,14 @@ class TorLogsComposeFragment : Fragment() { |
| 108 | 108 | bottom = 16.dp,
|
| 109 | 109 | ),
|
| 110 | 110 | ) {
|
| 111 | - DisableSelection {
|
|
| 112 | - Text(
|
|
| 113 | - text = log.timestamp.toString(),
|
|
| 114 | - color = PhotonColors.LightGrey40,
|
|
| 115 | - modifier = modifier
|
|
| 116 | - .padding(bottom = 4.dp),
|
|
| 117 | - )
|
|
| 118 | - }
|
|
| 119 | 111 | Text(
|
| 120 | - text = log.text,
|
|
| 112 | + text = log.timestamp,
|
|
| 113 | + color = PhotonColors.LightGrey40,
|
|
| 114 | + modifier = modifier
|
|
| 115 | + .padding(bottom = 4.dp),
|
|
| 116 | + )
|
|
| 117 | + Text(
|
|
| 118 | + text = "[${log.type}] " + log.text,
|
|
| 121 | 119 | color = PhotonColors.LightGrey05,
|
| 122 | 120 | )
|
| 123 | 121 | }
|
| ... | ... | @@ -10,22 +10,18 @@ import android.content.ClipboardManager |
| 10 | 10 | import android.content.Context
|
| 11 | 11 | import android.os.Build
|
| 12 | 12 | import android.widget.Toast
|
| 13 | -import androidx.compose.runtime.Stable
|
|
| 14 | 13 | import androidx.lifecycle.AndroidViewModel
|
| 15 | 14 | import androidx.lifecycle.LiveData
|
| 16 | 15 | import androidx.lifecycle.MutableLiveData
|
| 17 | 16 | import org.mozilla.fenix.R
|
| 18 | 17 | import org.mozilla.fenix.ext.components
|
| 19 | -import java.sql.Timestamp
|
|
| 20 | 18 | |
| 21 | 19 | class TorLogsViewModel(application: Application) : AndroidViewModel(application), TorLogs {
|
| 22 | 20 | private val torController = application.components.torController
|
| 23 | 21 | private val clipboardManager =
|
| 24 | 22 | application.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
| 25 | 23 | |
| 26 | - private val _torLogs: MutableLiveData<List<TorLog>> = MutableLiveData(
|
|
| 27 | - mutableListOf(TorLog("---------------" + application.getString(R.string.tor_initializing_log) + "---------------")),
|
|
| 28 | - )
|
|
| 24 | + private val _torLogs: MutableLiveData<List<TorLog>> = MutableLiveData(mutableListOf())
|
|
| 29 | 25 | |
| 30 | 26 | fun torLogs(): LiveData<List<TorLog>> {
|
| 31 | 27 | return _torLogs
|
| ... | ... | @@ -38,20 +34,14 @@ class TorLogsViewModel(application: Application) : AndroidViewModel(application) |
| 38 | 34 | init {
|
| 39 | 35 | setupClipboardListener()
|
| 40 | 36 | torController.registerTorLogListener(this)
|
| 41 | - val currentEntries = torController.logEntries.filter { it.second != null }
|
|
| 42 | - .filter { !(it.second!!.startsWith("Circuit") && it.first == "ON") }
|
|
| 43 | - // Keep synchronized with format in onTorStatusUpdate
|
|
| 44 | - .flatMap { listOf(TorLog("[${it.first}] ${it.second}")) }
|
|
| 37 | + val currentEntries = torController.logEntries
|
|
| 45 | 38 | for (log in currentEntries) {
|
| 46 | 39 | addLog(log)
|
| 47 | 40 | }
|
| 48 | 41 | }
|
| 49 | 42 | |
| 50 | - override fun onLog(type: String?, message: String?) {
|
|
| 51 | - if (message == null || type == null) return
|
|
| 52 | - if (type == "ON" && type.startsWith("Circuit")) return
|
|
| 53 | - |
|
| 54 | - addLog(TorLog("[$type] $message"))
|
|
| 43 | + override fun onLog(type: String?, message: String?, timestamp: String?) {
|
|
| 44 | + addLog(TorLog(type ?: "null", message ?: "null", timestamp ?: "null"))
|
|
| 55 | 45 | }
|
| 56 | 46 | |
| 57 | 47 | override fun onCleared() {
|
| ... | ... | @@ -86,14 +76,8 @@ class TorLogsViewModel(application: Application) : AndroidViewModel(application) |
| 86 | 76 | var ret = ""
|
| 87 | 77 | for (log in torLogs().value
|
| 88 | 78 | ?: return getApplication<Application>().getString(R.string.default_error_msg)) {
|
| 89 | - ret += log.text + '\n'
|
|
| 79 | + ret += "${log.timestamp} [${log.type}] ${log.text}\n"
|
|
| 90 | 80 | }
|
| 91 | 81 | return ret
|
| 92 | 82 | }
|
| 93 | 83 | } |
| 94 | - |
|
| 95 | -@Stable
|
|
| 96 | -data class TorLog(
|
|
| 97 | - val text: String,
|
|
| 98 | - val timestamp: Timestamp = Timestamp(System.currentTimeMillis()),
|
|
| 99 | -) |
| ... | ... | @@ -169,8 +169,9 @@ public class TorIntegrationAndroid implements BundleEventListener { |
| 169 | 169 | } else if (EVENT_TOR_LOGS.equals(event)) {
|
| 170 | 170 | String msg = message.getString("message");
|
| 171 | 171 | String type = message.getString("logType");
|
| 172 | + String timestamp = message.getString("timestamp");
|
|
| 172 | 173 | for (TorLogListener listener : mLogListeners) {
|
| 173 | - listener.onLog(type, msg);
|
|
| 174 | + listener.onLog(type, msg, timestamp);
|
|
| 174 | 175 | }
|
| 175 | 176 | }
|
| 176 | 177 | }
|
| ... | ... | @@ -636,7 +637,7 @@ public class TorIntegrationAndroid implements BundleEventListener { |
| 636 | 637 | }
|
| 637 | 638 | |
| 638 | 639 | public interface TorLogListener {
|
| 639 | - void onLog(String logType, String message);
|
|
| 640 | + void onLog(String logType, String message, String timestamp);
|
|
| 640 | 641 | }
|
| 641 | 642 | |
| 642 | 643 | private @NonNull void reloadSettings() {
|
| ... | ... | @@ -47,7 +47,7 @@ const logger = console.createInstance({ |
| 47 | 47 | */
|
| 48 | 48 | /**
|
| 49 | 49 | * @typedef {object} LogEntry An object with a log message
|
| 50 | - * @property {Date} date The date at which we received the message
|
|
| 50 | + * @property {string} timestamp The local date-time stamp at which we received the message
|
|
| 51 | 51 | * @property {string} type The message level
|
| 52 | 52 | * @property {string} msg The message
|
| 53 | 53 | */
|
| ... | ... | @@ -518,13 +518,7 @@ export class TorProvider { |
| 518 | 518 | */
|
| 519 | 519 | getLog() {
|
| 520 | 520 | return this.#logs
|
| 521 | - .map(logObj => {
|
|
| 522 | - const timeStr = logObj.date
|
|
| 523 | - .toISOString()
|
|
| 524 | - .replace("T", " ")
|
|
| 525 | - .replace("Z", "");
|
|
| 526 | - return `${timeStr} [${logObj.type}] ${logObj.msg}`;
|
|
| 527 | - })
|
|
| 521 | + .map(logObj => `${logObj.timestamp} [${logObj.type}] ${logObj.msg}`)
|
|
| 528 | 522 | .join(TorLauncherUtil.isWindows ? "\r\n" : "\n");
|
| 529 | 523 | }
|
| 530 | 524 | |
| ... | ... | @@ -1031,9 +1025,16 @@ export class TorProvider { |
| 1031 | 1025 | Services.obs.notifyObservers(null, TorProviderTopics.HasWarnOrErr);
|
| 1032 | 1026 | }
|
| 1033 | 1027 | |
| 1034 | - Services.obs.notifyObservers({ type, msg }, TorProviderTopics.TorLog);
|
|
| 1028 | + const timestamp = new Date()
|
|
| 1029 | + .toISOString()
|
|
| 1030 | + .replace("T", " ")
|
|
| 1031 | + .replace("Z", "");
|
|
| 1032 | + |
|
| 1033 | + Services.obs.notifyObservers(
|
|
| 1034 | + { type, msg, timestamp },
|
|
| 1035 | + TorProviderTopics.TorLog
|
|
| 1036 | + );
|
|
| 1035 | 1037 | |
| 1036 | - const date = new Date();
|
|
| 1037 | 1038 | const maxEntries = Services.prefs.getIntPref(
|
| 1038 | 1039 | Preferences.MaxLogEntries,
|
| 1039 | 1040 | 1000
|
| ... | ... | @@ -1042,7 +1043,7 @@ export class TorProvider { |
| 1042 | 1043 | this.#logs.splice(0, 1);
|
| 1043 | 1044 | }
|
| 1044 | 1045 | |
| 1045 | - this.#logs.push({ date, type, msg });
|
|
| 1046 | + this.#logs.push({ type, msg, timestamp });
|
|
| 1046 | 1047 | switch (type) {
|
| 1047 | 1048 | case "ERR":
|
| 1048 | 1049 | logger.error(`[Tor error] ${msg}`);
|
| ... | ... | @@ -136,6 +136,7 @@ class TorAndroidIntegrationImpl { |
| 136 | 136 | type: EmittedEvents.torLogs,
|
| 137 | 137 | logType: subj.wrappedJSObject.type ?? "",
|
| 138 | 138 | message: subj.wrappedJSObject.msg ?? "",
|
| 139 | + timestamp: subj.wrappedJSObject.timestamp ?? "",
|
|
| 139 | 140 | });
|
| 140 | 141 | break;
|
| 141 | 142 | case lazy.TorSettingsTopics.Ready:
|