twilio / audioswitch

An Android audio management library for real-time communication apps.
Apache License 2.0
160 stars 49 forks source link

Cannot use bluetooth headsets when targetSdkVersion < 31 and Build.VERSION >= 31 #127

Closed nredaatepic closed 1 year ago

nredaatepic commented 1 year ago

Describe the bug In adding support for API level 31, commit 07dfe6fd3052ec90346b5700ad08bcc5f5c92e7d introduced logic in BluetoothHeadsetManager.kt to determine a strategy for checking against the new bluetooth permissions.

However, I believe this logic is incorrect - it is checking Build.VERSION, but internally (at least in BluetoothHeadset.java) android checks for targetSdkVersion.

From what I can tell, the BLUETOOTH and BLUETOOTH_CONNECT permissions are mutually exclusive (requesting one denies the other), so it's impossible to pass both of these checks when targetSdkVersion < 31 (fails in BluetoothHeadset.java) and Build.VERSION >= 31 (fails in BluetoothHeadsetManager.kt)

AudioSwitch Version

davidliu commented 1 year ago

As a workaround, you can request the BLUETOOTH permission without specifying a maxSdkVersion, and it should pass since the BLUETOOTH permission can't normally be denied, and will be granted if the targetSdkVersion is <31.

afalls-twilio commented 1 year ago

Thank you @davidliu @nredaatepic for the fix. We would like to offer you something for your contribution... please reach out to afalls@twilio.com

kanclalg commented 1 year ago

@afalls-twilio when are you planning to release this fix?