Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash due to missing BLUETOOTH_CONNECT permission on Sony Xperia 1/5 IV with Android 13 #25

Open
mlewandowskipt opened this issue Jun 6, 2023 · 0 comments

Comments

@mlewandowskipt
Copy link

Hi, we get following crash on app startup:

Fatal Exception: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@21d96a8c: AdapterService getRemoteName
       at com.android.bluetooth.Utils.checkPermissionForDataDelivery(Utils.java:460)
       at com.android.bluetooth.Utils.checkConnectPermissionForDataDelivery(Utils.java:492)
       at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getRemoteName(AdapterService.java:3031)
       at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.getRemoteName(AdapterService.java:3022)
       at android.bluetooth.IBluetooth$Stub.onTransact(IBluetooth.java:1219)
       at android.os.Binder.execTransactInternal(Binder.java:1285)
       at android.os.Binder.execTransact(Binder.java:1244)

We've spotted this in our crash reporting system and also users report this. The crash occurs only on two devices:

  • Sony Xperia 1 IV
  • Sony Xperia 5 IV

with Android 13 (but I guess it could be also Android 12).

While this looks like an OS-specific issue, or at least "different, more rigorous behavior", we obviously can't wait for Sony to fix this so we're looking for fix/workaround on our side.

We can't say for 100% that this crash is caused by Voxeet, but there's no other library in our app that may call Bluetooth APIs. Also we don't have any of those devices so we can't verify if detaching Voxeet from the app fixes the crash.

But what I've spotted in the code is that despite of some changes that were done when adjusting Voxeet SDK Android and Voxeet SDK Android Audio to not crash when BLUETOOTH_CONNECT is not granted, there are still some android.bluetooth.* APIs called from Voxeet that don't catch SecurityException.

I'm looking at BluetoothHeadsetServiceListener and in the constructor I can see following code

try {
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
} catch (VerifyError exception) {
    Log.e(TAG, "BluetoothHeadsetMachine: VerifyError exception for this device. Please report", exception);
    bluetoothAdapter = null;
    exception.printStackTrace();
}

As you can see there's a call to obtain BluetoothAdapter and it doesn't catch SecurityException, only VerifyError. This looks somehow related to the crash stacktrace where we can see AdapterService class. Not sure if this is the only place, there could be other ones.

I'm wondering if Voxeet SDK could be more cautious when it comes to using any Bluetooth system API. I mean, any call to android.bluetooth.* could be wrapped with try-catch block, so that any error raised by it won't stop the app from working, as Bluetooth is not a necessary functionality for the app/Voxeet SDK to work.

Let me know if you need any more details/information. We're using Voxeet Android SDK 3.8.0 at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant