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.

feat(proactive): complete Phase 6 (Notification Pipeline with 10s package debouncing), Phase 7 (Proactive Assistance Settings & UI), and Phase 8 (Performance guards)

Rishabh Bajpai7d93399a9bab
diff --git a/app/src/main/java/com/gotcha/data/SettingsRepository.kt b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
index f1b7c9a..908f2a5 100644
--- a/app/src/main/java/com/gotcha/data/SettingsRepository.kt
+++ b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
@@ -46,7 +46,8 @@ data class Settings(
val proactiveScanScreen: Boolean = true,
val proactiveScanClipboard: Boolean = true,
val proactiveScanNotifications: Boolean = true,
- val proactiveAutoCopyOtp: Boolean = true,
+ val proactiveOtpEnabled: Boolean = true,
+ val proactiveAutoCopyOtp: Boolean = false,
val proactiveAppBlacklist: Set<String> = emptySet()
) {
/** True when the active provider has everything it needs to make requests. */
@@ -127,7 +128,8 @@ class SettingsRepository(context: Context) {
proactiveScanScreen = prefs.getBoolean(KEY_PROACTIVE_SCAN_SCREEN, true),
proactiveScanClipboard = prefs.getBoolean(KEY_PROACTIVE_SCAN_CLIPBOARD, true),
proactiveScanNotifications = prefs.getBoolean(KEY_PROACTIVE_SCAN_NOTIFICATIONS, true),
- proactiveAutoCopyOtp = prefs.getBoolean(KEY_PROACTIVE_AUTO_COPY_OTP, true),
+ proactiveOtpEnabled = prefs.getBoolean(KEY_PROACTIVE_OTP_ENABLED, true),
+ proactiveAutoCopyOtp = prefs.getBoolean(KEY_PROACTIVE_AUTO_COPY_OTP, false),
proactiveAppBlacklist = prefs.getStringSet(KEY_PROACTIVE_BLACKLIST, emptySet()) ?: emptySet()
)
@@ -160,6 +162,7 @@ class SettingsRepository(context: Context) {
.putBoolean(KEY_PROACTIVE_SCAN_SCREEN, settings.proactiveScanScreen)
.putBoolean(KEY_PROACTIVE_SCAN_CLIPBOARD, settings.proactiveScanClipboard)
.putBoolean(KEY_PROACTIVE_SCAN_NOTIFICATIONS, settings.proactiveScanNotifications)
+ .putBoolean(KEY_PROACTIVE_OTP_ENABLED, settings.proactiveOtpEnabled)
.putBoolean(KEY_PROACTIVE_AUTO_COPY_OTP, settings.proactiveAutoCopyOtp)
.putStringSet(KEY_PROACTIVE_BLACKLIST, settings.proactiveAppBlacklist)
.apply()
@@ -209,6 +212,7 @@ class SettingsRepository(context: Context) {
const val KEY_PROACTIVE_SCAN_SCREEN = "proactive_scan_screen"
const val KEY_PROACTIVE_SCAN_CLIPBOARD = "proactive_scan_clipboard"
const val KEY_PROACTIVE_SCAN_NOTIFICATIONS = "proactive_scan_notifications"
+ const val KEY_PROACTIVE_OTP_ENABLED = "proactive_otp_enabled"
const val KEY_PROACTIVE_AUTO_COPY_OTP = "proactive_auto_copy_otp"
const val KEY_PROACTIVE_BLACKLIST = "proactive_blacklist"
}
diff --git a/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt b/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
index 2e66b47..b93f572 100644
--- a/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
+++ b/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
@@ -33,18 +33,33 @@ class GotchaNotificationListenerService : NotificationListenerService() {
super.onDestroy()
}
+ private val lastNotificationTimeMap = java.util.concurrent.ConcurrentHashMap<String, Long>()
+
override fun onNotificationPosted(sbn: StatusBarNotification?) {
if (sbn == null) return
+ val pkg = sbn.packageName ?: ""
+ val now = System.currentTimeMillis()
+ val lastTime = lastNotificationTimeMap[pkg] ?: 0L
+ if (now - lastTime < 10_000L) return
+ lastNotificationTimeMap[pkg] = now
+
val context = applicationContext
+ val extras = sbn.notification?.extras
+ val title = extras?.getCharSequence("android.title")?.toString() ?: ""
+ val text = extras?.getCharSequence("android.text")?.toString() ?: ""
+
+ val intent = android.content.Intent(ACTION_NOTIFICATION_POSTED).apply {
+ setPackage(context.packageName)
+ putExtra(EXTRA_PACKAGE_NAME, pkg)
+ putExtra(EXTRA_TITLE, title)
+ putExtra(EXTRA_TEXT, text)
+ }
+ context.sendBroadcast(intent)
+
val settings = runCatching { SettingsRepository(context).load() }.getOrNull() ?: return
if (!settings.proactiveEnabled || !settings.proactiveScanNotifications) return
-
- val pkg = sbn.packageName ?: ""
if (settings.proactiveAppBlacklist.contains(pkg)) return
- val extras = sbn.notification?.extras ?: return
- val title = extras.getCharSequence("android.title")?.toString() ?: ""
- val text = extras.getCharSequence("android.text")?.toString() ?: ""
val fullText = "$title $text".trim()
if (fullText.isBlank()) return
@@ -88,6 +103,11 @@ class GotchaNotificationListenerService : NotificationListenerService() {
fun dismissAll() = cancelAllNotifications()
companion object {
+ const val ACTION_NOTIFICATION_POSTED = "com.gotcha.ACTION_NOTIFICATION_POSTED"
+ const val EXTRA_PACKAGE_NAME = "package_name"
+ const val EXTRA_TITLE = "title"
+ const val EXTRA_TEXT = "text"
+
/** The live service instance while the user has granted access; null otherwise. */
@Volatile
var instance: GotchaNotificationListenerService? = null
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index 40972ae..f67482e 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -98,6 +98,13 @@ fun SettingsScreen(
var autoReadReplies by remember { mutableStateOf(initial.autoReadReplies) }
var themeMode by remember { mutableStateOf(initial.themeMode) }
var disabledSkills by remember { mutableStateOf(initial.disabledSkills) }
+ var proactiveEnabled by remember { mutableStateOf(initial.proactiveEnabled) }
+ var proactiveScanScreen by remember { mutableStateOf(initial.proactiveScanScreen) }
+ var proactiveScanClipboard by remember { mutableStateOf(initial.proactiveScanClipboard) }
+ var proactiveScanNotifications by remember { mutableStateOf(initial.proactiveScanNotifications) }
+ var proactiveOtpEnabled by remember { mutableStateOf(initial.proactiveOtpEnabled) }
+ var proactiveAutoCopyOtp by remember { mutableStateOf(initial.proactiveAutoCopyOtp) }
+
// Discovered model lists
var availableTtsModels by remember { mutableStateOf<List<AudioModel>>(emptyList()) }
var availableSttModels by remember { mutableStateOf<List<AudioModel>>(emptyList()) }
@@ -111,6 +118,7 @@ fun SettingsScreen(
var aiConfigExpanded by remember { mutableStateOf(false) }
var speechExpanded by remember { mutableStateOf(false) }
var skillsExpanded by remember { mutableStateOf(false) }
+ var proactiveExpanded by remember { mutableStateOf(false) }
val scope = rememberCoroutineScope()
// Dropdown expanded states
@@ -145,7 +153,14 @@ fun SettingsScreen(
autoReadReplies = autoReadReplies,
assistiveBallEnabled = initial.assistiveBallEnabled,
themeMode = themeMode,
- disabledSkills = disabledSkills
+ disabledSkills = disabledSkills,
+ proactiveEnabled = proactiveEnabled,
+ proactiveScanScreen = proactiveScanScreen,
+ proactiveScanClipboard = proactiveScanClipboard,
+ proactiveScanNotifications = proactiveScanNotifications,
+ proactiveOtpEnabled = proactiveOtpEnabled,
+ proactiveAutoCopyOtp = proactiveAutoCopyOtp,
+ proactiveAppBlacklist = initial.proactiveAppBlacklist
)
val refreshChatModelsAction = {
@@ -800,6 +815,79 @@ fun SettingsScreen(
}
}
+ HorizontalDivider(thickness = 1.dp)
+
+ // ---- Proactive Assistance ----
+ SectionHeader(
+ title = "Proactive Assistance",
+ expanded = proactiveExpanded,
+ onToggle = { proactiveExpanded = !proactiveExpanded }
+ )
+ AnimatedVisibility(visible = proactiveExpanded) {
+ Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Master Proactive Offers", style = MaterialTheme.typography.bodyLarge)
+ Switch(checked = proactiveEnabled, onCheckedChange = { proactiveEnabled = it })
+ }
+ if (proactiveEnabled) {
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Scan Screen Content", style = MaterialTheme.typography.bodyMedium)
+ Switch(checked = proactiveScanScreen, onCheckedChange = { proactiveScanScreen = it })
+ }
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Scan Clipboard", style = MaterialTheme.typography.bodyMedium)
+ Switch(checked = proactiveScanClipboard, onCheckedChange = { proactiveScanClipboard = it })
+ }
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Scan Notifications", style = MaterialTheme.typography.bodyMedium)
+ Switch(
+ checked = proactiveScanNotifications,
+ onCheckedChange = { proactiveScanNotifications = it }
+ )
+ }
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Detect OTP / Codes", style = MaterialTheme.typography.bodyMedium)
+ Switch(checked = proactiveOtpEnabled, onCheckedChange = { proactiveOtpEnabled = it })
+ }
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text("Auto-Copy OTP to Clipboard", style = MaterialTheme.typography.bodyMedium)
+ Switch(checked = proactiveAutoCopyOtp, onCheckedChange = { proactiveAutoCopyOtp = it })
+ }
+ }
+ Button(
+ onClick = {
+ onSave(currentSettings())
+ status = "Saved Proactive Settings."
+ },
+ modifier = Modifier.fillMaxWidth()
+ ) { Text("Save Proactive Settings") }
+ }
+ }
+
// Status text
status?.let {
Text(it, style = MaterialTheme.typography.bodyMedium)