opentok-android-sdk-samples icon indicating copy to clipboard operation
opentok-android-sdk-samples copied to clipboard

API level 31 - Need android.permission.BLUETOOTH_CONNECT permission

Open baole opened this issue 2 years ago • 2 comments

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

baole avatar Jan 26 '22 08:01 baole

@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

DanielGalarza avatar May 11 '22 21:05 DanielGalarza

@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.

baole avatar May 12 '22 13:05 baole

@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.

v-kpheng avatar Oct 26 '22 21:10 v-kpheng

@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?

dimitar-zabaznoski avatar Nov 02 '22 19:11 dimitar-zabaznoski