diff options
Diffstat (limited to 'java/direct_bt/tinyb/DBTAdapter.java')
-rw-r--r-- | java/direct_bt/tinyb/DBTAdapter.java | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java index 637fec05..46879a67 100644 --- a/java/direct_bt/tinyb/DBTAdapter.java +++ b/java/direct_bt/tinyb/DBTAdapter.java @@ -87,24 +87,41 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter @Override public synchronized void close() { + close(false); + } + + /* pp */ synchronized void close(final boolean isShutdown) { if( !isValid() ) { return; } - stopDiscovery(); + if( !isShutdown ) { // avoid all interaction @ JVM shutdown, native dtor (deleteImpl) cleans up. - final List<BluetoothDevice> devices = getDevices(); - for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) { - final BluetoothDevice d = id.next(); - d.close(); - } + // mute all listener first + removeAllStatusListener(); + disableDiscoverableNotifications(); + disableDiscoveringNotifications(); + disablePairableNotifications(); + disablePoweredNotifications(); + + stopDiscovery(); + + final List<BluetoothDevice> devices = getDevices(); + for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) { + final DBTDevice d = (DBTDevice) id.next(); + d.close( false ); + } + + // done in native dtor: removeDevicesImpl(); - removeAllStatusListener(); - disableDiscoverableNotifications(); - disableDiscoveringNotifications(); - disablePairableNotifications(); - disablePoweredNotifications(); + } else { - removeDevicesImpl(); + final List<BluetoothDevice> devices = getDevices(); + for(final Iterator<BluetoothDevice> id = devices.iterator(); id.hasNext(); ) { + final DBTDevice d = (DBTDevice) id.next(); + d.close( true ); + } + + } discoveredDevices.clear(); super.close(); |