From ccaf68d043665c9742d046b8c396b3bf599fd16a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 9 Jul 2018 23:05:48 +0200 Subject: [PATCH] Fabric-log enabled plugins once a day. --- .../receivers/KeepAliveReceiver.java | 10 ++++--- .../info/nightscout/utils/FabricPrivacy.java | 29 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index af46321901..8ef966c340 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -1,9 +1,5 @@ package info.nightscout.androidaps.receivers; -/** - * Created by mike on 07.07.2016. - */ - import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -11,6 +7,7 @@ import android.content.Context; import android.content.Intent; import android.os.PowerManager; +import info.nightscout.utils.FabricPrivacy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +22,10 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.utils.LocalAlertUtils; + +/** + * Created by mike on 07.07.2016. + */ public class KeepAliveReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class); public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L; @@ -45,6 +46,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { LocalAlertUtils.shortenSnoozeInterval(); LocalAlertUtils.checkStaleBGAlert(); checkPump(); + FabricPrivacy.reportPluginStats(); log.debug("KeepAlive received"); wl.release(); diff --git a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java b/app/src/main/java/info/nightscout/utils/FabricPrivacy.java index bd117ed5c3..2cbc2d9daa 100644 --- a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java +++ b/app/src/main/java/info/nightscout/utils/FabricPrivacy.java @@ -3,6 +3,12 @@ package info.nightscout.utils; import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.PluginBase; + +import java.util.Date; /** * Created by jamorham on 21/02/2018. @@ -80,4 +86,27 @@ public class FabricPrivacy { } } + public static void reportPluginStats() { + if (!FabricPrivacy.fabricEnabled()) return; + + long lastUploadDay = SP.getLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), 0L); + + Date date = new Date(); + date.setHours(0); + date.setMinutes(0); + date.setSeconds(0); + long today = date.getTime() - date.getTime() % 1000; + + if (today > lastUploadDay) { + CustomEvent pluginStats = new CustomEvent("PluginStats"); + pluginStats.putCustomAttribute("version", BuildConfig.VERSION); + for (PluginBase plugin : MainApp.getPluginsList()) { + if (plugin.isEnabled(plugin.getType()) && !plugin.pluginDescription.alwaysEnabled) { + pluginStats.putCustomAttribute(plugin.getName(), "enabled"); + } + } + FabricPrivacy.getInstance().logCustom(pluginStats); + SP.putLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), today); + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0550c33339..79cc57d62c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1164,6 +1164,7 @@ Stored settings found Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time. Generated eCarbs with amount: %1$dg, duration: %2$dh, delay: %3$dm + key_plugin_stats_report_timestamp %d day