Merge remote-tracking branch 'origin/dagger3' into rs
This commit is contained in:
commit
e31d2041e3
|
@ -78,6 +78,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject AndroidPermission androidPermission;
|
||||
@Inject SP sp;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject VersionCheckerUtils versionCheckerUtils;
|
||||
|
@ -161,12 +162,12 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
AndroidPermission.notifyForStoragePermission(this);
|
||||
AndroidPermission.notifyForBatteryOptimizationPermission(this);
|
||||
androidPermission.notifyForStoragePermission(this);
|
||||
androidPermission.notifyForBatteryOptimizationPermission(this);
|
||||
if (Config.PUMPDRIVERS) {
|
||||
AndroidPermission.notifyForLocationPermissions(this);
|
||||
AndroidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin);
|
||||
AndroidPermission.notifyForSystemWindowPermissions(this);
|
||||
androidPermission.notifyForLocationPermissions(this);
|
||||
androidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin);
|
||||
androidPermission.notifyForSystemWindowPermissions(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,9 +114,6 @@ public class MainApp extends DaggerApplication {
|
|||
|
||||
static DatabaseHelper sDatabaseHelper = null;
|
||||
|
||||
DataReceiver dataReceiver = new DataReceiver();
|
||||
TimeDateOrTZChangeReceiver timeDateOrTZChangeReceiver;
|
||||
|
||||
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 Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||
|
@ -330,23 +327,28 @@ public class MainApp extends DaggerApplication {
|
|||
}
|
||||
|
||||
private void registerLocalBroadcastReceiver() {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intents.ACTION_NEW_TREATMENT);
|
||||
filter.addAction(Intents.ACTION_CHANGED_TREATMENT);
|
||||
filter.addAction(Intents.ACTION_REMOVED_TREATMENT);
|
||||
filter.addAction(Intents.ACTION_NEW_SGV);
|
||||
filter.addAction(Intents.ACTION_NEW_PROFILE);
|
||||
filter.addAction(Intents.ACTION_NEW_MBG);
|
||||
filter.addAction(Intents.ACTION_NEW_CAL);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(new DataReceiver(), filter);
|
||||
|
||||
this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
|
||||
this.timeDateOrTZChangeReceiver.registerBroadcasts(this);
|
||||
filter = new IntentFilter();
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -421,11 +423,7 @@ public class MainApp extends DaggerApplication {
|
|||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
|
||||
aapsLogger.debug(LTag.CORE, "onTerminate");
|
||||
|
||||
if (timeDateOrTZChangeReceiver != null)
|
||||
unregisterReceiver(timeDateOrTZChangeReceiver);
|
||||
unregisterActivityLifecycleCallbacks(activityMonitor);
|
||||
keepAliveManager.cancelAlarm(this);
|
||||
super.onTerminate();
|
||||
|
|
|
@ -3,14 +3,18 @@ package info.nightscout.androidaps.dependencyInjection
|
|||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
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.NetworkChangeReceiver
|
||||
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
abstract class ReceiversModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesDataReceiver(): DataReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesNetworkChangeReceiver(): NetworkChangeReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesRileyLinkBluetoothStateReceiver(): RileyLinkBluetoothStateReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver
|
||||
}
|
|
@ -6,9 +6,11 @@ class EventNetworkChange : Event() {
|
|||
|
||||
var mobileConnected = false
|
||||
var wifiConnected = false
|
||||
var vpnConnected = false
|
||||
|
||||
var ssid = ""
|
||||
var roaming = false
|
||||
var metered = false
|
||||
|
||||
fun connectedSsid(): String {
|
||||
return StringUtils.removeSurroundingQuotes(ssid)
|
||||
|
|
|
@ -15,17 +15,7 @@ class EventPreferenceChange : Event {
|
|||
changedKey = resourceHelper.gs(resourceID)
|
||||
}
|
||||
|
||||
@Deprecated("use injected version")
|
||||
constructor(resources: Resources, id: Int) {
|
||||
changedKey == resources.getString(id)
|
||||
}
|
||||
|
||||
fun isChanged(resourceHelper: ResourceHelper, id: Int): Boolean {
|
||||
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
|
||||
|
||||
enum class LTag(val tag: String, val defaultValue : Boolean = false, val requiresRestart: Boolean = false) {
|
||||
CORE("CORE", defaultValue = false),
|
||||
APS("APS", defaultValue = false),
|
||||
AUTOSENS("AUTOSENS"),
|
||||
AUTOMATION("AUTOMATION", defaultValue = false),
|
||||
BGSOURCE("BGSOURCE", defaultValue = false),
|
||||
enum class LTag(val tag: String, val defaultValue : Boolean = true, val requiresRestart: Boolean = false) {
|
||||
CORE("CORE"),
|
||||
APS("APS"),
|
||||
AUTOSENS("AUTOSENS", defaultValue = false),
|
||||
AUTOMATION("AUTOMATION"),
|
||||
BGSOURCE("BGSOURCE"),
|
||||
CONFIGBUILDER("CONFIGBUILDER"),
|
||||
CONSTRAINTS("CONSTRAINTS", defaultValue = false),
|
||||
DATABASE("DATABASE", defaultValue = false),
|
||||
DATAFOOD("DATAFOOD"),
|
||||
DATASERVICE("DATASERVICE", defaultValue = false),
|
||||
DATATREATMENTS("DATATREATMENTS", defaultValue = false),
|
||||
CONSTRAINTS("CONSTRAINTS"),
|
||||
DATABASE("DATABASE"),
|
||||
DATAFOOD("DATAFOOD", defaultValue = false),
|
||||
DATASERVICE("DATASERVICE"),
|
||||
DATATREATMENTS("DATATREATMENTS"),
|
||||
EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
|
||||
GLUCOSE("GLUCOSE"),
|
||||
LOCATION("LOCATION", defaultValue = false),
|
||||
NOTIFICATION("NOTIFICATION", defaultValue = false),
|
||||
NSCLIENT("NSCLIENT", defaultValue = false),
|
||||
LOCATION("LOCATION"),
|
||||
NOTIFICATION("NOTIFICATION"),
|
||||
NSCLIENT("NSCLIENT"),
|
||||
OVERVIEW("OVERVIEW", defaultValue = false),
|
||||
PUMP("PUMP", defaultValue = false),
|
||||
PUMPBTCOMM("PUMPBTCOMM"),
|
||||
PUMPCOMM("PUMPCOMM", defaultValue = false),
|
||||
PUMPQUEUE("PUMPQUEUE", defaultValue = false),
|
||||
PROFILE("PROFILE", defaultValue = false),
|
||||
SMS("SMS", defaultValue = false),
|
||||
PUMP("PUMP"),
|
||||
PUMPBTCOMM("PUMPBTCOMM", defaultValue = false),
|
||||
PUMPCOMM("PUMPCOMM"),
|
||||
PUMPQUEUE("PUMPQUEUE"),
|
||||
PROFILE("PROFILE"),
|
||||
SMS("SMS"),
|
||||
TIDEPOOL("TIDEPOOL"),
|
||||
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.EventObjectivesUpdateGui
|
||||
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.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
|
@ -48,6 +48,7 @@ class ObjectivesFragment : DaggerFragment() {
|
|||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var objectivesPlugin: ObjectivesPlugin
|
||||
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
|
||||
private val objectivesAdapter = ObjectivesAdapter()
|
||||
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.setTextColor(-0x3e3e3f)
|
||||
holder.verify.setOnClickListener {
|
||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||
receiverStatusStore.updateNetworkStatus()
|
||||
if (objectives_fake.isChecked) {
|
||||
objective.accomplishedOn = DateUtil.now()
|
||||
scrollToCurrentObjective()
|
||||
|
@ -257,12 +258,12 @@ class ObjectivesFragment : DaggerFragment() {
|
|||
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
||||
}
|
||||
}
|
||||
}, NetworkChangeReceiver.isConnected())
|
||||
}, receiverStatusStore.isConnected)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
holder.start.setOnClickListener {
|
||||
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||
receiverStatusStore.updateNetworkStatus()
|
||||
if (objectives_fake.isChecked) {
|
||||
objective.startedOn = DateUtil.now()
|
||||
scrollToCurrentObjective()
|
||||
|
@ -292,7 +293,7 @@ class ObjectivesFragment : DaggerFragment() {
|
|||
rxBus.send(EventNtpStatus(resourceHelper.gs(R.string.failedretrievetime), 99))
|
||||
}
|
||||
}
|
||||
}, NetworkChangeReceiver.isConnected())
|
||||
}, receiverStatusStore.isConnected)
|
||||
}.start()
|
||||
}
|
||||
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.StaticLabel
|
||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
|
||||
class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
|
||||
var ssid = InputString(injector)
|
||||
var comparator = Comparator(injector)
|
||||
|
||||
|
@ -39,7 +43,7 @@ class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
}
|
||||
|
||||
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) {
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||
return true
|
||||
|
|
|
@ -71,7 +71,7 @@ public class NSClientPlugin extends PluginBase {
|
|||
|
||||
public NSClientService nsClientService = null;
|
||||
|
||||
private NsClientReceiverDelegate nsClientReceiverDelegate = new NsClientReceiverDelegate();
|
||||
private NsClientReceiverDelegate nsClientReceiverDelegate;
|
||||
|
||||
@Inject
|
||||
public NSClientPlugin(
|
||||
|
@ -80,7 +80,8 @@ public class NSClientPlugin extends PluginBase {
|
|||
RxBusWrapper rxBus,
|
||||
ResourceHelper resourceHelper,
|
||||
Context context,
|
||||
SP sp
|
||||
SP sp,
|
||||
NsClientReceiverDelegate nsClientReceiverDelegate
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
|
@ -97,6 +98,7 @@ public class NSClientPlugin extends PluginBase {
|
|||
this.resourceHelper = resourceHelper;
|
||||
this.context = context;
|
||||
this.sp = sp;
|
||||
this.nsClientReceiverDelegate = nsClientReceiverDelegate;
|
||||
|
||||
if (Config.NSCLIENT) {
|
||||
getPluginDescription().alwaysEnabled(true).visibleByDefault(true);
|
||||
|
|
|
@ -1,50 +1,71 @@
|
|||
package info.nightscout.androidaps.plugins.general.nsclient;
|
||||
|
||||
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.events.EventChargingState;
|
||||
import info.nightscout.androidaps.events.EventNetworkChange;
|
||||
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.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 {
|
||||
|
||||
private boolean allowedChargingState = true;
|
||||
private boolean allowedNetworkState = true;
|
||||
boolean allowed = true;
|
||||
|
||||
void grabReceiversState() {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
private AAPSLogger aapsLogger;
|
||||
private Context context;
|
||||
private RxBusWrapper rxBus;
|
||||
private ResourceHelper resourceHelper;
|
||||
private SP sp;
|
||||
private ReceiverStatusStore receiverStatusStore;
|
||||
|
||||
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(context);
|
||||
if (event != null) RxBus.Companion.getINSTANCE().send(event);
|
||||
@Inject
|
||||
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);
|
||||
if (eventChargingState != null) RxBus.Companion.getINSTANCE().send(eventChargingState);
|
||||
rxBus.send(eventChargingState);
|
||||
|
||||
}
|
||||
|
||||
void onStatusEvent(EventPreferenceChange ev) {
|
||||
if (ev.isChanged(MainApp.resources(), R.string.key_ns_wifionly) ||
|
||||
ev.isChanged(MainApp.resources(), R.string.key_ns_wifi_ssids) ||
|
||||
ev.isChanged(MainApp.resources(), R.string.key_ns_allowroaming)
|
||||
if (ev.isChanged(resourceHelper, R.string.key_ns_wifionly) ||
|
||||
ev.isChanged(resourceHelper, R.string.key_ns_wifi_ssids) ||
|
||||
ev.isChanged(resourceHelper, R.string.key_ns_allowroaming)
|
||||
) {
|
||||
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
||||
if (event != null)
|
||||
RxBus.Companion.getINSTANCE().send(event);
|
||||
} else if (ev.isChanged(MainApp.resources(), R.string.key_ns_chargingonly)) {
|
||||
EventChargingState event = ChargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
||||
if (event != null)
|
||||
RxBus.Companion.getINSTANCE().send(event);
|
||||
receiverStatusStore.updateNetworkStatus();
|
||||
} else if (ev.isChanged(resourceHelper, R.string.key_ns_chargingonly)) {
|
||||
EventChargingState event = ChargingStateReceiver.grabChargingState(context);
|
||||
rxBus.send(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,12 +91,12 @@ class NsClientReceiverDelegate {
|
|||
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
||||
if (newAllowedState != allowed) {
|
||||
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 chargingOnly = SP.getBoolean(R.string.key_ns_chargingonly, false);
|
||||
boolean chargingOnly = sp.getBoolean(R.string.key_ns_chargingonly, false);
|
||||
boolean newAllowedState = true;
|
||||
|
||||
if (!ev.isCharging() && chargingOnly) {
|
||||
|
@ -86,9 +107,9 @@ class NsClientReceiverDelegate {
|
|||
}
|
||||
|
||||
boolean calculateStatus(final EventNetworkChange ev) {
|
||||
boolean wifiOnly = SP.getBoolean(R.string.key_ns_wifionly, false);
|
||||
String allowedSSIDs = SP.getString(R.string.key_ns_wifi_ssids, "");
|
||||
boolean allowRoaming = SP.getBoolean(R.string.key_ns_allowroaming, true);
|
||||
boolean wifiOnly = sp.getBoolean(R.string.key_ns_wifionly, false);
|
||||
String allowedSSIDs = sp.getString(R.string.key_ns_wifi_ssids, "");
|
||||
boolean allowRoaming = sp.getBoolean(R.string.key_ns_allowroaming, 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.utils.RateLimit
|
||||
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.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
@ -51,7 +51,8 @@ class TidepoolPlugin @Inject constructor(
|
|||
private val tidepoolUploader: TidepoolUploader,
|
||||
private val uploadChunk: UploadChunk,
|
||||
private val sp: SP,
|
||||
private val rateLimit: RateLimit
|
||||
private val rateLimit: RateLimit,
|
||||
private val receiverStatusStore: ReceiverStatusStore
|
||||
) : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
.pluginName(R.string.tidepool)
|
||||
|
@ -103,7 +104,7 @@ class TidepoolPlugin @Inject constructor(
|
|||
uploadChunk.setLastEnd(bgReading.date)
|
||||
if (isEnabled(PluginType.GENERAL)
|
||||
&& (!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()))
|
||||
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,
|
||||
* 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
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import dagger.android.DaggerBroadcastReceiver
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface
|
||||
|
@ -18,19 +16,11 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
|
|||
override fun onReceive(context: Context, intent: Intent) {
|
||||
super.onReceive(context, intent)
|
||||
val action = intent.action
|
||||
val activePump: PumpInterface = activePlugin.getActivePump()
|
||||
val activePump: PumpInterface = activePlugin.activePump
|
||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
|
||||
if (action != null) {
|
||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
|
||||
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
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.Config
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
||||
|
@ -46,7 +46,7 @@ import javax.inject.Singleton
|
|||
class SWDefinition @Inject constructor(
|
||||
injector: HasAndroidInjector,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val mainApp: MainApp,
|
||||
private val context: Context,
|
||||
resourceHelper: ResourceHelper,
|
||||
private val sp: SP,
|
||||
private val profileFunction: ProfileFunction,
|
||||
|
@ -58,10 +58,11 @@ class SWDefinition @Inject constructor(
|
|||
private val loopPlugin: LoopPlugin,
|
||||
private val nsClientPlugin: NSClientPlugin,
|
||||
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()
|
||||
|
||||
fun getScreens(): List<SWScreen> {
|
||||
|
@ -83,7 +84,7 @@ class SWDefinition @Inject constructor(
|
|||
.preferenceId(R.string.key_language).label(R.string.language)
|
||||
.comment(R.string.setupwizard_language_prompt))
|
||||
.validator(SWValidator {
|
||||
update(mainApp)
|
||||
update(context)
|
||||
sp.contains(R.string.key_language)
|
||||
})
|
||||
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
|
||||
|
@ -127,10 +128,10 @@ class SWDefinition @Inject constructor(
|
|||
.add(SWBreak(injector))
|
||||
.add(SWButton(injector)
|
||||
.text(R.string.askforpermission)
|
||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
||||
.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) })
|
||||
.validator(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) }))
|
||||
.visibility(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)
|
||||
.skippable(false)
|
||||
.add(SWInfotext(injector)
|
||||
|
@ -138,10 +139,10 @@ class SWDefinition @Inject constructor(
|
|||
.add(SWBreak(injector))
|
||||
.add(SWButton(injector)
|
||||
.text(R.string.askforpermission)
|
||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
||||
.action(Runnable { AndroidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) }))
|
||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
||||
.validator(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) }))
|
||||
.visibility(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)
|
||||
.skippable(false)
|
||||
.add(SWInfotext(injector)
|
||||
|
@ -149,10 +150,10 @@ class SWDefinition @Inject constructor(
|
|||
.add(SWBreak(injector))
|
||||
.add(SWButton(injector)
|
||||
.text(R.string.askforpermission)
|
||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||
.action(Runnable { AndroidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) }))
|
||||
.visibility(SWValidator { AndroidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
||||
.validator(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) }))
|
||||
.visibility(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)
|
||||
.add(SWInfotext(injector)
|
||||
.label(R.string.storedsettingsfound))
|
||||
|
@ -160,7 +161,7 @@ class SWDefinition @Inject constructor(
|
|||
.add(SWButton(injector)
|
||||
.text(R.string.nav_import)
|
||||
.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)
|
||||
.skippable(true)
|
||||
.add(SWInfotext(injector)
|
||||
|
@ -219,13 +220,11 @@ class SWDefinition @Inject constructor(
|
|||
.text(R.string.insulinsourcesetup)
|
||||
.action(Runnable {
|
||||
val plugin = activePlugin.activeInsulin as PluginBase
|
||||
activity?.let { activity ->
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
}
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
})
|
||||
.visibility(SWValidator { (activePlugin.activeInsulin as PluginBase).preferencesId > 0 }))
|
||||
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
|
||||
|
@ -238,13 +237,11 @@ class SWDefinition @Inject constructor(
|
|||
.text(R.string.bgsourcesetup)
|
||||
.action(Runnable {
|
||||
val plugin = activePlugin.activeBgSource as PluginBase
|
||||
activity?.let { activity ->
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
}
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
})
|
||||
.visibility(SWValidator { (activePlugin.activeBgSource as PluginBase).preferencesId > 0 }))
|
||||
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
|
||||
|
@ -275,7 +272,7 @@ class SWDefinition @Inject constructor(
|
|||
.label(R.string.profileswitch_ismissing))
|
||||
.add(SWButton(injector)
|
||||
.text(R.string.doprofileswitch)
|
||||
.action(Runnable { ProfileSwitchDialog().show(activity!!.supportFragmentManager, "SetupWizard") }))
|
||||
.action(Runnable { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") }))
|
||||
.validator(SWValidator { profileFunction.getProfile() != null })
|
||||
.visibility(SWValidator { profileFunction.getProfile() == null })
|
||||
private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
|
||||
|
@ -288,13 +285,11 @@ class SWDefinition @Inject constructor(
|
|||
.text(R.string.pumpsetup)
|
||||
.action(Runnable {
|
||||
val plugin = activePlugin.activePump as PluginBase
|
||||
activity?.let { activity ->
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
}
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
})
|
||||
.visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 }))
|
||||
.add(SWButton(injector)
|
||||
|
@ -317,13 +312,11 @@ class SWDefinition @Inject constructor(
|
|||
.text(R.string.apssetup)
|
||||
.action(Runnable {
|
||||
val plugin = activePlugin.activeAPS as PluginBase
|
||||
activity?.let { activity ->
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
}
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
})
|
||||
.visibility(SWValidator { (activePlugin.activeAPS as PluginBase).preferencesId > 0 }))
|
||||
.visibility(SWValidator { Config.APS })
|
||||
|
@ -367,13 +360,11 @@ class SWDefinition @Inject constructor(
|
|||
.text(R.string.sensitivitysetup)
|
||||
.action(Runnable {
|
||||
val plugin = activePlugin.activeSensitivity as PluginBase
|
||||
activity?.let { activity ->
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
}
|
||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
val i = Intent(activity, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
activity.startActivity(i)
|
||||
}, null)
|
||||
})
|
||||
.visibility(SWValidator { (activePlugin.activeSensitivity as PluginBase).preferencesId > 0 }))
|
||||
private val getScreenObjectives = SWScreen(injector, R.string.objectives)
|
||||
|
|
|
@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
|
|||
import dagger.android.HasAndroidInjector
|
||||
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
|
||||
|
||||
fun add(fragment: Fragment): SWFragment {
|
||||
|
@ -14,6 +14,6 @@ class SWFragment(injecto:HasAndroidInjector, private var definition: SWDefinitio
|
|||
}
|
||||
|
||||
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 info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.data.ProfileStore
|
||||
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||
import org.json.JSONObject
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
|
@ -13,6 +14,9 @@ import org.mockito.junit.MockitoRule
|
|||
import java.util.*
|
||||
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
|
||||
// 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.
|
||||
@get:Rule
|
||||
|
|
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.ProfileStore
|
|||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
|
@ -18,7 +19,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest
|
|||
|
||||
@PrepareForTest(FabricPrivacy::class)
|
||||
open class TestBaseWithProfile : TestBase() {
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(Profile::class)
|
||||
class QuickWizardTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@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)
|
||||
class BgReadingTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
|
|
@ -19,8 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(MainApp::class, SP::class)
|
||||
class ConstraintTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
@Test fun doTests() {
|
||||
val b = Constraint(true)
|
||||
Assert.assertEquals(true, b.value())
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
|
||||
class LoopPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
|
|
|
@ -25,7 +25,6 @@ class ConfigBuilderPluginTest : TestBase() {
|
|||
@Mock lateinit var treatmentsPlugin: Lazy<TreatmentsPlugin>
|
||||
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.*
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class DstHelperPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class ObjectivesPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var sp: SP
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.junit.Test
|
|||
import org.mockito.Mock
|
||||
|
||||
class SignatureVerifierPluginTest : TestBase() {
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var context: Context
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class StorageConstraintPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
private val rxBusWrapper = RxBusWrapper()
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ class VersionCheckerUtilsKtTest : TestBase() {
|
|||
|
||||
lateinit var versionCheckerUtils: VersionCheckerUtils
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var context: Context
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class AutomationEventTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var loopPlugin: LoopPlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(NSUpload::class, RxBusWrapper::class)
|
||||
class ActionNotificationTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.androidaps.events.EventNetworkChange
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
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.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||
import info.nightscout.androidaps.services.LastLocationDataContainer
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.junit.Before
|
||||
import org.mockito.Mock
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
|
||||
|
@ -27,6 +31,14 @@ open class TriggerTestBase : TestBaseWithProfile() {
|
|||
@Mock lateinit var locationDataContainer: LastLocationDataContainer
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
|
||||
@Before
|
||||
fun prepareMock1() {
|
||||
receiverStatusStore = ReceiverStatusStore(context)
|
||||
}
|
||||
|
||||
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
|
@ -44,6 +56,9 @@ open class TriggerTestBase : TestBaseWithProfile() {
|
|||
if (it is TriggerBg) {
|
||||
it.profileFunction = profileFunction
|
||||
}
|
||||
if (it is TriggerWifiSsid) {
|
||||
it.receiverStatusStore = receiverStatusStore
|
||||
}
|
||||
if (it is InputBg) {
|
||||
it.profileFunction = profileFunction
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
|||
|
||||
@Test fun shouldRunTest() {
|
||||
val e = EventNetworkChange()
|
||||
PowerMockito.`when`(NetworkChangeReceiver.getLastEvent()).thenReturn(e)
|
||||
receiverStatusStore.lastNetworkEvent = e
|
||||
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
|
||||
e.wifiConnected = false
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
|
@ -45,7 +45,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
|||
Assert.assertTrue(t.shouldRun())
|
||||
|
||||
// no network data
|
||||
PowerMockito.`when`(NetworkChangeReceiver.getLastEvent()).thenReturn(null)
|
||||
receiverStatusStore.lastNetworkEvent = null
|
||||
Assert.assertFalse(t.shouldRun())
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ class MaintenancePluginTest : TestBase() {
|
|||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var nsSettingsStatus: NSSettingsStatus
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var buildHelper: BuildHelper
|
||||
|
||||
lateinit var sut: MaintenancePlugin
|
||||
|
|
|
@ -6,7 +6,11 @@ import info.nightscout.androidaps.R
|
|||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.events.EventChargingState
|
||||
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.Before
|
||||
import org.junit.Test
|
||||
|
@ -16,6 +20,7 @@ import org.mockito.ArgumentMatchers.anyBoolean
|
|||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.anyLong
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.mock
|
||||
|
@ -27,30 +32,38 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(MainApp::class, SP::class, Context::class)
|
||||
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
|
||||
|
||||
@Before fun prepare() {
|
||||
receiverStatusStore = ReceiverStatusStore(context)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
PowerMockito.mockStatic(MainApp::class.java)
|
||||
val mainApp: MainApp = mock(MainApp::class.java)
|
||||
`when`(MainApp.instance()).thenReturn(mainApp)
|
||||
PowerMockito.mockStatic(SP::class.java)
|
||||
`when`(SP.getLong(anyInt(), anyLong())).thenReturn(0L)
|
||||
`when`(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
|
||||
`when`(SP.getInt(anyInt(), anyInt())).thenReturn(0)
|
||||
`when`(SP.getString(anyInt(), anyString())).thenReturn("")
|
||||
`when`(sp.getLong(anyInt(), anyLong())).thenReturn(0L)
|
||||
`when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
|
||||
`when`(sp.getInt(anyInt(), anyInt())).thenReturn(0)
|
||||
`when`(sp.getString(anyInt(), anyString())).thenReturn("")
|
||||
|
||||
sut = NsClientReceiverDelegate()
|
||||
sut = NsClientReceiverDelegate(aapsLogger, context, rxBus, resourceHelper, sp, receiverStatusStore)
|
||||
}
|
||||
|
||||
@Test fun testCalculateStatusChargingState() {
|
||||
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)
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
ev = EventChargingState(false)
|
||||
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)
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
ev = EventChargingState(false)
|
||||
|
@ -61,15 +74,15 @@ class NsClientReceiverDelegateTest : TestBase() {
|
|||
PowerMockito.mockStatic(SP::class.java)
|
||||
// wifiOnly = false
|
||||
// allowRoaming = false as well
|
||||
Mockito.`when`(SP.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
||||
Mockito.`when`(SP.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("")
|
||||
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false)
|
||||
Mockito.`when`(sp.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("")
|
||||
val ev = EventNetworkChange()
|
||||
ev.ssid = "<unknown ssid>"
|
||||
ev.mobileConnected = true
|
||||
ev.wifiConnected = true
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
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))
|
||||
ev.ssid = "\"test\""
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
|
@ -78,7 +91,7 @@ class NsClientReceiverDelegateTest : TestBase() {
|
|||
|
||||
// wifiOnly = true
|
||||
// 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
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
ev.wifiConnected = false
|
||||
|
@ -86,39 +99,39 @@ class NsClientReceiverDelegateTest : TestBase() {
|
|||
|
||||
// wifiOnly = false
|
||||
// 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.roaming = true
|
||||
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
||||
|
||||
// wifiOnly = false
|
||||
// allowRoaming = true
|
||||
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_wifionly, false)).thenReturn(false)
|
||||
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||
ev.wifiConnected = false
|
||||
ev.roaming = true
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
|
||||
// wifiOnly = true
|
||||
// allowRoaming = 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_wifionly, false)).thenReturn(true)
|
||||
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||
ev.wifiConnected = false
|
||||
ev.roaming = true
|
||||
Assert.assertTrue(!sut!!.calculateStatus(ev))
|
||||
|
||||
// wifiOnly = true
|
||||
// allowRoaming = 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_wifionly, false)).thenReturn(true)
|
||||
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
|
||||
ev.wifiConnected = true
|
||||
ev.roaming = true
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
|
||||
// wifiOnly = false
|
||||
// allowRoaming = 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_wifionly, false)).thenReturn(false)
|
||||
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false)
|
||||
ev.wifiConnected = true
|
||||
ev.roaming = true
|
||||
Assert.assertTrue(sut!!.calculateStatus(ev))
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class)
|
||||
class AuthRequestTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var otp: OneTimePassword
|
||||
|
|
|
@ -30,7 +30,6 @@ class InsulinOrefFreePeakPluginTest : TestBase() {
|
|||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.*
|
|||
@PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class)
|
||||
class GlucoseStatusTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.*
|
|||
@PrepareForTest(FabricPrivacy::class)
|
||||
class IobCobCalculatorPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
private val rxBus: RxBusWrapper = RxBusWrapper()
|
||||
@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)
|
||||
class ComboPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
|
|
|
@ -14,8 +14,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class DetailedBolusInfoStorageTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private val info1 = DetailedBolusInfo()
|
||||
private val info2 = DetailedBolusInfo()
|
||||
private val info3 = DetailedBolusInfo()
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.mockito.Mock
|
|||
|
||||
open class DanaRTestBase : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var injector: HasAndroidInjector
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(FabricPrivacy::class)
|
||||
class VirtualPumpPluginUTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
val rxBus = RxBusWrapper()
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
class AbstractSensitivityPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var pluginDescription: PluginDescription
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.mockito.Mock
|
|||
class GlimpPluginTest : TestBase() {
|
||||
private lateinit var glimpPlugin: GlimpPlugin
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
@Before
|
||||
|
|
|
@ -17,7 +17,6 @@ class MM640GPluginTest : TestBase() {
|
|||
|
||||
private lateinit var mM640gPlugin: MM640gPlugin
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
@Before
|
||||
|
|
|
@ -18,7 +18,6 @@ class NSClientPluginTest : TestBase() {
|
|||
|
||||
private lateinit var nsClientSourcePlugin: NSClientSourcePlugin
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ class XdripPluginTest : TestBase() {
|
|||
|
||||
private lateinit var xdripPlugin: XdripPlugin
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
@Before
|
||||
|
|
|
@ -37,7 +37,6 @@ class BolusWizardTest : TestBase() {
|
|||
|
||||
private val PUMP_BOLUS_STEP = 0.1
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
|
|
Loading…
Reference in a new issue