Skip to content

Commit

Permalink
Potential workaround for Exynos gatt server implementation
Browse files Browse the repository at this point in the history
Related to #107. Potential workaround for Exynos gatt server implementation
- Existing gattServer instances on devices with the Exynos base chipset do not remove adverts from the same source app
- Affects Exynos version of some Samsung handsets, but not the more prevalent SnapDragon versions
- Only causes an issue in testing if Bluetooth is turned on/off 23 times - a rare occurrence in normal usage
- Without the fix Herald would still allow an affected device to interact with other devices (iOS and Android) thanks to the 'calling card' / write characteristic
- Does not cause an issue for detection unless write characteristic/calling card is disabled (Not done in the Herald code base or library)
- Issue #110 also occurs on Exynos based handsets only
- Committing to develop to allow third party ISV testing today
Signed-off-by: Adam Fowler <[email protected]>
  • Loading branch information
adamfowleruk committed Dec 17, 2020
1 parent a63669b commit f7cd8b6
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class ConcreteBLETransmitter implements BLETransmitter, BluetoothStateMan
private final BLEDatabase database;
private final ExecutorService operationQueue = Executors.newSingleThreadExecutor();

// Referenced by startAdvert and stopExistingGattServer ONLY
private BluetoothGattServer bluetoothGattServer = null;

/**
* Transmitter starts automatically when Bluetooth is enabled.
*/
Expand Down Expand Up @@ -203,13 +206,29 @@ public void accept(Boolean value) {

// MARK:- Start and stop advert

private void stopExistingGattServer() {
if (null != bluetoothGattServer) {
// Stop old version, if there's already a proxy reference
try {
bluetoothGattServer.clearServices();
bluetoothGattServer.close();
bluetoothGattServer = null;
} catch (Throwable e2) {
logger.fault("stopGattServer failed to stop EXISTING GATT server", e2);
bluetoothGattServer = null;
}
}
}

private void startAdvert(final BluetoothLeAdvertiser bluetoothLeAdvertiser, final Callback<Triple<Boolean, AdvertiseCallback, BluetoothGattServer>> callback) {
logger.debug("startAdvert");
operationQueue.execute(new Runnable() {
@Override
public void run() {
boolean result = true;
BluetoothGattServer bluetoothGattServer = null;

stopExistingGattServer();

try {
bluetoothGattServer = startGattServer(logger, context, payloadDataSupplier, database);
} catch (Throwable e) {
Expand Down

0 comments on commit f7cd8b6

Please sign in to comment.