Assistant
What the role is
Android lets one app be the digital assistant (Settings › Default apps › Digital assistant
app). To be offered there an app must provide a VoiceInteractionService with a session service
and a recognition service -- Android rejects one without both. LLeMbas provides:
| Component | Job |
|---|---|
LembasAssistService |
the service the system binds while LLeMbas is the assistant |
LembasAssistSessionService / LembasAssistSession |
one invocation: a sheet over the current app |
LembasRecognitionService |
speech-to-text through the instance (/v1/audio/transcriptions); any app using the system recognizer gets it while LLeMbas is the assistant |
AssistActivity |
the same sheet in a see-through activity: ACTION_ASSIST, the tile, the "Ask" shortcut, the lock-screen path and the microphone's permission prompt |
AssistController |
what the sheet does: listening, asking, the stream, voice out |
AssistSheet.kt |
the frame (dim, drag, stops) and the contents, drawn from state |
PhoneRecognizer (Voice.kt) |
the phone's own recogniser, for Voice input › Phone |
How it is opened
| Way | Notes |
|---|---|
| Hold the power button | Pixel and most phones on Android 12+, when LLeMbas is the assistant |
| Samsung side key | Settings › Advanced features › Side button › Press and hold › Digital assistant (Bixby otherwise wins) |
| The assist gesture | swipe up from a bottom corner, where the phone has it |
| Quick Settings tile | "Ask LLeMbas" -- add it from the tile editor; always shown ready (STATE_INACTIVE), never as a switch |
| Launcher shortcuts | long-press the icon › Ask LLeMbas, Speak, Last chat -- published from code (widget/AskWidget.kt Shortcuts), because a static shortcuts.xml names the package and the test build's is ….debug |
| Home-screen widget | AskWidget (RemoteViews, colours from values*/tokens.xml): Ask anything, the microphone (the sheet listening), the clock (the last assistant chat). Nothing from the account on it |
| Headset voice button | ACTION_VOICE_COMMAND (locked: VOICE_SEARCH_HANDS_FREE) opens AssistActivity listening, whatever Settings says about listening first |
| Share menu | "Ask LLeMbas": ShareActivity, the same sheet frame -- what came in, an optional request, new chat or the last assistant chat; files uploaded first; the chat opens in the app; a new chat made there becomes the assistant's last |
| Wake word | opt-in, below |
| Lock screen | the sheet opens; sending asks to unlock first, and nothing from the account is shown before (below) |
AssistActivity reads what a way in asked for with Opening.of(intent): ACTION_LISTEN
(widget, Speak shortcut, headset), ACTION_CONTINUE (widget, Last chat shortcut), a question
handed over by the session, or just the sheet; onNewIntent takes a second press while it is up.
Experimental. The wake word, and the hands-free parts of the voice assistant -- opening listening, finding the end of what you said, the spoken conversation, listening over the lock screen -- are new and have been tried on few phones. Settings marks them so. Typing a question and the microphone button are the parts to rely on.
Over the lock screen
While the phone is locked nothing goes to the instance and nothing of the account is shown or
spoken. AssistController asks the keyguard itself (its locked function), so the rule holds
whoever calls it:
ask()does not ask: it holds the question (hold,Held) untilunlocked().- With Voice input › LLeMbas the recording is not written down while it runs
(
writeDownAsSaidskips), the end is found by the level alone (EndOfSpeech), and the finished recording waits on the phone (AssistUiState.waitingRecording): the sheet says Question heard, with no words, and Unlock to send.unlocked()sends it to be written down and asks it. It is kept in memory only. - With Voice input › Phone the phone's recogniser writes it down; the words are shown while
they wait (
AssistUiState.waiting). Where that recogniser sends the recording is its own business, as always. /api/v2/meand the model list are asked for on unlock (loadRemote); the microphone opens without them (loadLocalonly).- The sheet draws no turns, no model chip, no last chat and no failure text while locked; no
answer is read aloud (
speak) and a spoken conversation does not go on.
AssistActivity is setShowWhenLocked; what it does when opened over the lock is
lockedStart() (tested):
| Opened | Locked behaviour |
|---|---|
| to listen -- the wake word, a headset's button -- with the microphone allowed | Listen: the sheet stays up and listens; what it hears is held, and Android is asked to unlock at once (requestDismissKeyguard: a face or a fingerprint is enough). If nobody unlocks, the sheet stays as it is |
| with a question handed over by the session | Hold: the same, without listening |
| anything else (the plain sheet, the last chat, the microphone's permission prompt) | Unlock: Android is asked to unlock first, and the sheet goes if that is turned down |
The held question is asked when the phone is unlocked -- Android's answer to the request, the
person's own unlock (ACTION_USER_PRESENT), or the sheet coming back -- once, and only when the
keyguard itself says so. A question typed over the lock screen takes the place of one that
waited. The screen is kept on while the sheet listens, works or speaks.
The phone locking while the sheet is up. ACTION_SCREEN_OFF stops the microphone and the
voice whatever the lock says yet (screenOff), blanks the sheet for the picture Android keeps
of it, and finishes a sheet that was over the lock screen. Found locked then or on the way back
(onStart), lockedNow also stops following the answer. The assistant's own sheet (the
session) is hidden by Android when the screen goes off, and its controller has the same rule.
Who may ask what of the activity (OwnIntents.kt). It is exported, because Android's
ACTION_ASSIST and the headset actions must reach it -- so any app can start it with any
extras. Therefore:
- a question never travels in an intent. The session leaves it in the app's memory
(
AssistHandOff.leave) and the intent carries a one-time ticket (EXTRA_HANDOFF); ACTION_LISTEN,ACTION_CONTINUE,EXTRA_LISTEN,EXTRA_WAKEand the ticket count only on an intent with the app's own mark (OwnIntents.own/isOwn: a random value made once, kept in private storage, carried inside the widget'sPendingIntents and the shortcuts, which no other app can read). Without it they are just the sheet.AskWidget.refreshat start gives a widget placed by an older version its marked buttons;VOICE_COMMANDandVOICE_SEARCH_HANDS_FREEare Android's and open it listening for anybody: over the lock that records on the phone and sends nothing.
The activity handles configuration changes itself (configChanges), runs take() once, and
saves a held question's words across being made again; a held recording is not saved.
The wake word with the screen off used to show the sheet for a moment only: a locked phone took
the "ask to unlock first" path, and onDismissCancelled -- which is what Android answers when
nobody unlocks -- finished the activity.
Not done: an answer over the lock screen. A wake word from across the room gets its
question heard and then waits for the unlock. Answering aloud without unlocking would be a
setting of its own (off by default, voice only, nothing drawn), since it lets anyone near the
phone use the account. Also not covered: LembasRecognitionService, the system recogniser
other apps get, sends its recording to the instance whenever an app asks it to, locked or not.
The sheet
The assistant is a sheet over the app it was opened from, never a page of its own: a
see-through window with its own dim (AssistSheetFrame), the sheet rising to about half the
height. Its handle (and the bar beside it) drags it to the full height, or down and away; Back
or a tap on the dim closes it too. With the keyboard up, the stops are measured above it.
settle() decides where a let-go drag ends (a fling by its direction, a slow release by the
nearest stop). Both ways in -- the session and AssistActivity -- draw the same
AssistSheetContent, from its state alone, which is what the screenshot tests render.
| Part | What it does |
|---|---|
| The bar | The model and connection chip (picture, name, the instance, a dot: answering, not, or being asked; a tap picks another model, kept for next time), voice reply on or off, Open in app |
| The model | Settings › Assistant › Assistant model (Prefs.assistantModel): Instance default (the account's default, then the instance's) or one of the instance's models, for every new assistant chat -- the sheet, the wake word, Share. AssistController.assistantModelFor resolves it; the controller keeps it apart from the model of a continued chat, so New chat goes back to it |
| Before a question | The last chat the assistant made, to continue; the quick actions when a screen was handed over (Summarise / Translate / Explain this -- each sends the screen); how to open it, and why there is no wake word |
| The questions | Each question a bubble, each answer full width as it is written; follow-ups stay in the same chat until New chat; Read aloud under the last answer |
| The foot | Use screen; the microphone (or Send once there are words) |
Microphone first. It opens listening (Settings › Assistant can turn that off), except
before the microphone is allowed -- the session cannot show the permission prompt, so it hands
over to AssistActivity (EXTRA_LISTEN) -- and over the lock screen, where only a way in that
means to speak listens (above).
Voice input (Settings › Voice input):
- LLeMbas -- the instance's speech-to-text (
/v1/audio/transcriptions, through the server). That endpoint takes a whole recording, so the words shown while speaking are the recording so far, written down again every 1.2 s (one request at a time, not past the first minute, and not before the microphone heard anything above the room). When to stop isEndOfSpeech(assist/EndOfSpeech.kt, tested with level sequences), fed the microphone's level (RMS) every 100 ms. No level is absolute: the noise floor is the quietest level of the last two seconds, taken at once when it falls and slowly, in calm moments only, when it rises (so a voice does not lift it under itself; a first sound louder than any room is a guess until a dip or a calm moment shows the room). Speech begins when the level is over about twice the floor in three of the last eight ticks, or stays above the floor for a second without being steady (listening that begins mid-sentence); a pause is back within 1.6 times of it, and an exact zero after sound -- a headset that gates its noise -- is a pause too. A pause of 1.5 s after speech sends it; nothing said gives up after 5 s and sends nothing (a speech-to-text model asked to write down silence invents a sentence, so its words count as speech only when the microphone heard something above the room); the same words for 4.5 s end it; and never past 60 s. Known limits: sound that is not steady (music, a television, other people) counts as speech, and a very loud room at the very start can be taken for a voice once. Earlier it was two fixed levels (0.02 speaking, 0.01 quiet): a room between them never counted as a pause and it listened to the two-minute limit. - Phone -- the phone's own recogniser through
SpeechRecognizer, with partial results. While LLeMbas is the digital assistant the system's default recogniser is LLeMbas's own (LembasRecognitionService), soPhoneRecognizernever asks for the default: it takes the on-device recogniser (Android 12+), else another installed app's (found through<queries>forandroid.speech.RecognitionService). No Google library is linked; a phone with none says so in Settings. If the instance has no speech-to-text, the phone's is used. It is asked for the same 1.5 s pause (EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, a hint not every recogniser takes) and watched (phoneWatch): no words and no sign of speech (its "speech began", a loud level) for 8 s gives up, the same words for 4.5 s in quiet asks it to stop, and one that does not answer has its words taken as they are.
LembasRecognitionService (what other apps get as the system's recogniser) ends by
EndOfSpeech too, within its 15 s limit.
Voice reply is the instance's text-to-speech (/v1/audio/speech), for a spoken question when
the switch at the top is on; Read aloud reads any answer. Shown only when the instance offers it
to the account (/api/v2/me services.tts).
Spoken conversation (Settings › Assistant › Keep a spoken conversation going, on; needs
voice replies). A spoken question answered aloud sets conversation; when Speaker.playToEnd
says the answer was heard to the end, the sheet listens again. It ends on a stop phrase
(assist_stop_words, |-separated per language, matched by isStopPhrase: the phrase alone or
with up to two words around it), End on the In conversation strip, typing, a stopped voice,
a card waiting, or nothing said (the usual silence rules). With a Bluetooth headset connected,
HeadsetRoute makes it the communication device (Android 12+) and the recorder prefers its
microphone; a wired headset's is the default anyway.
Notification summaries (Settings › Assistant › Notification summaries, off; plus Android's
notification access, which only the person can give) -- in the notifications build only.
LembasNotificationListener keeps nothing; NotificationAccess.read takes what is up when a
question asks -- the Summarise my notifications chip, or a question naming them
(assist_notifications_phrases) -- and nothing while the phone is locked. They go with that one
question as "My notifications:" text (NotificationReader.asText, in every build).
The listener and its manifest entry live in src/notifications/ alone. The standard builds
(src/standard/) have a NotificationAccess that can do nothing and declare no listener and no
permission of it: Google Play Protect blocks installing an app from outside the Play Store that
can read notifications, and it blocked 1.0.0-beta.7. Settings there says which build has the
feature and why. scripts/check-apk.sh checks the built files, in CI and before a release is
published.
Open in app continues the same chat in the app. A reply waiting on a card (an approval or a question) says to open it in the app: the sheet does not answer cards.
The screen
onHandleAssist delivers the screen's text and onHandleScreenshot a picture -- only if the
person allowed it (Settings › Default apps › Assist & voice input › Use text from screen / Use
screenshot), and never from an app that marks its window secure. The sheet offers Use
screen, off every time it opens; on, the text goes with the next question and the screenshot
as an attachment -- one question, then it is off again. The session makes a fresh controller as
it hides, so the next invocation's screen, which may arrive before or after its onShow, lands
in the controller that shows it.
The wake word (opt-in, experimental)
The platform's always-on hotword -- the low-power detector Gemini uses -- needs
CAPTURE_AUDIO_HOTWORD and MANAGE_HOTWORD_DETECTION, both signature|privileged: only an
assistant built into the phone can hold them. What an app can do is listen for itself, and that is
what Settings › Assistant › Wake word turns on (off by default).
- Engine: sherpa-onnx keyword spotting (Apache-2.0, k2-fsa) with its English
kws-zipformer-gigaspeech-3.3Mmodel (Apache-2.0, int8 encoder/decoder/joiner, ~5 MB). openWakeWord's pre-trained models are non-commercial (CC BY-NC-SA) and Picovoice needs a proprietary key; both are out. - Fetched, not committed:
scripts/fetch-wakeword.pydownloads the project's prebuilt AAR (2.0.1, onnxruntime inside, MIT) and the model archive from its GitHub releases, checks each against a SHA-256, and puts them inapp/libs/andapp/src/full/assets/wakeword/(gitignored). CI and the release workflow run it before Gradle. fullonly. Thefdroidflavour has a stub (src/fdroid/.../wake/Engine.kt,AVAILABLE = false) and Settings says why: F-Droid builds every library from source, and sherpa-onnx is not built from source here yet. ABIs: arm64-v8a and armeabi-v7a in a release; a debug build adds x86_64 for the emulator. Of the AAR's libraries onlylibsherpa-onnx-jni.soandlibonnxruntime.soare packaged (the C and C++ API libraries are for other callers).- The model is copied out of the APK by stream (
unpackWakeModel), once per model version (assets/wakeword/version, a hash of the pinned files written by the fetch script), into the app's no-backup files.AssetManager.openFdworks only for an asset stored uncompressed, and 1.0.0-beta.7 used it on compressed ones: the engine never loaded on any phone, silently. The.onnxassets are stored now as well (noCompress), and CI checks the APK. - A phrase is a greeting and a name: Hey / OK / Hello, then Assistant / Computer / Google or an
ordinary name (
WakeWords, default "Hey Assistant"). Only words the model was trained to hear: "Hey Lembas" had to be repeated until it happened to land, because Lembas is no word of the model's. Settings savesgreeting_name; an id that is no phrase any more reads as the default. - The token pieces are generated, never typed:
scripts/fetch-wakeword.pyalso takes the model'sbpe.modelfrom the same pinned archive (tobuild/wakeword/, not into the APK), andscripts/gen-wake-phrases.py(sentencepiece, pinned inscripts/wake-requirements.txt) writeswake/WakeWords.kt. CI checks the committed table against the tokenizer, andWakeWordsTestevery piece againsttokens.txt. "OK" is spelled OKAY, one piece, as the model's speech was transcribed. A name with four or more single-letter pieces is dropped (Elizabeth, Benjamin). - The engine ends the process on a piece it does not know (
exit(-1)in its keyword encoder), socheckKeywordschecks every keywords line againsttokens.txtfirst. - Boost and threshold go on each keywords line (
:boost #threshold, sherpa-onnx's syntax), from Settings › Wake word › Sensitivity: Low 1.0 / 0.35, Normal 1.5 / 0.25, High 2.0 / 0.15, and 0.05 stricter for a phrase of fewer than five pieces. The threshold is the least average probability of the heard pieces (0.25 is the engine's default, 0.35 its documentation's stricter example);numTrailingBlanksis the engine's own 1. Starting values, not yet tuned on phones. - One state, shown (
WakeStateinWakeStatus.state): Off, Starting, Listening(phrase), Paused(why), Failed(why, detail). The service writes it; its notification (wakeNotification, written from the state in one place), Settings' row and "Test the wake word" read it. A start never posts a phrase by default: 1.0.0-beta.7 posted "Listening for Hey Lembas" on every app open, whatever was chosen and whether or not anything listened. WakeListeneris the loop apart from Android (tested on the JVM with a fake engine and microphone): an engine that does not load, a microphone that does not start or stops, areFailedwith the reason, logged (LLeMbasWake), retried after 2 s, 5 s, 15 s, 1 min, then every 5 min. A new plan cancels and joins the old loop before the engine is released. Five seconds of exact zeros isPaused(Silent): Android hands a background app silence while another app has the microphone, or its switch is off.WakeWordService(foregroundServiceType="microphone", notification up the whole time, with Stop): 16 kHz audio to the engine in memory, nothing kept or sent. Pauses while the sheet is up (AssistPresence, counted by the session and the activity), in battery saver, and with the screen off unless Only while the screen is on is off. It is not started without the microphone permission (the state says so), and the app looks again each time it comes to the screen. On the word: the sheet opens listening throughLembasAssistService.current.showSessionwhen LLeMbas is the assistant (Android lets the bound voice-interaction service do that from the background), else as an activity, else a "tap to ask" notification.- Opening the assistant is decided by what Android allows (
wakeOpening): throughshowSessionwhen LLeMbas is the assistant; as an activity while one of the app's activities is started (AppVisibility, counted inLembasApp); otherwise a notification, Heard you. Tap to ask. (wakeHeardNotification, its own high-importance channel, gone after a minute or when the sheet opens). An activity started from the background is blocked without an exception, sostartActivitysucceeding proves nothing. Settings says that only the digital assistant app opens by voice over other apps. - Answering the word runs beside the listening, never inside it.
WakeListenerhandsheardto the scope around the loop, and the service runs the wake on the app's own scope: the wake's first step pauses the listener (the sheet takes the microphone), which cancels the loop that heard the word -- a wake run in that loop was cancelled by its own first step. WakeOpener(wake/WakeLog.kt, tested without Android) holds the order: wait up to 1 s for the connection when Android says the service is active; the session (connected, screen on) or the sheet's activity (connected, screen off: it hassetTurnScreenOn); "opened" only once a sheet says it is up (AssistLink.shown; the activity fromonStart/onNewIntent); a session that was not refused gets a second wait before anything else is shown, and when it does come late it closes a sheet the wake word opened in its place (never two); then the activity where Android will start it (service connected, or app on screen); else the notification.- The record (
WakeAttempt, last five inPrefs.wakeLog, logcatLLeMbasWake, shown as Last wake): time, phrase, way, outcome (opened/not_connected/refused+ the exception /no_sheet), fallback, ms until the sheet; role held,isActiveService,FEATURE_VOICE_RECOGNIZERS, screen on, locked, app visible; the service'sonCreate,onReady,onShutdown,onDestroytimes; whether the connection was waited for;onPrepareToShowSession/onShowSessionFailed(Android 14+); a lateronReady. - Role is not service. Holding the assistant role does not make Android use the service: it
resets
voice_interaction_serviceat start-up when no accepted recogniser is set, and the long press then opensACTION_ASSISTas a screen. Settings says so (isActiveServicefalse with the role held) and sends the person to choose LLeMbas again. - The pause counts sheets truly: a session once per show (
onShowmay come twice,onHideonce), the activity fromonStarttoonStop. - The engine wants a pause after the phrase: with
numTrailingBlanks = 1it triggers once more than one blank frame follows (about 80 ms). Settings and the test row say so. - Starts and stops: nobody calls
stopService. Stop (the switch, the notification's button) is the setting going off; the loop ends and the service stops itself by the newest start id it was given (stopSelf(lastStart)), so a start still on its way is not stopped under -- that closes the app. Each instance writes the state with a token (WakeStatus.begin), and the hold of the microphone after the word (AssistPresence.holdFor) ends on a process scope. A tap on a failure in Settings retries now (WakeStatus.retryNow). - Test the wake word (Settings): for ten seconds a heard phrase is counted
(
WakeStatus.heardInTrial) instead of opening the assistant. A deadline, not a switch. - Android's rules: a microphone service starts only from the app on screen and never at
boot --
WakeBootReceiverposts "tap to listen again", and the app restarts a service the phone stopped whenever it opens. Settings links the battery-optimisation page and names dontkillmyapp.com for phones that kill background services. - Cost: a continuous microphone and CPU inference without the hotword chip. Not yet measured on a phone.
Phone actions (spec 3.6.0)
The server's phone_action tool (harness/phone.md in the CLI) is offered in a chat once a
message comes from the app: every message declares client: ["phone_actions"]. A call waits on a
phone_action card in the ask frame; CardItem.phone is the checked action (action,
summary, its fields). The card (ui/chat/PhoneCard.kt) is drawn in the chat's card sheet and
inline in the assistant's sheet: the model's summary, how it will be done, its facts, and
Cancel / Do it. Cancel answers {result: {status: declined}}; Do it runs
actions/ActionRunner and answers done, or failed with the reason (English, for the model).
Never while the phone is locked.
| Action | How |
|---|---|
| alarm, timer | AlarmClock.ACTION_SET_ALARM / ACTION_SET_TIMER (SET_ALARM permission) |
| calendar_event | ACTION_INSERT on CalendarContract.Events: the person saves it |
| sms_draft, email_draft | ACTION_SENDTO smsto: (numbers only; a name is left to the person) / mailto: |
| dial | ACTION_DIAL: the person places the call |
| open_app, open_url | the launcher's app by its label (<queries> for the launcher); http/https only |
| media, torch | AudioManager.dispatchMediaKeyEvent; CameraManager.setTorchMode |
| settings_panel | Settings.Panel (wifi, internet, nfc, volume) or the page (bluetooth, location, do not disturb) |
| automation_intent | Tasker's ACTION_TASK by name, values as %local variables (PERMISSION_RUN_TASKS; Tasker's Allow external access), else the broadcast eu.llembas.android.action.AUTOMATION with task, app and the values |
| navigate, add_stop, search_nearby, stop_navigation | the navigation app, below |
Navigation app (Settings): whichever of Google Maps and OsmAnd is installed; with both, the
card asks. Google Maps: google.navigation:, the maps/dir URL with waypoints, geo:0,0?q=;
it cannot take a stop into a running route (the route starts again through the stop) and cannot be
told to stop (failed, with why). OsmAnd: its intent API only (osmand.api:// navigate,
navigate_gpx with the route as GPX data -- every point needs lat/lon --, navigate_search,
stop_navigation); its AIDL classes are GPLv3 and are not used. replace_route is OsmAnd's
force. Optional: Ask OsmAnd about the route uses get_info (through a see-through
ResultActivity) for the phone's position and the running route's destination, once the person
allowed LLeMbas inside OsmAnd -- so a search near here and add_stop without a destination work.
Not walked on a phone: OsmAnd's permission screen wording, and whether Google Maps keeps the
waypoints in navigation mode.