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.

build: move Samosa endpoints into build-time configuration

Durganshu Mishra52822f546441
diff --git a/RUNNING.md b/RUNNING.md
index d9fcd4a..51b72cb 100644
--- a/RUNNING.md
+++ b/RUNNING.md
@@ -29,6 +29,47 @@ If you open on another machine, delete that line and let Android Studio regenera
If sync succeeds, `app` appears as a run configuration in the toolbar.
+### Samosa endpoints (optional, developers only)
+
+This repository ships with **inert placeholder endpoints**, so a fresh checkout
+builds and runs but cannot reach the Samosa backend — "Samosa AI" sign-in will
+not work until you supply real values. Everything else, including the
+OpenAI-compatible provider flow, works out of the box.
+
+Three build-time values control it:
+
+| Variable | Placeholder | What it is |
+|---|---|---|
+| `SAMOSA_API_URL` | `https://api.samosa-ai.example` | API root, **no** trailing slash. `/v1/` and the auth root are derived from it. |
+| `SAMOSA_SKILL_HOST` | `samosa-ai.example` | Host allowed for community-skill imports |
+| `SAMOSA_WEB_CLIENT_ID` | `YOUR_GOOGLE_WEB_CLIENT_ID.…` | Google **WEB** OAuth client ID (not the Android one) |
+
+Supply them either way — environment variables take precedence, so CI can
+override a developer's file:
+
+```bash
+# Option A — environment (per shell, nothing on disk)
+export SAMOSA_API_URL="https://api.example.com"
+export SAMOSA_SKILL_HOST="example.com"
+export SAMOSA_WEB_CLIENT_ID="1234567890-abcdef.apps.googleusercontent.com"
+./gradlew installDebug
+```
+
+```properties
+# Option B — local.properties at the repo root (gitignored, persists across shells)
+SAMOSA_API_URL=https://api.example.com
+SAMOSA_SKILL_HOST=example.com
+SAMOSA_WEB_CLIENT_ID=1234567890-abcdef.apps.googleusercontent.com
+```
+
+They are read in `app/build.gradle.kts` and exposed as `BuildConfig.SAMOSA_*`.
+Changing either source triggers a rebuild of `BuildConfig` automatically.
+
+> **Never commit real values.** `local.properties` is gitignored and the
+> generated `BuildConfig.java` lives under `app/build/`, which is also ignored —
+> but note the values *are* compiled into any APK you build, so treat a release
+> APK built with real endpoints accordingly.
+
## 3. Get a device ready
**Option A — Emulator (easiest):**
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index a076fdd..f364ed8 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -16,6 +16,17 @@ val keystoreProps = Properties().apply {
if (f.exists()) f.inputStream().use { load(it) }
}
+/**
+ * Developer-specific Samosa endpoints. A public checkout builds against inert
+ * placeholders so it cannot reach the real backend; supply your own values via
+ * an environment variable or `local.properties` (both gitignored, neither is
+ * ever committed). Environment wins, so CI can override a developer's file.
+ */
+fun samosaConfig(name: String, placeholder: String): String =
+ providers.environmentVariable(name).orNull
+ ?: keystoreProps.getProperty(name)
+ ?: placeholder
+
android {
namespace = "com.gotcha"
compileSdk = 34
@@ -31,6 +42,25 @@ android {
vectorDrawables {
useSupportLibrary = true
}
+
+ buildConfigField(
+ "String",
+ "SAMOSA_API_URL",
+ "\"${samosaConfig("SAMOSA_API_URL", "https://api.samosa-ai.example")}\""
+ )
+ buildConfigField(
+ "String",
+ "SAMOSA_SKILL_HOST",
+ "\"${samosaConfig("SAMOSA_SKILL_HOST", "samosa-ai.example")}\""
+ )
+ buildConfigField(
+ "String",
+ "SAMOSA_WEB_CLIENT_ID",
+ "\"${samosaConfig(
+ "SAMOSA_WEB_CLIENT_ID",
+ "YOUR_GOOGLE_WEB_CLIENT_ID.apps.googleusercontent.com"
+ )}\""
+ )
}
signingConfigs {
@@ -68,6 +98,7 @@ android {
buildFeatures {
compose = true
+ buildConfig = true
}
packaging {
diff --git a/app/src/main/java/com/gotcha/agent/skills/SkillImporter.kt b/app/src/main/java/com/gotcha/agent/skills/SkillImporter.kt
index c8071ca..fa76f43 100644
--- a/app/src/main/java/com/gotcha/agent/skills/SkillImporter.kt
+++ b/app/src/main/java/com/gotcha/agent/skills/SkillImporter.kt
@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit
* The fetcher is intentionally tiny: HTTPS only, host allowlist, short
* timeouts, a single body-size cap, and a strict JSON parser. We follow
* redirects only when each hop lands on a host in the same allowlist
- * (e.g. samosa-ai.example -> samosa.ai), and never chase cross-host redirects.
+ * (e.g. example.com -> evil.com), and never chase cross-host redirects.
*/
@Suppress("ThrowsCount", "SwallowedException")
class SkillImporter(
diff --git a/app/src/main/java/com/gotcha/auth/SamosaAuthApi.kt b/app/src/main/java/com/gotcha/auth/SamosaAuthApi.kt
index 0ca4fa9..9b7e79d 100644
--- a/app/src/main/java/com/gotcha/auth/SamosaAuthApi.kt
+++ b/app/src/main/java/com/gotcha/auth/SamosaAuthApi.kt
@@ -1,5 +1,6 @@
package com.gotcha.auth
+import com.gotcha.BuildConfig
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@@ -36,9 +37,9 @@ data class RegisterResponse(
)
/**
- * Samosa AI auth endpoints (base URL https://api.samosa-ai.example/).
+ * Samosa AI auth endpoints (base URL [AUTH_BASE_URL], from BuildConfig).
* The OpenAI-compatible chat/model endpoints are handled by the existing
- * LLMClient against https://api.samosa-ai.example/v1/ — these are auth-only.
+ * LLMClient against the /v1/ proxy root — these are auth-only.
*/
interface SamosaAuthApi {
@@ -53,7 +54,7 @@ interface SamosaAuthApi {
companion object {
/** Auth-manager root (no /v1). Trailing slash required by Retrofit. */
- const val AUTH_BASE_URL = "https://api.samosa-ai.example/"
+ val AUTH_BASE_URL: String = "${BuildConfig.SAMOSA_API_URL}/"
fun create(): SamosaAuthApi {
@OptIn(kotlinx.serialization.ExperimentalSerializationApi::class)
diff --git a/app/src/main/java/com/gotcha/auth/SamosaAuthManager.kt b/app/src/main/java/com/gotcha/auth/SamosaAuthManager.kt
index 35ecefb..b9215ab 100644
--- a/app/src/main/java/com/gotcha/auth/SamosaAuthManager.kt
+++ b/app/src/main/java/com/gotcha/auth/SamosaAuthManager.kt
@@ -9,6 +9,7 @@ import androidx.credentials.exceptions.GetCredentialException
import androidx.credentials.exceptions.NoCredentialException
import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
+import com.gotcha.BuildConfig
import com.gotcha.data.SettingsRepository
import retrofit2.HttpException
import java.io.IOException
@@ -134,8 +135,11 @@ class SamosaAuthManager(
/**
* WEB OAuth client ID. Google mints the ID token with aud = this value,
* which is what the backend verifies. Do NOT use the Android client ID.
+ *
+ * Supplied at build time via the `SAMOSA_WEB_CLIENT_ID` environment
+ * variable or `local.properties`; a public checkout falls back to an
+ * inert placeholder, so Samosa sign-in is disabled until you set it.
*/
- const val WEB_CLIENT_ID =
- "YOUR_GOOGLE_WEB_CLIENT_ID.apps.googleusercontent.com"
+ val WEB_CLIENT_ID: String = BuildConfig.SAMOSA_WEB_CLIENT_ID
}
}
diff --git a/app/src/main/java/com/gotcha/data/LlmProvider.kt b/app/src/main/java/com/gotcha/data/LlmProvider.kt
index 97f290c..b807cdb 100644
--- a/app/src/main/java/com/gotcha/data/LlmProvider.kt
+++ b/app/src/main/java/com/gotcha/data/LlmProvider.kt
@@ -1,5 +1,7 @@
package com.gotcha.data
+import com.gotcha.BuildConfig
+
/**
* Which LLM backend the app talks to.
*
@@ -16,8 +18,11 @@ enum class LlmProvider(val label: String) {
OPENAI_COMPATIBLE("OpenAI Compatible");
companion object {
- /** OpenAI-compatible proxy exposed by the Samosa AI backend. */
- const val SAMOSA_BASE_URL = "https://api.samosa-ai.example/v1/"
+ /**
+ * OpenAI-compatible proxy exposed by the Samosa AI backend. Derived from
+ * the build-time `SAMOSA_API_URL` (environment or `local.properties`).
+ */
+ val SAMOSA_BASE_URL: String = "${BuildConfig.SAMOSA_API_URL}/v1/"
fun fromName(name: String?): LlmProvider =
entries.firstOrNull { it.name == name } ?: SAMOSA_AI
diff --git a/app/src/main/java/com/gotcha/data/SettingsRepository.kt b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
index 851860b..31fff90 100644
--- a/app/src/main/java/com/gotcha/data/SettingsRepository.kt
+++ b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
@@ -2,6 +2,7 @@ package com.gotcha.data
import android.content.Context
import android.content.SharedPreferences
+import com.gotcha.BuildConfig
import com.gotcha.audio.AudioProvider
data class Settings(
@@ -51,7 +52,7 @@ data class Settings(
/** Chime when a reply arrives. Off by default — audible in a way a buzz is not. */
val notifyChimeEnabled: Boolean = false,
val assistiveBallEnabled: Boolean = false,
- /** Server-driven notifications from `api.samosa-ai.example/v1/gotcha/notifications`. */
+ /** Server-driven notifications from `<SAMOSA_API_URL>/v1/gotcha/notifications`. */
val serverMessagesEnabled: Boolean = true,
/** Epoch millis of the last successful server-messages fetch. 0 = never. */
val serverMessagesLastFetchedAt: Long = 0L,
@@ -100,7 +101,7 @@ data class Settings(
val userResponseStyle: String = "",
val preferredLanguage: String = "English",
val preferredCurrency: String = "USD",
- val communitySkillHosts: Set<String> = setOf("samosa-ai.example"),
+ val communitySkillHosts: Set<String> = setOf(BuildConfig.SAMOSA_SKILL_HOST),
/**
* Version tag of the Terms / Disclaimer / Data Retention bundle the user has
* accepted. Empty string means "never accepted." The first-launch consent
@@ -516,7 +517,7 @@ class SettingsRepository(context: Context) {
const val KEY_ONBOARDING_DONE = "onboarding_completed"
const val KEY_TOUR_STEP = "tour_step_id"
const val KEY_ONBOARDING_VERSION = "onboarding_version"
- val defaultCommunitySkillHosts: Set<String> = setOf("samosa-ai.example")
+ val defaultCommunitySkillHosts: Set<String> = setOf(BuildConfig.SAMOSA_SKILL_HOST)
}
}
diff --git a/app/src/main/java/com/gotcha/notifications/NotificationApi.kt b/app/src/main/java/com/gotcha/notifications/NotificationApi.kt
index 62a331e..6f58cbf 100644
--- a/app/src/main/java/com/gotcha/notifications/NotificationApi.kt
+++ b/app/src/main/java/com/gotcha/notifications/NotificationApi.kt
@@ -1,6 +1,7 @@
package com.gotcha.notifications
import android.util.Log
+import com.gotcha.BuildConfig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
@@ -13,7 +14,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
/**
- * HTTP client for `GET https://api.samosa-ai.example/v1/gotcha/notifications`.
+ * HTTP client for `GET <SAMOSA_API_URL>/v1/gotcha/notifications`.
*
* Mirrors the [com.gotcha.audio.AudioApi] pattern (OkHttp directly, no
* Retrofit). Surfaces a 304 via [NotificationsApiResult.NotModified] so the
@@ -122,7 +123,7 @@ open class NotificationApi(
/** OpenAI-compatible proxy exposed by the Samosa AI backend; reused as the
* notifications host so a single network identity covers LLM/audio/notifications. */
- const val DEFAULT_BASE_URL = "https://api.samosa-ai.example"
+ val DEFAULT_BASE_URL: String = BuildConfig.SAMOSA_API_URL
}
}
diff --git a/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt b/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt
index ca9430c..159b37e 100644
--- a/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt
+++ b/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt
@@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
- * Wire DTOs for `GET /v1/gotcha/notifications` on `api.samosa-ai.example`.
+ * Wire DTOs for `GET /v1/gotcha/notifications` on the configured Samosa host.
*
* The server is stateless w.r.t. per-device delivery: all dedupe is enforced
* on the client against [NotificationStore.deliveredIds] and the per-id
diff --git a/app/src/main/java/com/gotcha/ui/NotificationsScreen.kt b/app/src/main/java/com/gotcha/ui/NotificationsScreen.kt
index 5270346..f0d0960 100644
--- a/app/src/main/java/com/gotcha/ui/NotificationsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/NotificationsScreen.kt
@@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
+import com.gotcha.BuildConfig
import com.gotcha.audio.CompletionFeedback
import com.gotcha.data.Settings
import kotlinx.coroutines.launch
@@ -94,7 +95,8 @@ fun NotificationsScreen(
style = MaterialTheme.typography.titleMedium
)
Text(
- "Updates, tips and maintenance notices from Gotcha, fetched from api.samosa-ai.example. " +
+ "Updates, tips and maintenance notices from Gotcha, fetched from " +
+ "${BuildConfig.SAMOSA_API_URL.removePrefix("https://")}. " +
"Each message shows at most the number of times the server asks; re-deliveries are suppressed automatically.",
style = MaterialTheme.typography.bodySmall
)
diff --git a/app/src/main/java/com/gotcha/ui/SkillsScreen.kt b/app/src/main/java/com/gotcha/ui/SkillsScreen.kt
index 9f047ae..22a9392 100644
--- a/app/src/main/java/com/gotcha/ui/SkillsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SkillsScreen.kt
@@ -34,6 +34,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
+import com.gotcha.BuildConfig
import com.gotcha.agent.skills.Skill
import com.gotcha.agent.skills.SkillRegistry
import com.gotcha.data.Settings
@@ -121,7 +122,7 @@ fun SkillsScreen(
fontWeight = FontWeight.Bold
)
Text(
- "Import skills from samosa-ai.example or paste JSON. " +
+ "Import skills from ${BuildConfig.SAMOSA_SKILL_HOST} or paste JSON. " +
"Community skills appear in the agent's system prompt " +
"as advisory guidance.",
style = MaterialTheme.typography.bodySmall
@@ -130,7 +131,7 @@ fun SkillsScreen(
OutlinedTextField(
value = communitySkillUrl,
onValueChange = { communitySkillUrl = it.trim() },
- label = { Text("Skill URL (https://samosa-ai.example/...)") },
+ label = { Text("Skill URL (https://${BuildConfig.SAMOSA_SKILL_HOST}/...)") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
)
@@ -336,7 +337,7 @@ fun SkillsScreen(
)
Text(
"Only HTTPS hosts in this list can be fetched. " +
- "Default: samosa-ai.example.",
+ "Default: ${BuildConfig.SAMOSA_SKILL_HOST}.",
style = MaterialTheme.typography.bodySmall
)
communitySkillHosts.forEach { host ->