dagger logging start

This commit is contained in:
AdrianLxM 2019-12-28 01:52:20 +01:00
parent a2d2dd38e3
commit 9a72912281
11 changed files with 202 additions and 144 deletions

View file

@ -34,9 +34,6 @@ import com.google.android.material.tabs.TabLayout;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeModule; import com.joanzapata.iconify.fonts.FontAwesomeModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
@ -53,7 +50,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRebuildTabs; import info.nightscout.androidaps.events.EventRebuildTabs;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt; import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt;
@ -71,7 +69,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
public class MainActivity extends NoSplashAppCompatActivity implements HasAndroidInjector { public class MainActivity extends NoSplashAppCompatActivity implements HasAndroidInjector {
private static Logger log = LoggerFactory.getLogger(L.CORE);
@Inject @Inject
DispatchingAndroidInjector<Object> androidInjector; DispatchingAndroidInjector<Object> androidInjector;
@ -85,6 +82,9 @@ public class MainActivity extends NoSplashAppCompatActivity implements HasAndroi
@Inject @Inject
SmsCommunicatorPlugin smsCommunicatorPlugin; SmsCommunicatorPlugin smsCommunicatorPlugin;
@Inject
AAPSLogger aapsLogger;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this); AndroidInjection.inject(this);
@ -327,7 +327,7 @@ public class MainActivity extends NoSplashAppCompatActivity implements HasAndroi
((TextView) alertDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); ((TextView) alertDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
return true; return true;
case R.id.nav_exit: case R.id.nav_exit:
log.debug("Exiting"); aapsLogger.debug(LTag.CORE, "Exiting");
RxBus.INSTANCE.send(new EventAppExit()); RxBus.INSTANCE.send(new EventAppExit());
finish(); finish();
System.runFinalization(); System.runFinalization();

View file

@ -33,7 +33,9 @@ import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
@ -121,12 +123,20 @@ public class MainApp extends DaggerApplication {
public static boolean devBranch; public static boolean devBranch;
public static boolean engineeringMode; public static boolean engineeringMode;
@Inject ConfigBuilderPlugin configBuilderPlugin; @Inject
AAPSLogger aapsLogger;
@Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin; @Inject
@Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin; ConfigBuilderPlugin configBuilderPlugin;
@Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
@Inject SmsCommunicatorPlugin smsCommunicatorPlugin; @Inject
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
@Inject
InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
@Inject
InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
@Inject
SmsCommunicatorPlugin smsCommunicatorPlugin;
@Override @Override
public void onCreate() { public void onCreate() {
@ -433,8 +443,8 @@ public class MainApp extends DaggerApplication {
@Override @Override
public void onTerminate() { public void onTerminate() {
if (L.isEnabled(L.CORE))
log.debug("onTerminate"); aapsLogger.debug(LTag.CORE, "onTerminate");
if (timeDateOrTZChangeReceiver != null) if (timeDateOrTZChangeReceiver != null)
unregisterReceiver(timeDateOrTZChangeReceiver); unregisterReceiver(timeDateOrTZChangeReceiver);

View file

@ -6,7 +6,11 @@ import dagger.Binds
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerDebug
import info.nightscout.androidaps.logging.AAPSLoggerProduction
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
@ -46,6 +50,16 @@ class AppModule {
return ResourceHelperImplementation(mainApp) return ResourceHelperImplementation(mainApp)
} }
@Provides
@Singleton
fun provideAAPSLogger(): AAPSLogger {
return if (BuildConfig.DEBUG) {
AAPSLoggerDebug()
} else {
AAPSLoggerProduction()
}
}
@Module @Module
interface AppBindings { interface AppBindings {

View file

@ -1,62 +0,0 @@
package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.data.Profile
interface ConstraintsInterface {
fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> {
return absoluteRate
}
fun applyBasalPercentConstraints(percentRate: Constraint<Int>, profile: Profile): Constraint<Int> {
return percentRate
}
fun applyBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
return insulin
}
fun applyExtendedBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
return insulin
}
fun applyCarbsConstraints(carbs: Constraint<Int>): Constraint<Int> {
return carbs
}
fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
return maxIob
}
}

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.logging
/**
* Created by adrian on 2019-12-27.
*/
interface AAPSLogger {
fun debug(tag: LTag, message: String)
fun info(tag: LTag, message: String)
fun error(tag: LTag, message: String)
fun error(tag: LTag, message: String, throwable: Throwable)
}

View file

@ -0,0 +1,28 @@
package info.nightscout.androidaps.logging
import android.util.Log
/**
* Created by adrian on 2019-12-27.
*/
class AAPSLoggerDebug : AAPSLogger {
override fun debug(tag: LTag, message: String) {
Log.d(tag.tag, message)
}
override fun info(tag: LTag, message: String) {
Log.i(tag.tag, message)
}
override fun error(tag: LTag, message: String) {
Log.e(tag.tag, message)
}
override fun error(tag: LTag, message: String, throwable: Throwable) {
Log.e(tag.tag, message, throwable)
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.logging
import org.slf4j.LoggerFactory
/**
* Created by adrian on 2019-12-27.
*/
class AAPSLoggerProduction : AAPSLogger {
override fun debug(tag: LTag, message: String) {
if (L.isEnabled(tag.tag)) {
LoggerFactory.getLogger(tag.tag).debug(message)
}
}
override fun info(tag: LTag, message: String) {
if (L.isEnabled(tag.tag)) {
LoggerFactory.getLogger(tag.tag).info(message)
}
}
override fun error(tag: LTag, message: String) {
if (L.isEnabled(tag.tag)) {
LoggerFactory.getLogger(tag.tag).error(message)
}
}
override fun error(tag: LTag, message: String, throwable: Throwable) {
if (L.isEnabled(tag.tag)) {
LoggerFactory.getLogger(tag.tag).error(message, throwable)
}
}
}

View file

@ -119,3 +119,31 @@ object L {
} }
} }
} }
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"),
SMS("SMS"),
}

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.configBuilder;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,7 +22,8 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
@ -39,9 +38,8 @@ import info.nightscout.androidaps.utils.SP;
*/ */
@Singleton @Singleton
public class ConfigBuilderPlugin extends PluginBase { public class ConfigBuilderPlugin extends PluginBase {
private Logger log = LoggerFactory.getLogger(L.CONFIGBUILDER);
private static ConfigBuilderPlugin configBuilderPlugin; private static ConfigBuilderPlugin configBuilderPlugin;
private final AAPSLogger aapsLogger; // TODO move to plugin base
/** /**
@ -78,7 +76,10 @@ public class ConfigBuilderPlugin extends PluginBase {
* Lazy dependencies in this constructor. * Lazy dependencies in this constructor.
* */ * */
@Inject @Inject
public ConfigBuilderPlugin(Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin) { public ConfigBuilderPlugin(
Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin,
AAPSLogger aapsLogger
) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
.fragmentClass(ConfigBuilderFragment.class.getName()) .fragmentClass(ConfigBuilderFragment.class.getName())
@ -90,6 +91,7 @@ public class ConfigBuilderPlugin extends PluginBase {
.description(R.string.description_config_builder) .description(R.string.description_config_builder)
); );
this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin; this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin;
this.aapsLogger = aapsLogger;
configBuilderPlugin = this; // TODO: only while transitioning to Dagger configBuilderPlugin = this; // TODO: only while transitioning to Dagger
} }
@ -122,8 +124,7 @@ public class ConfigBuilderPlugin extends PluginBase {
public void storeSettings(String from) { public void storeSettings(String from) {
if (pluginList != null) { if (pluginList != null) {
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Storing settings from: " + from);
log.debug("Storing settings from: " + from);
verifySelectionInCategories(); verifySelectionInCategories();
@ -146,19 +147,16 @@ public class ConfigBuilderPlugin extends PluginBase {
private void savePref(PluginBase p, PluginType type, boolean storeVisible) { private void savePref(PluginBase p, PluginType type, boolean storeVisible) {
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled"; String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
SP.putBoolean(settingEnabled, p.isEnabled(type)); SP.putBoolean(settingEnabled, p.isEnabled(type));
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Storing: " + settingEnabled + ":" + p.isEnabled(type));
log.debug("Storing: " + settingEnabled + ":" + p.isEnabled(type));
if (storeVisible) { if (storeVisible) {
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible"; String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
SP.putBoolean(settingVisible, p.isFragmentVisible()); SP.putBoolean(settingVisible, p.isFragmentVisible());
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Storing: " + settingVisible + ":" + p.isFragmentVisible());
log.debug("Storing: " + settingVisible + ":" + p.isFragmentVisible());
} }
} }
private void loadSettings() { private void loadSettings() {
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Loading stored settings");
log.debug("Loading stored settings");
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
PluginType type = p.getType(); PluginType type = p.getType();
loadPref(p, type, true); loadPref(p, type, true);
@ -178,8 +176,7 @@ public class ConfigBuilderPlugin extends PluginBase {
else if (p.getType() == type && (p.pluginDescription.enableByDefault || p.pluginDescription.alwaysEnabled)) { else if (p.getType() == type && (p.pluginDescription.enableByDefault || p.pluginDescription.alwaysEnabled)) {
p.setPluginEnabled(type, true); p.setPluginEnabled(type, true);
} }
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingEnabled + ":" + p.isEnabled(type));
log.debug("Loaded: " + settingEnabled + ":" + p.isEnabled(type));
if (loadVisible) { if (loadVisible) {
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible"; String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
if (SP.contains(settingVisible)) if (SP.contains(settingVisible))
@ -187,8 +184,7 @@ public class ConfigBuilderPlugin extends PluginBase {
else if (p.getType() == type && p.pluginDescription.visibleByDefault) { else if (p.getType() == type && p.pluginDescription.visibleByDefault) {
p.setFragmentVisible(type, true); p.setFragmentVisible(type, true);
} }
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingVisible + ":" + p.isFragmentVisible());
log.debug("Loaded: " + settingVisible + ":" + p.isFragmentVisible());
} }
} }
@ -196,11 +192,9 @@ public class ConfigBuilderPlugin extends PluginBase {
private void upgradeSettings() { private void upgradeSettings() {
if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled")) if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled"))
return; return;
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Upgrading stored settings");
log.debug("Upgrading stored settings");
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Processing " + p.getName());
log.debug("Processing " + p.getName());
for (int type = 1; type < 11; type++) { for (int type = 1; type < 11; type++) {
PluginType newType; PluginType newType;
switch (type) { switch (type) {
@ -291,9 +285,8 @@ public class ConfigBuilderPlugin extends PluginBase {
} }
public void logPluginStatus() { public void logPluginStatus() {
if (L.isEnabled(L.CONFIGBUILDER))
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
log.debug(p.getName() + ":" + aapsLogger.debug(LTag.CONFIGBUILDER, p.getName() + ":" +
(p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") + (p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") +
(p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") + (p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") +
(p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") + (p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") +
@ -320,8 +313,7 @@ public class ConfigBuilderPlugin extends PluginBase {
if (activeInsulin == null) { if (activeInsulin == null) {
activeInsulin = insulinOrefRapidActingPlugin.get(); activeInsulin = insulinOrefRapidActingPlugin.get();
insulinOrefRapidActingPlugin.get().setPluginEnabled(PluginType.INSULIN, true); insulinOrefRapidActingPlugin.get().setPluginEnabled(PluginType.INSULIN, true);
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting InsulinOrefRapidActingPlugin");
log.debug("Defaulting InsulinOrefRapidActingPlugin");
} }
this.setFragmentVisiblities(((PluginBase) activeInsulin).getName(), pluginsInCategory, PluginType.INSULIN); this.setFragmentVisiblities(((PluginBase) activeInsulin).getName(), pluginsInCategory, PluginType.INSULIN);
@ -331,8 +323,7 @@ public class ConfigBuilderPlugin extends PluginBase {
if (activeSensitivity == null) { if (activeSensitivity == null) {
activeSensitivity = SensitivityOref0Plugin.getPlugin(); activeSensitivity = SensitivityOref0Plugin.getPlugin();
SensitivityOref0Plugin.getPlugin().setPluginEnabled(PluginType.SENSITIVITY, true); SensitivityOref0Plugin.getPlugin().setPluginEnabled(PluginType.SENSITIVITY, true);
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting SensitivityOref0Plugin");
log.debug("Defaulting SensitivityOref0Plugin");
} }
this.setFragmentVisiblities(((PluginBase) activeSensitivity).getName(), pluginsInCategory, PluginType.SENSITIVITY); this.setFragmentVisiblities(((PluginBase) activeSensitivity).getName(), pluginsInCategory, PluginType.SENSITIVITY);
@ -348,8 +339,7 @@ public class ConfigBuilderPlugin extends PluginBase {
if (activePump == null) { if (activePump == null) {
activePump = VirtualPumpPlugin.getPlugin(); activePump = VirtualPumpPlugin.getPlugin();
VirtualPumpPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true); VirtualPumpPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true);
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting VirtualPumpPlugin");
log.debug("Defaulting VirtualPumpPlugin");
} }
this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP); this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP);
@ -407,8 +397,7 @@ public class ConfigBuilderPlugin extends PluginBase {
private void setFragmentVisiblities(String activePluginName, ArrayList<PluginBase> pluginsInCategory, private void setFragmentVisiblities(String activePluginName, ArrayList<PluginBase> pluginsInCategory,
PluginType pluginType) { PluginType pluginType) {
if (L.isEnabled(L.CONFIGBUILDER)) aapsLogger.debug(LTag.CONFIGBUILDER, "Selected interface: " + activePluginName);
log.debug("Selected interface: " + activePluginName);
for (PluginBase p : pluginsInCategory) { for (PluginBase p : pluginsInCategory) {
if (!p.getName().equals(activePluginName)) { if (!p.getName().equals(activePluginName)) {
p.setFragmentVisible(pluginType, false); p.setFragmentVisible(pluginType, false);

View file

@ -22,7 +22,9 @@ import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBus.send import info.nightscout.androidaps.plugins.bus.RxBus.send
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
@ -53,7 +55,8 @@ import javax.inject.Singleton
class SmsCommunicatorPlugin @Inject constructor( class SmsCommunicatorPlugin @Inject constructor(
val configBuilderPlugin: ConfigBuilderPlugin, val configBuilderPlugin: ConfigBuilderPlugin,
val resourceHelper: ResourceHelper, val resourceHelper: ResourceHelper,
val constraintChecker: ConstraintChecker val constraintChecker: ConstraintChecker,
val aapsLogger: AAPSLogger
) : PluginBase(PluginDescription() ) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
.fragmentClass(SmsCommunicatorFragment::class.java.name) .fragmentClass(SmsCommunicatorFragment::class.java.name)
@ -62,8 +65,6 @@ class SmsCommunicatorPlugin @Inject constructor(
.preferencesId(R.xml.pref_smscommunicator) .preferencesId(R.xml.pref_smscommunicator)
.description(R.string.description_sms_communicator) .description(R.string.description_sms_communicator)
) { ) {
private val log = LoggerFactory.getLogger(L.SMS)
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
var allowedNumbers: MutableList<String> = ArrayList() var allowedNumbers: MutableList<String> = ArrayList()
var messageToConfirm: AuthRequest? = null var messageToConfirm: AuthRequest? = null
@ -149,7 +150,7 @@ class SmsCommunicatorPlugin @Inject constructor(
for (number in substrings) { for (number in substrings) {
val cleaned = number.replace("\\s+".toRegex(), "") val cleaned = number.replace("\\s+".toRegex(), "")
allowedNumbers.add(cleaned) allowedNumbers.add(cleaned)
log.debug("Found allowed number: $cleaned") aapsLogger.debug(LTag.SMS,"Found allowed number: $cleaned")
} }
} }
} }
@ -181,11 +182,11 @@ class SmsCommunicatorPlugin @Inject constructor(
fun processSms(receivedSms: Sms) { fun processSms(receivedSms: Sms) {
if (!isEnabled(PluginType.GENERAL)) { if (!isEnabled(PluginType.GENERAL)) {
log.debug("Ignoring SMS. Plugin disabled.") aapsLogger.debug(LTag.SMS,"Ignoring SMS. Plugin disabled.")
return return
} }
if (!isAllowedNumber(receivedSms.phoneNumber)) { if (!isAllowedNumber(receivedSms.phoneNumber)) {
log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed") aapsLogger.debug(LTag.SMS,"Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed")
receivedSms.ignored = true receivedSms.ignored = true
messages.add(receivedSms) messages.add(receivedSms)
send(EventSmsCommunicatorUpdateGui()) send(EventSmsCommunicatorUpdateGui())
@ -193,7 +194,7 @@ class SmsCommunicatorPlugin @Inject constructor(
} }
val pump = configBuilderPlugin.activePump ?: return val pump = configBuilderPlugin.activePump ?: return
messages.add(receivedSms) messages.add(receivedSms)
log.debug(receivedSms.toString()) aapsLogger.debug(LTag.SMS,receivedSms.toString())
val splitted = receivedSms.text.split(Regex("\\s+")).toTypedArray() val splitted = receivedSms.text.split(Regex("\\s+")).toTypedArray()
val remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false) val remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)
if (splitted.isNotEmpty() && isCommand(splitted[0].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) { if (splitted.isNotEmpty() && isCommand(splitted[0].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) {
@ -858,7 +859,7 @@ class SmsCommunicatorPlugin @Inject constructor(
val smsManager = SmsManager.getDefault() val smsManager = SmsManager.getDefault()
sms.text = stripAccents(sms.text) sms.text = stripAccents(sms.text)
try { try {
if (L.isEnabled(L.SMS)) log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text) aapsLogger.debug(LTag.SMS,"Sending SMS to " + sms.phoneNumber + ": " + sms.text)
if (sms.text.toByteArray().size <= 140) smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null) if (sms.text.toByteArray().size <= 140) smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null)
else { else {
val parts = smsManager.divideMessage(sms.text) val parts = smsManager.divideMessage(sms.text)

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.services; package info.nightscout.androidaps.services;
import android.app.IntentService;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Telephony; import android.provider.Telephony;
@ -19,8 +18,10 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsFood;
import info.nightscout.androidaps.events.EventNsTreatment; import info.nightscout.androidaps.events.EventNsTreatment;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.BundleLogger;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg;
@ -44,7 +45,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class DataService extends DaggerIntentService { public class DataService extends DaggerIntentService {
private Logger log = LoggerFactory.getLogger(L.DATASERVICE);
public DataService() { public DataService() {
super("DataService"); super("DataService");
@ -53,15 +53,17 @@ public class DataService extends DaggerIntentService {
@Inject @Inject
SmsCommunicatorPlugin smsCommunicatorPlugin; SmsCommunicatorPlugin smsCommunicatorPlugin;
@Inject
AAPSLogger aapsLogger;
@Inject @Inject
SP sp; SP sp;
@Override @Override
protected void onHandleIntent(final Intent intent) { protected void onHandleIntent(final Intent intent) {
if (L.isEnabled(L.DATASERVICE)) { aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent " + intent);
log.debug("onHandleIntent " + intent); aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent " + BundleLogger.log(intent.getExtras()));
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
}
boolean acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, false); boolean acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, false);
Bundle bundles = intent.getExtras(); Bundle bundles = intent.getExtras();
@ -111,8 +113,7 @@ public class DataService extends DaggerIntentService {
smsCommunicatorPlugin.handleNewData(intent); smsCommunicatorPlugin.handleNewData(intent);
} }
if (L.isEnabled(L.DATASERVICE)) aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent exit " + intent);
log.debug("onHandleIntent exit " + intent);
DataReceiver.completeWakefulIntent(intent); DataReceiver.completeWakefulIntent(intent);
} }
@ -124,8 +125,7 @@ public class DataService extends DaggerIntentService {
private void handleNewDataFromNSClient(Intent intent) { private void handleNewDataFromNSClient(Intent intent) {
Bundle bundles = intent.getExtras(); Bundle bundles = intent.getExtras();
if (bundles == null) return; if (bundles == null) return;
if (L.isEnabled(L.DATASERVICE)) aapsLogger.debug(LTag.DATASERVICE, "Got intent: " + intent.getAction());
log.debug("Got intent: " + intent.getAction());
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) { if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
@ -143,7 +143,7 @@ public class DataService extends DaggerIntentService {
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e);
} }
} }
@ -164,7 +164,7 @@ public class DataService extends DaggerIntentService {
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e);
} }
} }
@ -185,7 +185,7 @@ public class DataService extends DaggerIntentService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e);
} }
} }
} }
@ -210,7 +210,7 @@ public class DataService extends DaggerIntentService {
double carbs = JsonHelper.safeGetDouble(json, "carbs"); double carbs = JsonHelper.safeGetDouble(json, "carbs");
String eventType = JsonHelper.safeGetString(json, "eventType"); String eventType = JsonHelper.safeGetString(json, "eventType");
if (eventType == null) { if (eventType == null) {
log.debug("Wrong treatment. Ignoring : " + json.toString()); aapsLogger.debug(LTag.DATASERVICE, "Wrong treatment. Ignoring : " + json.toString());
return; return;
} }
if (insulin > 0 || carbs > 0) { if (insulin > 0 || carbs > 0) {
@ -258,8 +258,7 @@ public class DataService extends DaggerIntentService {
NSMbg nsMbg = new NSMbg(mbgJson); NSMbg nsMbg = new NSMbg(mbgJson);
CareportalEvent careportalEvent = new CareportalEvent(nsMbg); CareportalEvent careportalEvent = new CareportalEvent(nsMbg);
MainApp.getDbHelper().createOrUpdate(careportalEvent); MainApp.getDbHelper().createOrUpdate(careportalEvent);
if (L.isEnabled(L.DATASERVICE)) aapsLogger.debug(LTag.DATASERVICE, "Adding/Updating new MBG: " + careportalEvent.toString());
log.debug("Adding/Updating new MBG: " + careportalEvent.toString());
} }
} }