Merge remote-tracking branch 'origin/dagger3' into rs

This commit is contained in:
Milos Kozak 2020-03-30 10:12:12 +02:00
commit 7e8c079210
10 changed files with 68 additions and 121 deletions

View file

@ -37,8 +37,6 @@ import javax.inject.Inject
@RunWith(AndroidJUnit4::class)
class RealPumpTest {
private val log = LoggerFactory.getLogger(L.CORE)
companion object {
const val R_PASSWORD = 1234
const val R_SERIAL = "PBB00013LR_P"
@ -120,12 +118,12 @@ class RealPumpTest {
preparePlugins()
while (!pump.isInitialized) {
log.debug("Waiting for initialization")
//log.debug("Waiting for initialization")
SystemClock.sleep(1000)
}
while (true) {
log.debug("Tick")
//log.debug("Tick")
SystemClock.sleep(1000)
}
}

View file

@ -1,65 +1,25 @@
package info.nightscout.androidaps.logging
import info.nightscout.androidaps.utils.SP
import androidx.preference.PreferenceManager
import info.nightscout.androidaps.MainApp
import java.util.*
object L {
private var logElements: MutableList<LogElement> = ArrayList()
const val CORE = "CORE"
const val AUTOSENS = "AUTOSENS"
const val AUTOMATION = "AUTOMATION"
const val EVENTS = "EVENTS"
const val GLUCOSE = "GLUCOSE"
const val BGSOURCE = "BGSOURCE"
const val OVERVIEW = "OVERVIEW"
const val NOTIFICATION = "NOTIFICATION"
const val DATASERVICE = "DATASERVICE"
const val DATABASE = "DATABASE"
const val DATAFOOD = "DATAFOOD"
const val DATATREATMENTS = "DATATREATMENTS"
const val NSCLIENT = "NSCLIENT"
const val TIDEPOOL = "TIDEPOOL"
const val CONSTRAINTS = "CONSTRAINTS"
const val PUMP = "PUMP"
const val PUMPQUEUE = "PUMPQUEUE"
const val PUMPCOMM = "PUMPCOMM"
const val PUMPBTCOMM = "PUMPBTCOMM"
const val APS = "APS"
const val PROFILE = "PROFILE"
const val CONFIGBUILDER = "CONFIGBUILDER"
const val UI = "UI"
const val LOCATION = "LOCATION"
const val SMS = "SMS"
const val WEAR = "WEAR"
init {
logElements.add(LogElement(APS, defaultValue = true))
logElements.add(LogElement(AUTOMATION, defaultValue = true))
logElements.add(LogElement(AUTOSENS, defaultValue = false))
logElements.add(LogElement(BGSOURCE, defaultValue = true))
logElements.add(LogElement(GLUCOSE, defaultValue = false))
logElements.add(LogElement(CONFIGBUILDER, defaultValue = false))
logElements.add(LogElement(CONSTRAINTS, defaultValue = true))
logElements.add(LogElement(CORE, defaultValue = true))
logElements.add(LogElement(DATABASE, defaultValue = true))
logElements.add(LogElement(DATAFOOD, false))
logElements.add(LogElement(DATASERVICE, true))
logElements.add(LogElement(DATATREATMENTS, true))
logElements.add(LogElement(EVENTS, false, requiresRestart = true))
logElements.add(LogElement(LOCATION, true))
logElements.add(LogElement(NOTIFICATION, true))
logElements.add(LogElement(NSCLIENT, true))
logElements.add(LogElement(TIDEPOOL, true))
logElements.add(LogElement(OVERVIEW, true))
logElements.add(LogElement(PROFILE, true))
logElements.add(LogElement(PUMP, true))
logElements.add(LogElement(PUMPBTCOMM, false))
logElements.add(LogElement(PUMPCOMM, true))
logElements.add(LogElement(PUMPQUEUE, true))
logElements.add(LogElement(SMS, true))
logElements.add(LogElement(UI, true))
logElements.add(LogElement(WEAR, true))
LTag.values().forEach { logElements.add(LogElement(it)) }
}
private fun findByName(name: String): LogElement {
@ -90,17 +50,13 @@ object L {
var enabled: Boolean
private var requiresRestart = false
internal constructor(name: String, defaultValue: Boolean) {
this.name = name
this.defaultValue = defaultValue
enabled = SP.getBoolean(getSPName(), defaultValue)
}
internal constructor(name: String, defaultValue: Boolean, requiresRestart: Boolean) {
this.name = name
this.defaultValue = defaultValue
this.requiresRestart = requiresRestart
enabled = SP.getBoolean(getSPName(), defaultValue)
internal constructor(tag: LTag) {
this.name = tag.tag
this.defaultValue = tag.defaultValue
this.requiresRestart = tag.requiresRestart
//TODO: remove after getting rid of old logging style "if (L.isEnabled(...))"
@Suppress("DEPRECATION")
enabled = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean(getSPName(), defaultValue)
}
internal constructor(defaultValue: Boolean) {
@ -113,40 +69,12 @@ object L {
fun enable(enabled: Boolean) {
this.enabled = enabled
SP.putBoolean(getSPName(), enabled)
@Suppress("DEPRECATION")
PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).edit().putBoolean(getSPName(), enabled).apply()
}
fun resetToDefault() {
enable(defaultValue)
}
}
}
enum class LTag(val tag: String) {
CORE("CORE"),
AUTOSENS("AUTOSENS"),
AUTOMATION("AUTOMATION"),
EVENTS("EVENTS"),
GLUCOSE("GLUCOSE"),
BGSOURCE("BGSOURCE"),
OVERVIEW("OVERVIEW"),
NOTIFICATION("NOTIFICATION"),
DATASERVICE("DATASERVICE"),
DATABASE("DATABASE"),
DATAFOOD("DATAFOOD"),
DATATREATMENTS("DATATREATMENTS"),
NSCLIENT("NSCLIENT"),
TIDEPOOL("TIDEPOOL"),
CONSTRAINTS("CONSTRAINTS"),
PUMP("PUMP"),
PUMPQUEUE("PUMPQUEUE"),
PUMPCOMM("PUMPCOMM"),
PUMPBTCOMM("PUMPBTCOMM"),
APS("APS"),
PROFILE("PROFILE"),
CONFIGBUILDER("CONFIGBUILDER"),
UI("UI"),
LOCATION("LOCATION"),
WEAR("WEAR"),
SMS("SMS"),
}

View file

@ -0,0 +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),
CONFIGBUILDER("CONFIGBUILDER"),
CONSTRAINTS("CONSTRAINTS", defaultValue = false),
DATABASE("DATABASE", defaultValue = false),
DATAFOOD("DATAFOOD"),
DATASERVICE("DATASERVICE", defaultValue = false),
DATATREATMENTS("DATATREATMENTS", defaultValue = false),
EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
GLUCOSE("GLUCOSE"),
LOCATION("LOCATION", defaultValue = false),
NOTIFICATION("NOTIFICATION", defaultValue = false),
NSCLIENT("NSCLIENT", defaultValue = false),
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),
TIDEPOOL("TIDEPOOL"),
UI("UI", defaultValue = false),
WEAR("WEAR")
}

View file

@ -366,7 +366,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
*/
public class DeviceStatus {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.APS);
private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT);
public String device = null;
public JSONObject pump = null;

View file

@ -334,8 +334,7 @@ public class LoopPlugin extends PluginBase {
Profile profile = profileFunction.getProfile();
if (profile == null || !profileFunction.isProfileValid("Loop")) {
if (L.isEnabled(L.APS))
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
rxBus.send(new EventLoopSetLastRunGui(resourceHelper.gs(R.string.noprofileselected)));
return;
}

View file

@ -109,8 +109,7 @@ public class DetermineBasalAdapterMAJS {
// Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
if (L.isEnabled(L.APS))
aapsLogger.debug(LTag.APS, "Result: " + result);
aapsLogger.debug(LTag.APS, "Result: " + result);
try {
determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result));
} catch (JSONException e) {

View file

@ -2,17 +2,14 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.LTag;
/**
* Created by mike on 06.01.2017.
*/
public class AutosensResult {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.AUTOSENS);
//default values to show when autosens algorithm is not called
public double ratio = 1d;
@ -30,7 +27,7 @@ public class AutosensResult {
ret.put("sensResult", sensResult);
ret.put("ratio", ratio);
} catch (JSONException e) {
log.error("Unhandled exception", e);
LoggerFactory.getLogger(LTag.CORE.getTag()).error("Unhandled exception", e);
}
return ret;
}

View file

@ -196,17 +196,15 @@ public class IobCobOref1Thread extends Thread {
try {
for (; past < 12; past++) {
AutosensData ad = autosensDataTable.valueAt(initialIndex + past);
if (L.isEnabled(L.AUTOSENS)) {
aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
if (ad == null) {
aapsLogger.debug(autosensDataTable.toString());
aapsLogger.debug(bucketed_data.toString());
aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString());
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
rxBus.send(new EventNewNotification(notification));
sp.putBoolean("log_AUTOSENS", true);
break;
}
aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
if (ad == null) {
aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString());
aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString());
aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString());
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
rxBus.send(new EventNewNotification(notification));
sp.putBoolean("log_AUTOSENS", true);
break;
}
// let it here crash on NPE to get more data as i cannot reproduce this bug
double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;

View file

@ -21,7 +21,6 @@ import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
@ -193,17 +192,15 @@ public class IobCobThread extends Thread {
try {
for (; past < 12; past++) {
AutosensData ad = autosensDataTable.valueAt(initialIndex + past);
if (L.isEnabled(L.AUTOSENS)) {
aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
if (ad == null) {
aapsLogger.debug(autosensDataTable.toString());
aapsLogger.debug(bucketed_data.toString());
aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString());
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
rxBus.send(new EventNewNotification(notification));
sp.putBoolean("log_AUTOSENS", true);
break;
}
aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
if (ad == null) {
aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString());
aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString());
aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString());
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
rxBus.send(new EventNewNotification(notification));
sp.putBoolean("log_AUTOSENS", true);
break;
}
// let it here crash on NPE to get more data as i cannot reproduce this bug
double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;

View file

@ -39,6 +39,7 @@ object OKDialog {
}
fun runOnUiThread(theRunnable: Runnable?) {
@Suppress("DEPRECATION"
val mainHandler = Handler(MainApp.instance().applicationContext.mainLooper)
theRunnable?.let { mainHandler.post(it) }
}