Skip to content

Commit

Permalink
android: add logging to see what's spamming editPrefs
Browse files Browse the repository at this point in the history
Updates tailscale/tailscale#14125

Signed-off-by: kari-ts <[email protected]>
  • Loading branch information
kari-ts committed Dec 10, 2024
1 parent 45ddef1 commit e8d6e64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ jobs:
distribution: "temurin"
java-version: "17"

# Add verbose log code check
- name: Check for verbose logs
run: |
if [[ "${{ github.ref_name }}" == release/* ]]; then
if grep -rE "Log.v" .; then
echo "❌ Debug code detected. Remove verbose logging before merging."
exit 1
fi
fi
# Clean should essentially be a no-op, but make sure that it works.
- name: Clean
run: make clean
Expand Down
14 changes: 10 additions & 4 deletions android/src/main/java/com/tailscale/ipn/ui/localapi/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.tailscale.ipn.ui.localapi

import android.content.Context
import com.tailscale.ipn.App
import com.tailscale.ipn.ui.model.BugReportID
import com.tailscale.ipn.ui.model.Errors
import com.tailscale.ipn.ui.model.Ipn
Expand All @@ -13,7 +14,6 @@ import com.tailscale.ipn.ui.model.StableNodeID
import com.tailscale.ipn.ui.model.Tailcfg
import com.tailscale.ipn.ui.util.InputStreamAdapter
import com.tailscale.ipn.util.TSLog
import com.tailscale.ipn.App
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -69,9 +69,7 @@ class Client(private val scope: CoroutineScope) {
private val TAG = Client::class.simpleName

// Access libtailscale.Application lazily
private val app: libtailscale.Application by lazy {
App.get().getLibtailscaleApp()
}
private val app: libtailscale.Application by lazy { App.get().getLibtailscaleApp() }

fun start(options: Ipn.Options, responseHandler: (Result<Unit>) -> Unit) {
val body = Json.encodeToString(options).toByteArray()
Expand Down Expand Up @@ -102,6 +100,14 @@ class Client(private val scope: CoroutineScope) {
}

fun editPrefs(prefs: Ipn.MaskedPrefs, responseHandler: (Result<Ipn.Prefs>) -> Unit) {
// Log the stack trace for debugging purposes for
// https://github.com/tailscale/tailscale/issues/14125
val stackTrace =
Thread.currentThread().stackTrace.joinToString("\n") { element ->
"at ${element.className}.${element.methodName}(${element.fileName}:${element.lineNumber})"
}
TSLog.v("editPrefs", "Called editPrefs with prefs: $prefs\nStack trace:\n$stackTrace")

val body = Json.encodeToString(prefs).toByteArray()
return patch(Endpoint.PREFS, body, responseHandler = responseHandler)
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/java/com/tailscale/ipn/util/TSLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ object TSLog {
libtailscaleWrapper.sendLog(tag, message)
}

fun v(tag: String?, message: String) {
Log.v(tag, message)
libtailscaleWrapper.sendLog(tag, message)
}

// Overloaded function without Throwable because Java does not support default parameters
@JvmStatic
fun e(tag: String?, message: String) {
Expand Down

0 comments on commit e8d6e64

Please sign in to comment.