From e432346fc53d9d8677826c78eea99c648d2d0507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Mon, 17 Aug 2020 00:21:56 +0200 Subject: [PATCH] Turn RFSpy and RileyLinkBLE into Dagger singletons --- .../medtronic/service/RileyLinkMedtronicService.java | 3 +-- .../pump/omnipod/service/RileyLinkOmnipodService.java | 4 ---- .../hw/rileylink/RileyLinkCommunicationManager.java | 1 - .../plugins/pump/common/hw/rileylink/ble/RFSpy.java | 8 +++++++- .../pump/common/hw/rileylink/ble/RileyLinkBLE.java | 11 ++++++++--- .../common/hw/rileylink/service/RileyLinkService.java | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java index 2342e0aaa5..9013b578f4 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java @@ -40,6 +40,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { @Inject MedtronicUtil medtronicUtil; @Inject MedtronicUIPostprocessor medtronicUIPostprocessor; @Inject MedtronicPumpStatus medtronicPumpStatus; + @Inject RFSpy rfSpy; private MedtronicUIComm medtronicUIComm; private MedtronicCommunicationManager medtronicCommunicationManager; @@ -99,8 +100,6 @@ public class RileyLinkMedtronicService extends RileyLinkService { // get most recently used RileyLink address rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); - rileyLinkBLE = new RileyLinkBLE(injector, this); // or this - rfspy = new RFSpy(injector, rileyLinkBLE); rfspy.startReader(); // init rileyLinkCommunicationManager diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java index 49c629b84e..d44fc80785 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java @@ -14,8 +14,6 @@ import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; @@ -94,8 +92,6 @@ public class RileyLinkOmnipodService extends RileyLinkService { // get most recently used RileyLink address rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); - rileyLinkBLE = new RileyLinkBLE(injector, this); // or this - rfspy = new RFSpy(injector, rileyLinkBLE); rfspy.startReader(); initializeErosOmnipodManager(); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java index 8a47453ad3..aeb77cb014 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java @@ -53,7 +53,6 @@ public abstract class RileyLinkCommunicationManager { public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) { this.injector = injector; - injector.androidInjector().inject(this); this.rfspy = rfspy; } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index dc5e648194..128152aa31 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -5,6 +5,7 @@ import android.os.SystemClock; import java.util.UUID; import javax.inject.Inject; +import javax.inject.Singleton; import dagger.android.HasAndroidInjector; @@ -40,6 +41,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; /** * Created by geoff on 5/26/16. */ +@Singleton public class RFSpy { @Inject AAPSLogger aapsLogger; @@ -64,10 +66,14 @@ public class RFSpy { private Double currentFrequencyMHz; + @Inject public RFSpy(HasAndroidInjector injector, RileyLinkBLE rileyLinkBle) { - injector.androidInjector().inject(this); this.injector = injector; this.rileyLinkBle = rileyLinkBle; + } + + @Inject + public void onInit() { aapsLogger.debug("RileyLinkServiceData:" + rileyLinkServiceData); reader = new RFSpyReader(aapsLogger, rileyLinkBle); } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java index a132218751..77359fe4f9 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java @@ -18,6 +18,7 @@ import java.util.UUID; import java.util.concurrent.Semaphore; import javax.inject.Inject; +import javax.inject.Singleton; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.logging.AAPSLogger; @@ -40,6 +41,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil; * Created by geoff on 5/26/16. * Added: State handling, configuration of RF for different configuration ranges, connection handling */ +@Singleton public class RileyLinkBLE { @Inject AAPSLogger aapsLogger; @@ -58,13 +60,11 @@ public class RileyLinkBLE { private Runnable radioResponseCountNotified; private boolean mIsConnected = false; - + @Inject public RileyLinkBLE(HasAndroidInjector injector, final Context context) { - injector.androidInjector().inject(this); this.context = context; this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter); bluetoothGattCallback = new BluetoothGattCallback() { @Override @@ -257,6 +257,11 @@ public class RileyLinkBLE { }; } + @Inject + public void onInit() { + aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter); + } + private boolean isAnyRileyLinkServiceFound(BluetoothGattService service) { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java index c0ae9d3140..986bbf4d9d 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java @@ -45,10 +45,10 @@ public abstract class RileyLinkService extends DaggerService { @Inject protected ResourceHelper resourceHelper; @Inject protected RileyLinkServiceData rileyLinkServiceData; @Inject protected ActivePluginProvider activePlugin; + @Inject protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management + @Inject protected RFSpy rfspy; // interface for RL xxx Mhz radio. - @NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData protected BluetoothAdapter bluetoothAdapter; - protected RFSpy rfspy; // interface for RL xxx Mhz radio. protected RileyLinkBroadcastReceiver mBroadcastReceiver; protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;