From cfff357e6b6fc70fbaed44286a30fa94c6b497d0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 28 Jul 2018 17:58:52 +0200 Subject: [PATCH] NSCLIENT logging --- .../info/nightscout/androidaps/Config.java | 2 +- .../info/nightscout/androidaps/Constants.java | 2 +- .../NSClientInternal/NSClientFragment.java | 2 - .../NSClientInternal/NSClientPlugin.java | 43 ++++++------ .../plugins/NSClientInternal/UploadQueue.java | 70 +++++++++---------- .../NSClientInternal/acks/NSAddAck.java | 16 +++-- .../NSClientInternal/acks/NSUpdateAck.java | 6 +- .../broadcasts/BroadcastAckAlarm.java | 1 - .../broadcasts/BroadcastAlarm.java | 2 - .../broadcasts/BroadcastAnnouncement.java | 2 - .../broadcasts/BroadcastCals.java | 2 - .../broadcasts/BroadcastClearAlarm.java | 2 - .../broadcasts/BroadcastDeviceStatus.java | 48 ------------- .../broadcasts/BroadcastFood.java | 2 - .../broadcasts/BroadcastMbgs.java | 2 - .../broadcasts/BroadcastProfile.java | 2 - .../broadcasts/BroadcastQueueStatus.java | 35 ---------- .../broadcasts/BroadcastSgvs.java | 23 ------ .../broadcasts/BroadcastStatus.java | 3 +- .../broadcasts/BroadcastTreatment.java | 47 +------------ .../broadcasts/BroadcastUrgentAlarm.java | 2 - .../NSClientInternal/data/DbLogger.java | 21 +++--- .../NSClientInternal/data/NSAlarm.java | 4 +- .../plugins/NSClientInternal/data/NSCal.java | 6 +- .../NSClientInternal/data/NSDeviceStatus.java | 4 +- .../plugins/NSClientInternal/data/NSMbg.java | 6 +- .../data/NSSettingsStatus.java | 8 +-- .../plugins/NSClientInternal/data/NSSgv.java | 4 +- .../NSClientInternal/data/NSTreatment.java | 4 +- .../receivers/AckAlarmReceiver.java | 7 +- .../receivers/DBAccessReceiver.java | 10 ++- .../services/NSClientService.java | 53 +++++++------- 32 files changed, 146 insertions(+), 295 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 4ee5371cd1..8096ba1486 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -41,9 +41,9 @@ public class Config { public static final boolean logNotification = true; public static final boolean logAlarm = false; public static final boolean logDataService = true; - public static final boolean logDataNS = true; public static final boolean logDataFood = true; public static final boolean logDataTreatments = true; + public static final boolean logNsclient = true; // DanaR specific public static final boolean logDanaBTComm = true; diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 6e54954cc6..df98eef47e 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -77,7 +77,7 @@ public class Constants { public static final String NOTIFICATION = "NOTIFICATION"; public static final String ALARM = "ALARM"; public static final String DATASERVICE = "DATASERVICE"; - public static final String DATANS = "DATANS"; public static final String DATAFOOD = "DATAFOOD"; public static final String DATATREATMENTS = "DATATREATMENTS"; + public static final String NSCLIENT = "NSCLIENT"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java index 3bff1c9be3..64e2091eb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java @@ -34,8 +34,6 @@ import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.SP; public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { - private static Logger log = LoggerFactory.getLogger(NSClientFragment.class); - private TextView logTextView; private TextView queueTextView; private TextView urlTextView; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java index 6949cdc8b1..f08e4e8e23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java @@ -37,7 +37,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; public class NSClientPlugin extends PluginBase { - private static Logger log = LoggerFactory.getLogger(NSClientPlugin.class); + private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); static NSClientPlugin nsClientPlugin; @@ -53,8 +53,8 @@ public class NSClientPlugin extends PluginBase { private final List listLog = new ArrayList<>(); Spanned textLog = Html.fromHtml(""); - public boolean paused = false; - boolean autoscroll = true; + public boolean paused; + boolean autoscroll; public String status = ""; @@ -132,12 +132,14 @@ public class NSClientPlugin extends PluginBase { private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { - log.debug("Service is disconnected"); + if (Config.logNsclient) + log.debug("Service is disconnected"); nsClientService = null; } public void onServiceConnected(ComponentName name, IBinder service) { - log.debug("Service is connected"); + if (Config.logNsclient) + log.debug("Service is connected"); NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service; if (mLocalBinder != null) // is null when running in roboelectric nsClientService = mLocalBinder.getServiceInstance(); @@ -155,7 +157,8 @@ public class NSClientPlugin extends PluginBase { @Subscribe public void onStatusEvent(final EventNSClientNewLog ev) { addToLog(ev); - log.debug(ev.action + " " + ev.logText); + if (Config.logNsclient) + log.debug(ev.action + " " + ev.logText); } @Subscribe @@ -165,30 +168,24 @@ public class NSClientPlugin extends PluginBase { } synchronized void clearLog() { - handler.post(new Runnable() { - @Override - public void run() { - synchronized (listLog) { - listLog.clear(); - } - MainApp.bus().post(new EventNSClientUpdateGUI()); + handler.post(() -> { + synchronized (listLog) { + listLog.clear(); } + MainApp.bus().post(new EventNSClientUpdateGUI()); }); } private synchronized void addToLog(final EventNSClientNewLog ev) { - handler.post(new Runnable() { - @Override - public void run() { - synchronized (listLog) { - listLog.add(ev); - // remove the first line if log is too large - if (listLog.size() >= Constants.MAX_LOG_LINES) { - listLog.remove(0); - } + handler.post(() -> { + synchronized (listLog) { + listLog.add(ev); + // remove the first line if log is too large + if (listLog.size() >= Constants.MAX_LOG_LINES) { + listLog.remove(0); } - MainApp.bus().post(new EventNSClientUpdateGUI()); } + MainApp.bus().post(new EventNSClientUpdateGUI()); }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java index 17cc1dced3..3b516a2ec7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java @@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory; import java.sql.SQLException; +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; @@ -22,7 +24,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ * Created by mike on 21.02.2016. */ public class UploadQueue { - private static Logger log = LoggerFactory.getLogger(UploadQueue.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public static String status() { return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); @@ -43,15 +45,13 @@ public class UploadQueue { public static void add(final DbRequest dbr) { startService(); if (NSClientService.handler != null) { - NSClientService.handler.post(new Runnable() { - @Override - public void run() { - log.debug("QUEUE adding: " + dbr.data); - MainApp.getDbHelper().create(dbr); - NSClientPlugin plugin = NSClientPlugin.getPlugin(); - if (plugin != null) { - plugin.resend("newdata"); - } + NSClientService.handler.post(() -> { + if (Config.logNsclient) + log.debug("Adding to queue: " + dbr.data); + MainApp.getDbHelper().create(dbr); + NSClientPlugin plugin = NSClientPlugin.getPlugin(); + if (plugin != null) { + plugin.resend("newdata"); } }); } @@ -60,13 +60,12 @@ public class UploadQueue { public static void clearQueue() { startService(); if (NSClientService.handler != null) { - NSClientService.handler.post(new Runnable() { - @Override - public void run() { - log.debug("QUEUE ClearQueue"); - MainApp.getDbHelper().deleteAllDbRequests(); + NSClientService.handler.post(() -> { + if (Config.logNsclient) + log.debug("ClearQueue"); + MainApp.getDbHelper().deleteAllDbRequests(); + if (Config.logNsclient) log.debug(status()); - } }); } } @@ -74,22 +73,20 @@ public class UploadQueue { public static void removeID(final JSONObject record) { startService(); if (NSClientService.handler != null) { - NSClientService.handler.post(new Runnable() { - @Override - public void run() { - try { - String id; - if (record.has("NSCLIENT_ID")) { - id = record.getString("NSCLIENT_ID"); - } else { - return; - } - if (MainApp.getDbHelper().deleteDbRequest(id) == 1) { - log.debug("Removed item from UploadQueue. " + UploadQueue.status()); - } - } catch (JSONException e) { - log.error("Unhandled exception", e); + NSClientService.handler.post(() -> { + try { + String id; + if (record.has("NSCLIENT_ID")) { + id = record.getString("NSCLIENT_ID"); + } else { + return; } + if (MainApp.getDbHelper().deleteDbRequest(id) == 1) { + if (Config.logNsclient) + log.debug("Removed item from UploadQueue. " + UploadQueue.status()); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); } }); } @@ -100,18 +97,17 @@ public class UploadQueue { return; startService(); if (NSClientService.handler != null) { - NSClientService.handler.post(new Runnable() { - @Override - public void run() { - MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); - } + NSClientService.handler.post(() -> { + MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); + if (Config.logNsclient) + log.debug("Removing " + _id + " from UploadQueue. " + UploadQueue.status()); }); } } public String textList() { String result = ""; - CloseableIterator iterator = null; + CloseableIterator iterator; try { iterator = MainApp.getDbHelper().getDbRequestInterator(); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java index e90dce3bec..d4cf775356 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java @@ -1,11 +1,12 @@ package info.nightscout.androidaps.plugins.NSClientInternal.acks; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; @@ -15,17 +16,18 @@ import io.socket.client.Ack; * Created by mike on 29.12.2015. */ public class NSAddAck extends Event implements Ack { - private static Logger log = LoggerFactory.getLogger(NSAddAck.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public String _id = null; public String nsClientID = null; public JSONObject json = null; - public void call(Object...args) { + + public void call(Object... args) { // Regular response try { JSONArray responsearray = (JSONArray) (args[0]); JSONObject response = null; - if (responsearray.length()>0) { - response = responsearray.getJSONObject(0); + if (responsearray.length() > 0) { + response = responsearray.getJSONObject(0); _id = response.getString("_id"); json = response; if (response.has("NSCLIENT_ID")) { @@ -35,6 +37,7 @@ public class NSAddAck extends Event implements Ack { MainApp.bus().post(this); return; } catch (Exception e) { + log.error("Unhandled exception", e); } // Check for not authorized try { @@ -45,7 +48,8 @@ public class NSAddAck extends Event implements Ack { MainApp.bus().post(new EventNSClientRestart()); return; } - log.debug("DBACCESS " + response.getString("result")); + if (Config.logNsclient) + log.debug("DBACCESS " + response.getString("result")); } return; } catch (Exception e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java index 2bf520da64..7081318c01 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java @@ -5,6 +5,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.Event; import io.socket.client.Ack; @@ -13,9 +14,9 @@ import io.socket.client.Ack; * Created by mike on 21.02.2016. */ public class NSUpdateAck extends Event implements Ack { - private static Logger log = LoggerFactory.getLogger(NSUpdateAck.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public boolean result = false; - public String _id = null; + public String _id; public String action; public void call(Object...args) { JSONObject response = (JSONObject)args[0]; @@ -29,6 +30,7 @@ public class NSUpdateAck extends Event implements Ack { } MainApp.bus().post(this); } catch (JSONException e) { + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java index 216fa3d19a..fb8ef4c7ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java @@ -22,7 +22,6 @@ import info.nightscout.utils.SP; */ public class BroadcastAckAlarm { - private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class); public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java index 0fee6600bd..992a3d92b1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java @@ -21,8 +21,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastAlarm { - private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class); - public static void handleAlarm(JSONObject alarm, Context context) { Bundle bundle = new Bundle(); bundle.putString("data", alarm.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java index 9b133c2551..03a56fad60 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java @@ -22,8 +22,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastAnnouncement { - private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class); - public static void handleAnnouncement(JSONObject announcement, Context context) { Bundle bundle = new Bundle(); bundle.putString("data", announcement.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java index 7580a00088..ddbbd359d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java @@ -21,8 +21,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastCals { - private static Logger log = LoggerFactory.getLogger(BroadcastCals.class); - public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java index 23406837a7..b310a8ff53 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java @@ -21,8 +21,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastClearAlarm { - private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class); - public static void handleClearAlarm(JSONObject clearalarm, Context context) { Bundle bundle = new Bundle(); bundle.putString("data", clearalarm.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java index 59f5ab136c..b58702feb9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java @@ -20,27 +20,6 @@ import info.nightscout.utils.SP; public class BroadcastDeviceStatus { - private static Logger log = LoggerFactory.getLogger(BroadcastDeviceStatus.class); - - public static void handleNewDeviceStatus(JSONObject status, Context context, boolean isDelta) { - Bundle bundle = new Bundle(); - bundle.putString("devicestatus", status.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - - if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { - bundle = new Bundle(); - bundle.putString("devicestatus", status.toString()); - bundle.putBoolean("delta", isDelta); - intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - } - } public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) { List splitted = BroadcastTreatment.splitArray(statuses); @@ -67,31 +46,4 @@ public class BroadcastDeviceStatus { } } } - - public static void handleNewFoods(JSONArray foods, Context context, boolean isDelta) { - - List splitted = BroadcastTreatment.splitArray(foods); - for (JSONArray part: splitted) { - Bundle bundle = new Bundle(); - bundle.putString("foods", part.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_NEW_FOOD); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - } - - if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { - splitted = BroadcastTreatment.splitArray(foods); - for (JSONArray part : splitted) { - Bundle bundle = new Bundle(); - bundle.putString("foods", part.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_NEW_FOOD); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - } - } - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java index dbb3385fbb..a3b258abb5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java @@ -24,8 +24,6 @@ import info.nightscout.utils.SP; * Created by mike on 20.02.2016. */ public class BroadcastFood { - private static Logger log = LoggerFactory.getLogger(BroadcastFood.class); - public static void handleNewFood(JSONArray foods, Context context, boolean isDelta) { List splitted = BroadcastTreatment.splitArray(foods); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java index a715747791..6602d51eb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java @@ -21,8 +21,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastMbgs { - private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class); - public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java index 3802b09657..e10dac3d61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java @@ -22,8 +22,6 @@ import info.nightscout.utils.SP; * Created by mike on 20.02.2016. */ public class BroadcastProfile { - private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class); - public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java deleted file mode 100644 index abc49be18a..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.PowerManager; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.Services.Intents; -import info.nightscout.utils.SP; - -/** - * Created by mike on 28.02.2016. - */ -public class BroadcastQueueStatus { - public static void handleNewStatus(int size, Context context) { - - if(!SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) return; - - PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, - "sendQueue"); - wakeLock.acquire(); - try { - Bundle bundle = new Bundle(); - bundle.putInt("size", size); - Intent intent = new Intent(Intents.ACTION_QUEUE_STATUS); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - } finally { - wakeLock.release(); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java index 65a90f3b74..cbb119c189 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java @@ -22,29 +22,6 @@ import info.nightscout.utils.SP; * Created by mike on 22.02.2016. */ public class BroadcastSgvs { - private static Logger log = LoggerFactory.getLogger(BroadcastSgvs.class); - - public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) { - - Bundle bundle = new Bundle(); - bundle.putString("sgv", sgv.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_NEW_SGV); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - - if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { - bundle = new Bundle(); - bundle.putString("sgv", sgv.toString()); - bundle.putBoolean("delta", isDelta); - intent = new Intent(Intents.ACTION_NEW_SGV); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - } - } - public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) { List splitted = BroadcastTreatment.splitArray(sgvs); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java index a2b6e64aec..4d736cf2d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; @@ -23,7 +24,7 @@ import info.nightscout.utils.SP; * Created by mike on 24.02.2016. */ public class BroadcastStatus { - private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) { LocalBroadcastManager.getInstance(MainApp.instance()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 94b83c56bd..3da560b9d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; @@ -22,7 +23,7 @@ import info.nightscout.utils.SP; * Created by mike on 20.02.2016. */ public class BroadcastTreatment { - private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public static void handleNewTreatment(JSONObject treatment, boolean isDelta, boolean isLocalBypass) { @@ -73,28 +74,6 @@ public class BroadcastTreatment { } } - public void handleChangedTreatment(JSONObject treatment, boolean isDelta) { - - Bundle bundle = new Bundle(); - bundle.putString("treatment", treatment.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - - - if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { - bundle = new Bundle(); - bundle.putString("treatment", treatment.toString()); - bundle.putBoolean("delta", isDelta); - intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - MainApp.instance().getApplicationContext().sendBroadcast(intent); - } - } - public static void handleChangedTreatment(JSONArray treatments, boolean isDelta) { List splitted = splitArray(treatments); @@ -122,28 +101,6 @@ public class BroadcastTreatment { } } - public static void handleRemovedTreatment(JSONObject treatment, boolean isDelta) { - - Bundle bundle = new Bundle(); - bundle.putString("treatment", treatment.toString()); - bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - - - if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { - bundle = new Bundle(); - bundle.putString("treatment", treatment.toString()); - bundle.putBoolean("delta", isDelta); - intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - MainApp.instance().getApplicationContext().sendBroadcast(intent); - } - } - public static void handleRemovedTreatment(JSONArray treatments, boolean isDelta) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java index c332be03af..0cdffb563e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java @@ -21,8 +21,6 @@ import info.nightscout.utils.SP; * Created by mike on 26.06.2016. */ public class BroadcastUrgentAlarm { - private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class); - public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { Bundle bundle = new Bundle(); bundle.putString("data", urgentalarm.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java index 2723fc0748..4c237d91c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.utils.ToastUtils; @@ -17,23 +18,27 @@ import info.nightscout.utils.ToastUtils; * Created by mike on 02.07.2016. */ public class DbLogger { - private static Logger log = LoggerFactory.getLogger(DbLogger.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public static void dbAdd(Intent intent, String data) { List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0); if (q.size() < 1) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.gs(R.string.nsclientnotinstalled)); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.nsclientnotinstalled)); log.error("DBADD No receivers"); - } else if (Config.logNSUpload) - log.debug("DBADD dbAdd " + q.size() + " receivers " + data); + } else if (Config.logNSUpload) { + if (Config.logNsclient) + log.debug("DBADD dbAdd " + q.size() + " receivers " + data); + } } - public static void dbRemove(Intent intent, String data) { + public static void dbRemove(Intent intent, String data) { List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0); if (q.size() < 1) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.gs(R.string.nsclientnotinstalled)); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.nsclientnotinstalled)); log.error("DBREMOVE No receivers"); - } else if (Config.logNSUpload) - log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data); + } else if (Config.logNSUpload) { + if (Config.logNsclient) + log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java index 1c28b790d7..3506c3aa1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java @@ -5,12 +5,14 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; + /** * Created by mike on 11.06.2017. */ public class NSAlarm { - private static Logger log = LoggerFactory.getLogger(NSAlarm.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); JSONObject data; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java index 93d46fa18e..bb50d6ce75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java @@ -5,8 +5,10 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; + public class NSCal { - private static Logger log = LoggerFactory.getLogger(NSCal.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public long date; public double slope; public double intercept; @@ -20,7 +22,7 @@ public class NSCal { scale = json.getDouble("scale"); } catch (JSONException e) { log.error("Unhandled exception", e); - log.debug("Data: " + json.toString()); + log.error("Data: " + json.toString()); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index e39f717af2..9d1ef6439f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -80,7 +80,7 @@ import info.nightscout.utils.SP; } */ public class NSDeviceStatus { - private Logger log = LoggerFactory.getLogger(Constants.DATANS); + private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); private static NSDeviceStatus instance = null; @@ -99,7 +99,7 @@ public class NSDeviceStatus { Bundle bundle = intent.getExtras(); if (bundle == null) return; - if (Config.logDataNS) + if (Config.logNsclient) log.debug("Got NS devicestatus: " + BundleLogger.log(bundle)); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java index 353dd49b74..92ac6de937 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java @@ -5,8 +5,10 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; + public class NSMbg { - private static Logger log = LoggerFactory.getLogger(NSMbg.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); public long date; public double mbg; public String json; @@ -18,7 +20,7 @@ public class NSMbg { this.json = json.toString(); } catch (JSONException e) { log.error("Unhandled exception", e); - log.debug("Data: " + json.toString()); + log.error("Data: " + json.toString()); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java index d5d52fd68a..2a45b1a1a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java @@ -114,7 +114,7 @@ import info.nightscout.utils.BundleLogger; } */ public class NSSettingsStatus { - private Logger log = LoggerFactory.getLogger(Constants.DATANS); + private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); private static NSSettingsStatus instance = null; @@ -140,7 +140,7 @@ public class NSSettingsStatus { Bundle bundle = intent.getExtras(); if (bundle == null) return; - if (Config.logDataNS) + if (Config.logNsclient) log.debug("Got NS status: " + BundleLogger.log(bundle)); if (bundle.containsKey("nsclientversioncode")) { @@ -149,7 +149,7 @@ public class NSSettingsStatus { nightscoutVersionName = bundle.getString("nightscoutversionname"); Integer nsClientVersionCode = bundle.getInt("nsclientversioncode"); String nsClientVersionName = bundle.getString("nsclientversionname"); - if (Config.logDataNS) + if (Config.logNsclient) log.debug("Got versions: NSClient: " + nsClientVersionName + " Nightscout: " + nightscoutVersionName); try { if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) { @@ -175,7 +175,7 @@ public class NSSettingsStatus { try { JSONObject statusJson = new JSONObject(bundle.getString("status")); setData(statusJson); - if (Config.logDataNS) + if (Config.logNsclient) log.debug("Received status: " + statusJson.toString()); Double targetHigh = getThreshold("bgTargetTop"); Double targetlow = getThreshold("bgTargetBottom"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java index 50336a5f52..c9b8605e9e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java @@ -5,12 +5,14 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; + /** * * {"mgdl":105,"mills":1455136282375,"device":"xDrip-BluetoothWixel","direction":"Flat","filtered":98272,"unfiltered":98272,"noise":1,"rssi":100} */ public class NSSgv { - private static Logger log = LoggerFactory.getLogger(NSSgv.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); private JSONObject data; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java index a9f960edd0..a494024928 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java @@ -7,8 +7,10 @@ import org.slf4j.LoggerFactory; import java.util.Date; +import info.nightscout.androidaps.Constants; + public class NSTreatment { - private static Logger log = LoggerFactory.getLogger(NSTreatment.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); private JSONObject data; private String action = null; // "update", "remove" or null (add) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java index 2aae41538a..6145a57b50 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java @@ -9,6 +9,8 @@ import android.os.PowerManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; @@ -19,7 +21,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ import info.nightscout.utils.SP; public class AckAlarmReceiver extends BroadcastReceiver { - private static Logger log = LoggerFactory.getLogger(AckAlarmReceiver.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); @Override @@ -32,7 +34,8 @@ public class AckAlarmReceiver extends BroadcastReceiver { return; } if (SP.getBoolean(R.string.key_ns_noupload, false)) { - log.debug("Upload disabled. Message dropped"); + if (Config.logNsclient) + log.debug("Upload disabled. Message dropped"); return; } wakeLock.acquire(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 332ccc2ea3..996e62b306 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -11,6 +11,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DbRequest; @@ -22,7 +23,7 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.SP; public class DBAccessReceiver extends BroadcastReceiver { - private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); @Override @@ -43,18 +44,21 @@ public class DBAccessReceiver extends BroadcastReceiver { try { collection = bundles.getString("collection"); } catch (Exception e) { + log.error("Unhandled exception", e); } try { _id = bundles.getString("_id"); } catch (Exception e) { + log.error("Unhandled exception", e); } try { data = new JSONObject(bundles.getString("data")); } catch (Exception e) { + log.error("Unhandled exception", e); } if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) { - log.debug("DBACCESS no data inside record"); + log.error("DBACCESS no data inside record"); return; } @@ -70,7 +74,7 @@ public class DBAccessReceiver extends BroadcastReceiver { } if (!isAllowedCollection(collection)) { - log.debug("DBACCESS wrong collection specified"); + log.error("DBACCESS wrong collection specified"); return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index fab9a181c4..a97069f015 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -26,6 +26,7 @@ import java.sql.SQLException; import java.util.Date; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; @@ -70,7 +71,7 @@ import io.socket.client.Socket; import io.socket.emitter.Emitter; public class NSClientService extends Service { - private static Logger log = LoggerFactory.getLogger(NSClientService.class); + private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT); static public PowerManager.WakeLock mWakeLock; private IBinder mBinder = new NSClientService.LocalBinder(); @@ -156,13 +157,13 @@ public class NSClientService extends Service { @Subscribe public void onStatusEvent(EventAppExit event) { - if (Config.logFunctionCalls) + if (Config.logNsclient) log.debug("EventAppExit received"); destroy(); stopSelf(); - if (Config.logFunctionCalls) + if (Config.logNsclient) log.debug("EventAppExit finished"); } @@ -250,7 +251,8 @@ public class NSClientService extends Service { private Emitter.Listener onDisconnect = new Emitter.Listener() { @Override public void call(Object... args) { - log.debug("disconnect reason: {}", args); + if (Config.logNsclient) + log.debug("disconnect reason: {}", args); MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event")); } }; @@ -326,8 +328,7 @@ public class NSClientService extends Service { private Emitter.Listener onPing = new Emitter.Listener() { @Override public void call(final Object... args) { - if (Config.detailedLog) - MainApp.bus().post(new EventNSClientNewLog("PING", "received")); + MainApp.bus().post(new EventNSClientNewLog("PING", "received")); // send data if there is something waiting resend("Ping received"); } @@ -352,6 +353,7 @@ public class NSClientService extends Service { data = (JSONObject) args[0]; } catch (Exception e) { FabricPrivacy.log("Wrong Announcement from NS: " + args[0]); + log.error("Unhandled exception", e); return; } if (Config.detailedLog) @@ -359,9 +361,11 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(data, "message", "received"))); } catch (Exception e) { FabricPrivacy.logException(e); + log.error("Unhandled exception", e); } BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext()); - log.debug(data.toString()); + if (Config.logNsclient) + log.debug(data.toString()); } }; @@ -381,17 +385,18 @@ public class NSClientService extends Service { */ @Override public void call(final Object... args) { - if (Config.detailedLog) - MainApp.bus().post(new EventNSClientNewLog("ALARM", "received")); + MainApp.bus().post(new EventNSClientNewLog("ALARM", "received")); JSONObject data; try { data = (JSONObject) args[0]; } catch (Exception e) { FabricPrivacy.log("Wrong alarm from NS: " + args[0]); + log.error("Unhandled exception", e); return; } BroadcastAlarm.handleAlarm(data, getApplicationContext()); - log.debug(data.toString()); + if (Config.logNsclient) + log.debug(data.toString()); } }; @@ -416,12 +421,13 @@ public class NSClientService extends Service { data = (JSONObject) args[0]; } catch (Exception e) { FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]); + log.error("Unhandled exception", e); return; } - if (Config.detailedLog) - MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received")); + MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received")); BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext()); - log.debug(data.toString()); + if (Config.logNsclient) + log.debug(data.toString()); } }; @@ -441,12 +447,13 @@ public class NSClientService extends Service { data = (JSONObject) args[0]; } catch (Exception e) { FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]); + log.error("Unhandled exception", e); return; } - if (Config.detailedLog) - MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received")); + MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received")); BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext()); - log.debug(data.toString()); + if (Config.logNsclient) + log.debug(data.toString()); } }; @@ -743,17 +750,6 @@ public class NSClientService extends Service { } } - private boolean isCurrent(NSTreatment treatment) { - long now = (new Date()).getTime(); - long minPast = now - nsHours * 60L * 60 * 1000; - if (treatment.getMills() == null) { - log.debug("treatment.getMills() == null " + treatment.getData().toString()); - return false; - } - if (treatment.getMills() > minPast) return true; - return false; - } - public void resend(final String reason) { if (UploadQueue.size() == 0) return; @@ -766,7 +762,8 @@ public class NSClientService extends Service { if (mSocket == null || !mSocket.connected()) return; if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { - log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); + if (Config.logNsclient) + log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); return; } lastResendTime = System.currentTimeMillis();