Bolo 麥克風按鈕在鍵盤仍開啟時消失:如何避免把同一訊號當成確認證據
The mic vanished over an open keyboard: when 'I can't see the keyboard' is not evidence the keyboard closed
Bolo 修正了浮動麥克風按鈕在螢幕鍵盤仍開啟時消失的錯誤,原因是一次暫時性的鍵盤偵測結果關閉了視窗追蹤,之後的確認便無法獨立判斷鍵盤狀態。新規則只在追蹤仍開啟時才把「沒有鍵盤」視為證據,並在麥克風仍顯示時禁止停止追蹤。測試重現舊錯誤,並驗證修正後麥克風會在鍵盤保持開啟時繼續顯示。
Disclosure: I'm the developer of Bolo, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the project's source code.
Bolo (search "Bolo AI" on Google Play) shows a small floating mic next to a text field, only while the on-screen keyboard is open. A bug report said: close the keyboard, open it, close it, open it again quickly, and the mic is gone while the keyboard is plainly on screen. The phone log made the cause clear, and it is a pattern worth knowing: one signal was being used to switch itself off and then used as proof.
The log, in four lines
- The input restarted after a send.
- A safety check read "keyboard may be gone": one transient read while the keyboard re-laid out.
- The same check switched window tracking off, to save battery.
- With tracking off, the list of windows the service can see is empty. Every confirming check then also read "no keyboard", so the mic was hidden over an open keyboard.
The confirmation was not independent. Its answer was produced by step 3.
The rule that fixes it
Two small functions, kept in one object so they can be tested without a phone:
internal object WindowTrackingPolicy {
fun mayStopTracking(trackingOn: Boolean, keyboardSeen: Boolean, bubbleShowing: Boolean) =
trackingOn && !keyboardSeen && !bubbleShowing
fun canConfirmKeyboardGone(trackingOn: Boolean) = trackingOn
}
- "No keyboard" counts as evidence only while tracking is on. An empty window list with tracking off means "I am not looking", not "it is closed".
- Tracking may stop only once no mic is on screen. The battery saving is for after the mic is hidden, never what hides it.
And in the delayed hide, if tracking is off, the service turns it on and re-checks instead of hiding:
if (bubbleManager.isShowing() && !WindowTrackingPolicy.canConfirmKeyboardGone(windowTrackingEnabled)) {
setWindowTracking(true)
schedulePendingHide(KEYBOARD_CLOSE_CONFIRM_MS)
return@Runnable}```
## Test it by replaying the log
The test does not mock Android. It models only the parts that decide the mic (tracking flag, mic showing, "keyboard seen" cache) and replays the real timeline, once with the old rule and once with the new one:
```kotlin
@Test fun `old rule hides the mic over an open keyboard`() {
val old = Replay(newRule = false); runLog(old)
assertFalse(old.tracking); assertFalse(old.bubbleShowing)
}
@Test fun `new rule keeps the mic while the keyboard stays open`() {
val fixed = Replay(newRule = true); runLog(fixed)
assertTrue(fixed.tracking); assertTrue(fixed.bubbleShowing)
}
Keeping the old-rule test is deliberate: it proves the replay reproduces the bug, so the passing new-rule test means something. Two more tests pin the other directions: close-open-open (the last state wins) and a real close (the mic still hides, and tracking then stops).
The general lesson
When a check can change the conditions under which later checks run, a confirmation taken afterwards is not a second opinion. Either re-establish the conditions before confirming, or never let the check that saves resources run while the thing it affects is still on screen.
Bolo's Accessibility use is limited to detecting text fields so the mic can appear next to them.
Made by the developer whose account published this; drafted and published by an AI agent.
來源:DEV Community · dev.to