NSCLIENT logging

This commit is contained in:
Milos Kozak 2018-07-28 17:58:52 +02:00
parent a7efa317be
commit cfff357e6b
32 changed files with 146 additions and 295 deletions

View file

@ -41,9 +41,9 @@ public class Config {
public static final boolean logNotification = true; public static final boolean logNotification = true;
public static final boolean logAlarm = false; public static final boolean logAlarm = false;
public static final boolean logDataService = true; public static final boolean logDataService = true;
public static final boolean logDataNS = true;
public static final boolean logDataFood = true; public static final boolean logDataFood = true;
public static final boolean logDataTreatments = true; public static final boolean logDataTreatments = true;
public static final boolean logNsclient = true;
// DanaR specific // DanaR specific
public static final boolean logDanaBTComm = true; public static final boolean logDanaBTComm = true;

View file

@ -77,7 +77,7 @@ public class Constants {
public static final String NOTIFICATION = "NOTIFICATION"; public static final String NOTIFICATION = "NOTIFICATION";
public static final String ALARM = "ALARM"; public static final String ALARM = "ALARM";
public static final String DATASERVICE = "DATASERVICE"; public static final String DATASERVICE = "DATASERVICE";
public static final String DATANS = "DATANS";
public static final String DATAFOOD = "DATAFOOD"; public static final String DATAFOOD = "DATAFOOD";
public static final String DATATREATMENTS = "DATATREATMENTS"; public static final String DATATREATMENTS = "DATATREATMENTS";
public static final String NSCLIENT = "NSCLIENT";
} }

View file

@ -34,8 +34,6 @@ import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(NSClientFragment.class);
private TextView logTextView; private TextView logTextView;
private TextView queueTextView; private TextView queueTextView;
private TextView urlTextView; private TextView urlTextView;

View file

@ -37,7 +37,7 @@ import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
public class NSClientPlugin extends PluginBase { public class NSClientPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(NSClientPlugin.class); private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
static NSClientPlugin nsClientPlugin; static NSClientPlugin nsClientPlugin;
@ -53,8 +53,8 @@ public class NSClientPlugin extends PluginBase {
private final List<EventNSClientNewLog> listLog = new ArrayList<>(); private final List<EventNSClientNewLog> listLog = new ArrayList<>();
Spanned textLog = Html.fromHtml(""); Spanned textLog = Html.fromHtml("");
public boolean paused = false; public boolean paused;
boolean autoscroll = true; boolean autoscroll;
public String status = ""; public String status = "";
@ -132,12 +132,14 @@ public class NSClientPlugin extends PluginBase {
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
log.debug("Service is disconnected"); if (Config.logNsclient)
log.debug("Service is disconnected");
nsClientService = null; nsClientService = null;
} }
public void onServiceConnected(ComponentName name, IBinder service) { 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; NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service;
if (mLocalBinder != null) // is null when running in roboelectric if (mLocalBinder != null) // is null when running in roboelectric
nsClientService = mLocalBinder.getServiceInstance(); nsClientService = mLocalBinder.getServiceInstance();
@ -155,7 +157,8 @@ public class NSClientPlugin extends PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventNSClientNewLog ev) { public void onStatusEvent(final EventNSClientNewLog ev) {
addToLog(ev); addToLog(ev);
log.debug(ev.action + " " + ev.logText); if (Config.logNsclient)
log.debug(ev.action + " " + ev.logText);
} }
@Subscribe @Subscribe
@ -165,30 +168,24 @@ public class NSClientPlugin extends PluginBase {
} }
synchronized void clearLog() { synchronized void clearLog() {
handler.post(new Runnable() { handler.post(() -> {
@Override synchronized (listLog) {
public void run() { listLog.clear();
synchronized (listLog) {
listLog.clear();
}
MainApp.bus().post(new EventNSClientUpdateGUI());
} }
MainApp.bus().post(new EventNSClientUpdateGUI());
}); });
} }
private synchronized void addToLog(final EventNSClientNewLog ev) { private synchronized void addToLog(final EventNSClientNewLog ev) {
handler.post(new Runnable() { handler.post(() -> {
@Override synchronized (listLog) {
public void run() { listLog.add(ev);
synchronized (listLog) { // remove the first line if log is too large
listLog.add(ev); if (listLog.size() >= Constants.MAX_LOG_LINES) {
// remove the first line if log is too large listLog.remove(0);
if (listLog.size() >= Constants.MAX_LOG_LINES) {
listLog.remove(0);
}
} }
MainApp.bus().post(new EventNSClientUpdateGUI());
} }
MainApp.bus().post(new EventNSClientUpdateGUI());
}); });
} }

