From 3bb1a228ec778999bdad1664dc64e320e280e960 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Tue, 5 Jul 2016 21:48:10 +0200 Subject: [PATCH] Fix crash during device discovery --- .../gadgetbridge/activities/ControlCenter.java | 2 +- .../gadgetbridge/devices/DeviceManager.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java index 47c94ff8c..73fd863c8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java @@ -82,7 +82,7 @@ public class ControlCenter extends GBActivity { }; private void refreshBusyState(GBDevice dev) { - if (dev.isBusy()) { + if (dev != null && dev.isBusy()) { swipeLayout.setRefreshing(true); } else { boolean wasBusy = swipeLayout.isRefreshing(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java index a5f37715e..994889316 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java @@ -5,6 +5,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; import org.slf4j.Logger; @@ -86,12 +87,13 @@ public class DeviceManager { if (selectedDevice == null) { selectedDevice = dev; } else { - if (!selectedDevice.equals(dev)) { + if (selectedDevice.equals(dev)) { + selectedDevice = dev; // equality vs identity! + } else { if (selectedDevice.isConnected() && dev.isConnected()) { LOG.warn("multiple connected devices -- this is currently not really supported"); selectedDevice = dev; // use the last one that changed - } - if (!selectedDevice.isConnected()) { + } else if (!selectedDevice.isConnected()) { selectedDevice = dev; // use the last one that changed } } @@ -118,6 +120,7 @@ public class DeviceManager { return Collections.unmodifiableList(deviceList); } + @Nullable public GBDevice getSelectedDevice() { return selectedDevice; }