Describe the bug
AudioSwitch crashes if bluetooth permission is denied with targetSDK <= 30 but device version >= 30.
To Reproduce
Steps to reproduce the behavior:
App must be targetSdkVersion <= 30.
Deploy to a phone with version Android 12 above (>API 30)
In settings, manually disable the nearby devices (bluetooth) permission.
Call AudioSwitch.start()
Expected behavior
App should not crash, and AudioSwitch should start without bluetooth capabilities.
Actual behavior
App crashes.
Application Logs
09-12 19:46:21.096 12135 12135 D AS/AudioSwitch: AudioSwitch(1.1.5)
09-12 19:46:21.097 12135 12135 D AS/AudioSwitch: Preferred device list = [BluetoothHeadset, WiredHeadset, Speakerphone, Earpiece]
09-12 19:46:21.098 12135 12135 D AndroidRuntime: Shutting down VM
09-12 19:46:21.099 12135 12135 E AndroidRuntime: FATAL EXCEPTION: main
09-12 19:46:21.099 12135 12135 E AndroidRuntime: Process: com.livekit_demo, PID: 12135
09-12 19:46:21.099 12135 12135 E AndroidRuntime: java.lang.SecurityException: Need BLUETOOTH permission
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.bluetooth.BluetoothHeadset.<init>(BluetoothHeadset.java:379)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.bluetooth.BluetoothAdapter.getProfileProxy(BluetoothAdapter.java:3017)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.twilio.audioswitch.bluetooth.BluetoothHeadsetManager.start(BluetoothHeadsetManager.kt:156)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.twilio.audioswitch.AudioSwitch.start(AudioSwitch.kt:160)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.livekit.reactnative.audio.AudioSwitchManager.lambda$start$2$AudioSwitchManager(AudioSwitchManager.java:67)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.livekit.reactnative.audio.-$$Lambda$AudioSwitchManager$fFICgN134BrX9CXU0E4mntsl1q8.run(Unknown Source:2)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7870)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
09-12 19:46:21.099 12135 12135 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
AudioSwitch Version
Version: 1.1.5
Android Device (please complete the following information):
Device: Pixel 4
API Version: Android 12
Additional context
Looks like the current method of checking just the device API version is insufficient. The current app's targetSdkVersion should also be checked as well, and if the targetSdkVersion <= 30, the BLUETOOTH permission should be checked instead.
On a side note, looks like disabling the bluetooth permission in this manner is irreversible.
Describe the bug AudioSwitch crashes if bluetooth permission is denied with targetSDK <= 30 but device version >= 30.
To Reproduce Steps to reproduce the behavior:
Expected behavior App should not crash, and AudioSwitch should start without bluetooth capabilities.
Actual behavior App crashes.
Application Logs
AudioSwitch Version
Android Device (please complete the following information):
Additional context Looks like the current method of checking just the device API version is insufficient. The current app's targetSdkVersion should also be checked as well, and if the targetSdkVersion <= 30, the BLUETOOTH permission should be checked instead.
On a side note, looks like disabling the bluetooth permission in this manner is irreversible.