From fe752e88e00739a72a61e28f4df778296f69ce1a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 29 Jun 2020 06:39:03 +0200 Subject: DBTDevice.java: Update 'name' on deviceUpdate EIRDataTypeSet.DataType.NAME (drop final qualifier, add volatile) On rare occasions (?) it may happen that the device discovery didn't include the device's name when reported via deviceFound(..) callback etc. Therefor allow updating of the name, using the C++ DBTDevice::getName(). --- java/direct_bt/tinyb/DBTDevice.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'java/direct_bt') diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java index 8f0b0c4e..c34b8776 100644 --- a/java/direct_bt/tinyb/DBTDevice.java +++ b/java/direct_bt/tinyb/DBTDevice.java @@ -52,8 +52,8 @@ public class DBTDevice extends DBTObject implements BluetoothDevice private final String address; private final BluetoothAddressType addressType; - private final String name; private final long ts_creation; + private volatile String name; long ts_last_discovery; long ts_last_update; @@ -83,8 +83,19 @@ public class DBTDevice extends DBTObject implements BluetoothDevice final AdapterStatusListener statusListener = new AdapterStatusListener() { @Override public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { + if( DEBUG ) { + System.err.println("Device.StatusListener.UPDATED: "+updateMask+" of "+device); + } + final boolean nameUpdated = updateMask.isSet( EIRDataTypeSet.DataType.NAME ); final boolean rssiUpdated = updateMask.isSet( EIRDataTypeSet.DataType.RSSI ); final boolean mdUpdated = updateMask.isSet( EIRDataTypeSet.DataType.MANUF_DATA ); + if( nameUpdated ) { + final String oldName = DBTDevice.this.name; + DBTDevice.this.name = getNameImpl(); + if( DEBUG ) { + System.err.println("Device.StatusListener.UPDATED: NAME: '"+oldName+"' -> '"+DBTDevice.this.name+"'"); + } + } if( rssiUpdated || mdUpdated ) { synchronized(userCallbackLock) { if( rssiUpdated && null != userRSSINotificationsCB ) { @@ -187,8 +198,8 @@ public class DBTDevice extends DBTObject implements BluetoothDevice this.wbr_adapter = new WeakReference(adptr); this.address = address; this.addressType = BluetoothAddressType.get(intAddressType); - this.name = name; this.ts_creation = ts_creation; + this.name = name; ts_last_discovery = ts_creation; ts_last_update = ts_creation; appearance = 0; @@ -258,6 +269,8 @@ public class DBTDevice extends DBTObject implements BluetoothDevice @Override public String getName() { return name; } + private native String getNameImpl(); + @Override public BluetoothType getBluetoothType() { return class_type(); } -- cgit v1.2.3