Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Requests: choose the vibration and whether the screen wakes (each vibration has its own channel)

Claudee9c83a067613
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
index cb2c7b8b..af62022b 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
@@ -141,6 +141,7 @@ class AppModel(private val context: Context) : LinkListener {
settings = next
UserSettings.save(kv, next)
applySound()
+ notifier.applyApprovalSettings(settings.vibration, settings.keepScreenOff)
// Switching the relay on or off rebuilds the connection with the right routes.
if (relayChanged) currentPairing?.let { restartLink(it) }
}
@@ -150,7 +151,10 @@ class AppModel(private val context: Context) : LinkListener {
sounds.volume = settings.volume
}
- init { applySound() }
+ init {
+ applySound()
+ notifier.applyApprovalSettings(settings.vibration, settings.keepScreenOff)
+ }
/** What the computer says Mochi wears ("auto" or an outfit); the last one it told, kept for when it is away. */
var computerOutfit by mutableStateOf(com.coucou.android.mochi.outfit.Wardrobe.parse(kv.getString("computer_outfit", "")))
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt b/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
index beb65871..91e1313f 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
@@ -13,6 +13,7 @@ import android.net.Uri
import android.util.Log
import com.coucou.android.MainActivity
import com.coucou.android.R
+import com.coucou.android.core.ApprovalChannels
import com.coucou.android.core.ApprovalSheetPlan
import com.coucou.android.core.Glance
import com.coucou.android.core.GlanceTone
@@ -20,6 +21,7 @@ import com.coucou.android.core.OverlayPolicy
import com.coucou.android.core.OngoingGate
import com.coucou.android.core.SafeText
import com.coucou.android.core.ToolLabels
+import com.coucou.android.core.VibrationChoice
import com.coucou.android.link.ApprovalRequest
import com.coucou.android.mochi.BotState
@@ -54,13 +56,34 @@ class Notifications(private val context: Context) {
setShowBadge(false)
},
)
+ // The approvals channel is made by applyApprovalSettings (its id depends on the vibration choice).
+ }
+
+ private var vibration = VibrationChoice.STANDARD
+ private var keepScreenOff = false
+ private var channelFor: VibrationChoice? = null
+
+ /**
+ * The two Settings choices about a request: how it buzzes and whether it lights the screen. A channel's vibration cannot change
+ * after it exists, so a new choice means a new channel id and the old channel is deleted. The channel stays IMPORTANCE_HIGH with
+ * Mochi's sound whatever is chosen: a request is never muted or hidden.
+ */
+ fun applyApprovalSettings(v: VibrationChoice, screenOff: Boolean) {
+ keepScreenOff = screenOff
+ if (channelFor == v) return // the channel exists already: nothing to rebuild when another setting moves
+ channelFor = v
+ vibration = v
+ ApprovalChannels.othersThan(v).forEach { nm.deleteNotificationChannel(it) }
nm.createNotificationChannel(
- NotificationChannel(CH_APPROVAL, "Approvals", NotificationManager.IMPORTANCE_HIGH).apply {
+ NotificationChannel(ApprovalChannels.id(v), "Approvals", NotificationManager.IMPORTANCE_HIGH).apply {
description = "An agent is waiting for your permission"
- // A short buzz, so a request is felt even when the notification volume is 0 (a channel cannot change
- // later, which is why this one has a new id).
- enableVibration(true)
- vibrationPattern = longArrayOf(0, 500, 150, 500)
+ val pattern = v.pattern
+ if (pattern != null) {
+ enableVibration(true)
+ vibrationPattern = pattern
+ } else {
+ enableVibration(false)
+ }
// Mochi's own approval sound, bundled in res/raw.
setSound(
Uri.parse("${ContentResolver.SCHEME_ANDROID_RESOURCE}://${context.packageName}/${R.raw.approval}"),
@@ -123,7 +146,7 @@ class Notifications(private val context: Context) {
}
fun showApproval(r: ApprovalRequest, agentName: String, alert: OverlayPolicy.ApprovalAlert = OverlayPolicy.ApprovalAlert.HEADS_UP) {
- val channel = if (alert == OverlayPolicy.ApprovalAlert.QUIET) CH_APPROVAL_QUIET else CH_APPROVAL
+ val channel = if (alert == OverlayPolicy.ApprovalAlert.QUIET) CH_APPROVAL_QUIET else ApprovalChannels.id(vibration)
Log.d("CoucouOverlay", "approval notification: $alert")
val id = idFor(r.fingerprint)
val deny = PendingIntent.getBroadcast(
@@ -151,7 +174,7 @@ class Notifications(private val context: Context) {
}
.build()
runCatching { nm.notify(id, n) } // POST_NOTIFICATIONS may be denied: the in-app card still works
- if (alert == OverlayPolicy.ApprovalAlert.HEADS_UP) wakeScreen()
+ if (alert == OverlayPolicy.ApprovalAlert.HEADS_UP && !keepScreenOff) wakeScreen()
}
/**
@@ -218,7 +241,6 @@ class Notifications(private val context: Context) {
companion object {
const val CH_LINK = "link"
private const val WAKE_MS = 6_000L
- const val CH_APPROVAL = "approvals_v3"
const val CH_APPROVAL_QUIET = "approvals_quiet"
const val CH_UPDATES = "updates"
private const val STATUS_TAG = "status"
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/ApprovalAlerts.kt b/android/app/src/main/kotlin/com/coucou/android/core/ApprovalAlerts.kt
new file mode 100644
index 00000000..7265c526
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/core/ApprovalAlerts.kt
@@ -0,0 +1,32 @@
+package com.coucou.android.core
+
+/**
+ * How a request for permission buzzes the phone. The approval is never muted or hidden by any of these choices: it is always a
+ * heads-up notification with Mochi's sound; only the buzz changes (and the Settings choice "Don't wake the screen" only stops the
+ * screen from lighting up, the notification is still posted).
+ */
+enum class VibrationChoice(val key: String, val pattern: LongArray?) {
+ /** Today's pattern: two half-second buzzes. */
+ STANDARD("standard", longArrayOf(0, 500, 150, 500)),
+ SHORT("short", longArrayOf(0, 200)),
+ OFF("off", null);
+
+ companion object {
+ /** An unknown or missing key is today's behaviour. */
+ fun parse(key: String?): VibrationChoice = values().firstOrNull { it.key == key } ?: STANDARD
+ }
+}
+
+/**
+ * The notification channel of approvals. Android never lets an app change the vibration of a channel after it exists, so each choice
+ * has its own id; only the chosen one exists at a time (the others are deleted), so Android's own settings show a single "Approvals".
+ * The standard id is the one the app has always used, so a user who changed that channel in Android's settings keeps the changes.
+ */
+object ApprovalChannels {
+ const val STANDARD_ID = "approvals_v3"
+
+ fun id(v: VibrationChoice): String = if (v == VibrationChoice.STANDARD) STANDARD_ID else "${STANDARD_ID}_${v.key}"
+
+ /** The ids to delete when [v] is chosen. */
+ fun othersThan(v: VibrationChoice): List<String> = VibrationChoice.values().filter { it != v }.map { id(it) }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt b/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt
index bea3e393..6efe4fb9 100644
--- a/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt
@@ -38,6 +38,10 @@ data class UserSettings(
val outfit: String = com.coucou.android.mochi.outfit.Wardrobe.FOLLOW,
/** Use the relay when the computer is not reachable on this network (only matters when the pairing includes one). */
val useRelay: Boolean = true,
+ /** Do not light the screen when a request arrives on a sleeping phone (the notification is still posted). Off = today's behaviour. */
+ val keepScreenOff: Boolean = false,
+ /** How a request buzzes the phone; the standard pattern is today's. */
+ val vibration: VibrationChoice = VibrationChoice.STANDARD,
) {
companion object {
private const val SOUND = "sound_on"
@@ -48,6 +52,8 @@ data class UserSettings(
private const val Q_TO = "quiet_to"
private const val OUTFIT = "outfit_choice"
private const val RELAY = "use_relay"
+ private const val NO_WAKE = "no_wake_screen"
+ private const val VIBRATION = "vibration_choice"
fun load(store: KeyValueStore): UserSettings {
val d = UserSettings()
@@ -62,6 +68,8 @@ data class UserSettings(
),
outfit = com.coucou.android.mochi.outfit.Wardrobe.parseLocal(store.getString(OUTFIT, d.outfit)),
useRelay = store.getBoolean(RELAY, d.useRelay),
+ keepScreenOff = store.getBoolean(NO_WAKE, d.keepScreenOff),
+ vibration = VibrationChoice.parse(store.getString(VIBRATION, d.vibration.key)),
)
}
@@ -74,6 +82,8 @@ data class UserSettings(
store.put(Q_TO, QuietHours.wrap(s.quiet.toMin))
store.put(OUTFIT, com.coucou.android.mochi.outfit.Wardrobe.parseLocal(s.outfit))
store.put(RELAY, s.useRelay)
+ store.put(NO_WAKE, s.keepScreenOff)
+ store.put(VIBRATION, s.vibration.key)
}
}
}
diff --git a/android/app/src/test/kotlin/com/coucou/android/ApprovalAlertsTest.kt b/android/app/src/test/kotlin/com/coucou/android/ApprovalAlertsTest.kt
new file mode 100644
index 00000000..4de627d4
--- /dev/null
+++ b/android/app/src/test/kotlin/com/coucou/android/ApprovalAlertsTest.kt
@@ -0,0 +1,79 @@
+package com.coucou.android
+
+import com.coucou.android.core.ApprovalChannels
+import com.coucou.android.core.KeyValueStore
+import com.coucou.android.core.UserSettings
+import com.coucou.android.core.VibrationChoice
+import java.io.File
+import org.junit.Assert.assertArrayEquals
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class ApprovalAlertsTest {
+ private class MapStore : KeyValueStore {
+ val m = HashMap<String, Any>()
+ override fun getBoolean(key: String, default: Boolean) = m[key] as? Boolean ?: default
+ override fun getInt(key: String, default: Int) = m[key] as? Int ?: default
+ override fun getFloat(key: String, default: Float) = m[key] as? Float ?: default
+ override fun getString(key: String, default: String) = m[key] as? String ?: default
+ override fun put(key: String, value: Any) { m[key] = value }
+ }
+
+ @Test fun theDefaultsAreTodaysBehaviour() {
+ val d = UserSettings()
+ assertFalse("the screen wakes as before", d.keepScreenOff)
+ assertEquals(VibrationChoice.STANDARD, d.vibration)
+ assertArrayEquals("the pattern is the one the app always had", longArrayOf(0, 500, 150, 500), VibrationChoice.STANDARD.pattern)
+ assertEquals(d, UserSettings.load(MapStore()))
+ }
+
+ @Test fun theChoicesAreSavedAndRead() {
+ val store = MapStore()
+ UserSettings.save(store, UserSettings(keepScreenOff = true, vibration = VibrationChoice.SHORT))
+ val back = UserSettings.load(store)
+ assertTrue(back.keepScreenOff)
+ assertEquals(VibrationChoice.SHORT, back.vibration)
+ assertArrayEquals(longArrayOf(0, 200), back.vibration.pattern)
+ UserSettings.save(store, back.copy(vibration = VibrationChoice.OFF))
+ assertNull(UserSettings.load(store).vibration.pattern)
+ }
+
+ @Test fun anUnknownVibrationKeyIsTheStandardOne() {
+ assertEquals(VibrationChoice.STANDARD, VibrationChoice.parse(null))
+ assertEquals(VibrationChoice.STANDARD, VibrationChoice.parse("strong"))
+ for (v in VibrationChoice.values()) assertEquals(v, VibrationChoice.parse(v.key))
+ }
+
+ @Test fun eachChoiceHasItsOwnChannelAndTheOldOnesGoAway() {
+ // A channel's vibration cannot change after it exists: a new id per choice, and only the chosen one is kept.
+ assertEquals("the id the app has always used", "approvals_v3", ApprovalChannels.id(VibrationChoice.STANDARD))
+ val ids = VibrationChoice.values().map { ApprovalChannels.id(it) }
+ assertEquals(ids.size, ids.toSet().size)
+ for (v in VibrationChoice.values()) {
+ val gone = ApprovalChannels.othersThan(v)
+ assertFalse(ApprovalChannels.id(v) in gone)
+ assertEquals(VibrationChoice.values().size - 1, gone.size)
+ }
+ }
+
+ @Test fun aRequestIsNeverMutedByTheseChoices() {
+ val src = File("src/main/kotlin/com/coucou/android/app/Notifications.kt").readText()
+ // The channel is always high importance with Mochi's sound; the choices only touch vibration and the wake.
+ val block = src.substringAfter("fun applyApprovalSettings").substringBefore("private fun open(")
+ assertTrue(block.contains("IMPORTANCE_HIGH"))
+ assertTrue(block.contains("R.raw.approval"))
+ assertFalse(block.contains("IMPORTANCE_LOW") || block.contains("IMPORTANCE_NONE") || block.contains("IMPORTANCE_MIN"))
+ assertTrue(src.contains("!keepScreenOff) wakeScreen()"))
+ // The notification is posted whatever the choices are.
+ assertTrue(src.contains("runCatching { nm.notify(id, n) }"))
+ }
+
+ @Test fun settingsShowBothChoices() {
+ val ui = File("src/main/kotlin/com/coucou/android/ui/SettingsScreens.kt").readText()
+ assertTrue(ui.contains("R.string.settings_no_wake") && ui.contains("R.string.settings_vibration"))
+ assertTrue(ui.contains("VibrationChoice.SHORT") && ui.contains("VibrationChoice.OFF"))
+ }
+}