From 5e8004756fefb1bc1f57ce4758e8bd4eb7768682 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Wed, 29 Jan 2020 19:11:24 +0100 Subject: [PATCH] A little cleanup --- .../devices/qhybrid/QHybridSupport.java | 17 +++++++++++++---- .../adapter/misfit/MisfitWatchAdapter.java | 18 ++++++------------ 2 files changed, 19 insertions(+), 16 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 ecef9610e..5845afb2b 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 @@ -145,6 +145,10 @@ public class QHybridSupport extends QHybridBaseSupport { public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); NotificationConfiguration config = extras == null ? null : (NotificationConfiguration) intent.getExtras().get("CONFIG"); + if (intent.getAction() == null) { + return; + } + switch (intent.getAction()) { case QHYBRID_COMMAND_CONTROL: { log("sending control request"); @@ -161,16 +165,21 @@ public class QHybridSupport extends QHybridBaseSupport { break; } case QHYBRID_COMMAND_SET: { - watchAdapter.setHands(config.getHour(), config.getMin()); - + if (config != null) { + watchAdapter.setHands(config.getHour(), config.getMin()); + } break; } case QHYBRID_COMMAND_VIBRATE: { - watchAdapter.vibrate(config.getVibration()); + if (config != null) { + watchAdapter.vibrate(config.getVibration()); + } break; } case QHYBRID_COMMAND_NOTIFICATION: { - watchAdapter.playNotification(config); + if (config != null) { + watchAdapter.playNotification(config); + } break; } case QHYBRID_COMMAND_UPDATE: { 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 b2fe7c443..07296a4ea 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 @@ -92,7 +92,7 @@ public class MisfitWatchAdapter extends WatchAdapter { private Queue requestQueue = new ArrayDeque<>(); - Logger logger = LoggerFactory.getLogger(getClass()); + private Logger logger = LoggerFactory.getLogger(getClass()); public MisfitWatchAdapter(QHybridSupport deviceSupport) { super(deviceSupport); @@ -179,12 +179,9 @@ public class MisfitWatchAdapter extends WatchAdapter { log("unknown shit on " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())); try { File charLog = new File("/sdcard/qFiles/charLog.txt"); - if (!charLog.exists()) { - charLog.createNewFile(); + try (FileOutputStream fos = new FileOutputStream(charLog, true)) { + fos.write((new Date().toString() + ": " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())).getBytes()); } - - FileOutputStream fos = new FileOutputStream(charLog, true); - fos.write((new Date().toString() + ": " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())).getBytes()); } catch (IOException e) { GB.log("error", GB.ERROR, e); } @@ -249,13 +246,10 @@ public class MisfitWatchAdapter extends WatchAdapter { if (!f.exists()) f.mkdir(); File file = new File("/sdcard/qFiles/steps"); - if (!file.exists()) { - file.createNewFile(); - } logger.debug("Writing file " + file.getPath()); - FileOutputStream fos = new FileOutputStream(file, true); - fos.write((System.currentTimeMillis() + ": " + steps + "\n").getBytes()); - fos.close(); + try (FileOutputStream fos = new FileOutputStream(file, true)) { + fos.write((System.currentTimeMillis() + ": " + steps + "\n").getBytes()); + } logger.debug("file written."); } catch (Exception e) { GB.log("error", GB.ERROR, e);