andengineering / A-D-HDP-Android-Demo

Sample App for connect Android device to A&D Continua Device
www.andonline.com
28 stars 18 forks source link

Android 5.1.1: HDP problems - unable to connect to Bloodpressure device #8

Closed kenneththorman closed 7 years ago

kenneththorman commented 8 years ago

We are experiencing problems connecting to the Bloodpressure device on Android 5.1.1 using BT

We have a quite few medical devices connected to our Android app. Most of these devices are using a proprietary SDK to connect to the device, but 2 devices are not

Both of these devices are using Android HDP (Android implementation of the Continua standard). All proprietary devices/SDKs work on Android 5.1.1. The HDP Bloodpressure device does not (I am not sure if the Precision Scale currently works or not since I do not have one currently in house for testing)

It works on other Android versions, and it does not seem specifically related to the kernel version shipped with the different devices.

We are getting this error in the logcat log

E/BluetoothHealth(14202): Could not bind to Bluetooth Health Service with Intent { act=android.bluetooth.IBluetoothHealth }

which when you do a Google search it indicate that the error is from this class

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothHealth.java#31


/**
 * Public API for Bluetooth Health Profile.
 *
 * <p>BluetoothHealth is a proxy object for controlling the Bluetooth
 * Service via IPC.
 *
 * <p> How to connect to a health device which is acting in the source role.
 *  <li> Use {@link BluetoothAdapter#getProfileProxy} to get
 *  the BluetoothHealth proxy object. </li>
 *  <li> Create an {@link BluetoothHealth} callback and call
 *  {@link #registerSinkAppConfiguration} to register an application
 *  configuration </li>
 *  <li> Pair with the remote device. This currently needs to be done manually
 *  from Bluetooth Settings </li>
 *  <li> Connect to a health device using {@link #connectChannelToSource}. Some
 *  devices will connect the channel automatically. The {@link BluetoothHealth}
 *  callback will inform the application of channel state change. </li>
 *  <li> Use the file descriptor provided with a connected channel to read and
 *  write data to the health channel. </li>
 *  <li> The received data needs to be interpreted using a health manager which
 *  implements the IEEE 11073-xxxxx specifications.
 *  <li> When done, close the health channel by calling {@link #disconnectChannel}
 *  and unregister the application configuration calling
 *  {@link #unregisterAppConfiguration}
 *
 */

I have been searching high and low on Google and not really come up with anything useful

Links

kenneththorman commented 8 years ago

This is with all the lowest level of debugging logging that I can set using logcat

D:\Android\android-sdk\platform-tools>adb logcat bt-btm:V bt-l2cap:V bt-btif:V BluetoothMapService:V BluetoothManagerServvice:V BluetoothHealth:V *:S
--------- beginning of system
--------- beginning of main

This below logline is displayed as soon as the Activity that starts the bluetooth connection to the device is displayed on the screen

E/BluetoothHealth(30083): Could not bind to Bluetooth Health Service with Intent { act=android.bluetooth.IBluetoothHealth }

These below lines show up in the log when the measurement it showing on the Bloodpressure device display, no values are visible on the tablet or phone

W/bt-btm  (10164): btm_acl_role_changed: BDA: 00-09-1f-80-99-17
W/bt-btm  (10164): btm_acl_role_changed: New role: 0
W/bt-btm  (10164): btm_acl_created hci_handle=11 link_role=1  transport=1
W/bt-btm  (10164): btm_acl_created hci_handle=11 link_role=0  transport=1
W/bt-l2cap(10164): L2CAP - st: CLOSED evt: 10
W/bt-l2cap(10164): L2CAP - st: TERM_W4_SEC_COMP evt: 7
W/bt-l2cap(10164): L2CA_ErtmConnectRsp()  CID: 0x0046  Result: 0  Status: 0  BDA: 00091f809917  p_ertm_info:0x00000000
W/bt-l2cap(10164): L2CAP - st: W4_L2CA_CON_RSP evt: 22
W/bt-l2cap(10164): L2CAP - st: CONFIG evt: 24
W/bt-l2cap(10164): L2CAP - st: CONFIG evt: 14
W/bt-l2cap(10164): L2CAP - st: CONFIG evt: 25
W/bt-l2cap(10164): L2CAP-Upper layer Config_Rsp,Local CID: 0x0046,Remote CID: 0x0040,PSM: 1,our MTU present:1,our MTU:768
W/bt-l2cap(10164): L2CAP - st: CONFIG evt: 15
W/bt-l2cap(10164): L2CAP-peer_Config_Rsp,Local CID: 0x0046,Remote CID: 0x0040,PSM: 1,peer MTU present: 0,peer MTU: 672
W/bt-btm  (10164): btm_read_remote_version_complete: BDA: 00-09-1f-80-99-17
W/bt-btm  (10164): btm_read_remote_version_complete lmp_version 4 manufacturer 10 lmp_subversion 64399
W/bt-btif (10164): info:x10
W/bt-l2cap(10164): L2CA_SetDesireRole() new:x0, disallow_switch:0
E/bt-btm  (10164): Ignoring RNR as the state is not BTM_SEC_STATE_GETTING_NAME
W/bt-l2cap(10164): L2CA_DisconnectRsp()  CID: 0x0046
W/bt-l2cap(10164): L2CAP - st: W4_L2CA_DISC_RSP evt: 28
E/bt-btm  (10164): btm_sec_disconnected - Clearing Pending flag
W/bt-l2cap(10164): L2CA_SetDesireRole() new:x0, disallow_switch:0
D/BluetoothMapService(10164): onReceive
D/BluetoothMapService(10164): onReceive, action android.bluetooth.device.action.ACL_DISCONNECTED
kenneththorman commented 8 years ago

