Wake word: what it tried and how it went is kept and shown; the screen comes on
CI / check (push) Canceled after 0s

The phrase was heard, LLeMbas was the assistant, and still only "Heard you.
Tap to ask." came: wake() reached the notification when the assistant
service was not connected or showSession threw, and kept neither reason.

- WakeAttempt: when, the phrase, the way tried (wakeWay: session, the
  sheet's activity through the assistant service when the screen is off,
  the activity while the app is on screen, a notification), the outcome
  (opened / not connected / refused with the exception / no sheet came),
  the fallback, whether the role was held, and when Android last connected
  and disconnected the service in this process. The last five live in the
  settings, are logged under LLeMbasWake, and are shown as "Last wake".
  An attempt that found the service not connected is told when a later
  onReady arrives.
- "Opened" is counted only once a sheet says it is up (AssistLink.shown,
  2.5 s); otherwise the fallback follows.
- Settings says when LLeMbas holds the role but the service is not
  connected, with the way to the system's assistant setting.
- The sheet opened by the wake word turns the screen on: setTurnScreenOn on
  the activity; with the screen off and the service connected the activity
  is started through the service instead of a session, whose window wakes
  nothing.
- The fallback notification says "Could not open by itself -- tap to ask"
  when LLeMbas is the assistant.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 10:30:02 +00:00
1 parent 613eba4154
commit 80ba7f70b9
23 files changed
+818 -50

No files matched your search

