Catch NetworkState changes correctly

This commit is contained in:
Markus M. May 2018-04-25 22:22:37 +02:00
parent 3fb17e6869
commit 55ea10e88f
2 changed files with 11 additions and 2 deletions

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventChargingState;
import info.nightscout.androidaps.events.EventNetworkChange; import info.nightscout.androidaps.events.EventNetworkChange;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
@ -113,6 +114,7 @@ public class NSClientPlugin extends PluginBase {
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();
context.unbindService(mConnection); context.unbindService(mConnection);
context.unregisterReceiver(networkChangeReceiver);
} }
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
@ -142,6 +144,11 @@ public class NSClientPlugin extends PluginBase {
} }
} }
@Subscribe
public void onStatusEvent(final EventChargingState ev) {
}
@Subscribe @Subscribe
public void onStatusEvent(final EventNetworkChange ev) { public void onStatusEvent(final EventNetworkChange ev) {
boolean wifiOnly = SP.getBoolean(R.string.key_ns_wifionly, false); boolean wifiOnly = SP.getBoolean(R.string.key_ns_wifionly, false);
@ -163,8 +170,10 @@ public class NSClientPlugin extends PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventAppExit ignored) { public void onStatusEvent(final EventAppExit ignored) {
if (nsClientService != null) if (nsClientService != null) {
MainApp.instance().getApplicationContext().unbindService(mConnection); MainApp.instance().getApplicationContext().unbindService(mConnection);
MainApp.instance().getApplicationContext().unregisterReceiver(networkChangeReceiver);
}
} }
@Subscribe @Subscribe

View file

@ -33,7 +33,6 @@ import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
@ -251,6 +250,7 @@ public class NSClientService extends Service {
private Emitter.Listener onDisconnect = new Emitter.Listener() { private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
log.debug("disconnect reason: {}", args);
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event")); MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
} }
}; };