diff options
author | Sven Gothel <[email protected]> | 2020-06-29 06:39:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-06-29 06:39:03 +0200 |
commit | fe752e88e00739a72a61e28f4df778296f69ce1a (patch) | |
tree | d2598ffed7b27a2459ad0cfc8c51597dca1aa18c /java/direct_bt | |
parent | cb2875cf12344f47eb2640d393483eea464ebea4 (diff) |
DBTDevice.java: Update 'name' on deviceUpdate EIRDataTypeSet.DataType.NAME (drop final qualifier, add volatile)v2.1.9
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().
Diffstat (limited to 'java/direct_bt')
-rw-r--r-- | java/direct_bt/tinyb/DBTDevice.java | 17 |
1 files changed, 15 insertions, 2 deletions
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<DBTAdapter>(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(); } |