diff options
author | Sven Gothel <[email protected]> | 2020-07-22 02:31:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-22 02:31:17 +0200 |
commit | 8b08db6177dc2e5ce6df69d6ea3589a53158b173 (patch) | |
tree | 05a361d12fa024dccd7844389d240f797983098e /java/direct_bt/tinyb/DBTDevice.java | |
parent | 60e72dd2776dfd3649a791ad5f8dbab20c77cc1e (diff) |
Java DBTAdapter + DBTDevice close @ JVM shutdown: Avoid all interaction, native dtor (deleteImpl) cleans up.
Shortcut of 'close' take-down @ JVM shutdown, avoiding any potential deadlocks.
However, all device's and adapter's deleteImpl() gets issued,
allowing the native adapter's destructor to be called for orderly device cleanup.
Diffstat (limited to 'java/direct_bt/tinyb/DBTDevice.java')
-rw-r--r-- | java/direct_bt/tinyb/DBTDevice.java | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/java/direct_bt/tinyb/DBTDevice.java b/java/direct_bt/tinyb/DBTDevice.java index a98636bb..1f9ec3be 100644 --- a/java/direct_bt/tinyb/DBTDevice.java +++ b/java/direct_bt/tinyb/DBTDevice.java @@ -233,30 +233,36 @@ public class DBTDevice extends DBTObject implements BluetoothDevice @Override public synchronized void close() { + close(false); + } + + /* pp */ synchronized void close(final boolean isShutdown) { if( !isValid() ) { return; } - disconnect(); + if( !isShutdown ) { // avoid all interaction @ JVM shutdown, native dtor (deleteImpl) cleans up. + disconnect(); - disableConnectedNotifications(); - disableRSSINotifications(); - disableManufacturerDataNotifications(); - disableServicesResolvedNotifications(); + disableConnectedNotifications(); + disableRSSINotifications(); + disableManufacturerDataNotifications(); + disableServicesResolvedNotifications(); - disableBlockedNotifications(); - disableBlockedNotificationsImpl(); - disablePairedNotifications(); - disablePairedNotificationsImpl(); - disableServiceDataNotifications(); - disableTrustedNotifications(); - // FIXME disableTrustedNotificationsImpl(); + disableBlockedNotifications(); + disableBlockedNotificationsImpl(); + disablePairedNotifications(); + disablePairedNotificationsImpl(); + disableServiceDataNotifications(); + disableTrustedNotifications(); + // FIXME disableTrustedNotificationsImpl(); - clearServiceCache(); + clearServiceCache(); - final DBTAdapter a = getAdapter(); - if( null != a ) { - a.removeStatusListener(statusListener); - a.removeDiscoveredDevice(this); + final DBTAdapter a = getAdapter(); + if( null != a ) { + a.removeStatusListener(statusListener); + a.removeDiscoveredDevice(this); + } } super.close(); } |