- fixed NPE in RiuleyLinkStatus History
- added 2 Broadcast Receivers: - TimeDateOrTZChangeReceiver, this one in registered with MainApp in MainApp - RileyLinkBluetoothReceiver, this one is registered with MainApp from RileyLinkService
This commit is contained in:
parent
be05ff3510
commit
7de907f3d6
|
@ -94,6 +94,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||||
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
|
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
|
||||||
|
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver;
|
||||||
import info.nightscout.androidaps.services.Intents;
|
import info.nightscout.androidaps.services.Intents;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import io.fabric.sdk.android.Fabric;
|
import io.fabric.sdk.android.Fabric;
|
||||||
|
@ -122,6 +123,7 @@ public class MainApp extends Application {
|
||||||
private static DBAccessReceiver dbAccessReciever = new DBAccessReceiver();
|
private static DBAccessReceiver dbAccessReciever = new DBAccessReceiver();
|
||||||
private LocalBroadcastManager lbm;
|
private LocalBroadcastManager lbm;
|
||||||
BroadcastReceiver btReceiver;
|
BroadcastReceiver btReceiver;
|
||||||
|
TimeDateOrTZChangeReceiver timeDateOrTZChangeReceiver;
|
||||||
|
|
||||||
public static boolean devBranch;
|
public static boolean devBranch;
|
||||||
public static boolean engineeringMode;
|
public static boolean engineeringMode;
|
||||||
|
@ -163,7 +165,7 @@ public class MainApp extends Application {
|
||||||
|
|
||||||
//trigger here to see the new version on app start after an update
|
//trigger here to see the new version on app start after an update
|
||||||
triggerCheckVersion();
|
triggerCheckVersion();
|
||||||
setBTReceiver();
|
//setBTReceiver();
|
||||||
|
|
||||||
if (pluginsList == null) {
|
if (pluginsList == null) {
|
||||||
pluginsList = new ArrayList<>();
|
pluginsList = new ArrayList<>();
|
||||||
|
@ -265,56 +267,12 @@ public class MainApp extends Application {
|
||||||
|
|
||||||
//register dbaccess
|
//register dbaccess
|
||||||
lbm.registerReceiver(dbAccessReciever, new IntentFilter(Intents.ACTION_DATABASE));
|
lbm.registerReceiver(dbAccessReciever, new IntentFilter(Intents.ACTION_DATABASE));
|
||||||
}
|
|
||||||
|
|
||||||
|
this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
|
||||||
private void setBTReceiver() {
|
this.timeDateOrTZChangeReceiver.registerBroadcasts(this);
|
||||||
|
|
||||||
// RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device,
|
|
||||||
// also detected if timezone/time/date changed and send notification to any active pump driver.
|
|
||||||
btReceiver = new BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
final String action = intent.getAction();
|
|
||||||
|
|
||||||
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
|
||||||
|
|
||||||
if (action != null && activePump != null) {
|
|
||||||
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
|
||||||
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
|
||||||
switch (state) {
|
|
||||||
case BluetoothAdapter.STATE_OFF:
|
|
||||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
|
||||||
case BluetoothAdapter.STATE_TURNING_ON:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_ON: {
|
|
||||||
if ("Medtronic".equals(activePump.manufacter())) {
|
|
||||||
Log.v("MainApp", "Bluetooth on");
|
|
||||||
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
activePump.timeDateOrTimeZoneChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register for broadcasts on BluetoothAdapter state change
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
|
||||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
|
||||||
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
|
||||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
|
||||||
registerReceiver(btReceiver, filter);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void startKeepAliveService() {
|
private void startKeepAliveService() {
|
||||||
if (keepAliveReceiver == null) {
|
if (keepAliveReceiver == null) {
|
||||||
keepAliveReceiver = new KeepAliveReceiver();
|
keepAliveReceiver = new KeepAliveReceiver();
|
||||||
|
@ -502,5 +460,10 @@ public class MainApp extends Application {
|
||||||
if (btReceiver != null) {
|
if (btReceiver != null) {
|
||||||
unregisterReceiver(btReceiver);
|
unregisterReceiver(btReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timeDateOrTZChangeReceiver!=null) {
|
||||||
|
unregisterReceiver(timeDateOrTZChangeReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,10 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshData() {
|
public void refreshData() {
|
||||||
|
if (RileyLinkUtil.getRileyLinkHistory()!=null) {
|
||||||
recyclerViewAdapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory());
|
recyclerViewAdapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
|
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
|
|
||||||
public class BluetoothStateReceiver extends BroadcastReceiver {
|
public class RileyLinkBluetoothStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private static Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
private static Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
||||||
|
|
||||||
|
@ -24,8 +26,6 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
|
|
||||||
LOG.debug("BluetoothStateReceiver");
|
|
||||||
|
|
||||||
if (action != null && activePump != null) {
|
if (action != null && activePump != null) {
|
||||||
|
|
||||||
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
||||||
|
@ -36,15 +36,23 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_ON: {
|
case BluetoothAdapter.STATE_ON: {
|
||||||
if ("Medtronic".equals(activePump.manufacter())) {
|
LOG.debug("RileyLinkBluetoothStateReceiver: Bluetooth back on. Sending broadcast to RileyLink Framework");
|
||||||
LOG.debug("BluetoothStateReceiver: Bluetooth back on. Sending broadcast to RileyLink Framework");
|
|
||||||
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
|
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void unregisterBroadcasts() {
|
||||||
|
MainApp.instance().unregisterReceiver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerBroadcasts() {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
|
MainApp.instance().registerReceiver(this, filter);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -254,4 +254,7 @@ public class RileyLinkBroadcastReceiver extends BroadcastReceiver {
|
||||||
return (L.isEnabled(L.PUMPCOMM));
|
return (L.isEnabled(L.PUMPCOMM));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unregisterBroadcasts() {
|
||||||
|
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public abstract class RileyLinkService extends Service {
|
||||||
protected Context context;
|
protected Context context;
|
||||||
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
|
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
|
||||||
protected RileyLinkServiceData rileyLinkServiceData;
|
protected RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;
|
||||||
|
|
||||||
public RileyLinkService(Context context) {
|
public RileyLinkService(Context context) {
|
||||||
super();
|
super();
|
||||||
|
@ -87,6 +88,15 @@ public abstract class RileyLinkService extends Service {
|
||||||
rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close)
|
rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close)
|
||||||
rileyLinkBLE = null;
|
rileyLinkBLE = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mBroadcastReceiver!=null) {
|
||||||
|
mBroadcastReceiver.unregisterBroadcasts();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bluetoothStateReceiver!=null) {
|
||||||
|
bluetoothStateReceiver.unregisterBroadcasts();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +108,10 @@ public abstract class RileyLinkService extends Service {
|
||||||
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
|
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
|
||||||
mBroadcastReceiver.registerBroadcasts();
|
mBroadcastReceiver.registerBroadcasts();
|
||||||
|
|
||||||
|
|
||||||
|
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
|
||||||
|
bluetoothStateReceiver.registerBroadcasts();
|
||||||
|
|
||||||
//LOG.debug("onCreate(): It's ALIVE!");
|
//LOG.debug("onCreate(): It's ALIVE!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,20 @@ public class InitializePumpManagerTask extends ServiceTask {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
double lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
|
double lastGoodFrequency = 0.0d;
|
||||||
|
|
||||||
|
if (RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency==null) {
|
||||||
|
|
||||||
|
lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
|
||||||
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
|
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
|
||||||
|
|
||||||
RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
|
RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
|
||||||
|
|
||||||
if (RileyLinkUtil.getRileyLinkTargetFrequency() == null) {
|
// if (RileyLinkUtil.getRileyLinkTargetFrequency() == null) {
|
||||||
String pumpFrequency = SP.getString(MedtronicConst.Prefs.PumpFrequency, null);
|
// String pumpFrequency = SP.getString(MedtronicConst.Prefs.PumpFrequency, null);
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
lastGoodFrequency = RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lastGoodFrequency > 0.0d)
|
if ((lastGoodFrequency > 0.0d)
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
package info.nightscout.androidaps.receivers;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
@ -29,4 +32,14 @@ public class TimeDateOrTZChangeReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerBroadcasts(MainApp mainApp) {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||||
|
mainApp.registerReceiver(this, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue