opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
211 stars 169 forks source link

API level 31 - Need android.permission.BLUETOOTH_CONNECT permission #414

Closed baole closed 1 year ago

baole commented 2 years ago

After update our app's target to API level 31, we get a crash from OpenTok SDK because of missing BLUETOOTH_CONNECT

Fatal Exception: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@70b53eb3: 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.opentok.android.DefaultAudioDevice$6.onServiceConnected(SourceFile:22)
       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:7839)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

This is because the recent changes in API level 31 as described here: https://developer.android.com/guide/topics/connectivity/bluetooth/permissions

We expect OpenTok SDK handles the case where android.permission.BLUETOOTH_CONNECT is not granted by user instead of crashes

DanielGalarza commented 2 years ago

@baole it was fixed in version 2.21.5 https://tokbox.com/developer/sdks/android/release-notes.html

Screen Shot 2022-05-11 at 3 22 09 PM
baole commented 2 years ago

@DanielGalarza

Is there a particular reason that the BLUETOOTH_CONNECT permission is required, even there is no bluetooth device is connected? In the UX perspective, it's really strange to ask the permission for devices that doesn't have a bluetooth headset.

v-kpheng commented 1 year ago

@baole, the permissions were added because they're mandatory for Android 12+. We had to include them in our SDK to provide better bluetooth experience.

Hope that helps.

dimitar-zabaznoski commented 1 year ago

@v-kpheng

We understand Android requires this, but the issue was opened because the OpenTok SDK could/should function even if this permission is not granted. Let them users have bad bluetooth experience if the permission is not granted.

Also, it's a little bit confusing that the documentation says this permission is required, but if the user does not grant it (at runtime) I can still have a normal video call. Could you clearly say in the documentation when should we absolutely request this permission to avoid error? From the start even if no bluetooth device is used?