aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-29 06:39:03 +0200
committerSven Gothel <[email protected]>2020-06-29 06:39:03 +0200
commitfe752e88e00739a72a61e28f4df778296f69ce1a (patch)
treed2598ffed7b27a2459ad0cfc8c51597dca1aa18c
parentcb2875cf12344f47eb2640d393483eea464ebea4 (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().
-rw-r--r--java/direct_bt/tinyb/DBTDevice.java17
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx11
2 files changed, 26 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(); }
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index e0acb004..808a3e2e 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -146,6 +146,17 @@ void Java_direct_1bt_tinyb_DBTDevice_initImpl(JNIEnv *env, jobject obj)
}
}
+jstring Java_direct_1bt_tinyb_DBTDevice_getNameImpl(JNIEnv *env, jobject obj) {
+ try {
+ DBTDevice *nativePtr = getInstance<DBTDevice>(env, obj);
+ JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
+ return from_string_to_jstring(env, nativePtr->getName());
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return nullptr;
+}
+
jstring Java_direct_1bt_tinyb_DBTDevice_toStringImpl(JNIEnv *env, jobject obj) {
try {
DBTDevice *nativePtr = getInstance<DBTDevice>(env, obj);