Skip to content

Wrap Android connect permission failures#1167

Open
himu-gupta wants to merge 3 commits into
JuulLabs:mainfrom
himu-gupta:fix/android-connect-permission-exception
Open

Wrap Android connect permission failures#1167
himu-gupta wants to merge 3 commits into
JuulLabs:mainfrom
himu-gupta:fix/android-connect-permission-exception

Conversation

@himu-gupta

@himu-gupta himu-gupta commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • translate SecurityException from Android connectGatt() into IllegalStateException
  • preserve the original exception as the cause and release threading resources before propagating the failure
  • add Android host regression coverage for a missing BLUETOOTH_CONNECT permission

Closes #1166

Verification

  • ./gradlew :kable-core:lintKotlinAndroidMain :kable-core:lintKotlinAndroidHostTest :kable-core:testAndroidHostTest
  • ./gradlew assemble -PsuppressWarnings=true
  • ./gradlew -PRELEASE_SIGNING_ENABLED=false publishToMavenLocal
  • ./gradlew check progressed through Rust, JVM, Android, JS, Wasm, iOS, and macOS verification; local execution stopped only because Xcode lacks the watchOS simulator SDK required by watchosSimulatorArm64Test

Note

Medium Risk
Touches core connect/cancellation paths on Android and in shared peripheral logic; behavior changes for callers that relied on broad IllegalStateException handling in awaitConnect.

Overview
Android connectGatt() SecurityExceptions (e.g. missing BLUETOOTH_CONNECT) are now turned into IllegalStateException with the original exception as cause, and threading is released before the error propagates.

awaitConnect no longer treats every IllegalStateException as a cancelled peripheral. It catches CancellationException and InactiveScopeException separately so real connect failures (including the new permission wrapper) surface unchanged, while disconnect/cancel still map to "Cannot connect peripheral that has been cancelled". SharedRepeatableAction throws InactiveScopeException when the parent scope is inactive instead of using check().

Regression tests cover Android connect permission failure and common awaitConnect behavior (preserved IllegalStateException, inactive scope, cancelled action).

Reviewed by Cursor Bugbot for commit 783b21d. Configure here.

@himu-gupta himu-gupta requested review from a team and twyatt as code owners June 12, 2026 23:04
@himu-gupta himu-gupta requested a review from Phoenix7351 June 12, 2026 23:04
Comment thread kable-core/src/androidMain/kotlin/BluetoothDevice.kt
@himu-gupta

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 783b21d. Configure here.

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.

Android: Missing android.permission.BLUETOOTH_CONNECT bubbles up as java.lang.SecurityException

1 participant