From afc177078abccb85a5a860726d5178115516e2ca Mon Sep 17 00:00:00 2001 From: dakhnod Date: Thu, 21 Nov 2019 22:12:10 +0100 Subject: [PATCH] modified logging --- .../service/devices/qhybrid/QHybridSupport.java | 10 +++++++--- .../adapter/fossil/FossilWatchAdapter.java | 7 ++++++- .../adapter/misfit/MisfitWatchAdapter.java | 17 +++++++++++------ .../devices/qhybrid/requests/Request.java | 6 +++++- .../requests/misfit/EraseFileRequest.java | 2 +- .../misfit/GetCountdownSettingsRequest.java | 2 +- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java index fed7473a3..fd0887e24 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java @@ -112,7 +112,7 @@ public class QHybridSupport extends QHybridBaseSupport { NotificationConfiguration config = extras == null ? null : (NotificationConfiguration) intent.getExtras().get("CONFIG"); switch (intent.getAction()) { case QHYBRID_COMMAND_CONTROL: { - Log.d("Service", "sending control request"); + log("sending control request"); watchAdapter.requestHandsControl(); if (config != null) { watchAdapter.setHands(config.getHour(), config.getMin()); @@ -261,7 +261,7 @@ public class QHybridSupport extends QHybridBaseSupport { @Override public void onNotification(NotificationSpec notificationSpec) { - Log.d("Service", "notif from " + notificationSpec.sourceAppId + " " + notificationSpec.sender + " " + notificationSpec.phoneNumber); + log("notif from " + notificationSpec.sourceAppId + " " + notificationSpec.sender + " " + notificationSpec.phoneNumber); //new Exception().printStackTrace(); String packageName = notificationSpec.sourceName; @@ -274,7 +274,7 @@ public class QHybridSupport extends QHybridBaseSupport { } if (config == null) return; - Log.d("Service", "handling notification"); + log("handling notification"); if (config.getRespectSilentMode()) { int mode = ((AudioManager) getContext().getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).getRingerMode(); @@ -288,6 +288,10 @@ public class QHybridSupport extends QHybridBaseSupport { showNotificationsByAllActive(enforceActivityHandNotification); } + private void log(String message){ + logger.debug(message); + } + @Override public void onDeleteNotification(int id) { super.onDeleteNotification(id); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java index ca827761c..b1ef7ec3e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java @@ -7,6 +7,9 @@ import android.os.Build; import android.util.Log; import android.widget.Toast; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; @@ -49,6 +52,8 @@ public class FossilWatchAdapter extends WatchAdapter { private int lastButtonIndex = -1; + Logger logger = LoggerFactory.getLogger(getClass()); + public FossilWatchAdapter(QHybridSupport deviceSupport) { super(deviceSupport); } @@ -371,7 +376,7 @@ public class FossilWatchAdapter extends WatchAdapter { } private void log(String message) { - Log.d("FossilWatchAdapter", message); + logger.debug(message); } public void queueWrite(SetDeviceStateRequest request, boolean priorise) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/misfit/MisfitWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/misfit/MisfitWatchAdapter.java index b97638399..3f4ebc357 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/misfit/MisfitWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/misfit/MisfitWatchAdapter.java @@ -55,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.mis import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.SetVibrationStrengthRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.UploadFileRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.VibrateRequest; +import nodomain.freeyourgadget.gadgetbridge.util.GB; import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport.ITEM_ACTIVITY_POINT; import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport.ITEM_STEP_COUNT; @@ -66,13 +67,14 @@ import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybr public class MisfitWatchAdapter extends WatchAdapter { private int lastButtonIndex = -1; private final SparseArray responseFilters = new SparseArray<>(); - private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class); private UploadFileRequest uploadFileRequest; private Request fileRequest = null; private Queue requestQueue = new ArrayDeque<>(); + Logger logger = LoggerFactory.getLogger(getClass()); + public MisfitWatchAdapter(QHybridSupport deviceSupport) { super(deviceSupport); @@ -155,7 +157,7 @@ public class MisfitWatchAdapter extends WatchAdapter { break; } default: { - Log.d("Service", "unknown shit on " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())); + log("unknown shit on " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())); try { File charLog = new File("/sdcard/qFiles/charLog.txt"); if (!charLog.exists()) { @@ -191,10 +193,10 @@ public class MisfitWatchAdapter extends WatchAdapter { byte[] sequence = object.getStartSequence(); if (sequence.length > 1) { responseFilters.put((int) object.getStartSequence()[1], object); - Log.d("Service", "response filter " + object.getStartSequence()[1] + ": " + c.getSimpleName()); + log("response filter " + object.getStartSequence()[1] + ": " + c.getSimpleName()); } } catch (NoSuchMethodException | IllegalAccessException | InstantiationException e) { - Log.d("Service", "skipping class " + c.getName()); + log("skipping class " + c.getName()); } } } @@ -209,10 +211,10 @@ public class MisfitWatchAdapter extends WatchAdapter { for (int i = 1; i < characteristic.getValue().length; i++) { valueString.append(", ").append(values[i]); } - Log.d("Service", "unable to resolve " + characteristic.getUuid().toString() + ": " + valueString); + log("unable to resolve " + characteristic.getUuid().toString() + ": " + valueString); return true; } - Log.d("Service", "response: " + request.getClass().getSimpleName()); + log("response: " + request.getClass().getSimpleName()); request.handleResponse(characteristic); if (request instanceof GetStepGoalRequest) { @@ -347,6 +349,9 @@ public class MisfitWatchAdapter extends WatchAdapter { return true; } + private void log(String message){ + logger.debug(message); + } public void setActivityHand(double progress) { queueWrite(new SetCurrentStepCountRequest(Math.min((int) (1000000 * progress), 999999))); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java index c320352fd..e03b4aa7d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/Request.java @@ -3,12 +3,16 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests; import android.bluetooth.BluetoothGattCharacteristic; import android.util.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.UUID; public abstract class Request { protected byte[] data; + private Logger logger = (Logger) LoggerFactory.getLogger(getName()); //protected ByteBuffer buffer; public Request(){ @@ -48,7 +52,7 @@ public abstract class Request { } protected void log(String message){ - Log.d(getName(), message); + logger.debug(message); } public boolean isBasicRequest(){ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/EraseFileRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/EraseFileRequest.java index 9fbe6d42f..a7a19a911 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/EraseFileRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/EraseFileRequest.java @@ -20,7 +20,7 @@ public class EraseFileRequest extends FileRequest{ public void handleResponse(BluetoothGattCharacteristic characteristic) { super.handleResponse(characteristic); if(!characteristic.getUuid().toString().equals(getRequestUUID().toString())){ - Log.d(getName(), "wrong descriptor"); + log("wrong descriptor"); return; } ByteBuffer buffer = ByteBuffer.wrap(characteristic.getValue()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/GetCountdownSettingsRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/GetCountdownSettingsRequest.java index e29cff4a6..a1e732ce9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/GetCountdownSettingsRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/misfit/GetCountdownSettingsRequest.java @@ -25,7 +25,7 @@ public class GetCountdownSettingsRequest extends Request { byte progress = buffer.get(13); short offset = buffer.getShort(11); - Log.d("countdown", "progress: " + progress); + log("progress: " + progress); }