Skip to content

Fix: Stop auto-connect from retrying when blocked by Android#460

Merged
d4rken merged 1 commit intomainfrom
fix/autoconnect-security-exception
Mar 23, 2026
Merged

Fix: Stop auto-connect from retrying when blocked by Android#460
d4rken merged 1 commit intomainfrom
fix/autoconnect-security-exception

Conversation

@d4rken
Copy link
Member

@d4rken d4rken commented Mar 23, 2026

What changed

Fixed auto-connect repeatedly failing every second on newer Android versions. The app now detects when the connection method is blocked by the OS and stops retrying. Also added a note in the setting description that this feature may not work on newer Android versions.

Technical Context

  • Root cause: BluetoothHeadset.connect() is a hidden API that now requires MODIFY_PHONE_STATE — a system-only permission that third-party apps cannot obtain. Confirmed on both Samsung S22 Ultra and Pixel 8 running Android 16.
  • On failure, nudgeConnection was silently returning false without distinguishing permanent from transient failures. AutoConnect would retry on every BLE scan result (~1s), spamming the same SecurityException indefinitely.
  • Fix detects SecurityException (direct or wrapped in InvocationTargetException) and sets isNudgeAvailable = false for the process lifetime. AutoConnect checks this flag before calling nudgeConnection.
  • There is no viable public API alternative for programmatic Bluetooth audio profile connection from third-party apps. CompanionDeviceManager, GATT, intents — none can trigger HFP/A2DP connection.

BluetoothHeadset.connect() requires MODIFY_PHONE_STATE on modern Android, which is a system-only permission. Detect the SecurityException and stop further attempts instead of retrying every second.
@d4rken d4rken added the bug Something isn't working label Mar 23, 2026
@d4rken d4rken merged commit 53447f3 into main Mar 23, 2026
10 checks passed
@d4rken d4rken deleted the fix/autoconnect-security-exception branch March 23, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant