kable icon indicating copy to clipboard operation
kable copied to clipboard

Wrap Android connect permission failures

Open himu-gupta opened this issue 5 months ago • 1 comments

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 783b21dd921fc925b210f391af9fefbf5bec53a5. Configure here.

himu-gupta avatar Jun 12 '26 23:06 himu-gupta

@cursor review

himu-gupta avatar Jun 12 '26 23:06 himu-gupta