View file

@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException; import java.sql.SQLException;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.DbRequest; 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. * Created by mike on 21.02.2016.
*/ */
public class UploadQueue { public class UploadQueue {
private static Logger log = LoggerFactory.getLogger(UploadQueue.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
public static String status() { public static String status() {
return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS);
@ -43,15 +45,13 @@ public class UploadQueue {
public static void add(final DbRequest dbr) { public static void add(final DbRequest dbr) {
startService(); startService();
if (NSClientService.handler != null) { if (NSClientService.handler != null) {
NSClientService.handler.post(new Runnable() { NSClientService.handler.post(() -> {
@Override if (Config.logNsclient)
public void run() { log.debug("Adding to queue: " + dbr.data);
log.debug("QUEUE adding: " + dbr.data); MainApp.getDbHelper().create(dbr);
MainApp.getDbHelper().create(dbr); NSClientPlugin plugin = NSClientPlugin.getPlugin();
NSClientPlugin plugin = NSClientPlugin.getPlugin(); if (plugin != null) {
if (plugin != null) { plugin.resend("newdata");
plugin.resend("newdata");
}
} }
}); });
} }
@ -60,13 +60,12 @@ public class UploadQueue {
public static void clearQueue() { public static void clearQueue() {
startService(); startService();
if (NSClientService.handler != null) { if (NSClientService.handler != null) {
NSClientService.handler.post(new Runnable() { NSClientService.handler.post(() -> {
@Override if (Config.logNsclient)
public void run() { log.debug("ClearQueue");
log.debug("QUEUE ClearQueue"); MainApp.getDbHelper().deleteAllDbRequests();
MainApp.getDbHelper().deleteAllDbRequests(); if (Config.logNsclient)
log.debug(status()); log.debug(status());
}
}); });
} }
} }
@ -74,22 +73,20 @@ public class UploadQueue {
public static void removeID(final JSONObject record) { public static void removeID(final JSONObject record) {
startService(); startService();
if (NSClientService.handler != null) { if (NSClientService.handler != null) {
NSClientService.handler.post(new Runnable() { NSClientService.handler.post(() -> {
@Override try {
public void run() { String id;
try { if (record.has("NSCLIENT_ID")) {
String id; id = record.getString("NSCLIENT_ID");
if (record.has("NSCLIENT_ID")) { } else {
id = record.getString("NSCLIENT_ID"); return;
} else {
return;
}
if (MainApp.getDbHelper().deleteDbRequest(id) == 1) {
log.debug("Removed item from UploadQueue. " + UploadQueue.status());
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
} }
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; return;
startService(); startService();
if (NSClientService.handler != null) { if (NSClientService.handler != null) {
NSClientService.handler.post(new Runnable() { NSClientService.handler.post(() -> {
@Override MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id);
public void run() { if (Config.logNsclient)
MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); log.debug("Removing " + _id + " from UploadQueue. " + UploadQueue.status());
}
}); });
} }
} }
public String textList() { public String textList() {
String result = ""; String result = "";
CloseableIterator<DbRequest> iterator = null; CloseableIterator<DbRequest> iterator;
try { try {
iterator = MainApp.getDbHelper().getDbRequestInterator(); iterator = MainApp.getDbHelper().getDbRequestInterator();
try { try {

View file

@ -1,11 +1,12 @@
package info.nightscout.androidaps.plugins.NSClientInternal.acks; package info.nightscout.androidaps.plugins.NSClientInternal.acks;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
@ -15,17 +16,18 @@ import io.socket.client.Ack;
* Created by mike on 29.12.2015. * Created by mike on 29.12.2015.
*/ */
public class NSAddAck extends Event implements Ack { 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 _id = null;
public String nsClientID = null; public String nsClientID = null;
public JSONObject json = null; public JSONObject json = null;
public void call(Object...args) {
public void call(Object... args) {
// Regular response // Regular response
try { try {
JSONArray responsearray = (JSONArray) (args[0]); JSONArray responsearray = (JSONArray) (args[0]);
JSONObject response = null; JSONObject response = null;
if (responsearray.length()>0) { if (responsearray.length() > 0) {
response = responsearray.getJSONObject(0); response = responsearray.getJSONObject(0);
_id = response.getString("_id"); _id = response.getString("_id");
json = response; json = response;
if (response.has("NSCLIENT_ID")) { if (response.has("NSCLIENT_ID")) {
@ -35,6 +37,7 @@ public class NSAddAck extends Event implements Ack {
MainApp.bus().post(this); MainApp.bus().post(this);
return; return;
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e);
} }
// Check for not authorized // Check for not authorized
try { try {
@ -45,7 +48,8 @@ public class NSAddAck extends Event implements Ack {
MainApp.bus().post(new EventNSClientRestart()); MainApp.bus().post(new EventNSClientRestart());
return; return;
} }
log.debug("DBACCESS " + response.getString("result")); if (Config.logNsclient)
log.debug("DBACCESS " + response.getString("result"));
} }
return; return;
} catch (Exception e) { } catch (Exception e) {

View file

@ -5,6 +5,7 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.Event;
import io.socket.client.Ack; import io.socket.client.Ack;
@ -13,9 +14,9 @@ import io.socket.client.Ack;
* Created by mike on 21.02.2016. * Created by mike on 21.02.2016.
*/ */
public class NSUpdateAck extends Event implements Ack { 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 boolean result = false;
public String _id = null; public String _id;
public String action; public String action;
public void call(Object...args) { public void call(Object...args) {
JSONObject response = (JSONObject)args[0]; JSONObject response = (JSONObject)args[0];
@ -29,6 +30,7 @@ public class NSUpdateAck extends Event implements Ack {
} }
MainApp.bus().post(this); MainApp.bus().post(this);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e);
} }
} }

View file

@ -22,7 +22,6 @@ import info.nightscout.utils.SP;
*/ */
public class BroadcastAckAlarm { public class BroadcastAckAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class);
public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) { public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) {

View file

@ -21,8 +21,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastAlarm { public class BroadcastAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class);
public static void handleAlarm(JSONObject alarm, Context context) { public static void handleAlarm(JSONObject alarm, Context context) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", alarm.toString()); bundle.putString("data", alarm.toString());

View file

@ -22,8 +22,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastAnnouncement { public class BroadcastAnnouncement {
private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class);
public static void handleAnnouncement(JSONObject announcement, Context context) { public static void handleAnnouncement(JSONObject announcement, Context context) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", announcement.toString()); bundle.putString("data", announcement.toString());

View file

@ -21,8 +21,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastCals { public class BroadcastCals {
private static Logger log = LoggerFactory.getLogger(BroadcastCals.class);
public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) { public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View file

@ -21,8 +21,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastClearAlarm { public class BroadcastClearAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class);
public static void handleClearAlarm(JSONObject clearalarm, Context context) { public static void handleClearAlarm(JSONObject clearalarm, Context context) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", clearalarm.toString()); bundle.putString("data", clearalarm.toString());

View file

@ -20,27 +20,6 @@ import info.nightscout.utils.SP;
public class BroadcastDeviceStatus { 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) { public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
List<JSONArray> splitted = BroadcastTreatment.splitArray(statuses); List<JSONArray> splitted = BroadcastTreatment.splitArray(statuses);
@ -67,31 +46,4 @@ public class BroadcastDeviceStatus {
} }
} }
} }
public static void handleNewFoods(JSONArray foods, Context context, boolean isDelta) {
List<JSONArray> 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);
}
}
}
} }

View file

@ -24,8 +24,6 @@ import info.nightscout.utils.SP;
* Created by mike on 20.02.2016. * Created by mike on 20.02.2016.
*/ */
public class BroadcastFood { public class BroadcastFood {
private static Logger log = LoggerFactory.getLogger(BroadcastFood.class);
public static void handleNewFood(JSONArray foods, Context context, boolean isDelta) { public static void handleNewFood(JSONArray foods, Context context, boolean isDelta) {
List<JSONArray> splitted = BroadcastTreatment.splitArray(foods); List<JSONArray> splitted = BroadcastTreatment.splitArray(foods);

View file

@ -21,8 +21,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastMbgs { public class BroadcastMbgs {
private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class);
public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View file

@ -22,8 +22,6 @@ import info.nightscout.utils.SP;
* Created by mike on 20.02.2016. * Created by mike on 20.02.2016.
*/ */
public class BroadcastProfile { public class BroadcastProfile {
private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class);
public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View file

@ -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();
}
}
}

View file

@ -22,29 +22,6 @@ import info.nightscout.utils.SP;
* Created by mike on 22.02.2016. * Created by mike on 22.02.2016.
*/ */
public class BroadcastSgvs { 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) { public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
List<JSONArray> splitted = BroadcastTreatment.splitArray(sgvs); List<JSONArray> splitted = BroadcastTreatment.splitArray(sgvs);

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
@ -23,7 +24,7 @@ import info.nightscout.utils.SP;
* Created by mike on 24.02.2016. * Created by mike on 24.02.2016.
*/ */
public class BroadcastStatus { 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) { public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) {
LocalBroadcastManager.getInstance(MainApp.instance()) LocalBroadcastManager.getInstance(MainApp.instance())

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
@ -22,7 +23,7 @@ import info.nightscout.utils.SP;
* Created by mike on 20.02.2016. * Created by mike on 20.02.2016.
*/ */
public class BroadcastTreatment { 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) { 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) { public static void handleChangedTreatment(JSONArray treatments, boolean isDelta) {
List<JSONArray> splitted = splitArray(treatments); List<JSONArray> 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) { public static void handleRemovedTreatment(JSONArray treatments, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View file

@ -21,8 +21,6 @@ import info.nightscout.utils.SP;
* Created by mike on 26.06.2016. * Created by mike on 26.06.2016.
*/ */
public class BroadcastUrgentAlarm { public class BroadcastUrgentAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class);
public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", urgentalarm.toString()); bundle.putString("data", urgentalarm.toString());

View file

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
@ -17,23 +18,27 @@ import info.nightscout.utils.ToastUtils;
* Created by mike on 02.07.2016. * Created by mike on 02.07.2016.
*/ */
public class DbLogger { 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) { public static void dbAdd(Intent intent, String data) {
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0); List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) { 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"); log.error("DBADD No receivers");
} else if (Config.logNSUpload) } else if (Config.logNSUpload) {
log.debug("DBADD dbAdd " + q.size() + " receivers " + data); 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<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0); List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) { 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"); log.error("DBREMOVE No receivers");
} else if (Config.logNSUpload) } else if (Config.logNSUpload) {
log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data); if (Config.logNsclient)
log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data);
}
} }
} }

View file

@ -5,12 +5,14 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
/** /**
* Created by mike on 11.06.2017. * Created by mike on 11.06.2017.
*/ */
public class NSAlarm { public class NSAlarm {
private static Logger log = LoggerFactory.getLogger(NSAlarm.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
JSONObject data; JSONObject data;

View file

@ -5,8 +5,10 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
public class NSCal { public class NSCal {
private static Logger log = LoggerFactory.getLogger(NSCal.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
public long date; public long date;
public double slope; public double slope;
public double intercept; public double intercept;
@ -20,7 +22,7 @@ public class NSCal {
scale = json.getDouble("scale"); scale = json.getDouble("scale");
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
log.debug("Data: " + json.toString()); log.error("Data: " + json.toString());
} }
} }
} }

View file

@ -80,7 +80,7 @@ import info.nightscout.utils.SP;
} }
*/ */
public class NSDeviceStatus { public class NSDeviceStatus {
private Logger log = LoggerFactory.getLogger(Constants.DATANS); private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
private static NSDeviceStatus instance = null; private static NSDeviceStatus instance = null;
@ -99,7 +99,7 @@ public class NSDeviceStatus {
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
if (bundle == null) return; if (bundle == null) return;
if (Config.logDataNS) if (Config.logNsclient)
log.debug("Got NS devicestatus: " + BundleLogger.log(bundle)); log.debug("Got NS devicestatus: " + BundleLogger.log(bundle));
try { try {

View file

@ -5,8 +5,10 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
public class NSMbg { public class NSMbg {
private static Logger log = LoggerFactory.getLogger(NSMbg.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
public long date; public long date;
public double mbg; public double mbg;
public String json; public String json;
@ -18,7 +20,7 @@ public class NSMbg {
this.json = json.toString(); this.json = json.toString();
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
log.debug("Data: " + json.toString()); log.error("Data: " + json.toString());
} }
} }
} }

View file

@ -114,7 +114,7 @@ import info.nightscout.utils.BundleLogger;
} }
*/ */
public class NSSettingsStatus { public class NSSettingsStatus {
private Logger log = LoggerFactory.getLogger(Constants.DATANS); private Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
private static NSSettingsStatus instance = null; private static NSSettingsStatus instance = null;
@ -140,7 +140,7 @@ public class NSSettingsStatus {
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
if (bundle == null) return; if (bundle == null) return;
if (Config.logDataNS) if (Config.logNsclient)
log.debug("Got NS status: " + BundleLogger.log(bundle)); log.debug("Got NS status: " + BundleLogger.log(bundle));
if (bundle.containsKey("nsclientversioncode")) { if (bundle.containsKey("nsclientversioncode")) {
@ -149,7 +149,7 @@ public class NSSettingsStatus {
nightscoutVersionName = bundle.getString("nightscoutversionname"); nightscoutVersionName = bundle.getString("nightscoutversionname");
Integer nsClientVersionCode = bundle.getInt("nsclientversioncode"); Integer nsClientVersionCode = bundle.getInt("nsclientversioncode");
String nsClientVersionName = bundle.getString("nsclientversionname"); String nsClientVersionName = bundle.getString("nsclientversionname");
if (Config.logDataNS) if (Config.logNsclient)
log.debug("Got versions: NSClient: " + nsClientVersionName + " Nightscout: " + nightscoutVersionName); log.debug("Got versions: NSClient: " + nsClientVersionName + " Nightscout: " + nightscoutVersionName);
try { try {
if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) { if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
@ -175,7 +175,7 @@ public class NSSettingsStatus {
try { try {
JSONObject statusJson = new JSONObject(bundle.getString("status")); JSONObject statusJson = new JSONObject(bundle.getString("status"));
setData(statusJson); setData(statusJson);
if (Config.logDataNS) if (Config.logNsclient)
log.debug("Received status: " + statusJson.toString()); log.debug("Received status: " + statusJson.toString());
Double targetHigh = getThreshold("bgTargetTop"); Double targetHigh = getThreshold("bgTargetTop");
Double targetlow = getThreshold("bgTargetBottom"); Double targetlow = getThreshold("bgTargetBottom");

View file

@ -5,12 +5,14 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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} * {"mgdl":105,"mills":1455136282375,"device":"xDrip-BluetoothWixel","direction":"Flat","filtered":98272,"unfiltered":98272,"noise":1,"rssi":100}
*/ */
public class NSSgv { public class NSSgv {
private static Logger log = LoggerFactory.getLogger(NSSgv.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
private JSONObject data; private JSONObject data;

View file

@ -7,8 +7,10 @@ import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Constants;
public class NSTreatment { public class NSTreatment {
private static Logger log = LoggerFactory.getLogger(NSTreatment.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
private JSONObject data; private JSONObject data;
private String action = null; // "update", "remove" or null (add) private String action = null; // "update", "remove" or null (add)

View file

@ -9,6 +9,8 @@ import android.os.PowerManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
@ -19,7 +21,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class AckAlarmReceiver extends BroadcastReceiver { public class AckAlarmReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(AckAlarmReceiver.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
@Override @Override
@ -32,7 +34,8 @@ public class AckAlarmReceiver extends BroadcastReceiver {
return; return;
} }
if (SP.getBoolean(R.string.key_ns_noupload, false)) { 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; return;
} }
wakeLock.acquire(); wakeLock.acquire();

View file

@ -11,6 +11,7 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.db.DbRequest;
@ -22,7 +23,7 @@ import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class DBAccessReceiver extends BroadcastReceiver { public class DBAccessReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class); private static Logger log = LoggerFactory.getLogger(Constants.NSCLIENT);
@Override @Override
@ -43,18 +44,21 @@ public class DBAccessReceiver extends BroadcastReceiver {
try { try {
collection = bundles.getString("collection"); collection = bundles.getString("collection");
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e);
} }
try { try {
_id = bundles.getString("_id"); _id = bundles.getString("_id");
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e);
} }
try { try {
data = new JSONObject(bundles.getString("data")); data = new JSONObject(bundles.getString("data"));
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e);
} }
if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) { 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; return;
} }
@ -70,7 +74,7 @@ public class DBAccessReceiver extends BroadcastReceiver {
} }
if (!isAllowedCollection(collection)) { if (!isAllowedCollection(collection)) {
log.debug("DBACCESS wrong collection specified"); log.error("DBACCESS wrong collection specified");
return; return;
} }

View file

@ -26,6 +26,7 @@ import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
@ -70,7 +71,7 @@ import io.socket.client.Socket;
import io.socket.emitter.Emitter; import io.socket.emitter.Emitter;
public class NSClientService extends Service { 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; static public PowerManager.WakeLock mWakeLock;
private IBinder mBinder = new NSClientService.LocalBinder(); private IBinder mBinder = new NSClientService.LocalBinder();
@ -156,13 +157,13 @@ public class NSClientService extends Service {
@Subscribe @Subscribe
public void onStatusEvent(EventAppExit event) { public void onStatusEvent(EventAppExit event) {
if (Config.logFunctionCalls) if (Config.logNsclient)
log.debug("EventAppExit received"); log.debug("EventAppExit received");
destroy(); destroy();
stopSelf(); stopSelf();
if (Config.logFunctionCalls) if (Config.logNsclient)
log.debug("EventAppExit finished"); log.debug("EventAppExit finished");
} }
@ -250,7 +251,8 @@ public class NSClientService extends Service {
private Emitter.Listener onDisconnect = new Emitter.Listener() { private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { 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")); MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
} }
}; };
@ -326,8 +328,7 @@ public class NSClientService extends Service {
private Emitter.Listener onPing = new Emitter.Listener() { private Emitter.Listener onPing = new Emitter.Listener() {
@Override @Override
public void call(final Object... args) { 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 // send data if there is something waiting
resend("Ping received"); resend("Ping received");
} }
@ -352,6 +353,7 @@ public class NSClientService extends Service {
data = (JSONObject) args[0]; data = (JSONObject) args[0];
} catch (Exception e) { } catch (Exception e) {
FabricPrivacy.log("Wrong Announcement from NS: " + args[0]); FabricPrivacy.log("Wrong Announcement from NS: " + args[0]);
log.error("Unhandled exception", e);
return; return;
} }
if (Config.detailedLog) if (Config.detailedLog)
@ -359,9 +361,11 @@ public class NSClientService extends Service {
MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(data, "message", "received"))); MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(data, "message", "received")));
} catch (Exception e) { } catch (Exception e) {
FabricPrivacy.logException(e); FabricPrivacy.logException(e);
log.error("Unhandled exception", e);
} }
BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext()); 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 @Override
public void call(final Object... args) { 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; JSONObject data;
try { try {
data = (JSONObject) args[0]; data = (JSONObject) args[0];
} catch (Exception e) { } catch (Exception e) {
FabricPrivacy.log("Wrong alarm from NS: " + args[0]); FabricPrivacy.log("Wrong alarm from NS: " + args[0]);
log.error("Unhandled exception", e);
return; return;
} }
BroadcastAlarm.handleAlarm(data, getApplicationContext()); 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]; data = (JSONObject) args[0];
} catch (Exception e) { } catch (Exception e) {
FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]); FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]);
log.error("Unhandled exception", e);
return; return;
} }
if (Config.detailedLog) MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext()); 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]; data = (JSONObject) args[0];
} catch (Exception e) { } catch (Exception e) {
FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]); FabricPrivacy.log("Wrong Urgent alarm from NS: " + args[0]);
log.error("Unhandled exception", e);
return; return;
} }
if (Config.detailedLog) MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext()); 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) { public void resend(final String reason) {
if (UploadQueue.size() == 0) if (UploadQueue.size() == 0)
return; return;
@ -766,7 +762,8 @@ public class NSClientService extends Service {
if (mSocket == null || !mSocket.connected()) return; if (mSocket == null || !mSocket.connected()) return;
if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { 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; return;
} }
lastResendTime = System.currentTimeMillis(); lastResendTime = System.currentTimeMillis();