Skip to content

Bluetooth MIC detection logic fixes. Add "Always use Bluetooth mic when available" setting with related state management.#157

Open
Dimowner wants to merge 1 commit into
feature/v2_2_0from
fix_bluetooth_mic_detection
Open

Bluetooth MIC detection logic fixes. Add "Always use Bluetooth mic when available" setting with related state management.#157
Dimowner wants to merge 1 commit into
feature/v2_2_0from
fix_bluetooth_mic_detection

Conversation

@Dimowner

@Dimowner Dimowner commented Jul 4, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a new "Always use Bluetooth mic when available" feature, allowing users to automatically enable Bluetooth microphone routing whenever a compatible device is connected. It also improves the reliability and safety of Bluetooth audio routing by centralizing and safeguarding routing state transitions. The changes span UI, preferences, state management, and the audio helper logic.

Bluetooth mic auto-enable feature:

  • Added a new preference and UI checkbox for "Always use Bluetooth mic when available", with corresponding state management in HomeViewModel and persistence in preferences. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Bluetooth audio routing reliability and safety:

  • Centralized logic for enabling/disabling Bluetooth routing into a new disableBluetoothRouting() method in AudioManagerHelper, ensuring that audio mode and device state are only changed when this helper enabled routing, preventing side effects with other apps. [1] [2] [3] [4] [5] [6]
  • Improved state tracking with the new isCommunicationDeviceSet flag to avoid clobbering the global audio mode and to safely restore previous audio states. [1] [2]

UI and state management updates:

  • Updated BluetoothMicSelector and its usages to support the new "always use" checkbox and wire up callbacks for preference changes. [1] [2] [3] [4]
  • Ensured the Home screen preserves Bluetooth mic state across resets, preventing loss of device information and auto-enable state.

Testing and defaults:

  • Added tests for the new preference to ensure correct default and persistence behavior.
  • Set the default value for the "always use Bluetooth mic" preference to false.

Minor improvements:

  • Fixed type usage in tests for obtaining resources. [1] [2]

Other bugs fixed in AudioManagerHelper

  1. Audio-mode corruption on repeated enable (API 31+): enabling twice captured MODE_IN_COMMUNICATION as the "previous" mode, so disabling could never restore the original mode. Now the mode is only captured when routing
    isn't already active, tracked via a new isCommunicationDeviceSet flag.
  2. Global audio state stomped when never enabled: onAudioDevicesRemoved, enableBluetoothMic(false), and release() unconditionally called clearCommunicationDevice() and reset the audio mode — even if the app never enabled
    routing (which could interfere with, e.g., an ongoing call). All cleanup now goes through one disableBluetoothRouting() that only undoes what the helper actually set.
  3. Stuck MODE_IN_COMMUNICATION after device loss: cleanup previously only ran if the explicitly selected device was removed. If the user just toggled the switch (no explicit selection) and the buds disconnected, SCO/audio
    mode were never reset. Now routing is disabled whenever it's active and the last Bluetooth input device disappears.
  4. Selecting a device while enabled did nothing: picking a different device from the dropdown only updated the selection; routing stayed on the old device until toggled off/on. selectBluetoothDevice() now re-routes
    immediately when routing is active (API 31+).

…en available" setting with related state management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant