Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.7.0
-
None
Description
Following QTBUG-40172 Android Bluetooth Socket Connection fails in some cases, and the patch: https://codereview.qt-project.org/#/c/90473/, a fallback connection method was introduced, this calls the hidden API method getServiceChannel() on Android's BluetoothDevice class:
jint socketChannel = remoteDevice.callMethod<jint>("getServiceChannel", "(Landroid/os/ParcelUuid;)I", parcelUuid.object()); ... if (socketChannel == remoteDevice.getStaticField<jint>("android/bluetooth/BluetoothDevice", "ERROR")) { qCWarning(QT_BT_ANDROID) << "Cannot determine RFCOMM service channel."; } else { qCWarning(QT_BT_ANDROID) << "Using found rfcomm channel" << socketChannel; channel = socketChannel; }
This method always returns an error since Android 4.4 and in more recent versions is removed, causing the workaround to always fail:
/** @hide */ public int getServiceChannel(ParcelUuid uuid) { //TODO(BT) /* try { return sService.getRemoteServiceChannel(this, uuid); } catch (RemoteException e) {Log.e(TAG, "", e);}*/ return BluetoothDevice.ERROR; }
I am testing an app on a MediaTek tablet and a Samsung tablet both running Android 4.4.2. The Samsung tablet does not require the workaround and connects to my device with no errors, however the MediaTek tablet does and I get the following output:
W/BluetoothAdapter(22349): getBluetoothService() called with no BluetoothManagerCallback D/BluetoothSocket(22349): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[70]} D/BluetoothDevice(22349): mAddress: 00:17:EC:4D:67:D0 W/System.err(22349): java.io.IOException: read failed, socket might closed or timeout, read ret: -1 W/System.err(22349): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:505) W/System.err(22349): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:516) W/System.err(22349): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:320) W/System.err(22349): at dalvik.system.NativeStart.run(Native Method) W/libSophieLITEBluetoothApp.so(22349): (null):0 ((null)): qt.bluetooth.android: Falling back to workaround. W/libSophieLITEBluetoothApp.so(22349): (null):0 ((null)): qt.bluetooth.android: Cannot determine RFCOMM service channel. D/BluetoothDevice(22349): mAddress: 00:17:EC:4D:67:D0 W/libSophieLITEBluetoothApp.so(22349): (null):0 ((null)): qt.bluetooth.android: Workaround thread invoked. D/dalvikvm(22349): threadid=14: bye! D/dalvikvm(22349): threadid=14: interp stack at 0x64f21000 W/BluetoothAdapter(22349): getBluetoothService() called with no BluetoothManagerCallback D/BluetoothSocket(22349): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[72]} W/System.err(22349): java.io.IOException: read failed, socket might closed or timeout, read ret: -1 W/System.err(22349): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:505) W/System.err(22349): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:516) W/System.err(22349): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:320) W/System.err(22349): at dalvik.system.NativeStart.run(Native Method) W/libSophieLITEBluetoothApp.so(22349): (null):0 ((null)): qt.bluetooth.android: Socket connect via workaround failed. D/libSophieLITEBluetoothApp.so(22349): (null):0 ((null)): Socket error: QBluetoothSocket::ServiceNotFoundError D/dalvikvm(22349): threadid=14: bye!
I suspect this is the cause of the error. Could the fallback channel be determined in some other manner, or default to a sensible value e.g. 1?
Attachments
Issue Links
- resulted from
-
QTBUG-40172 Android Bluetooth Socket Connection fails in some cases.
- Closed