From ccaf68d043665c9742d046b8c396b3bf599fd16a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 9 Jul 2018 23:05:48 +0200 Subject: [PATCH 1/3] 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 From 09a1d23bc89bd4cf5f9ebe7cb2bfdc94fdd3211a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 10 Jul 2018 17:55:50 +0200 Subject: [PATCH 2/3] Move logging of app start to Fabric class. --- .../info/nightscout/androidaps/MainApp.java | 13 ++----------- .../info/nightscout/utils/FabricPrivacy.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 24631b10c8..4ec1655848 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -194,18 +194,9 @@ public class MainApp extends Application { MainApp.getConfigBuilder().initialize(); } - NSUpload.uploadAppStart(); - if (Config.NSCLIENT) - FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-NSClient")); - else if (Config.G5UPLOADER) - FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-G5Uploader")); - else if (Config.PUMPCONTROL) - FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-PumpControl")); - else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) - FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop")); - else - FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); + NSUpload.uploadAppStart(); + FabricPrivacy.logAppStart(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (pump != null) { diff --git a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java b/app/src/main/java/info/nightscout/utils/FabricPrivacy.java index 2cbc2d9daa..5064b881dc 100644 --- a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java +++ b/app/src/main/java/info/nightscout/utils/FabricPrivacy.java @@ -4,6 +4,7 @@ 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.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; @@ -86,8 +87,22 @@ public class FabricPrivacy { } } + public static void logAppStart() { + if (Config.NSCLIENT) + getInstance().logCustom(new CustomEvent("AppStart-NSClient")); + else if (Config.G5UPLOADER) + getInstance().logCustom(new CustomEvent("AppStart-G5Uploader")); + else if (Config.PUMPCONTROL) + getInstance().logCustom(new CustomEvent("AppStart-PumpControl")); + else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) + getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop")); + else + getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); + + } + public static void reportPluginStats() { - if (!FabricPrivacy.fabricEnabled()) return; + if (!fabricEnabled()) return; long lastUploadDay = SP.getLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), 0L); From 63027696523186f4cdd4b691e4793ce143b21bf8 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 11 Jul 2018 20:19:42 +0200 Subject: [PATCH 3/3] Log app usage type daily. --- .../info/nightscout/androidaps/MainApp.java | 1 - .../receivers/KeepAliveReceiver.java | 2 +- .../info/nightscout/utils/FabricPrivacy.java | 56 +++++++++++-------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 4ec1655848..dbb6ddee8b 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -196,7 +196,6 @@ public class MainApp extends Application { } NSUpload.uploadAppStart(); - FabricPrivacy.logAppStart(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (pump != null) { 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 8ef966c340..d574b08f40 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -46,7 +46,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { LocalAlertUtils.shortenSnoozeInterval(); LocalAlertUtils.checkStaleBGAlert(); checkPump(); - FabricPrivacy.reportPluginStats(); + FabricPrivacy.uploadDailyStats(); 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 5064b881dc..ce4217b1de 100644 --- a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java +++ b/app/src/main/java/info/nightscout/utils/FabricPrivacy.java @@ -87,21 +87,7 @@ public class FabricPrivacy { } } - public static void logAppStart() { - if (Config.NSCLIENT) - getInstance().logCustom(new CustomEvent("AppStart-NSClient")); - else if (Config.G5UPLOADER) - getInstance().logCustom(new CustomEvent("AppStart-G5Uploader")); - else if (Config.PUMPCONTROL) - getInstance().logCustom(new CustomEvent("AppStart-PumpControl")); - else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) - getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop")); - else - getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); - - } - - public static void reportPluginStats() { + public static void uploadDailyStats() { if (!fabricEnabled()) return; long lastUploadDay = SP.getLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), 0L); @@ -113,15 +99,39 @@ public class FabricPrivacy { 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); + uploadAppUsageType(); + uploadPluginStats(); + SP.putLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), today); } } + + private static void uploadPluginStats() { + 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"); + } + } + + getInstance().logCustom(pluginStats); + } + + private static void uploadAppUsageType() { + CustomEvent type = new CustomEvent("AppUsageType"); + if (Config.NSCLIENT) + type.putCustomAttribute("type", "NSClient"); + else if (Config.G5UPLOADER) + type.putCustomAttribute("type", "G5Uploader"); + else if (Config.PUMPCONTROL) + type.putCustomAttribute("type", "PumpControl"); + else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) + type.putCustomAttribute("type", "ClosedLoop"); + else + type.putCustomAttribute("type", "OpenLoop"); + + getInstance().logCustom(type); + } + }