Skip to content

armgit / andee

Public Imported from GitHub
0

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、支持任意模型,记忆和密码绝不离开设备。

fix(android): a key saved from the self-check sheet reaches the running brain

booboosui1ae1bd3ebee0
diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
index 4922573..94fced8 100644
--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt
@@ -2110,25 +2110,7 @@ class BodyCoreService : Service() {
if (rebuiltByReset) {
rebuiltByReset = false
} else {
- val after = net.kuafuai.andee.config.VoiceConfig.hubConfig(this)
- val afterBrain = net.kuafuai.andee.config.VoiceConfig.brainConfig(this)
- if (before.url != after.url || before.deviceName != after.deviceName ||
- !beforeBrain.sameBackend(afterBrain)
- ) {
- android.util.Log.i("Body", "brain/hub config changed → restart brain")
- // Restarting the local brain discards the conversation,
- // which is the right trade only when the user changed
- // *who* answers: the key, the endpoint or the mode.
- stopBrain()
- startBrain()
- } else if (beforeBrain != afterBrain) {
- // Model, thinking or effort: the same backend, asked
- // differently on the next request. Rebuilding for this
- // used to wipe a conversation every time the thinking
- // switch was touched.
- android.util.Log.i("Body", "brain tuned in place: model=${afterBrain.model} thinking=${afterBrain.thinking}/${afterBrain.reasoningEffort}")
- localBrain?.retune(afterBrain)
- }
+ reconcileBackendAfterSettings(before, beforeBrain)
}
// The self-check card can be sitting *under* this sheet: its
// 打开设置 row opens us on top of itself. So this picker is
@@ -2842,6 +2824,42 @@ class BodyCoreService : Service() {
* is written either way: it is a log of what happened, not an
* interruption.
*/
+ /**
+ * Re-read the backend after a settings sheet closed, and bounce the brain if
+ * *who answers* changed.
+ *
+ * Public because this service is not the only host that raises a
+ * [SettingsUi]: [net.kuafuai.andee.ui.SelfCheckActivity] raises its own, on
+ * the reasoning that the page only appears when there is no service. That is
+ * true of one of the two ways the page appears and false of the other — it
+ * also appears while this service is running, when only *accessibility* is
+ * missing, and then there is a live brain holding whatever was configured
+ * when it started. Saving a key from that sheet used to write the pref and
+ * leave the ball answering "no key" until the next process start, because
+ * nothing re-read the config.
+ *
+ * Restarting the local brain discards the conversation, which is the right
+ * trade only when the user changed *who* answers: the key, the endpoint or
+ * the mode. Model, thinking and effort are re-applied in place.
+ */
+ fun reconcileBackendAfterSettings(
+ beforeHub: net.kuafuai.andee.config.VoiceConfig.HubConfig,
+ beforeBrain: net.kuafuai.andee.config.BrainConfig,
+ ) {
+ val afterHub = net.kuafuai.andee.config.VoiceConfig.hubConfig(this)
+ val afterBrain = net.kuafuai.andee.config.VoiceConfig.brainConfig(this)
+ if (beforeHub.url != afterHub.url || beforeHub.deviceName != afterHub.deviceName ||
+ !beforeBrain.sameBackend(afterBrain)
+ ) {
+ android.util.Log.i("Body", "brain/hub config changed → restart brain")
+ stopBrain()
+ startBrain()
+ } else if (beforeBrain != afterBrain) {
+ android.util.Log.i("Body", "brain tuned in place: model=${afterBrain.model} thinking=${afterBrain.thinking}/${afterBrain.reasoningEffort}")
+ localBrain?.retune(afterBrain)
+ }
+ }
+
private fun startBrain(announce: Boolean = true) {
val bc = net.kuafuai.andee.config.VoiceConfig.brainConfig(this)
// One line that answers "is my override in effect?" without reading
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
index 9aaa682..3a34da0 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt
@@ -526,10 +526,19 @@ class SelfCheckActivity : StageActivity() {
*
* 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 `BodyCoreService.clearChatHistory`: what that method's second half is
- * *for* is a model still holding the conversation, and on this path nothing
- * is.
+ * call, because the wipes themselves need no brain. That is not a degraded
+ * version of `BodyCoreService.clearChatHistory`: what that method's second
+ * half is *for* is a model still holding the conversation, and on this path
+ * nothing is.
+ *
+ * **"This is the path where there is no service" is only half true**, and
+ * the other half is why [openOwnSettings] now reconciles the backend on
+ * dismiss: the page also appears while the service *is* running — it falls
+ * through whenever [BodyCoreService.ensureOverlays] cannot vouch for the
+ * overlay, which includes the case where accessibility is off but the
+ * service and its brain are alive. Saving a key from this sheet in that
+ * state wrote the pref and left the ball answering "no key" until the next
+ * launch, because nothing re-read the config.
*
* 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
@@ -543,10 +552,17 @@ class SelfCheckActivity : StageActivity() {
*/
private fun openOwnSettings() {
if (settings?.isShowing() == true) return
+ // Snapshot before the sheet opens. This page can be up while the service
+ // is running (see the note above), so the brain that has to be told is
+ // whatever `get()` answers now — not a null check we could skip.
+ val beforeHub = VoiceConfig.hubConfig(this)
+ val beforeBrain = VoiceConfig.brainConfig(this)
val s = SettingsUi(
context = this,
onDismiss = {
settings = null
+ BodyCoreService.get()
+ ?.reconcileBackendAfterSettings(beforeHub, beforeBrain)
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