@@ -3,10 +3,12 @@ package eu.llembas.android
import android.app.Application
import android.app.Notification
import android.app.NotificationManager
import eu.llembas.android.wake.WakeAttempt
import eu.llembas.android.wake.WakeFailure
import eu.llembas.android.wake.WakePause
import eu.llembas.android.wake.WakeState
import eu.llembas.android.wake.WakeWordService
import eu.llembas.android.wake.wakeAttemptWords
import eu.llembas.android.wake.wakeHeardNotification
import eu.llembas.android.wake.wakeNotification
import eu.llembas.android.wake.wakeTitle
@@ -19,6 +21,8 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.time.ZoneOffset
import java.util.Locale
/**
* What the wake word's notification says, from its state alone: the phrase only while it really
@@ -95,4 +99,70 @@ class WakeNotificationTest {
assertEquals(Notification.FLAG_AUTO_CANCEL, heard.flags and Notification.FLAG_AUTO_CANCEL)
assertNotNull(heard.contentIntent)
}
@Test
fun theFallbackSaysWhyInFixedWords() {
fun line(assistant: Boolean) = wakeHeardNotification(app, assistant).extras.getCharSequence(Notification.EXTRA_TEXT).toString()
// The assistant, and still it could not open by itself this time.
assertEquals("Could not open by itself — tap to ask", line(assistant = true))
// Not the assistant: that is the reason.
assertEquals("LLeMbas can open by itself over other apps only as the phone's digital assistant app.", line(assistant = false))
}
@Test
fun theLastWakeInPlainWords() {
val zone = ZoneOffset.UTC
val at = 1_773_129_600_000 // Tue 10 Mar 2026, 08:00:00 UTC
fun words(attempt: WakeAttempt) = wakeAttemptWords(app, attempt, zone, Locale.ENGLISH)
assertEquals(
listOf("Tue 10 Mar, 08:00:00 · “Hey Assistant”", "Opened the assistant."),
words(WakeAttempt(at = at, phrase = "Hey Assistant", way = "session", outcome = WakeAttempt.OUT_OPENED, assistant = true, readyAt = at - 60_000)),
)
// The assistant in name, never connected in this run of the app: said step by step.
assertEquals(
listOf(
"Tue 10 Mar, 08:00:00 · “Hey Assistant”",
"Android had not connected LLeMbas as the assistant, so it could not open the sheet.",
"Posted a notification to tap instead.",
"LLeMbas was the digital assistant app.",
"Android had not connected the assistant since the app started.",
"Android connected it again at Tue 10 Mar, 08:00:30.",
),
words(
WakeAttempt(
at = at,
phrase = "Hey Assistant",
way = "notification",
outcome = WakeAttempt.OUT_NOT_CONNECTED,
fallback = "notification",
assistant = true,
connectedLater =
at + 30_000,
),
),
)
// Android's own words where it refused, and when it had connected and dropped the service.
val refused = words(
WakeAttempt(
at = at,
phrase = "OK Computer",
way = "session",
outcome = WakeAttempt.OUT_REFUSED,
detail = "SecurityException: not the current voice interaction service",
fallback = "activity",
readyAt = at - 3_600_000,
shutdownAt = at - 60_000,
),
)
assertEquals("Android refused to open the assistant: SecurityException: not the current voice interaction service", refused[1])
assertEquals("Opened it as a screen of the app instead.", refused[2])
assertEquals("LLeMbas was not the digital assistant app.", refused[3])
assertEquals("Android had connected the assistant at Tue 10 Mar, 07:00:00.", refused[4])
assertEquals("Android had disconnected it at Tue 10 Mar, 07:59:00.", refused[5])
assertEquals("Heard in a test: nothing was to open.", words(WakeAttempt(at = at, phrase = "Hey Assistant", outcome = WakeAttempt.OUT_TESTED))[1])
assertEquals(
"Asked Android to open the assistant; it did not refuse, but no sheet came.",
words(WakeAttempt(at = at, phrase = "Hey Assistant", way = "session", outcome = WakeAttempt.OUT_NO_SHEET, fallback = "notification"))[1],
)
}
}
@@ -3,23 +3,28 @@ package eu.llembas.android
import eu.llembas.android.api.LembasJson
import eu.llembas.android.auth.Prefs
import eu.llembas.android.wake.AppVisibility
import eu.llembas.android.wake.AssistLink
import eu.llembas.android.wake.AssistPresence
import eu.llembas.android.wake.WakeAttempt
import eu.llembas.android.wake.WakeError
import eu.llembas.android.wake.WakeFailure
import eu.llembas.android.wake.WakeOpening
import eu.llembas.android.wake.WakePause
import eu.llembas.android.wake.WakePhrases
import eu.llembas.android.wake.WakeSensitivity
import eu.llembas.android.wake.WakeState
import eu.llembas.android.wake.WakeStatus
import eu.llembas.android.wake.WakeWay
import eu.llembas.android.wake.WakeWords
import eu.llembas.android.wake.checkKeywords
import eu.llembas.android.wake.unpackWakeModel
import eu.llembas.android.wake.wakeBackoff
import eu.llembas.android.wake.wakeFallback
import eu.llembas.android.wake.wakeKeywords
import eu.llembas.android.wake.wakeOpening
import eu.llembas.android.wake.wakeLogAdd
import eu.llembas.android.wake.wakeLogConnected
import eu.llembas.android.wake.wakePause
import eu.llembas.android.wake.wakeStateAtStart
import eu.llembas.android.wake.wakeWay
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
@@ -160,13 +165,18 @@ class WakeTest {
@Test
fun theAssistantIsOpenedOnlyTheWayAndroidAllows() {
// The phone's assistant: its own service shows the sheet, on screen or not.
assertEquals(WakeOpening.Session, wakeOpening(isAssistant = true, appVisible = false))
assertEquals(WakeOpening.Session, wakeOpening(isAssistant = true, appVisible = true))
// Not the assistant, but on screen: the sheet's activity may start.
assertEquals(WakeOpening.Activity, wakeOpening(isAssistant = false, appVisible = true))
// Neither: an activity start is blocked without a word, so the notification is what is relied on.
assertEquals(WakeOpening.Notification, wakeOpening(isAssistant = false, appVisible = false))
// The assistant service connected and the screen on: it shows its sheet, on screen or not.
assertEquals(WakeWay.Session, wakeWay(connected = true, screenOn = true, appVisible = false))
assertEquals(WakeWay.Session, wakeWay(connected = true, screenOn = true, appVisible = true))
// Connected, the screen off: the sheet's activity through the service, which turns the screen on.
assertEquals(WakeWay.AssistantActivity, wakeWay(connected = true, screenOn = false, appVisible = false))
// Not connected -- whether or not LLeMbas is the assistant in name: only what the app itself may do.
assertEquals(WakeWay.Activity, wakeWay(connected = false, screenOn = true, appVisible = true))
assertEquals(WakeWay.Notification, wakeWay(connected = false, screenOn = true, appVisible = false))
assertEquals(WakeWay.Notification, wakeWay(connected = false, screenOn = false, appVisible = false))
// And when the assistant's own way did not open the sheet.
assertEquals(WakeWay.Activity, wakeFallback(appVisible = true))
assertEquals(WakeWay.Notification, wakeFallback(appVisible = false))
repeat(3) { AppVisibility.activityStopped() }
assertFalse(AppVisibility.visible)
AppVisibility.activityStarted()
@@ -220,6 +230,45 @@ class WakeTest {
assertEquals(WakeState.Starting, wakeStateAtStart(running = true, current = WakeState.Off))
}
@Test
fun theLastFiveWakesAreKeptNewestFirst() {
var log = emptyList<WakeAttempt>()
for (i in 1..7) log = wakeLogAdd(log, WakeAttempt(at = i * 1_000L, phrase = "Hey Assistant", way = "session", outcome = WakeAttempt.OUT_OPENED))
assertEquals(listOf(7_000L, 6_000L, 5_000L, 4_000L, 3_000L), log.map { it.at })
// They live in the phone's settings, and read back as they were written.
val saved = LembasJson.encodeToString(Prefs.serializer(), Prefs(wakeLog = log))
assertEquals(log, LembasJson.decodeFromString(Prefs.serializer(), saved).wakeLog)
assertTrue(Prefs().wakeLog.isEmpty())
}
@Test
fun anAttemptThatFoundTheAssistantNotConnectedLearnsThatItCameLater() {
val missed = WakeAttempt(at = 5_000, outcome = WakeAttempt.OUT_NOT_CONNECTED, fallback = "notification", assistant = true)
val earlier = WakeAttempt(at = 1_000, outcome = WakeAttempt.OUT_NOT_CONNECTED)
val told = wakeLogConnected(listOf(missed, earlier), now = 9_000)
assertEquals(9_000L, told[0].connectedLater)
// Only the newest, only once, and never by a connection from before it.
assertEquals(0L, told[1].connectedLater)
assertEquals(told, wakeLogConnected(told, now = 12_000))
assertEquals(listOf(missed), wakeLogConnected(listOf(missed), now = 4_000))
// An attempt that opened, or an empty record, has nothing to learn.
val opened = listOf(WakeAttempt(at = 5_000, outcome = WakeAttempt.OUT_OPENED))
assertEquals(opened, wakeLogConnected(opened, now = 9_000))
assertTrue(wakeLogConnected(emptyList(), now = 9_000).isEmpty())
}
@Test
fun theAssistantsLinkIsWhatAndroidLastSaid() {
AssistLink.ready(now = 1_000)
assertTrue(AssistLink.connected.value)
assertEquals(1_000L, AssistLink.readyAt)
AssistLink.shutdown(now = 2_000)
assertFalse(AssistLink.connected.value)
assertEquals(2_000L, AssistLink.shutdownAt)
AssistLink.sheetShown(elapsed = 77)
assertEquals(77L, AssistLink.shown.value)
}
@Test
fun onlyTheNewestServiceWritesTheState() {
val old = WakeStatus.begin()
@@ -61,6 +61,7 @@ import eu.llembas.android.ui.scheduled.ScheduleState
import eu.llembas.android.ui.scheduled.ScheduledState
import eu.llembas.android.ui.settings.SettingsState
import eu.llembas.android.ui.settings.WakeTestShown
import eu.llembas.android.wake.WakeAttempt
import eu.llembas.android.wake.WakeFailure
import eu.llembas.android.wake.WakeState
import kotlinx.serialization.json.JsonPrimitive
@@ -383,6 +384,24 @@ object Fakes {
wakeTest = WakeTestShown(done = true),
)
/** The assistant in name but not connected, and a last wake that says so step by step. */
val settingsWakeUnbound = settings.copy(
assistantConnected = false,
prefs = settings.prefs.copy(
wakeLog = listOf(
WakeAttempt(
at = 1_773_129_600_000,
phrase = "OK Google",
way = "notification",
outcome = WakeAttempt.OUT_NOT_CONNECTED,
fallback = "notification",
assistant = true,
),
WakeAttempt(at = 1_773_126_000_000, phrase = "OK Google", way = "session", outcome = WakeAttempt.OUT_OPENED, assistant = true),
),
),
)
/** A standard build: the test heard the phrase twice, and notification summaries are in the other build. */
val settingsWakeTested = settings.copy(wakeTest = WakeTestShown(running = true, heard = 2), notificationsBuild = false, isAssistant = false)
@@ -217,6 +217,9 @@ class ScreenShots {
shoot("08-wake-listening", Phone.Scroll) { groups(Fakes.settings) }
shoot("08-wake-failed", Phone.Scroll) { groups(Fakes.settingsWakeFailed) }
shoot("08-wake-failed", Phone.SmallScroll, fontScale = 1.5f) { groups(Fakes.settingsWakeFailed) }
// The assistant not connected right now, and the last wake that found it so.
shoot("08-wake-unbound", Phone.Scroll) { groups(Fakes.settingsWakeUnbound) }
shoot("08-wake-unbound", Phone.SmallScroll, fontScale = 1.5f) { groups(Fakes.settingsWakeUnbound) }
shoot("08-wake-tested", Phone.Scroll) { groups(Fakes.settingsWakeTested) }
shoot("08-wake-tested", Phone.SmallScroll, fontScale = 1.5f) { groups(Fakes.settingsWakeTested) }
}