mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
dispose DeviceSupports if connect() throws an exception (#5045)
This commit is contained in:
+20
-11
@@ -719,20 +719,29 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
}
|
||||
|
||||
if (deviceSupport != null) {
|
||||
final boolean connected;
|
||||
if (firstTime) {
|
||||
connected = deviceSupport.connectFirstTime();
|
||||
} else {
|
||||
deviceSupport.setAutoReconnect(autoReconnect);
|
||||
deviceSupport.setScanReconnect(reconnectViaScan);
|
||||
if (BuildConfig.DEBUG) {
|
||||
connected = stressTestConnect(deviceSupport);
|
||||
try {
|
||||
final boolean connected;
|
||||
if (firstTime) {
|
||||
connected = deviceSupport.connectFirstTime();
|
||||
} else {
|
||||
connected = deviceSupport.connect();
|
||||
deviceSupport.setAutoReconnect(autoReconnect);
|
||||
deviceSupport.setScanReconnect(reconnectViaScan);
|
||||
if (BuildConfig.DEBUG) {
|
||||
connected = stressTestConnect(deviceSupport);
|
||||
} else {
|
||||
connected = deviceSupport.connect();
|
||||
}
|
||||
}
|
||||
LOG.debug("connectToDevice - {} connected:{} firstTime:{}", deviceAddress,
|
||||
connected, firstTime);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
deviceSupport.dispose();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
registeredStruct.setDeviceSupport(null);
|
||||
throw e;
|
||||
}
|
||||
LOG.debug("connectToDevice - {} connected:{} firstTime:{}", deviceAddress,
|
||||
connected, firstTime);
|
||||
} else {
|
||||
GB.toast(this, getString(R.string.cannot_connect, "Can't create device support"), Toast.LENGTH_SHORT, GB.ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user