NSCLIENT logging
This commit is contained in:
parent
a7efa317be
commit
cfff357e6b
32 changed files with 146 additions and 295 deletions
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<EventNSClientNewLog> listLog = new ArrayList<>();
|
||||
Spanned textLog = Html.fromHtml("");
|
||||
|
||||
public boolean paused = false;
|
||||
boolean autoscroll = true;
|
||||
public boolean paused;
|
||||
boolean autoscroll;
|
||||
|
||||
public String status = "";
|
||||
|
||||
|
@ -132,11 +132,13 @@ public class NSClientPlugin extends PluginBase {
|
|||
private ServiceConnection mConnection = new ServiceConnection() {
|
||||
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("Service is disconnected");
|
||||
nsClientService = null;
|
||||
}
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("Service is connected");
|
||||
NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service;
|
||||
if (mLocalBinder != null) // is null when running in roboelectric
|
||||
|
@ -155,6 +157,7 @@ public class NSClientPlugin extends PluginBase {
|
|||
@Subscribe
|
||||
public void onStatusEvent(final EventNSClientNewLog ev) {
|
||||
addToLog(ev);
|
||||
if (Config.logNsclient)
|
||||
log.debug(ev.action + " " + ev.logText);
|
||||
}
|
||||
|
||||
|
@ -165,21 +168,16 @@ public class NSClientPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
synchronized void clearLog() {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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() {
|
||||
handler.post(() -> {
|
||||
synchronized (listLog) {
|
||||
listLog.add(ev);
|
||||
// remove the first line if log is too large
|
||||
|
@ -188,7 +186,6 @@ public class NSClientPlugin extends PluginBase {
|
|||
}
|
||||
}
|
||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,16 +45,14 @@ 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);
|
||||
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");
|
||||
NSClientService.handler.post(() -> {
|
||||
if (Config.logNsclient)
|
||||
log.debug("ClearQueue");
|
||||
MainApp.getDbHelper().deleteAllDbRequests();
|
||||
if (Config.logNsclient)
|
||||
log.debug(status());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -74,9 +73,7 @@ public class UploadQueue {
|
|||
public static void removeID(final JSONObject record) {
|
||||
startService();
|
||||
if (NSClientService.handler != null) {
|
||||
NSClientService.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NSClientService.handler.post(() -> {
|
||||
try {
|
||||
String id;
|
||||
if (record.has("NSCLIENT_ID")) {
|
||||
|
@ -85,12 +82,12 @@ public class UploadQueue {
|
|||
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() {
|
||||
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<DbRequest> iterator = null;
|
||||
CloseableIterator<DbRequest> iterator;
|
||||
try {
|
||||
iterator = MainApp.getDbHelper().getDbRequestInterator();
|
||||
try {
|
||||
|
|
|
@ -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,16 +16,17 @@ 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) {
|
||||
if (responsearray.length() > 0) {
|
||||
response = responsearray.getJSONObject(0);
|
||||
_id = response.getString("_id");
|
||||
json = response;
|
||||
|
@ -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,6 +48,7 @@ public class NSAddAck extends Event implements Ack {
|
|||
MainApp.bus().post(new EventNSClientRestart());
|
||||
return;
|
||||
}
|
||||
if (Config.logNsclient)
|
||||
log.debug("DBACCESS " + response.getString("result"));
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<JSONArray> splitted = BroadcastTreatment.splitArray(foods);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<JSONArray> splitted = BroadcastTreatment.splitArray(sgvs);
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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<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) {
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<ResolveInfo> 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)
|
||||
} else if (Config.logNSUpload) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void dbRemove(Intent intent, String data) {
|
||||
List<ResolveInfo> 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)
|
||||
} else if (Config.logNSUpload) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,6 +34,7 @@ public class AckAlarmReceiver extends BroadcastReceiver {
|
|||
return;
|
||||
}
|
||||
if (SP.getBoolean(R.string.key_ns_noupload, false)) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("Upload disabled. Message dropped");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,6 +251,7 @@ public class NSClientService extends Service {
|
|||
private Emitter.Listener onDisconnect = new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("disconnect reason: {}", args);
|
||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
|
||||
}
|
||||
|
@ -326,7 +328,6 @@ 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"));
|
||||
// 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,8 +361,10 @@ 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());
|
||||
if (Config.logNsclient)
|
||||
log.debug(data.toString());
|
||||
}
|
||||
};
|
||||
|
@ -381,16 +385,17 @@ public class NSClientService extends Service {
|
|||
*/
|
||||
@Override
|
||||
public void call(final Object... args) {
|
||||
if (Config.detailedLog)
|
||||
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());
|
||||
if (Config.logNsclient)
|
||||
log.debug(data.toString());
|
||||
}
|
||||
};
|
||||
|
@ -416,11 +421,12 @@ 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"));
|
||||
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
|
||||
if (Config.logNsclient)
|
||||
log.debug(data.toString());
|
||||
}
|
||||
};
|
||||
|
@ -441,11 +447,12 @@ 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"));
|
||||
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
|
||||
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,6 +762,7 @@ public class NSClientService extends Service {
|
|||
if (mSocket == null || !mSocket.connected()) return;
|
||||
|
||||
if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) {
|
||||
if (Config.logNsclient)
|
||||
log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue