Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。
feat(self-check): give the brain and voice-key rows a door, and one voice
booboosuifdcde6787fe5
diff --git a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.ktindex beadb37..2340b22 100644--- a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt+++ b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt@@ -2006,12 +2006,12 @@ class ScreenBodyService : AccessibilityService() {* fighting this one for the keyboard. Posted to the main thread because* `SettingsUi.show` adds a window.*- * A null service means no sheet — the caller's row is then a dead button,- * which is why [net.kuafuai.andee.ui.SelfCheckUi] draws no 打开设置 row at- * all when the accessibility check is red (see its `serviceUp`), and says so- * in words instead. Guarded on [window] rather than on any "am I- * alive" flag: a sheet over a service that never got its overlay attached- * has nothing to sit on, and the add would throw.+ * A null service means no sheet from *here*, which is why+ * [net.kuafuai.andee.ui.SelfCheckActivity] raises its own on the path where+ * this class does not exist — see its `openOwnSettings`. Guarded on+ * [window] rather than on any "am I alive" flag: a sheet over a service+ * that never got its overlay attached has nothing to sit on, and the add+ * would throw.*/fun openSettingsForUser() {ui.post { if (::window.isInitialized) openSettings() }diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.ktindex 82fe65e..435a680 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt@@ -2,8 +2,11 @@ package net.kuafuai.andee.uiimport android.graphics.drawable.ColorDrawableimport android.os.Bundle+import android.provider.Settingsimport android.widget.ImageViewimport net.kuafuai.andee.ScreenBodyService+import net.kuafuai.andee.config.FactoryReset+import net.kuafuai.andee.config.Notebookimport net.kuafuai.andee.config.VoiceConfigimport net.kuafuai.andee.i18n.AppLocale@@ -121,6 +124,12 @@ class SelfCheckActivity : StageActivity() {*/private var paintedLang = ""+ /**+ * Our settings sheet while it is up — see [openOwnSettings]. Held only so a+ * second tap on 打开设置 does not stack a second window on the first.+ */+ private var settings: SettingsUi? = null+override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)@@ -172,13 +181,25 @@ class SelfCheckActivity : StageActivity() {context = this,host = stage,onDismiss = { leave() },+ // The two rows a first-run user actually has to act on — 大脑 and+ // 语音密钥 — are `Fix.OurSettings`, and this page used to draw them+ // with no button at all on the argument that the sheet belongs to the+ // service. It does not: `SettingsUi` is a plain overlay built from a+ // Context, and the grant it needs is one of the rows right here. So+ // the door exists whenever that grant does, and only the+ // overlay-refused case falls back to words — see+ // [SelfCheckUi.canOpenSettings] and [openOwnSettings].+ onOpenSettings = if (Settings.canDrawOverlays(this)) {+ { openOwnSettings() }+ } else {+ null+ },// The card's picker writes the preference and repaints itself, but// this Activity is what *remembers* the language on screen —// otherwise the next [onResume] would read a mismatch it caused- // itself and swap the whole card for nothing. Both callbacks- // [SelfCheckUi] offers exist to tell the *service* something (open- // our sheet, repaint the ball), and the service is exactly what is- // missing on this path, which is what leaves this one free.+ // itself and swap the whole card for nothing. The other callback+ // [SelfCheckUi] offers used to exist only to tell the service+ // something, which is what left this one free.onLocaleChanged = { paintedLang = VoiceConfig.uiLanguage(this) },)// Local half first and it is not an optimisation: `local` is what the@@ -193,6 +214,57 @@ class SelfCheckActivity : StageActivity() {ScreenBodyService.get()?.ballWindow()?.setPagePerched(false)}+ /**+ * The settings sheet, raised by this page rather than by the service.+ *+ * This is the path where there is no service — that is the whole reason the+ * page is on screen — so `ScreenBodyService.openSettingsForUser` has nobody+ * to ask. `SettingsUi` never needed one: it is a `TYPE_APPLICATION_OVERLAY`+ * built from a Context, and it lands on top of this Activity exactly as it+ * lands on top of the assistant's card.+ *+ * The three wipes are the only thing the service was carrying, and each is+ * one static call plus a brain rebuild — so here they are just the static+ * call, because there is no brain to rebuild. That is not a degraded version+ * of `ScreenBodyService.clearChatHistory`: what that method's second half is+ * *for* is a model still holding the conversation, and on this path nothing+ * is.+ *+ * Two sheets can never exist at once. The only way to this page is+ * [onCreate] falling through, which happens when the service is absent or+ * has no overlay — and in the second case `canDrawOverlays` is false too, so+ * this is not even offered.+ *+ * Repainting on dismiss rather than trusting [onResume]: an overlay does not+ * pause the Activity underneath it, so a language changed inside the sheet+ * would otherwise leave this card in the old one until something else+ * happened to resume it.+ */+ private fun openOwnSettings() {+ if (settings?.isShowing() == true) return+ val s = SettingsUi(+ context = this,+ onDismiss = {+ settings = null+ paintedLang = VoiceConfig.uiLanguage(this)+ // Re-run the list, not just repaint it: the user came here to+ // fill in a key, and the row they were sent from is exactly the+ // one that should be green when they get back. [SelfCheckUi.start]+ // is what 重新检查 calls.+ if (::ui.isInitialized) ui.start()+ },+ onFactoryReset = { FactoryReset.wipe(this) },+ onClearChat = { ChatHistory.wipe(this) },+ onClearNotes = { Notebook.wipe(this) },+ onLocaleChanged = {+ paintedLang = VoiceConfig.uiLanguage(this)+ if (::ui.isInitialized) ui.repaintForLanguage()+ },+ )+ settings = s+ s.show()+ }+/*** Catch a language change that did not come from this card's picker.*@@ -203,13 +275,13 @@ class SelfCheckActivity : StageActivity() {* itself and hands the new value over through `onLocaleChanged` — so what* lands here is a change made somewhere this page cannot see.*- * Narrow today and kept on purpose: the 打开设置 row that used to make this- * reachable from inside the card is gone from this host by construction (it- * needs the service, and this is the service-is-off page), so the remaining- * path is a change written while the user was off in a system screen. It is- * one `SharedPreferences` read per resume — [AppLocale] deliberately does- * not cache, see its doc — and it is the check that stops mattering the day- * a door out of this page is added back.+ * Narrower than it looks, and deliberately kept anyway. The two doors out of+ * the card that *can* move the language — its own picker, and the settings+ * sheet at [openOwnSettings] — both hand the new value back directly, and the+ * sheet is an overlay that never pauses this Activity, so neither arrives+ * here. What is left is a change written while the user was off in a system+ * screen. It is one `SharedPreferences` read per resume — [AppLocale]+ * deliberately does not cache, see its doc.** `paintedLang` is set in [onCreate] before the first resume, so this cannot* fire on open. Guarded on [ui] for the *other* path through [onCreate]: the@@ -225,6 +297,11 @@ class SelfCheckActivity : StageActivity() {}override fun onDestroy() {+ // Our sheet is a window, not a child of this Activity, so nothing takes+ // it down with us — an Activity destroyed with it up would leave an+ // orphan overlay on screen with no way to close it.+ settings?.hide()+ settings = null// Guarded because this also runs when onCreate threw before the card was// built, and dying is not a good moment to throw a second exception.if (::ui.isInitialized) ui.destroy()diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.ktindex 7b3cdf4..8a02b54 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt@@ -171,17 +171,19 @@ class SelfCheckUi(private var last: List<SelfCheck.Finding>? = null/**- * Whether the assistant's own service is up, read off the list each time it- * is drawn rather than asked of [net.kuafuai.andee.ScreenBodyService]- * separately.+ * Whether there is a settings sheet to open at all — the difference between+ * 打开设置 opening a card and 打开设置 doing nothing.*- * Our settings sheet is an overlay that service owns, so this is the- * difference between 打开设置 opening a card and 打开设置 doing nothing —- * and [SelfCheck]'s `accessibility` row *is* the statement "that service is- * not running". One source of truth; a second test here could only ever- * disagree with the red row directly above it.+ * Asked of the caller rather than inferred from the `accessibility` row,+ * which is what this used to do. That inference was true while only the+ * service could raise our sheet; it stopped being true when+ * [SelfCheckActivity] learned to raise its own, and an inference is exactly+ * the wrong shape for a capability its owner already knows. The rows this+ * gates — 大脑 and 语音密钥 — are the two a user configures *before* the+ * assistant works, so suppressing their one button on a page reached with+ * the service off is suppressing it in the case it exists for.*/- private var serviceUp = true+ private val canOpenSettings = onOpenSettings != nullfun isShowing(): Boolean = root != null@@ -345,18 +347,16 @@ class SelfCheckUi(last = foundval attention = found.filter { SelfCheck.needsAttention(it) }val rest = found.filterNot { SelfCheck.needsAttention(it) }- // Before any row is built: [fixButton] reads this per row.- serviceUp = found.none { it.id == "accessibility" && it.level == SelfCheck.Level.FAIL }hero?.removeAllViews()hero?.addView(summary(attention.size))- // The one case where the card has to say it cannot help: our own- // settings sheet lives in the service, so with the service off there is- // nowhere for 打开设置 to go. Say that instead of showing a button that- // would do nothing — and note the row itself has no button either, see- // [fixButton]. Only reachable in host mode: the window host *is* the- // service, so if it is drawing this at all, accessibility is on.- if (!serviceUp) hero?.addView(note(lctx.getString(R.string.check_page_no_service)))+ // The one case where the card has to say it cannot help: our sheet is an+ // overlay either way, so with the overlay grant missing there is nowhere+ // for 打开设置 to go. Say that instead of showing a button that would do+ // nothing — and note the row itself has no button either, see+ // [fixButton]. Only reachable in host mode: the window host is already+ // drawing overlays, so if it is drawing this at all the grant is there.+ if (!canOpenSettings) hero?.addView(note(lctx.getString(R.string.check_page_no_overlay)))rows?.removeAllViews()attention.forEach { rows?.addView(row(it)) }@@ -693,10 +693,10 @@ class SelfCheckUi(* colour is this app's established "this is tappable" mark.*/private fun fixButton(f: SelfCheck.Finding): TextView? {- // Ours, and unreachable: see [serviceUp]. The note above the list has- // already said so, and a button that does nothing is worse than no+ // Ours, and unreachable: see [canOpenSettings]. The note above the list+ // has already said so, and a button that does nothing is worse than no// button — it is the exact failure this list exists to avoid.- if (f.fix is SelfCheck.Fix.OurSettings && !serviceUp) return null+ if (f.fix is SelfCheck.Fix.OurSettings && !canOpenSettings) return nullval label = when (val fix = f.fix) {// Zero means "the action's own word"; a fix instance gets to// override it when 去开启 would name the wrong errand — seediff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xmlindex 15b7dc7..5179af2 100644--- a/app/src/main/res/values-en/strings.xml+++ b/app/src/main/res/values-en/strings.xml@@ -330,8 +330,8 @@<string name="check_detail_network_on">Online.</string><string name="check_detail_network_off">Offline. Speech recognition, speech synthesis and every model call go over the network.</string><string name="check_detail_brain_on">Configured.</string>- <string name="check_detail_brain_hub_missing">The cloud address is empty — nothing knows where to send what you say.</string>- <string name="check_detail_brain_key_missing">The on-device assistant has no API key, so asking it anything gets no answer.</string>+ <string name="check_detail_brain_hub_missing">Not set. The brain is set to the cloud, so the address of your own hub goes in ⚙ → “Brain” → “Hub URL”. Without it there is nowhere to send what you say: no answers, and nothing on screen moves. To have this device think for itself, switch the brain to “On-device” in the same place.</string>+ <string name="check_detail_brain_key_missing">Not set. The brain is set to run on this device, so open a DeepSeek account of your own and put the key in ⚙ → “Brain” → “DeepSeek Key”. Without it, what you say arrives and nothing can be answered or acted on.</string><string name="check_detail_model_cloud">Cloud assistant — the model is not on this device.</string><string name="check_detail_model_no_key">No key yet. Fill one in and this becomes testable.</string><string name="check_detail_checking">Checking…</string>@@ -357,7 +357,7 @@<string name="check_detail_mic_on">Allowed.</string><string name="check_detail_mic_off">Not allowed. Tapping the ball does nothing at all — the failure that least resembles a permission problem.</string><string name="check_detail_voice_key_ok">Set. Recognition and synthesis use it to reach Volcengine.</string>- <string name="check_detail_voice_key_missing">Not set. The source ships without a key — open a Volcengine Speech service of your own and put its API key in ⚙ under “Voice API key”. Without it, hearing and speaking cannot connect, and what you get back is a connection timeout that looks like a network fault. Everything else works.</string>+ <string name="check_detail_voice_key_missing">Not set. The source ships without a key — open a Volcengine Speech service of your own and put the key in ⚙ → “Speech (Volcengine)” → “Volcengine API key”. Without it, hearing and speaking cannot connect, and what you get back is a connection timeout that looks like a network fault. Everything else works.</string><string name="check_detail_voice_host_ok">%1$s is reachable.</string><string name="check_detail_voice_host_bad">Could not reach %1$s: %2$s. Both recognition and synthesis will time out.</string><string name="check_detail_wake_on">Taught, and it wakes while the screen is on.</string>@@ -389,7 +389,7 @@<string name="check_page_done">Done</string><string name="check_page_issues">%1$d to sort out</string><string name="check_page_notes_lead">The rest is just for reference and changes nothing.</string>- <string name="check_page_no_service">Accessibility is off, so the assistant’s settings cannot be opened from here yet.</string>+ <string name="check_page_no_overlay">The settings sheet is drawn as a floating window — turn on “Draw over other apps” below first, then come back and fill these in.</string><string name="check_card_title">%1$d thing(s) need attention</string><string name="check_card_open">Fix it</string><string name="check_card_ack">Got it</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 2196ff7..8614783 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -385,8 +385,8 @@<string name="check_detail_network_on">已联网。</string><string name="check_detail_network_off">没联网。语音识别、语音合成、模型调用全都走网络。</string><string name="check_detail_brain_on">已配置。</string>- <string name="check_detail_brain_hub_missing">云端大脑地址是空的 —— 还不知道该把你说的话送去哪。</string>- <string name="check_detail_brain_key_missing">本地大脑没填 API Key,问了也不会有回答。</string>+ <string name="check_detail_brain_hub_missing">还没填。现在用的是云端大脑,得把你自己搭的 Hub 地址填进 ⚙ →「大脑」→「Hub 地址」。没有它,你说的话没地方送,问了不会有回答,屏幕也不会动。想让这台设备自己想,就在同一处把大脑切成「本机」。</string>+ <string name="check_detail_brain_key_missing">还没填。现在用的是本机大脑,得你自己去 DeepSeek 开一个,把 Key 填进 ⚙ →「大脑」→「DeepSeek Key」。没有它,你说的话我收得到,却答不出、也动不了手。</string><string name="check_detail_model_cloud">云端大脑,模型不在这台设备上。</string><string name="check_detail_model_no_key">还没填 Key,填了才测得了。</string><string name="check_detail_checking">检查中…</string>@@ -412,7 +412,7 @@<string name="check_detail_mic_on">已允许。</string><string name="check_detail_mic_off">没允许。点球不会有任何反应 —— 这是最不像权限问题的一条。</string><string name="check_detail_voice_key_ok">已填。识别和合成用它连火山。</string>- <string name="check_detail_voice_key_missing">还没填。源码里不带密钥,得你自己去火山引擎开一个语音服务,把 API Key 填进 ⚙ 的「语音密钥」。没有它,听和说都连不上——报出来的却是连接超时,看着像网络坏了。其余功能照常。</string>+ <string name="check_detail_voice_key_missing">还没填。源码里不带密钥,得你自己去火山引擎开一个语音服务,把 Key 填进 ⚙ →「语音(火山引擎)」→「火山 API Key」。没有它,听和说都连不上 —— 报出来的却是连接超时,看着像网络坏了。其余功能照常。</string><string name="check_detail_voice_host_ok">%1$s 可达。</string><string name="check_detail_voice_host_bad">连不上 %1$s:%2$s。识别和合成都会超时。</string><string name="check_detail_wake_on">已录入,亮屏时喊得醒。</string>@@ -443,7 +443,7 @@<string name="check_page_done">完成</string><string name="check_page_issues">%1$d 项需要处理</string><string name="check_page_notes_lead">下面几条仅供参考,不影响使用。</string>- <string name="check_page_no_service">无障碍还没开,设置面板暂时打不开。</string>+ <string name="check_page_no_overlay">设置面板是一张悬浮窗画出来的 —— 先把下面那条「悬浮窗」开起来,再回来填。</string><string name="check_card_title">有 %1$d 项需要处理</string><string name="check_card_open">去处理</string><string name="check_card_ack">知道了</string>