Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

Address PR #40 review follow-ups

Jalebi35cd2832d8f2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dfe24e2..062fc88 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,23 @@ All notable changes to Gotcha are documented here.
## [Unreleased]
+### Changed — Release builds ship none of the debug logging (#38)
+
+- **Debug log calls are compile-time no-ops in release.** A new `GotchaLog`
+ facade gates every `Log.d`/`Log.v` call behind `BuildConfig.DEBUG`, and all
+ 83 call sites route through it. Clipboard text and the copied URL, the first
+ 100 chars of a sub-agent's response, and the audio-provider endpoint/reply
+ previews no longer reach logcat in release — and their message strings are
+ never built there.
+- **OkHttp request/response tracing is off in release.** The
+ `HttpLoggingInterceptor` in `LLMClient`, `AudioApi`, `SamosaAuthApi` and
+ `NotificationApi` is gated on `BuildConfig.DEBUG`, so no full prompts, LLM
+ replies or request URLs are written to logcat (`LLMClient` ran at
+ `Level.BODY` before).
+- **A `NoRawDebugLog` detekt rule** fails the build on any new raw
+ `Log.d`/`Log.v` call outside `GotchaLog` itself, so the migration cannot
+ silently regress.
+
### Added — Document attachments in chat (#24)
- **Attach more than images.** The composer's "+" now opens a picker that accepts
diff --git a/app/src/main/java/com/gotcha/service/WakeWordDetector.kt b/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
index 94385f1..cc8ddc4 100644
--- a/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
+++ b/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
@@ -156,7 +156,12 @@ class WakeWordDetector(
}
private fun teardown(closeSessions: Boolean) {
- GotchaLog.d(TAG, Throwable("called from")) { if (closeSessions) "release()" else "pause()" }
+ // The Throwable snapshots the call stack for debug diagnostics; constructing
+ // it unconditionally would do that work on every pause()/release() in
+ // release builds too, so keep it behind the debug guard.
+ if (BuildConfig.DEBUG) {
+ GotchaLog.d(TAG, Throwable("called from")) { if (closeSessions) "release()" else "pause()" }
+ }
val oldRecorder: AudioRecord?
var oldSessions: Sessions? = null
val oldJob: Job?
diff --git a/app/src/main/java/com/gotcha/util/GotchaLog.kt b/app/src/main/java/com/gotcha/util/GotchaLog.kt
index b9d7c0d..97b2323 100644
--- a/app/src/main/java/com/gotcha/util/GotchaLog.kt
+++ b/app/src/main/java/com/gotcha/util/GotchaLog.kt
@@ -10,19 +10,22 @@ import com.gotcha.BuildConfig
* the field.
*/
object GotchaLog {
- fun d(tag: String, message: () -> String) {
+ // inline: in release BuildConfig.DEBUG folds to false, so the whole call
+ // (lambda allocation included) is removed at the call site rather than
+ // paying for a Function0 instance that never runs.
+ inline fun d(tag: String, message: () -> String) {
if (BuildConfig.DEBUG) Log.d(tag, message())
}
- fun d(tag: String, throwable: Throwable?, message: () -> String) {
+ inline fun d(tag: String, throwable: Throwable?, message: () -> String) {
if (BuildConfig.DEBUG) Log.d(tag, message(), throwable)
}
- fun v(tag: String, message: () -> String) {
+ inline fun v(tag: String, message: () -> String) {
if (BuildConfig.DEBUG) Log.v(tag, message())
}
- fun v(tag: String, throwable: Throwable?, message: () -> String) {
+ inline fun v(tag: String, throwable: Throwable?, message: () -> String) {
if (BuildConfig.DEBUG) Log.v(tag, message(), throwable)
}
}
diff --git a/app/src/test/java/com/gotcha/util/GotchaLogTest.kt b/app/src/test/java/com/gotcha/util/GotchaLogTest.kt
new file mode 100644
index 0000000..1d8859b
--- /dev/null
+++ b/app/src/test/java/com/gotcha/util/GotchaLogTest.kt
@@ -0,0 +1,52 @@
+package com.gotcha.util
+
+import android.util.Log
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertSame
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import org.robolectric.shadows.ShadowLog
+
+/**
+ * Debug-variant behaviour of [GotchaLog]: messages are evaluated and written to
+ * logcat. The mirror-image release assertions (no output, lambda never invoked)
+ * live in GotchaLogReleaseTest, which only runs under
+ * `:app:testReleaseUnitTest` where `BuildConfig.DEBUG` is false.
+ */
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [34])
+class GotchaLogTest {
+
+ @Test
+ fun `d evaluates the message and writes to Log`() {
+ var evaluated = false
+ GotchaLog.d("GotchaLogTest") {
+ evaluated = true
+ "debug message"
+ }
+ assertTrue(evaluated)
+ val entry = ShadowLog.getLogs().last { it.tag == "GotchaLogTest" }
+ assertEquals(Log.DEBUG, entry.type)
+ assertEquals("debug message", entry.msg)
+ }
+
+ @Test
+ fun `d with throwable passes both to Log`() {
+ val cause = RuntimeException("boom")
+ GotchaLog.d("GotchaLogTest", cause) { "with throwable" }
+ val entry = ShadowLog.getLogs().last { it.tag == "GotchaLogTest" }
+ assertEquals("with throwable", entry.msg)
+ assertSame(cause, entry.throwable)
+ }
+
+ @Test
+ fun `v evaluates the message and writes to Log`() {
+ GotchaLog.v("GotchaLogTest") { "verbose message" }
+ val entry = ShadowLog.getLogs().last { it.tag == "GotchaLogTest" }
+ assertEquals(Log.VERBOSE, entry.type)
+ assertEquals("verbose message", entry.msg)
+ }
+}
diff --git a/detekt-rules/build.gradle.kts b/detekt-rules/build.gradle.kts
index f27caa4..2431460 100644
--- a/detekt-rules/build.gradle.kts
+++ b/detekt-rules/build.gradle.kts
@@ -9,4 +9,7 @@ plugins {
dependencies {
compileOnly("io.gitlab.arturbosch.detekt:detekt-api:1.23.6")
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.22")
+ testImplementation("io.gitlab.arturbosch.detekt:detekt-api:1.23.6")
+ testImplementation("io.gitlab.arturbosch.detekt:detekt-test:1.23.6")
+ testImplementation("junit:junit:4.13.2")
}
diff --git a/detekt-rules/src/test/kotlin/com/gotcha/detekt/NoRawDebugLogTest.kt b/detekt-rules/src/test/kotlin/com/gotcha/detekt/NoRawDebugLogTest.kt
new file mode 100644
index 0000000..886f73f
--- /dev/null
+++ b/detekt-rules/src/test/kotlin/com/gotcha/detekt/NoRawDebugLogTest.kt
@@ -0,0 +1,57 @@
+package com.gotcha.detekt
+
+import io.gitlab.arturbosch.detekt.test.TestConfig
+import io.gitlab.arturbosch.detekt.test.lint
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class NoRawDebugLogTest {
+
+ private val rule = NoRawDebugLog(TestConfig())
+
+ @Test
+ fun `reports Log dot d`() {
+ val code = """
+ import android.util.Log
+ fun f() { Log.d("TAG", "msg") }
+ """.trimIndent()
+ assertEquals(1, rule.lint(code).size)
+ }
+
+ @Test
+ fun `reports Log dot v`() {
+ val code = """
+ import android.util.Log
+ fun f() { Log.v("TAG", "msg") }
+ """.trimIndent()
+ assertEquals(1, rule.lint(code).size)
+ }
+
+ @Test
+ fun `reports fully qualified android util Log d`() {
+ val code = """
+ fun f() { android.util.Log.d("TAG", "msg") }
+ """.trimIndent()
+ assertEquals(1, rule.lint(code).size)
+ }
+
+ @Test
+ fun `does not report GotchaLog d`() {
+ val code = """
+ fun f() { GotchaLog.d("TAG") { "msg" } }
+ """.trimIndent()
+ assertEquals(0, rule.lint(code).size)
+ }
+
+ @Test
+ fun `does not report Log w or Log e`() {
+ val code = """
+ import android.util.Log
+ fun f() {
+ Log.w("TAG", "msg")
+ Log.e("TAG", "msg", IllegalStateException())
+ }
+ """.trimIndent()
+ assertEquals(0, rule.lint(code).size)
+ }
+}