Could we work around this issue by using a proprietary SDK for the device or it is only Continua/HDP capable?

asinisalo commented 8 years ago

Short:

Google damaged HDP BT profile about 2 years ago and there is no fix (except rootkitting phone's OS). However this problem is limited to newer Androids + older BT (2/3) device combinations only.

Proprietary SDK's work fine because they use Serial or COMM profiles (but are not Continua).

This problem does not exist in Bluetooth 4.0 (BTLE, BT Smart) and all device manufacturers are upgrading to it.

So focus development in there, old devices in this context are trash.

BR, Ari

From: Kenneth Thorman [mailto:notifications@github.com] Sent: 20. huhtikuuta 2016 12:02 To: andengineering/A-D-HDP-Android-Demo Subject: Re: [andengineering/A-D-HDP-Android-Demo] Android 5.1.1: HDP problems - unable to connect to Bloodpressure device (#8)

Could we work around this issue by using a proprietary SDK for the device or it is only Continua/HDP capable? — You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/andengineering/A-D-HDP-Android-Demo/issues/8#issuecomment-212338492 https://github.com/notifications/beacon/ADvTQtALEixZl3M_qAWoraP-B5pZSOSoks5p5etqgaJpZM4ILZAq.gif

kenneththorman commented 7 years ago

Ok, just as a followup now that I think I have come to the bottom of this with the help of AnD as well as a few other really experienced Bluetooth developers.

To understand what has happened one needs to understand what happened behind the scenes, and it was never officially announced.

Toward the end of 2012, Google switched the Bluetooth stack in Android—for reasons unknown, though there has always been speculation about licensing—from the GPL-licensed BlueZ to the Apache-licensed BlueDroid. That switch was for the release of Android 4.2 (one of the Jelly Bean releases). Since the switch, though, Intel and the BlueZ project have been working to restore the option of running Android with BlueZ, which provides a whole raft of additional features lacking in BlueDroid. Marcel Holtmann of the Intel Open Source Technology Center reported on the BlueZ option at the Android Builders Summit (ABS) held in San Jose, CA, April 29–May 1.

After the October 2012 Android release with BlueDroid, the initial reviews of the new stack were "not that good", Holtmann said, which is not a huge surprise for a completely new Bluetooth stack. As it turns out, based on Google's February 2014 numbers, 73% of Android devices are actually still running BlueZ because they are running earlier releases. The initial release of Google Glass ran BlueZ as well.

(https://lwn.net/Articles/597293/)

The devices that I am referencing in this issue are all Continua / HDP based devices, in order for them to work they require the BlueZ Bluetooth stack. They will not work with the BlueDroid stack.

This is the reason, they work on some devices and not other devices. They will always work on the same hardware model, with the same Android and kernel versions. Meaning if they work on one then they will work on another.

There is no guarantee that it will work on 2 different models hardware with the same Android and kernel versions if the release of these models are years apart. Even if the kernel versions maybe the same, the build number might not be, and it is the specific build configuration for Android that is relevant.

High end devices are typically with the newest version of the OS/Android like 6.0, but 2-3 years later you will be able to buy mid/low end devices with version 6.0.

Even if it worked on the high end with 6.0 it may not work on the much later released models.

So the only way to know if it works is to know how they built the Android/kernel version that is running on the device you are interested in.

There are some guides various places on the internet on how to build the kernel/Android to switch to BlueZ from BlueDroid.

This is not a trivial task.