twilio / audioswitch

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

Android 12 BLUETOOTH_CONNECT permission #101

Closed dostalleos closed 2 years ago

dostalleos commented 2 years ago

Could you please add Android 12 support? When targeting Android 12, AudioSwitch causes app to crash, because of missing BLUETOOTH_CONNECT permission. Please see stack trace bellow.

I know that I can add this permission myself, but I do not want bother users with this permissions request, just because they might have BT headphones. Is it really necessary to request this permission?

Thank you

java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@509fd176: HeadsetService
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
        at android.os.Parcel.createException(Parcel.java:2409)
        at android.os.Parcel.readException(Parcel.java:2392)
        at android.os.Parcel.readException(Parcel.java:2334)
        at android.bluetooth.IBluetoothHeadset$Stub$Proxy.getConnectedDevicesWithAttribution(IBluetoothHeadset.java:1040)
        at android.bluetooth.BluetoothHeadset.getConnectedDevices(BluetoothHeadset.java:549)
        at com.twilio.audioswitch.bluetooth.BluetoothHeadsetManager.onServiceConnected(BluetoothHeadsetManager.kt:86)
        at android.bluetooth.BluetoothHeadset$3.handleMessage(BluetoothHeadset.java:1422)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
mrea1 commented 2 years ago

We are also seeing this issue. It would be a pretty bad user experience to request Bluetooth every time, when only a small subset of users use Bluetooth with our app

And with Android 12 dropping any day now, this is high priority for us

4brunu commented 2 years ago

Same issue here. Maybe @paynerc or @aaalaniz can help with this?

mrea1 commented 2 years ago

Checking in - any ETA on this one?

4brunu commented 2 years ago

There is a draft PR that is related to this issue https://github.com/twilio/audioswitch/pull/102

afalls-twilio commented 2 years ago

This issue is fixed in the release version 1.1.3.

mykola-tarchanyn commented 2 years ago

Looks like 1.1.3 has side effects that will lead to a crash. I filled a separate ticket about it. cc @afalls-twilio @4brunu

PeterLecky commented 2 years ago

I am using latest version (1.5) in the project which is compiled against lower api and bluetooth crash mentioned in the description of this bug still happens when running on android 12 also in situation when i have required permission.