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.
feat: remove screenshot option from share card
Durganshu Mishra5c95468590ac
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.ktindex 9cc41ef..26f898a 100644--- a/app/src/main/java/com/gotcha/MainActivity.kt+++ b/app/src/main/java/com/gotcha/MainActivity.kt@@ -800,7 +800,6 @@ class MainActivity : ComponentActivity() {loading = sharePoster.loading,preview = sharePoster.preview,error = sharePoster.error,- hasImage = chatViewModel.activeSessionHasImage(),onGenerate = sharePoster::generate,onShare = { sharePoster.preview?.let { sharePoster.share(it) } },onSave = { sharePoster.preview?.let { sharePoster.save(it) } },diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.ktindex 00c9ca3..01c1a66 100644--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt@@ -1086,8 +1086,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A* hops to the main thread internally.*/suspend fun generateShareCard(- runs: List<RunSummary>,- includeScreenshot: Boolean = false+ runs: List<RunSummary>): Result<Bitmap> = runCatching {val client = ShareCardClient(getApplication(), settings)val content = client.generate(runs)@@ -1095,54 +1094,8 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), Aerror("Nothing accomplished in this run to showcase yet.")}val stats = PosterStatsBuilder.from(runs)- val screenshot = if (includeScreenshot) loadShareScreenshot() else nullwithContext(Dispatchers.Main) {- PosterRenderer.render(getApplication(), content, stats, screenshot)- }- }-- /**- * Best-effort screenshot for the poster thumbnail: the newest image in the- * engine session's chat history (a user-attached photo or an agent screen- * capture), else null.- *- * Guarded so a huge or malformed image can't OOM the decode: files over- * [MAX_SHARE_SCREENSHOT_BYTES] are skipped, and anything larger than- * [MAX_SHARE_SCREENSHOT_DIM] on either side is downsampled before decoding- * (the poster draws the thumbnail at 460×345, so full-res is wasteful).- */- private fun loadShareScreenshot(): Bitmap? {- // Snapshot before scanning: the engine coroutine mutates history as it- // runs, and this is read from the UI thread. asReversed() alone is a- // live view, not a copy.- val dataUri = agentEngine.history.toList().asReversed()- .firstNotNullOfOrNull { it.imageUrl() }- ?: return null- // Early bound on the URI before allocating the Base64 byte array:- // Base64 inflates payload by 4/3, so even a 50 MB payload produces a- // ~67 MB string; reject anything that cannot possibly fit under the- // byte cap without decoding it.- if (dataUri.length > MAX_SHARE_SCREENSHOT_BYTES * 4 / 3 + SAFE_DATA_URI_PREFIX) {- return null- }- val base64 = dataUri.substringAfter("base64,")- return try {- val bytes = android.util.Base64.decode(base64, android.util.Base64.DEFAULT)- if (bytes.size > MAX_SHARE_SCREENSHOT_BYTES) return null- val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }- BitmapFactory.decodeByteArray(bytes, 0, bytes.size, bounds)- val w = bounds.outWidth- val h = bounds.outHeight- if (w <= 0 || h <= 0) return null- val options = BitmapFactory.Options().apply {- inSampleSize = when {- w <= MAX_SHARE_SCREENSHOT_DIM && h <= MAX_SHARE_SCREENSHOT_DIM -> 1- else -> maxOf(w, h) / MAX_SHARE_SCREENSHOT_DIM- }- }- BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options)- } catch (_: Exception) {- null+ PosterRenderer.render(getApplication(), content, stats)}}@@ -1167,18 +1120,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), Areturn synthesizeRunSummariesFromHistory(snapshot, settings.model, engineAgent.name)}- /**- * True when the session currently bound to the engine has an image in its- * history. Drives whether the poster sheet offers "Include a screenshot":- * the option only makes sense when there is something to embed, and it must- * disappear once the image is culled from history.- */- fun activeSessionHasImage(): Boolean {- // Snapshot before reading: the engine coroutine mutates history as it- // runs, and this is read from the UI thread.- return agentEngine.history.toList().any { it.hasImage }- }-/** Formats a SUBAGENT_STEPS tool message (description, steps, result) for chat export. */private fun appendSubAgentExport(sb: StringBuilder, text: String) {val descEnd = text.indexOf('\n', "SUBAGENT_STEPS:".length)@@ -1214,18 +1155,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), Aprivate companion object {const val GATE_TIMEOUT_MS = 120_000Lconst val MIGRATED_CHAT_DIRS_KEY = "migrated_chat_dirs_v1"-- /** Poster-thumbnail screenshot guards (see [loadShareScreenshot]). */- const val MAX_SHARE_SCREENSHOT_BYTES = 50L * 1024 * 1024- const val MAX_SHARE_SCREENSHOT_DIM = 2048-- /**- * Slack added to the dataUri length ceiling to account for the- * `data:image/...;base64,` MIME prefix that Base64 decoding strips.- * 64 bytes is far more than any real MIME prefix and well below the- * 4/3 inflation ratio that motivates the guard.- */- const val SAFE_DATA_URI_PREFIX = 64L}}diff --git a/app/src/main/java/com/gotcha/marketing/PosterRenderer.kt b/app/src/main/java/com/gotcha/marketing/PosterRenderer.ktindex ff8b34a..4ae2dcb 100644--- a/app/src/main/java/com/gotcha/marketing/PosterRenderer.kt+++ b/app/src/main/java/com/gotcha/marketing/PosterRenderer.kt@@ -46,8 +46,7 @@ object PosterRenderer {fun render(context: Context,content: PosterContent,- stats: PosterStats,- screenshot: Bitmap? = null+ stats: PosterStats): Bitmap {val bitmap = Bitmap.createBitmap(WIDTH_PX, HEIGHT_PX, Bitmap.Config.ARGB_8888)val canvas = Canvas(bitmap)@@ -58,7 +57,7 @@ object PosterRenderer {val downloadQr = runCatching {android.graphics.BitmapFactory.decodeResource(context.resources, R.drawable.gotcha_download_qr)}.getOrNull()- PosterPainter(typeface, brandColors, logo, downloadQr).draw(canvas, content, stats, screenshot)+ PosterPainter(typeface, brandColors, logo, downloadQr).draw(canvas, content, stats)return bitmap}@@ -152,8 +151,7 @@ object PosterRenderer {fun draw(canvas: Canvas,content: PosterContent,- stats: PosterStats,- screenshot: Bitmap?+ stats: PosterStats) {drawBackground(canvas)@@ -206,37 +204,10 @@ object PosterRenderer {)y += 40f- // Body / screenshot / achievements. The CTA band starts ~500px up- // from the bottom, so content above it must stop before that. A- // provided screenshot wins over everything else — the user opted- // into embedding it, so it must never be silently dropped.+ // Body / achievements. The CTA band starts ~500px up from the+ // bottom, so content above it must stop before that.val ctaBandTop = HEIGHT_PX - 500f - CTA_PILL_H - 120fwhen {- screenshot != null -> {- val sw = 460f- val sh = 345f- val left = (WIDTH_PX - sw) / 2f- canvas.drawRoundRect(- RectF(left - 12f, y - 12f, left + sw + 12f, y + sh + 12f),- 40f,- 40f,- Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.argb(120, 255, 255, 255) }- )- canvas.save()- canvas.clipPath(- android.graphics.Path().apply {- addRoundRect(- RectF(left, y, left + sw, y + sh),- 28f,- 28f,- android.graphics.Path.Direction.CW- )- }- )- canvas.drawBitmap(screenshot, null, RectF(left, y, left + sw, y + sh), Paint(Paint.ANTI_ALIAS_FLAG))- canvas.restore()- y += sh + 40f- }content.template == "recap" && content.achievements.isNotEmpty() -> {y = drawAchievements(canvas, content.achievements, y, ctaBandTop)y += 46fdiff --git a/app/src/main/java/com/gotcha/ui/SharePosterSheet.kt b/app/src/main/java/com/gotcha/ui/SharePosterSheet.ktindex f8daaed..ba238ff 100644--- a/app/src/main/java/com/gotcha/ui/SharePosterSheet.kt+++ b/app/src/main/java/com/gotcha/ui/SharePosterSheet.kt@@ -15,14 +15,9 @@ import androidx.compose.foundation.verticalScrollimport androidx.compose.material3.Buttonimport androidx.compose.material3.CircularProgressIndicatorimport androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Switchimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.asImageBitmap@@ -35,7 +30,7 @@ import com.gotcha.ui.theme.SkinAlertDialog/*** Share flow for the "Share your Gotcha moment" feature.*- * Phase 1 (config): an include-screenshot toggle + Generate button.+ * Phase 1 (config): a Generate button.* Phase 2 (preview): the rendered poster bitmap with Share / Save / Regenerate.** [runs] are the raw run summaries this card is built from; the caller supplies@@ -47,15 +42,12 @@ fun SharePosterSheet(loading: Boolean,preview: Bitmap?,error: String?,- hasImage: Boolean,- onGenerate: (includeScreenshot: Boolean) -> Unit,+ onGenerate: () -> Unit,onShare: () -> Unit,onSave: () -> Unit,- onRegenerate: (includeScreenshot: Boolean) -> Unit,+ onRegenerate: () -> Unit,onDismiss: () -> Unit) {- var includeScreenshot by remember { mutableStateOf(false) }-SkinAlertDialog(onDismissRequest = { if (!loading) onDismiss() },title = {@@ -75,24 +67,6 @@ fun SharePosterSheet(style = MaterialTheme.typography.bodyMedium)- // The screenshot toggle only makes sense when the chat history- // actually holds an image the poster can embed; hide it otherwise- // (e.g. the image was culled from the session).- if (hasImage) {- Row(- modifier = Modifier.fillMaxWidth(),- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.SpaceBetween- ) {- Text("Include a screenshot", style = MaterialTheme.typography.bodyMedium)- Switch(- checked = includeScreenshot,- onCheckedChange = { includeScreenshot = it },- enabled = !loading- )- }- }-when {loading -> Box(modifier = Modifier@@ -138,7 +112,7 @@ fun SharePosterSheet(}}TextButton(- onClick = { onRegenerate(includeScreenshot) },+ onClick = onRegenerate,modifier = Modifier.align(Alignment.CenterHorizontally),enabled = !loading) {@@ -154,7 +128,7 @@ fun SharePosterSheet()}Button(- onClick = { onGenerate(includeScreenshot) },+ onClick = onGenerate,modifier = Modifier.align(Alignment.CenterHorizontally)) {Text("Generate poster")diff --git a/app/src/main/java/com/gotcha/ui/SharePosterState.kt b/app/src/main/java/com/gotcha/ui/SharePosterState.ktindex c9ed133..c8ce151 100644--- a/app/src/main/java/com/gotcha/ui/SharePosterState.kt+++ b/app/src/main/java/com/gotcha/ui/SharePosterState.kt@@ -49,13 +49,13 @@ class SharePosterState(}/** Generates the poster (one LLM call + render) for the sheet's [runs]. */- fun generate(includeScreenshot: Boolean) {+ fun generate() {val runs = this.runs ?: returnloading = truepreview = nullerror = nullviewModel.viewModelScope.launch {- val result = viewModel.generateShareCard(runs, includeScreenshot)+ val result = viewModel.generateShareCard(runs)loading = falseresult.fold(onSuccess = { preview = it },diff --git a/app/src/test/java/com/gotcha/agent/ChatViewModelShareScreenshotTest.kt b/app/src/test/java/com/gotcha/agent/ChatViewModelShareScreenshotTest.ktdeleted file mode 100644index d64c4ae..0000000--- a/app/src/test/java/com/gotcha/agent/ChatViewModelShareScreenshotTest.kt+++ /dev/null@@ -1,79 +0,0 @@-package com.gotcha.agent--import android.app.Application-import androidx.test.core.app.ApplicationProvider-import com.gotcha.data.ChatHistoryRepository-import com.gotcha.data.Settings-import com.gotcha.data.SettingsRepository-import com.gotcha.llm.ChatMessage-import com.gotcha.llm.visionUserMessage-import com.gotcha.testsupport.FakeAndroidKeyStore-import kotlinx.serialization.json.JsonPrimitive-import org.junit.Assert.assertFalse-import org.junit.Assert.assertTrue-import org.junit.Before-import org.junit.Test-import org.junit.runner.RunWith-import org.robolectric.RobolectricTestRunner-import org.robolectric.annotation.Config-import org.robolectric.shadows.ShadowLooper--/**- * The poster sheet's "Include a screenshot" toggle must track the chat history:- * present while a vision message is in the session, gone once it is removed.- */-@RunWith(RobolectricTestRunner::class)-@Config(sdk = [34])-class ChatViewModelShareScreenshotTest {-- private val application: Application = ApplicationProvider.getApplicationContext()- private lateinit var settingsRepository: SettingsRepository-- // The repository is constructed only to satisfy ChatViewModel's constructor;- // the tests below reach the engine history directly via reflection and never- // open a session, so no per-session cleanup is needed.- private lateinit var historyRepository: ChatHistoryRepository- private lateinit var viewModel: ChatViewModel-- @Before- fun setUp() {- FakeAndroidKeyStore.setUp()- settingsRepository = SettingsRepository(application)- historyRepository = ChatHistoryRepository(application, "share-screenshot-test-chats")- settingsRepository.save(Settings(apiKey = "test-key"))- viewModel = ChatViewModel(application)- ShadowLooper.idleMainLooper()- }-- private fun engineHistory(): MutableList<ChatMessage> {- val engineField = ChatViewModel::class.java.getDeclaredField("agentEngine")- .apply { isAccessible = true }- @Suppress("UNCHECKED_CAST")- return (engineField.get(viewModel) as AgentEngine).history- }-- @Test- fun `hasImage is false on an empty or text-only history`() {- assertFalse(viewModel.activeSessionHasImage())-- engineHistory() += ChatMessage(role = "user", content = JsonPrimitive("hello"))- assertFalse(viewModel.activeSessionHasImage())- }-- @Test- fun `hasImage is true once a vision message lands in history`() {- engineHistory() += visionUserMessage("what is this", "QUJD", imageFormat = "jpeg")- assertTrue(viewModel.activeSessionHasImage())- }-- @Test- fun `hasImage flips back to false when the image is culled from history`() {- val history = engineHistory()- history += visionUserMessage("what is this", "QUJD", imageFormat = "jpeg")- assertTrue(viewModel.activeSessionHasImage())-- // Simulate the image being retracted / culled from the session.- history.removeAll { it.hasImage }- assertFalse(viewModel.activeSessionHasImage())- }-}