Merge remote-tracking branch 'origin/dagger3' into rs
This commit is contained in:
commit
e31d2041e3
57 changed files with 574 additions and 503 deletions
|
@ -78,6 +78,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
@Inject AAPSLogger aapsLogger;
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject RxBusWrapper rxBus;
|
@Inject RxBusWrapper rxBus;
|
||||||
|
@Inject AndroidPermission androidPermission;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject VersionCheckerUtils versionCheckerUtils;
|
@Inject VersionCheckerUtils versionCheckerUtils;
|
||||||
|
@ -161,12 +162,12 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidPermission.notifyForStoragePermission(this);
|
androidPermission.notifyForStoragePermission(this);
|
||||||
AndroidPermission.notifyForBatteryOptimizationPermission(this);
|
androidPermission.notifyForBatteryOptimizationPermission(this);
|
||||||
if (Config.PUMPDRIVERS) {
|
if (Config.PUMPDRIVERS) {
|
||||||
AndroidPermission.notifyForLocationPermissions(this);
|
androidPermission.notifyForLocationPermissions(this);
|
||||||
AndroidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin);
|
androidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin);
|
||||||
AndroidPermission.notifyForSystemWindowPermissions(this);
|
androidPermission.notifyForSystemWindowPermissions(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,9 +114,6 @@ public class MainApp extends DaggerApplication {
|
||||||
|
|
||||||
static DatabaseHelper sDatabaseHelper = null;
|
static DatabaseHelper sDatabaseHelper = null;
|
||||||
|
|
||||||
DataReceiver dataReceiver = new DataReceiver();
|
|
||||||
TimeDateOrTZChangeReceiver timeDateOrTZChangeReceiver;
|
|
||||||
|
|
||||||
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
|
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
|
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
|
@ -330,23 +327,28 @@ public class MainApp extends DaggerApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerLocalBroadcastReceiver() {
|
private void registerLocalBroadcastReceiver() {
|
||||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
|
IntentFilter filter = new IntentFilter();
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
filter.addAction(Intents.ACTION_NEW_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
|
filter.addAction(Intents.ACTION_CHANGED_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
|
filter.addAction(Intents.ACTION_REMOVED_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
|
filter.addAction(Intents.ACTION_NEW_SGV);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
|
filter.addAction(Intents.ACTION_NEW_PROFILE);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
|
filter.addAction(Intents.ACTION_NEW_MBG);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
|
filter.addAction(Intents.ACTION_NEW_CAL);
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(new DataReceiver(), filter);
|
||||||
|
|
||||||
this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
|
filter = new IntentFilter();
|
||||||
this.timeDateOrTZChangeReceiver.registerBroadcasts(this);
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||||
|
registerReceiver(new TimeDateOrTZChangeReceiver(), filter);
|
||||||
|
|
||||||
|
filter = new IntentFilter();
|
||||||
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
|
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
|
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||||
|
registerReceiver(new NetworkChangeReceiver(), filter);
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
|
||||||
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
||||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
||||||
registerReceiver(new NetworkChangeReceiver(), intentFilter);
|
|
||||||
registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,11 +423,7 @@ public class MainApp extends DaggerApplication {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTerminate() {
|
public void onTerminate() {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.CORE, "onTerminate");
|
aapsLogger.debug(LTag.CORE, "onTerminate");
|
||||||
|
|
||||||
if (timeDateOrTZChangeReceiver != null)
|
|
||||||
unregisterReceiver(timeDateOrTZChangeReceiver);
|
|
||||||
unregisterActivityLifecycleCallbacks(activityMonitor);
|
unregisterActivityLifecycleCallbacks(activityMonitor);
|
||||||
keepAliveManager.cancelAlarm(this);
|
keepAliveManager.cancelAlarm(this);
|
||||||
super.onTerminate();
|
super.onTerminate();
|
||||||
|
|
|
@ -3,14 +3,18 @@ package info.nightscout.androidaps.dependencyInjection
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkBluetoothStateReceiver
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkBluetoothStateReceiver
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver
|
import info.nightscout.androidaps.receivers.KeepAliveReceiver
|
||||||
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||||
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
|
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
abstract class ReceiversModule {
|
abstract class ReceiversModule {
|
||||||
|
|
||||||
|
@ContributesAndroidInjector abstract fun contributesDataReceiver(): DataReceiver
|
||||||
@ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver
|
@ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver
|
||||||
@ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver
|
@ContributesAndroidInjector abstract fun contributesNetworkChangeReceiver(): NetworkChangeReceiver
|
||||||
@ContributesAndroidInjector abstract fun contributesRileyLinkBluetoothStateReceiver(): RileyLinkBluetoothStateReceiver
|
@ContributesAndroidInjector abstract fun contributesRileyLinkBluetoothStateReceiver(): RileyLinkBluetoothStateReceiver
|
||||||
|
@ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver
|
||||||
}
|
}
|
|
@ -6,9 +6,11 @@ class EventNetworkChange : Event() {
|
||||||
|
|
||||||
var mobileConnected = false
|
var mobileConnected = false
|
||||||
var wifiConnected = false
|
var wifiConnected = false
|
||||||
|
var vpnConnected = false
|
||||||
|
|
||||||
var ssid = ""
|
var ssid = ""
|
||||||
var roaming = false
|
var roaming = false
|
||||||
|
var metered = false
|
||||||
|
|
||||||
fun connectedSsid(): String {
|
fun connectedSsid(): String {
|
||||||
return StringUtils.removeSurroundingQuotes(ssid)
|
return StringUtils.removeSurroundingQuotes(ssid)
|
||||||
|
|
|
@ -15,17 +15,7 @@ class EventPreferenceChange : Event {
|
||||||
changedKey = resourceHelper.gs(resourceID)
|
changedKey = resourceHelper.gs(resourceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("use injected version")
|
|
||||||
constructor(resources: Resources, id: Int) {
|
|
||||||
changedKey == resources.getString(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isChanged(resourceHelper: ResourceHelper, id: Int): Boolean {
|
fun isChanged(resourceHelper: ResourceHelper, id: Int): Boolean {
|
||||||
return changedKey == resourceHelper.gs(id)
|
return changedKey == resourceHelper.gs(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("use injected version")
|
|
||||||
fun isChanged(resources: Resources, id: Int): Boolean {
|
|
||||||
return changedKey == resources.getString(id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package info.nightscout.androidaps.logging
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 2019-12-27.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class AAPSLoggerTest : AAPSLogger {
|
||||||
|
|
||||||
|
override fun debug(message: String) {
|
||||||
|
println("DEBUG: $message")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun debug(enable: Boolean, tag: LTag, message: String) {
|
||||||
|
println("DEBUG: " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun debug(tag: LTag, message: String) {
|
||||||
|
println("DEBUG: : " + tag.tag + " " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
println("DEBUG: : " + tag.tag + " " + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun warn(tag: LTag, message: String) {
|
||||||
|
println("WARN: " + tag.tag + " " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun info(tag: LTag, message: String) {
|
||||||
|
println("INFO: " + tag.tag + " " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
println("INFO: : " + tag.tag + " " + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(tag: LTag, message: String) {
|
||||||
|
println("ERROR: " + tag.tag + " " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(message: String) {
|
||||||
|
println("ERROR: " + message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(message: String, throwable: Throwable) {
|
||||||
|
println("ERROR: " + message + " " + throwable)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(format: String, vararg arguments: Any?) {
|
||||||
|
println("ERROR: : " + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
||||||
|
println("ERROR: " + tag.tag + " " + message + " " + throwable)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
println("ERROR: : " + tag.tag + " " + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,30 +1,30 @@
|
||||||
package info.nightscout.androidaps.logging
|
package info.nightscout.androidaps.logging
|
||||||
|
|
||||||
enum class LTag(val tag: String, val defaultValue : Boolean = false, val requiresRestart: Boolean = false) {
|
enum class LTag(val tag: String, val defaultValue : Boolean = true, val requiresRestart: Boolean = false) {
|
||||||
CORE("CORE", defaultValue = false),
|
CORE("CORE"),
|
||||||
APS("APS", defaultValue = false),
|
APS("APS"),
|
||||||
AUTOSENS("AUTOSENS"),
|
AUTOSENS("AUTOSENS", defaultValue = false),
|
||||||
AUTOMATION("AUTOMATION", defaultValue = false),
|
AUTOMATION("AUTOMATION"),
|
||||||
BGSOURCE("BGSOURCE", defaultValue = false),
|
BGSOURCE("BGSOURCE"),
|
||||||
CONFIGBUILDER("CONFIGBUILDER"),
|
CONFIGBUILDER("CONFIGBUILDER"),
|
||||||
CONSTRAINTS("CONSTRAINTS", defaultValue = false),
|
CONSTRAINTS("CONSTRAINTS"),
|
||||||
DATABASE("DATABASE", defaultValue = false),
|
DATABASE("DATABASE"),
|
||||||
DATAFOOD("DATAFOOD"),
|
DATAFOOD("DATAFOOD", defaultValue = false),
|
||||||
DATASERVICE("DATASERVICE", defaultValue = false),
|
DATASERVICE("DATASERVICE"),
|
||||||
DATATREATMENTS("DATATREATMENTS", defaultValue = false),
|
DATATREATMENTS("DATATREATMENTS"),
|
||||||
EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
|
EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
|
||||||
GLUCOSE("GLUCOSE"),
|
GLUCOSE("GLUCOSE"),
|
||||||
LOCATION("LOCATION", defaultValue = false),
|
LOCATION("LOCATION"),
|
||||||
NOTIFICATION("NOTIFICATION", defaultValue = false),
|
NOTIFICATION("NOTIFICATION"),
|
||||||
NSCLIENT("NSCLIENT", defaultValue = false),
|
NSCLIENT("NSCLIENT"),
|
||||||
OVERVIEW("OVERVIEW", defaultValue = false),
|
OVERVIEW("OVERVIEW", defaultValue = false),
|
||||||
PUMP("PUMP", defaultValue = false),
|
PUMP("PUMP"),
|
||||||
PUMPBTCOMM("PUMPBTCOMM"),
|
PUMPBTCOMM("PUMPBTCOMM", defaultValue = false),
|
||||||
PUMPCOMM("PUMPCOMM", defaultValue = false),
|
PUMPCOMM("PUMPCOMM"),
|
||||||
PUMPQUEUE("PUMPQUEUE", defaultValue = false),
|
PUMPQUEUE("PUMPQUEUE"),
|
||||||
PROFILE("PROFILE", defaultValue = false),
|
PROFILE("PROFILE"),
|
||||||
SMS("SMS", defaultValue = false),
|
SMS("SMS"),
|
||||||
TIDEPOOL("TIDEPOOL"),
|
TIDEPOOL("TIDEPOOL"),
|
||||||
UI("UI", defaultValue = false),
|
UI("UI", defaultValue = false),
|
||||||
WEAR("WEAR")
|
WEAR("WEAR", defaultValue = false)
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProg
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
|
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
|
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
@ -48,6 +48,7 @@ class ObjectivesFragment : DaggerFragment() {
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var objectivesPlugin: ObjectivesPlugin
|
@Inject lateinit var objectivesPlugin: ObjectivesPlugin
|
||||||
|
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
|
|
||||||
private val objectivesAdapter = ObjectivesAdapter()
|
private val objectivesAdapter = ObjectivesAdapter()
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
@ -223,7 +224,7 @@ class ObjectivesFragment : DaggerFragment() {
|
||||||
holder.accomplished.text = resourceHelper.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
|
holder.accomplished.text = resourceHelper.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
|
||||||
holder.accomplished.setTextColor(-0x3e3e3f)
|
holder.accomplished.setTextColor(-0x3e3e3f)
|
||||||
holder.verify.setOnClickListener {
|
holder.verify.setOnClickListener {
|
||||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
receiverStatusStore.updateNetworkStatus()
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.accomplishedOn = DateUtil.now()
|
objective.accomplishedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
|
@ -257,12 +258,12 @@ class ObjectivesFragment : DaggerFragment() {
|
||||||
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, NetworkChangeReceiver.isConnected())
|
}, receiverStatusStore.isConnected)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
holder.start.setOnClickListener {
|
holder.start.setOnClickListener {
|
||||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
receiverStatusStore.updateNetworkStatus()
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.startedOn = DateUtil.now()
|
objective.startedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
|
@ -292,7 +293,7 @@ class ObjectivesFragment : DaggerFragment() {
|
||||||
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, NetworkChangeReceiver.isConnected())
|
}, receiverStatusStore.isConnected)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
holder.unStart.setOnClickListener {
|
holder.unStart.setOnClickListener {
|
||||||
|
|
|
@ -11,10 +11,14 @@ import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithE
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel
|
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||||
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
||||||
|
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
|
|
||||||
var ssid = InputString(injector)
|
var ssid = InputString(injector)
|
||||||
var comparator = Comparator(injector)
|
var comparator = Comparator(injector)
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldRun(): Boolean {
|
override fun shouldRun(): Boolean {
|
||||||
val eventNetworkChange = NetworkChangeReceiver.getLastEvent() ?: return false
|
val eventNetworkChange = receiverStatusStore.lastNetworkEvent ?: return false
|
||||||
if (!eventNetworkChange.wifiConnected && comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
if (!eventNetworkChange.wifiConnected && comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
|
|
||||||
public NSClientService nsClientService = null;
|
public NSClientService nsClientService = null;
|
||||||
|
|
||||||
private NsClientReceiverDelegate nsClientReceiverDelegate = new NsClientReceiverDelegate();
|
private NsClientReceiverDelegate nsClientReceiverDelegate;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public NSClientPlugin(
|
public NSClientPlugin(
|
||||||
|
@ -80,7 +80,8 @@ public class NSClientPlugin extends PluginBase {
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
Context context,
|
Context context,
|
||||||
SP sp
|
SP sp,
|
||||||
|
NsClientReceiverDelegate nsClientReceiverDelegate
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
|
@ -97,6 +98,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
|
this.nsClientReceiverDelegate = nsClientReceiverDelegate;
|
||||||
|
|
||||||
if (Config.NSCLIENT) {
|
if (Config.NSCLIENT) {
|
||||||
getPluginDescription().alwaysEnabled(true).visibleByDefault(true);
|
getPluginDescription().alwaysEnabled(true).visibleByDefault(true);
|
||||||
|
|
|
@ -1,50 +1,71 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient;
|
package info.nightscout.androidaps.plugins.general.nsclient;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventChargingState;
|
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.plugins.bus.RxBus;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
|
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
class NsClientReceiverDelegate {
|
class NsClientReceiverDelegate {
|
||||||
|
|
||||||
private boolean allowedChargingState = true;
|
private boolean allowedChargingState = true;
|
||||||
private boolean allowedNetworkState = true;
|
private boolean allowedNetworkState = true;
|
||||||
boolean allowed = true;
|
boolean allowed = true;
|
||||||
|
|
||||||
void grabReceiversState() {
|
private AAPSLogger aapsLogger;
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
private Context context;
|
||||||
|
private RxBusWrapper rxBus;
|
||||||
|
private ResourceHelper resourceHelper;
|
||||||
|
private SP sp;
|
||||||
|
private ReceiverStatusStore receiverStatusStore;
|
||||||
|
|
||||||
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(context);
|
@Inject
|
||||||
if (event != null) RxBus.Companion.getINSTANCE().send(event);
|
public NsClientReceiverDelegate(
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
Context context,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
SP sp,
|
||||||
|
ReceiverStatusStore receiverStatusStore
|
||||||
|
) {
|
||||||
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.context = context;
|
||||||
|
this.rxBus = rxBus;
|
||||||
|
this.resourceHelper = resourceHelper;
|
||||||
|
this.sp = sp;
|
||||||
|
this.receiverStatusStore = receiverStatusStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
void grabReceiversState() {
|
||||||
|
|
||||||
|
receiverStatusStore.updateNetworkStatus();
|
||||||
|
|
||||||
EventChargingState eventChargingState = ChargingStateReceiver.grabChargingState(context);
|
EventChargingState eventChargingState = ChargingStateReceiver.grabChargingState(context);
|
||||||
if (eventChargingState != null) RxBus.Companion.getINSTANCE().send(eventChargingState);
|
rxBus.send(eventChargingState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStatusEvent(EventPreferenceChange ev) {
|
void onStatusEvent(EventPreferenceChange ev) {
|
||||||
if (ev.isChanged(MainApp.resources(), R.string.key_ns_wifionly) ||
|
if (ev.isChanged(resourceHelper, R.string.key_ns_wifionly) ||
|
||||||
ev.isChanged(MainApp.resources(), R.string.key_ns_wifi_ssids) ||
|
ev.isChanged(resourceHelper, R.string.key_ns_wifi_ssids) ||
|
||||||
ev.isChanged(MainApp.resources(), R.string.key_ns_allowroaming)
|
ev.isChanged(resourceHelper, R.string.key_ns_allowroaming)
|
||||||
) {
|
) {
|
||||||
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
receiverStatusStore.updateNetworkStatus();
|
||||||
if (event != null)
|
} else if (ev.isChanged(resourceHelper, R.string.key_ns_chargingonly)) {
|
||||||
RxBus.Companion.getINSTANCE().send(event);
|
EventChargingState event = ChargingStateReceiver.grabChargingState(context);
|
||||||
} else if (ev.isChanged(MainApp.resources(), R.string.key_ns_chargingonly)) {
|
rxBus.send(event);
|
||||||
EventChargingState event = ChargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
|
||||||
if (event != null)
|
|
||||||
RxBus.Companion.getINSTANCE().send(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +91,12 @@ class NsClientReceiverDelegate {
|
||||||
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
||||||
if (newAllowedState != allowed) {
|
if (newAllowedState != allowed) {
|
||||||
allowed = newAllowedState;
|
allowed = newAllowedState;
|
||||||
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(MainApp.gs(R.string.key_nsclientinternal_paused)));
|
rxBus.send(new EventPreferenceChange(resourceHelper.gs(R.string.key_nsclientinternal_paused)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean calculateStatus(final EventChargingState ev) {
|
boolean calculateStatus(final EventChargingState ev) {
|
||||||
boolean chargingOnly = SP.getBoolean(R.string.key_ns_chargingonly, false);
|
boolean chargingOnly = sp.getBoolean(R.string.key_ns_chargingonly, false);
|
||||||
boolean newAllowedState = true;
|
boolean newAllowedState = true;
|
||||||
|
|
||||||
if (!ev.isCharging() && chargingOnly) {
|
if (!ev.isCharging() && chargingOnly) {
|
||||||
|
@ -86,9 +107,9 @@ class NsClientReceiverDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean calculateStatus(final EventNetworkChange ev) {
|
boolean calculateStatus(final EventNetworkChange ev) {
|
||||||
boolean wifiOnly = SP.getBoolean(R.string.key_ns_wifionly, false);
|
boolean wifiOnly = sp.getBoolean(R.string.key_ns_wifionly, false);
|
||||||
String allowedSSIDs = SP.getString(R.string.key_ns_wifi_ssids, "");
|
String allowedSSIDs = sp.getString(R.string.key_ns_wifi_ssids, "");
|
||||||
boolean allowRoaming = SP.getBoolean(R.string.key_ns_allowroaming, true);
|
boolean allowRoaming = sp.getBoolean(R.string.key_ns_allowroaming, true);
|
||||||
|
|
||||||
boolean newAllowedState = true;
|
boolean newAllowedState = true;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolS
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit
|
import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit
|
||||||
import info.nightscout.androidaps.receivers.ChargingStateReceiver
|
import info.nightscout.androidaps.receivers.ChargingStateReceiver
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -51,7 +51,8 @@ class TidepoolPlugin @Inject constructor(
|
||||||
private val tidepoolUploader: TidepoolUploader,
|
private val tidepoolUploader: TidepoolUploader,
|
||||||
private val uploadChunk: UploadChunk,
|
private val uploadChunk: UploadChunk,
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val rateLimit: RateLimit
|
private val rateLimit: RateLimit,
|
||||||
|
private val receiverStatusStore: ReceiverStatusStore
|
||||||
) : PluginBase(PluginDescription()
|
) : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
.pluginName(R.string.tidepool)
|
.pluginName(R.string.tidepool)
|
||||||
|
@ -103,7 +104,7 @@ class TidepoolPlugin @Inject constructor(
|
||||||
uploadChunk.setLastEnd(bgReading.date)
|
uploadChunk.setLastEnd(bgReading.date)
|
||||||
if (isEnabled(PluginType.GENERAL)
|
if (isEnabled(PluginType.GENERAL)
|
||||||
&& (!sp.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
|
&& (!sp.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
|
||||||
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
|
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || receiverStatusStore.isWifiConnected)
|
||||||
&& rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
|
&& rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
|
||||||
doUpload()
|
doUpload()
|
||||||
}, {
|
}, {
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService;
|
|
||||||
|
|
||||||
public class AutoStartReceiver extends BroadcastReceiver {
|
|
||||||
public AutoStartReceiver() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
||||||
context.startForegroundService(new Intent(context, DummyService.class));
|
|
||||||
else
|
|
||||||
context.startService(new Intent(context, DummyService.class));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService
|
||||||
|
|
||||||
|
class AutoStartReceiver : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
|
context.startForegroundService(Intent(context, DummyService::class.java))
|
||||||
|
else
|
||||||
|
context.startService(Intent(context, DummyService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import androidx.legacy.content.WakefulBroadcastReceiver;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
||||||
import info.nightscout.androidaps.services.DataService;
|
|
||||||
|
|
||||||
public class DataReceiver extends WakefulBroadcastReceiver {
|
|
||||||
private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATASERVICE);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (L.isEnabled(L.DATASERVICE))
|
|
||||||
log.debug("onReceive " + intent);
|
|
||||||
startWakefulService(context, new Intent(context, DataService.class)
|
|
||||||
.setAction(intent.getAction())
|
|
||||||
.putExtras(intent));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.legacy.content.WakefulBroadcastReceiver
|
||||||
|
import dagger.android.AndroidInjection
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
import info.nightscout.androidaps.services.DataService
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
// We are not ready to switch to JobScheduler
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
open class DataReceiver : WakefulBroadcastReceiver() {
|
||||||
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
AndroidInjection.inject(this, context)
|
||||||
|
aapsLogger.debug(LTag.DATASERVICE, "onReceive $intent")
|
||||||
|
startWakefulService(context, Intent(context, DataService::class.java)
|
||||||
|
.setAction(intent.action)
|
||||||
|
.putExtras(intent))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,83 +0,0 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.wifi.SupplicantState;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
|
|
||||||
public class NetworkChangeReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
private static Logger log = StacktraceLoggerWrapper.getLogger(L.CORE);
|
|
||||||
|
|
||||||
private static EventNetworkChange lastEvent = null;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(final Context context, final Intent intent) {
|
|
||||||
EventNetworkChange event = grabNetworkStatus(context);
|
|
||||||
if (event != null)
|
|
||||||
RxBus.Companion.getINSTANCE().send(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static EventNetworkChange grabNetworkStatus(final Context context) {
|
|
||||||
EventNetworkChange event = new EventNetworkChange();
|
|
||||||
|
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
if (cm == null) return null;
|
|
||||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
|
||||||
|
|
||||||
if (activeNetwork != null) {
|
|
||||||
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI && activeNetwork.isConnected()) {
|
|
||||||
event.setWifiConnected(true);
|
|
||||||
WifiManager wifiManager = (WifiManager) MainApp.instance().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
||||||
if (wifiManager != null) {
|
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
||||||
if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
|
|
||||||
event.setSsid(wifiInfo.getSSID());
|
|
||||||
}
|
|
||||||
if (L.isEnabled(L.CORE))
|
|
||||||
log.debug("NETCHANGE: Wifi connected. SSID: " + event.connectedSsid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
|
|
||||||
event.setMobileConnected(true);
|
|
||||||
event.setRoaming(activeNetwork.isRoaming());
|
|
||||||
if (L.isEnabled(L.CORE))
|
|
||||||
log.debug("NETCHANGE: Mobile connected. Roaming: " + event.getRoaming());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (L.isEnabled(L.CORE))
|
|
||||||
log.debug("NETCHANGE: Disconnected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
lastEvent = event;
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isWifiConnected() {
|
|
||||||
return lastEvent != null && lastEvent.getWifiConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isConnected() {
|
|
||||||
return lastEvent != null && (lastEvent.getWifiConnected() || lastEvent.getMobileConnected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EventNetworkChange getLastEvent() {
|
|
||||||
return lastEvent;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.wifi.SupplicantState
|
||||||
|
import android.net.wifi.WifiManager
|
||||||
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class NetworkChangeReceiver : DaggerBroadcastReceiver() {
|
||||||
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
super.onReceive(context, intent)
|
||||||
|
rxBus.send(grabNetworkStatus(context, aapsLogger))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun grabNetworkStatus(context: Context, aapsLogger: AAPSLogger): EventNetworkChange {
|
||||||
|
val event = EventNetworkChange()
|
||||||
|
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val networks: Array<Network> = cm.allNetworks
|
||||||
|
networks.forEach {
|
||||||
|
val capabilities = cm.getNetworkCapabilities(it)
|
||||||
|
event.wifiConnected = event.wifiConnected || (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|
||||||
|
|| capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET))
|
||||||
|
event.mobileConnected = event.mobileConnected || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||||
|
event.vpnConnected = event.vpnConnected || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
|
||||||
|
// if (event.vpnConnected) aapsLogger.debug(LTag.CORE, "NETCHANGE: VPN connected.")
|
||||||
|
if (event.wifiConnected) {
|
||||||
|
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||||
|
val wifiInfo = wifiManager.connectionInfo
|
||||||
|
if (wifiInfo.supplicantState == SupplicantState.COMPLETED) {
|
||||||
|
event.ssid = wifiInfo.ssid
|
||||||
|
// aapsLogger.debug(LTag.CORE, "NETCHANGE: Wifi connected. SSID: ${event.connectedSsid()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.mobileConnected) {
|
||||||
|
event.mobileConnected = true
|
||||||
|
event.roaming = event.roaming || !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)
|
||||||
|
event.metered = event.metered || !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
|
||||||
|
aapsLogger.debug(LTag.CORE, "NETCHANGE: Mobile connected. Roaming: ${event.roaming} Metered: ${event.metered}")
|
||||||
|
}
|
||||||
|
// aapsLogger.info(LTag.CORE, "Network: $it")
|
||||||
|
}
|
||||||
|
|
||||||
|
aapsLogger.debug(LTag.CORE, event.toString())
|
||||||
|
receiverStatusStore.lastNetworkEvent = event
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class ReceiverStatusStore @Inject constructor(val context: Context) {
|
||||||
|
|
||||||
|
var lastNetworkEvent: EventNetworkChange? = null
|
||||||
|
|
||||||
|
val isWifiConnected: Boolean
|
||||||
|
get() = lastNetworkEvent?.wifiConnected ?: false
|
||||||
|
|
||||||
|
val isConnected: Boolean
|
||||||
|
get() = lastNetworkEvent?.wifiConnected ?: false || lastNetworkEvent?.mobileConnected ?: false
|
||||||
|
|
||||||
|
fun updateNetworkStatus() {
|
||||||
|
context.sendBroadcast(Intent(context, NetworkChangeReceiver::class.java))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.androidaps.receivers;
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward received SMS intents. This is a separate class, because unlike local broadcasts handled by DataReceiver,
|
* Forward received SMS intents. This is a separate class, because unlike local broadcasts handled by DataReceiver,
|
||||||
* receiving SMS requires a special permission in the manifest, which necessitates a separate receiver.
|
* receiving SMS requires a special permission in the manifest, which necessitates a separate receiver.
|
||||||
*/
|
*/
|
||||||
public class SmsReceiver extends DataReceiver {}
|
class SmsReceiver : DataReceiver()
|
|
@ -1,9 +1,7 @@
|
||||||
package info.nightscout.androidaps.receivers
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
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 dagger.android.DaggerBroadcastReceiver
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface
|
import info.nightscout.androidaps.interfaces.PumpInterface
|
||||||
|
@ -18,19 +16,11 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
val action = intent.action
|
val action = intent.action
|
||||||
val activePump: PumpInterface = activePlugin.getActivePump()
|
val activePump: PumpInterface = activePlugin.activePump
|
||||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
|
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
|
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
|
||||||
activePump.timeDateOrTimeZoneChanged()
|
activePump.timeDateOrTimeZoneChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerBroadcasts(context: Context) {
|
|
||||||
val filter = IntentFilter()
|
|
||||||
filter.addAction(Intent.ACTION_TIME_CHANGED)
|
|
||||||
filter.addAction(Intent.ACTION_DATE_CHANGED)
|
|
||||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED)
|
|
||||||
context.registerReceiver(this, filter)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
package info.nightscout.androidaps.setupwizard
|
package info.nightscout.androidaps.setupwizard
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.Config
|
import info.nightscout.androidaps.Config
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
||||||
|
@ -46,7 +46,7 @@ import javax.inject.Singleton
|
||||||
class SWDefinition @Inject constructor(
|
class SWDefinition @Inject constructor(
|
||||||
injector: HasAndroidInjector,
|
injector: HasAndroidInjector,
|
||||||
private val rxBus: RxBusWrapper,
|
private val rxBus: RxBusWrapper,
|
||||||
private val mainApp: MainApp,
|
private val context: Context,
|
||||||
resourceHelper: ResourceHelper,
|
resourceHelper: ResourceHelper,
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
|
@ -58,10 +58,11 @@ class SWDefinition @Inject constructor(
|
||||||
private val loopPlugin: LoopPlugin,
|
private val loopPlugin: LoopPlugin,
|
||||||
private val nsClientPlugin: NSClientPlugin,
|
private val nsClientPlugin: NSClientPlugin,
|
||||||
private val nsProfilePlugin: NSProfilePlugin,
|
private val nsProfilePlugin: NSProfilePlugin,
|
||||||
private val protectionCheck: ProtectionCheck
|
private val protectionCheck: ProtectionCheck,
|
||||||
|
private val androidPermission: AndroidPermission
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var activity: AppCompatActivity? = null
|
lateinit var activity: AppCompatActivity
|
||||||
private val screens: MutableList<SWScreen> = ArrayList()
|
private val screens: MutableList<SWScreen> = ArrayList()
|
||||||
|
|
||||||
fun getScreens(): List<SWScreen> {
|
fun getScreens(): List<SWScreen> {
|
||||||
|
@ -83,7 +84,7 @@ class SWDefinition @Inject constructor(
|
||||||
.preferenceId(R.string.key_language).label(R.string.language)
|
.preferenceId(R.string.key_language).label(R.string.language)
|
||||||
.comment(R.string.setupwizard_language_prompt))
|
.comment(R.string.setupwizard_language_prompt))
|
||||||
.validator(SWValidator {
|
.validator(SWValidator {
|
||||||
update(mainApp)
|
update(context)
|
||||||
sp.contains(R.string.key_language)
|
sp.contains(R.string.key_language)
|
||||||
})
|
})
|
||||||
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
|
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
|
||||||
|
@ -127,10 +128,10 @@ class SWDefinition @Inject constructor(
|
||||||
.add(SWBreak(injector))
|
.add(SWBreak(injector))
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
.text(R.string.askforpermission)
|
.text(R.string.askforpermission)
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
||||||
.action(Runnable { AndroidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY) }))
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY) }))
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
||||||
.validator(SWValidator { !AndroidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
||||||
private val screenPermissionBt = SWScreen(injector, R.string.permission)
|
private val screenPermissionBt = SWScreen(injector, R.string.permission)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(SWInfotext(injector)
|
.add(SWInfotext(injector)
|
||||||
|
@ -138,10 +139,10 @@ class SWDefinition @Inject constructor(
|
||||||
.add(SWBreak(injector))
|
.add(SWBreak(injector))
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
.text(R.string.askforpermission)
|
.text(R.string.askforpermission)
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
||||||
.action(Runnable { AndroidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) }))
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) }))
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
||||||
.validator(SWValidator { !AndroidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
||||||
private val screenPermissionStore = SWScreen(injector, R.string.permission)
|
private val screenPermissionStore = SWScreen(injector, R.string.permission)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(SWInfotext(injector)
|
.add(SWInfotext(injector)
|
||||||
|
@ -149,10 +150,10 @@ class SWDefinition @Inject constructor(
|
||||||
.add(SWBreak(injector))
|
.add(SWBreak(injector))
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
.text(R.string.askforpermission)
|
.text(R.string.askforpermission)
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||||
.action(Runnable { AndroidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) }))
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) }))
|
||||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||||
.validator(SWValidator { !AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||||
private val screenImport = SWScreen(injector, R.string.nav_import)
|
private val screenImport = SWScreen(injector, R.string.nav_import)
|
||||||
.add(SWInfotext(injector)
|
.add(SWInfotext(injector)
|
||||||
.label(R.string.storedsettingsfound))
|
.label(R.string.storedsettingsfound))
|
||||||
|
@ -160,7 +161,7 @@ class SWDefinition @Inject constructor(
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
.text(R.string.nav_import)
|
.text(R.string.nav_import)
|
||||||
.action(Runnable { ImportExportPrefs.importSharedPreferences(activity) }))
|
.action(Runnable { ImportExportPrefs.importSharedPreferences(activity) }))
|
||||||
.visibility(SWValidator { ImportExportPrefs.file.exists() && !AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
.visibility(SWValidator { ImportExportPrefs.file.exists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||||
private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title)
|
private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title)
|
||||||
.skippable(true)
|
.skippable(true)
|
||||||
.add(SWInfotext(injector)
|
.add(SWInfotext(injector)
|
||||||
|
@ -219,13 +220,11 @@ class SWDefinition @Inject constructor(
|
||||||
.text(R.string.insulinsourcesetup)
|
.text(R.string.insulinsourcesetup)
|
||||||
.action(Runnable {
|
.action(Runnable {
|
||||||
val plugin = activePlugin.activeInsulin as PluginBase
|
val plugin = activePlugin.activeInsulin as PluginBase
|
||||||
activity?.let { activity ->
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
val i = Intent(activity, PreferencesActivity::class.java)
|
||||||
val i = Intent(activity, PreferencesActivity::class.java)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
activity.startActivity(i)
|
||||||
activity.startActivity(i)
|
}, null)
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.visibility(SWValidator { (activePlugin.activeInsulin as PluginBase).preferencesId > 0 }))
|
.visibility(SWValidator { (activePlugin.activeInsulin as PluginBase).preferencesId > 0 }))
|
||||||
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
|
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
|
||||||
|
@ -238,13 +237,11 @@ class SWDefinition @Inject constructor(
|
||||||
.text(R.string.bgsourcesetup)
|
.text(R.string.bgsourcesetup)
|
||||||
.action(Runnable {
|
.action(Runnable {
|
||||||
val plugin = activePlugin.activeBgSource as PluginBase
|
val plugin = activePlugin.activeBgSource as PluginBase
|
||||||
activity?.let { activity ->
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
val i = Intent(activity, PreferencesActivity::class.java)
|
||||||
val i = Intent(activity, PreferencesActivity::class.java)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
activity.startActivity(i)
|
||||||
activity.startActivity(i)
|
}, null)
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.visibility(SWValidator { (activePlugin.activeBgSource as PluginBase).preferencesId > 0 }))
|
.visibility(SWValidator { (activePlugin.activeBgSource as PluginBase).preferencesId > 0 }))
|
||||||
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
|
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
|
||||||
|
@ -275,7 +272,7 @@ class SWDefinition @Inject constructor(
|
||||||
.label(R.string.profileswitch_ismissing))
|
.label(R.string.profileswitch_ismissing))
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
.text(R.string.doprofileswitch)
|
.text(R.string.doprofileswitch)
|
||||||
.action(Runnable { ProfileSwitchDialog().show(activity!!.supportFragmentManager, "SetupWizard") }))
|
.action(Runnable { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") }))
|
||||||
.validator(SWValidator { profileFunction.getProfile() != null })
|
.validator(SWValidator { profileFunction.getProfile() != null })
|
||||||
.visibility(SWValidator { profileFunction.getProfile() == null })
|
.visibility(SWValidator { profileFunction.getProfile() == null })
|
||||||
private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
|
private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
|
||||||
|
@ -288,13 +285,11 @@ class SWDefinition @Inject constructor(
|
||||||
.text(R.string.pumpsetup)
|
.text(R.string.pumpsetup)
|
||||||
.action(Runnable {
|
.action(Runnable {
|
||||||
val plugin = activePlugin.activePump as PluginBase
|
val plugin = activePlugin.activePump as PluginBase
|
||||||
activity?.let { activity ->
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
val i = Intent(activity, PreferencesActivity::class.java)
|
||||||
val i = Intent(activity, PreferencesActivity::class.java)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
activity.startActivity(i)
|
||||||
activity.startActivity(i)
|
}, null)
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 }))
|
.visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 }))
|
||||||
.add(SWButton(injector)
|
.add(SWButton(injector)
|
||||||
|
@ -317,13 +312,11 @@ class SWDefinition @Inject constructor(
|
||||||
.text(R.string.apssetup)
|
.text(R.string.apssetup)
|
||||||
.action(Runnable {
|
.action(Runnable {
|
||||||
val plugin = activePlugin.activeAPS as PluginBase
|
val plugin = activePlugin.activeAPS as PluginBase
|
||||||
activity?.let { activity ->
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
val i = Intent(activity, PreferencesActivity::class.java)
|
||||||
val i = Intent(activity, PreferencesActivity::class.java)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
activity.startActivity(i)
|
||||||
activity.startActivity(i)
|
}, null)
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.visibility(SWValidator { (activePlugin.activeAPS as PluginBase).preferencesId > 0 }))
|
.visibility(SWValidator { (activePlugin.activeAPS as PluginBase).preferencesId > 0 }))
|
||||||
.visibility(SWValidator { Config.APS })
|
.visibility(SWValidator { Config.APS })
|
||||||
|
@ -367,13 +360,11 @@ class SWDefinition @Inject constructor(
|
||||||
.text(R.string.sensitivitysetup)
|
.text(R.string.sensitivitysetup)
|
||||||
.action(Runnable {
|
.action(Runnable {
|
||||||
val plugin = activePlugin.activeSensitivity as PluginBase
|
val plugin = activePlugin.activeSensitivity as PluginBase
|
||||||
activity?.let { activity ->
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
val i = Intent(activity, PreferencesActivity::class.java)
|
||||||
val i = Intent(activity, PreferencesActivity::class.java)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
activity.startActivity(i)
|
||||||
activity.startActivity(i)
|
}, null)
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.visibility(SWValidator { (activePlugin.activeSensitivity as PluginBase).preferencesId > 0 }))
|
.visibility(SWValidator { (activePlugin.activeSensitivity as PluginBase).preferencesId > 0 }))
|
||||||
private val getScreenObjectives = SWScreen(injector, R.string.objectives)
|
private val getScreenObjectives = SWScreen(injector, R.string.objectives)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.setupwizard.SWDefinition
|
import info.nightscout.androidaps.setupwizard.SWDefinition
|
||||||
|
|
||||||
class SWFragment(injecto:HasAndroidInjector, private var definition: SWDefinition) : SWItem(injecto, Type.FRAGMENT) {
|
class SWFragment(injector:HasAndroidInjector, private var definition: SWDefinition) : SWItem(injector, Type.FRAGMENT) {
|
||||||
lateinit var fragment: Fragment
|
lateinit var fragment: Fragment
|
||||||
|
|
||||||
fun add(fragment: Fragment): SWFragment {
|
fun add(fragment: Fragment): SWFragment {
|
||||||
|
@ -14,6 +14,6 @@ class SWFragment(injecto:HasAndroidInjector, private var definition: SWDefinitio
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateDialog(layout: LinearLayout) {
|
override fun generateDialog(layout: LinearLayout) {
|
||||||
definition.activity?.supportFragmentManager?.beginTransaction()?.add(layout.id, fragment, fragment.tag)?.commit()
|
definition.activity.supportFragmentManager.beginTransaction().add(layout.id, fragment, fragment.tag).commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,155 +0,0 @@
|
||||||
package info.nightscout.androidaps.utils;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction;
|
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
|
||||||
|
|
||||||
public class AndroidPermission {
|
|
||||||
|
|
||||||
public static final int CASE_STORAGE = 0x1;
|
|
||||||
public static final int CASE_SMS = 0x2;
|
|
||||||
public static final int CASE_LOCATION = 0x3;
|
|
||||||
public static final int CASE_BATTERY = 0x4;
|
|
||||||
public static final int CASE_PHONE_STATE = 0x5;
|
|
||||||
public static final int CASE_SYSTEM_WINDOW = 0x6;
|
|
||||||
|
|
||||||
private static boolean permission_battery_optimization_failed = false;
|
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
|
||||||
private static void askForPermission(Activity activity, String[] permission, Integer requestCode) {
|
|
||||||
boolean test = false;
|
|
||||||
boolean testBattery = false;
|
|
||||||
for (String s : permission) {
|
|
||||||
test = test || (ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED);
|
|
||||||
if (s.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
|
||||||
PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
|
|
||||||
String packageName = activity.getPackageName();
|
|
||||||
testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (test) {
|
|
||||||
ActivityCompat.requestPermissions(activity, permission, requestCode);
|
|
||||||
}
|
|
||||||
if (testBattery) {
|
|
||||||
try {
|
|
||||||
Intent i = new Intent();
|
|
||||||
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
||||||
i.setData(Uri.parse("package:" + activity.getPackageName()));
|
|
||||||
activity.startActivityForResult(i, CASE_BATTERY);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
permission_battery_optimization_failed = true;
|
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.permission), MainApp.gs(R.string.alert_dialog_permission_battery_optimization_failed), activity::recreate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void askForPermission(Activity activity, String permission, Integer requestCode) {
|
|
||||||
String[] permissions = {permission};
|
|
||||||
askForPermission(activity, permissions, requestCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean permissionNotGranted(Context context, String permission) {
|
|
||||||
boolean selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
|
||||||
if (permission.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
|
||||||
if (!permission_battery_optimization_failed) {
|
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
||||||
String packageName = context.getPackageName();
|
|
||||||
selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !selfCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void notifyForSMSPermissions(Activity activity, SmsCommunicatorPlugin smsCommunicatorPlugin) {
|
|
||||||
if (smsCommunicatorPlugin.isEnabled(PluginType.GENERAL)) {
|
|
||||||
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS,
|
|
||||||
Manifest.permission.SEND_SMS,
|
|
||||||
Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_SMS));
|
|
||||||
// Following is a bug in Android 8
|
|
||||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
|
||||||
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () ->
|
|
||||||
AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE));
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_PHONESTATE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
|
||||||
if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY));
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void notifyForStoragePermission(Activity activity) {
|
|
||||||
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE));
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_STORAGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
|
||||||
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION));
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized void notifyForSystemWindowPermissions(Activity activity) {
|
|
||||||
// Check if Android Q or higher
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
|
||||||
if (!Settings.canDrawOverlays(activity)) {
|
|
||||||
NotificationWithAction notification = new NotificationWithAction(MainApp.instance(), Notification.PERMISSION_SYSTEM_WINDOW, MainApp.gs(R.string.needsystemwindowpermission), Notification.URGENT);
|
|
||||||
notification.action(R.string.request, () -> {
|
|
||||||
// Check if Android Q or higher
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
|
||||||
// Show alert dialog to the user saying a separate permission is needed
|
|
||||||
// Launch the settings activity if the user prefers
|
|
||||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
||||||
Uri.parse("package:" + activity.getPackageName()));
|
|
||||||
activity.startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
|
||||||
} else
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PERMISSION_SYSTEM_WINDOW));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
package info.nightscout.androidaps.utils
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
|
||||||
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||||
|
import info.nightscout.androidaps.utils.OKDialog.show
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class AndroidPermission @Inject constructor(
|
||||||
|
val resourceHelper: ResourceHelper,
|
||||||
|
val rxBus: RxBusWrapper,
|
||||||
|
val injector: HasAndroidInjector
|
||||||
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CASE_STORAGE = 0x1
|
||||||
|
const val CASE_SMS = 0x2
|
||||||
|
const val CASE_LOCATION = 0x3
|
||||||
|
const val CASE_BATTERY = 0x4
|
||||||
|
const val CASE_PHONE_STATE = 0x5
|
||||||
|
const val CASE_SYSTEM_WINDOW = 0x6
|
||||||
|
}
|
||||||
|
|
||||||
|
private var permission_battery_optimization_failed = false
|
||||||
|
|
||||||
|
@SuppressLint("BatteryLife")
|
||||||
|
private fun askForPermission(activity: Activity, permission: Array<String>, requestCode: Int) {
|
||||||
|
var test = false
|
||||||
|
var testBattery = false
|
||||||
|
for (s in permission) {
|
||||||
|
test = test || ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED
|
||||||
|
if (s == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) {
|
||||||
|
val powerManager = activity.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
val packageName = activity.packageName
|
||||||
|
testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (test) {
|
||||||
|
ActivityCompat.requestPermissions(activity, permission, requestCode)
|
||||||
|
}
|
||||||
|
if (testBattery) {
|
||||||
|
try {
|
||||||
|
val i = Intent()
|
||||||
|
i.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||||
|
i.data = Uri.parse("package:" + activity.packageName)
|
||||||
|
activity.startActivityForResult(i, CASE_BATTERY)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
permission_battery_optimization_failed = true
|
||||||
|
show(activity, resourceHelper.gs(R.string.permission), resourceHelper.gs(R.string.alert_dialog_permission_battery_optimization_failed), Runnable { activity.recreate() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun askForPermission(activity: Activity, permission: String, requestCode: Int) {
|
||||||
|
val permissions = arrayOf(permission)
|
||||||
|
askForPermission(activity, permissions, requestCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun permissionNotGranted(context: Context, permission: String): Boolean {
|
||||||
|
var selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||||
|
if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) {
|
||||||
|
if (!permission_battery_optimization_failed) {
|
||||||
|
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
val packageName = context.packageName
|
||||||
|
selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !selfCheck
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun notifyForSMSPermissions(activity: Activity, smsCommunicatorPlugin: SmsCommunicatorPlugin) {
|
||||||
|
if (smsCommunicatorPlugin.isEnabled(PluginType.GENERAL)) {
|
||||||
|
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_SMS, resourceHelper.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable {
|
||||||
|
askForPermission(activity, arrayOf(Manifest.permission.RECEIVE_SMS,
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.RECEIVE_MMS), CASE_SMS)
|
||||||
|
})
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_SMS))
|
||||||
|
// Following is a bug in Android 8
|
||||||
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
||||||
|
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_PHONESTATE, resourceHelper.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable { askForPermission(activity, arrayOf(Manifest.permission.READ_PHONE_STATE), CASE_PHONE_STATE) })
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_PHONESTATE))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun notifyForBatteryOptimizationPermission(activity: Activity) {
|
||||||
|
if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_BATTERY, String.format(resourceHelper.gs(R.string.needwhitelisting), resourceHelper.gs(R.string.app_name)), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable { askForPermission(activity, arrayOf(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS), CASE_BATTERY) })
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_BATTERY))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized fun notifyForStoragePermission(activity: Activity) {
|
||||||
|
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_STORAGE, resourceHelper.gs(R.string.needstoragepermission), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable {
|
||||||
|
askForPermission(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE), CASE_STORAGE)
|
||||||
|
})
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_STORAGE))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized fun notifyForLocationPermissions(activity: Activity) {
|
||||||
|
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_LOCATION, resourceHelper.gs(R.string.needlocationpermission), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable { askForPermission(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), CASE_LOCATION) })
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_LOCATION))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized fun notifyForSystemWindowPermissions(activity: Activity) {
|
||||||
|
// Check if Android Q or higher
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
||||||
|
if (!Settings.canDrawOverlays(activity)) {
|
||||||
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_SYSTEM_WINDOW, resourceHelper.gs(R.string.needsystemwindowpermission), Notification.URGENT)
|
||||||
|
notification.action(R.string.request, Runnable {
|
||||||
|
// Check if Android Q or higher
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
||||||
|
// Show alert dialog to the user saying a separate permission is needed
|
||||||
|
// Launch the settings activity if the user prefers
|
||||||
|
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
|
Uri.parse("package:" + activity.packageName))
|
||||||
|
activity.startActivity(intent)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_SYSTEM_WINDOW))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.data.ProfileStore
|
import info.nightscout.androidaps.data.ProfileStore
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
|
@ -13,6 +14,9 @@ import org.mockito.junit.MockitoRule
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
open class TestBase {
|
open class TestBase {
|
||||||
|
|
||||||
|
val aapsLogger = AAPSLoggerTest()
|
||||||
|
|
||||||
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
||||||
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
||||||
@get:Rule
|
@get:Rule
|
||||||
|
|
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.ProfileStore
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch
|
import info.nightscout.androidaps.db.ProfileSwitch
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
@ -18,7 +19,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
@PrepareForTest(FabricPrivacy::class)
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
open class TestBaseWithProfile : TestBase() {
|
open class TestBaseWithProfile : TestBase() {
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(Profile::class)
|
@PrepareForTest(Profile::class)
|
||||||
class QuickWizardTest : TestBase() {
|
class QuickWizardTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.logging.Logger
|
||||||
@PrepareForTest(MainApp::class, Logger::class, L::class, SP::class, GlucoseStatus::class)
|
@PrepareForTest(MainApp::class, Logger::class, L::class, SP::class, GlucoseStatus::class)
|
||||||
class BgReadingTest : TestBase() {
|
class BgReadingTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
|
@ -19,8 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(MainApp::class, SP::class)
|
@PrepareForTest(MainApp::class, SP::class)
|
||||||
class ConstraintTest : TestBase() {
|
class ConstraintTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
|
|
||||||
@Test fun doTests() {
|
@Test fun doTests() {
|
||||||
val b = Constraint(true)
|
val b = Constraint(true)
|
||||||
Assert.assertEquals(true, b.value())
|
Assert.assertEquals(true, b.value())
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
|
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
|
||||||
class LoopPluginTest : TestBase() {
|
class LoopPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
|
@ -25,7 +25,6 @@ class ConfigBuilderPluginTest : TestBase() {
|
||||||
@Mock lateinit var treatmentsPlugin: Lazy<TreatmentsPlugin>
|
@Mock lateinit var treatmentsPlugin: Lazy<TreatmentsPlugin>
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.*
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
class DstHelperPluginTest : TestBase() {
|
class DstHelperPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
class ObjectivesPluginTest : TestBase() {
|
class ObjectivesPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.junit.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
|
||||||
class SignatureVerifierPluginTest : TestBase() {
|
class SignatureVerifierPluginTest : TestBase() {
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
class StorageConstraintPluginTest : TestBase() {
|
class StorageConstraintPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
private val rxBusWrapper = RxBusWrapper()
|
private val rxBusWrapper = RxBusWrapper()
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
||||||
|
|
||||||
lateinit var versionCheckerUtils: VersionCheckerUtils
|
lateinit var versionCheckerUtils: VersionCheckerUtils
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
class AutomationEventTest : TestBase() {
|
class AutomationEventTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var loopPlugin: LoopPlugin
|
@Mock lateinit var loopPlugin: LoopPlugin
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(NSUpload::class, RxBusWrapper::class)
|
@PrepareForTest(NSUpload::class, RxBusWrapper::class)
|
||||||
class ActionNotificationTest : TestBase() {
|
class ActionNotificationTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var rxBus: RxBusWrapper
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.triggers
|
package info.nightscout.androidaps.plugins.general.automation.triggers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
@ -13,9 +15,11 @@ import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabe
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
import info.nightscout.androidaps.services.LastLocationDataContainer
|
import info.nightscout.androidaps.services.LastLocationDataContainer
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import org.junit.Before
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@ -27,6 +31,14 @@ open class TriggerTestBase : TestBaseWithProfile() {
|
||||||
@Mock lateinit var locationDataContainer: LastLocationDataContainer
|
@Mock lateinit var locationDataContainer: LastLocationDataContainer
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
|
||||||
|
lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepareMock1() {
|
||||||
|
receiverStatusStore = ReceiverStatusStore(context)
|
||||||
|
}
|
||||||
|
|
||||||
var injector: HasAndroidInjector = HasAndroidInjector {
|
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -44,6 +56,9 @@ open class TriggerTestBase : TestBaseWithProfile() {
|
||||||
if (it is TriggerBg) {
|
if (it is TriggerBg) {
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
}
|
}
|
||||||
|
if (it is TriggerWifiSsid) {
|
||||||
|
it.receiverStatusStore = receiverStatusStore
|
||||||
|
}
|
||||||
if (it is InputBg) {
|
if (it is InputBg) {
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
val e = EventNetworkChange()
|
val e = EventNetworkChange()
|
||||||
PowerMockito.`when`(NetworkChangeReceiver.getLastEvent()).thenReturn(e)
|
receiverStatusStore.lastNetworkEvent = e
|
||||||
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
||||||
e.wifiConnected = false
|
e.wifiConnected = false
|
||||||
Assert.assertFalse(t.shouldRun())
|
Assert.assertFalse(t.shouldRun())
|
||||||
|
@ -45,7 +45,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
|
|
||||||
// no network data
|
// no network data
|
||||||
PowerMockito.`when`(NetworkChangeReceiver.getLastEvent()).thenReturn(null)
|
receiverStatusStore.lastNetworkEvent = null
|
||||||
Assert.assertFalse(t.shouldRun())
|
Assert.assertFalse(t.shouldRun())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ class MaintenancePluginTest : TestBase() {
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var nsSettingsStatus: NSSettingsStatus
|
@Mock lateinit var nsSettingsStatus: NSSettingsStatus
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var buildHelper: BuildHelper
|
@Mock lateinit var buildHelper: BuildHelper
|
||||||
|
|
||||||
lateinit var sut: MaintenancePlugin
|
lateinit var sut: MaintenancePlugin
|
||||||
|
|
|
@ -6,7 +6,11 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.events.EventChargingState
|
import info.nightscout.androidaps.events.EventChargingState
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -16,6 +20,7 @@ import org.mockito.ArgumentMatchers.anyBoolean
|
||||||
import org.mockito.ArgumentMatchers.anyInt
|
import org.mockito.ArgumentMatchers.anyInt
|
||||||
import org.mockito.ArgumentMatchers.anyLong
|
import org.mockito.ArgumentMatchers.anyLong
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.Mockito.mock
|
import org.mockito.Mockito.mock
|
||||||
|
@ -27,30 +32,38 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(MainApp::class, SP::class, Context::class)
|
@PrepareForTest(MainApp::class, SP::class, Context::class)
|
||||||
class NsClientReceiverDelegateTest : TestBase() {
|
class NsClientReceiverDelegateTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
lateinit var receiverStatusStore : ReceiverStatusStore
|
||||||
|
val rxBus: RxBusWrapper = RxBusWrapper()
|
||||||
|
|
||||||
private var sut: NsClientReceiverDelegate? = null
|
private var sut: NsClientReceiverDelegate? = null
|
||||||
|
|
||||||
@Before fun prepare() {
|
@Before fun prepare() {
|
||||||
|
receiverStatusStore = ReceiverStatusStore(context)
|
||||||
System.setProperty("disableFirebase", "true")
|
System.setProperty("disableFirebase", "true")
|
||||||
PowerMockito.mockStatic(MainApp::class.java)
|
PowerMockito.mockStatic(MainApp::class.java)
|
||||||
val mainApp: MainApp = mock(MainApp::class.java)
|
val mainApp: MainApp = mock(MainApp::class.java)
|
||||||
`when`(MainApp.instance()).thenReturn(mainApp)
|
`when`(MainApp.instance()).thenReturn(mainApp)
|
||||||
PowerMockito.mockStatic(SP::class.java)
|
PowerMockito.mockStatic(SP::class.java)
|
||||||
`when`(SP.getLong(anyInt(), anyLong())).thenReturn(0L)
|
`when`(sp.getLong(anyInt(), anyLong())).thenReturn(0L)
|
||||||
`when`(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
|
`when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
|
||||||
`when`(SP.getInt(anyInt(), anyInt())).thenReturn(0)
|
`when`(sp.getInt(anyInt(), anyInt())).thenReturn(0)
|
||||||
`when`(SP.getString(anyInt(), anyString())).thenReturn("")
|
`when`(sp.getString(anyInt(), anyString())).thenReturn("")
|
||||||
|
|
||||||
sut = NsClientReceiverDelegate()
|
sut = NsClientReceiverDelegate(aapsLogger, context, rxBus, resourceHelper, sp, receiverStatusStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun testCalculateStatusChargingState() {
|
@Test fun testCalculateStatusChargingState() {
|
||||||
PowerMockito.mockStatic(SP::class.java)
|
PowerMockito.mockStatic(SP::class.java)
|
||||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
||||||
var ev = EventChargingState(true)
|
var ev = EventChargingState(true)
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
ev = EventChargingState(false)
|
ev = EventChargingState(false)
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true)
|
||||||
ev = EventChargingState(true)
|
ev = EventChargingState(true)
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
ev = EventChargingState(false)
|
ev = EventChargingState(false)
|
||||||
|
@ -61,15 +74,15 @@ class NsClientReceiverDelegateTest : TestBase() {
|
||||||
PowerMockito.mockStatic(SP::class.java)
|
PowerMockito.mockStatic(SP::class.java)
|
||||||
// wifiOnly = false
|
// wifiOnly = false
|
||||||
// allowRoaming = false as well
|
// allowRoaming = false as well
|
||||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
||||||
Mockito.`when`(SP.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("")
|
Mockito.`when`(sp.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("")
|
||||||
val ev = EventNetworkChange()
|
val ev = EventNetworkChange()
|
||||||
ev.ssid = "<unknown ssid>"
|
ev.ssid = "<unknown ssid>"
|
||||||
ev.mobileConnected = true
|
ev.mobileConnected = true
|
||||||
ev.wifiConnected = true
|
ev.wifiConnected = true
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
ev.ssid = "test"
|
ev.ssid = "test"
|
||||||
Mockito.`when`(SP.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("\"test\"")
|
Mockito.`when`(sp.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("\"test\"")
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
ev.ssid = "\"test\""
|
ev.ssid = "\"test\""
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
|
@ -78,7 +91,7 @@ class NsClientReceiverDelegateTest : TestBase() {
|
||||||
|
|
||||||
// wifiOnly = true
|
// wifiOnly = true
|
||||||
// allowRoaming = true as well
|
// allowRoaming = true as well
|
||||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true)
|
||||||
ev.wifiConnected = true
|
ev.wifiConnected = true
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
ev.wifiConnected = false
|
ev.wifiConnected = false
|
||||||
|
@ -86,39 +99,39 @@ class NsClientReceiverDelegateTest : TestBase() {
|
||||||
|
|
||||||
// wifiOnly = false
|
// wifiOnly = false
|
||||||
// allowRoaming = false as well
|
// allowRoaming = false as well
|
||||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
||||||
ev.wifiConnected = false
|
ev.wifiConnected = false
|
||||||
ev.roaming = true
|
ev.roaming = true
|
||||||
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
||||||
|
|
||||||
// wifiOnly = false
|
// wifiOnly = false
|
||||||
// allowRoaming = true
|
// allowRoaming = true
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||||
ev.wifiConnected = false
|
ev.wifiConnected = false
|
||||||
ev.roaming = true
|
ev.roaming = true
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
|
|
||||||
// wifiOnly = true
|
// wifiOnly = true
|
||||||
// allowRoaming = true
|
// allowRoaming = true
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||||
ev.wifiConnected = false
|
ev.wifiConnected = false
|
||||||
ev.roaming = true
|
ev.roaming = true
|
||||||
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
||||||
|
|
||||||
// wifiOnly = true
|
// wifiOnly = true
|
||||||
// allowRoaming = true
|
// allowRoaming = true
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||||
ev.wifiConnected = true
|
ev.wifiConnected = true
|
||||||
ev.roaming = true
|
ev.roaming = true
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
|
|
||||||
// wifiOnly = false
|
// wifiOnly = false
|
||||||
// allowRoaming = false
|
// allowRoaming = false
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
|
||||||
Mockito.`when`(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false)
|
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false)
|
||||||
ev.wifiConnected = true
|
ev.wifiConnected = true
|
||||||
ev.roaming = true
|
ev.roaming = true
|
||||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class)
|
@PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class)
|
||||||
class AuthRequestTest : TestBase() {
|
class AuthRequestTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
|
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var otp: OneTimePassword
|
@Mock lateinit var otp: OneTimePassword
|
||||||
|
|
|
@ -30,7 +30,6 @@ class InsulinOrefFreePeakPluginTest : TestBase() {
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var rxBus: RxBusWrapper
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
|
|
||||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.*
|
||||||
@PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class)
|
@PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class)
|
||||||
class GlucoseStatusTest : TestBase() {
|
class GlucoseStatusTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
val injector = HasAndroidInjector {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.*
|
||||||
@PrepareForTest(FabricPrivacy::class)
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
class IobCobCalculatorPluginTest : TestBase() {
|
class IobCobCalculatorPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, Context::class, CommandQueue::class)
|
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, Context::class, CommandQueue::class)
|
||||||
class ComboPluginTest : TestBase() {
|
class ComboPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
|
@ -14,8 +14,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
class DetailedBolusInfoStorageTest : TestBase() {
|
class DetailedBolusInfoStorageTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
|
|
||||||
private val info1 = DetailedBolusInfo()
|
private val info1 = DetailedBolusInfo()
|
||||||
private val info2 = DetailedBolusInfo()
|
private val info2 = DetailedBolusInfo()
|
||||||
private val info3 = DetailedBolusInfo()
|
private val info3 = DetailedBolusInfo()
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.mockito.Mock
|
||||||
|
|
||||||
open class DanaRTestBase : TestBase() {
|
open class DanaRTestBase : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var injector: HasAndroidInjector
|
@Mock lateinit var injector: HasAndroidInjector
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
@PrepareForTest(FabricPrivacy::class)
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
class VirtualPumpPluginUTest : TestBase() {
|
class VirtualPumpPluginUTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
val rxBus = RxBusWrapper()
|
val rxBus = RxBusWrapper()
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
|
@ -19,7 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
class AbstractSensitivityPluginTest : TestBase() {
|
class AbstractSensitivityPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var pluginDescription: PluginDescription
|
@Mock lateinit var pluginDescription: PluginDescription
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.mockito.Mock
|
||||||
class GlimpPluginTest : TestBase() {
|
class GlimpPluginTest : TestBase() {
|
||||||
private lateinit var glimpPlugin: GlimpPlugin
|
private lateinit var glimpPlugin: GlimpPlugin
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -17,7 +17,6 @@ class MM640GPluginTest : TestBase() {
|
||||||
|
|
||||||
private lateinit var mM640gPlugin: MM640gPlugin
|
private lateinit var mM640gPlugin: MM640gPlugin
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -18,7 +18,6 @@ class NSClientPluginTest : TestBase() {
|
||||||
|
|
||||||
private lateinit var nsClientSourcePlugin: NSClientSourcePlugin
|
private lateinit var nsClientSourcePlugin: NSClientSourcePlugin
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class XdripPluginTest : TestBase() {
|
||||||
|
|
||||||
private lateinit var xdripPlugin: XdripPlugin
|
private lateinit var xdripPlugin: XdripPlugin
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -37,7 +37,6 @@ class BolusWizardTest : TestBase() {
|
||||||
|
|
||||||
private val PUMP_BOLUS_STEP = 0.1
|
private val PUMP_BOLUS_STEP = 0.1
|
||||||
|
|
||||||
@Mock lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
Loading…
Reference in a new issue