diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java index 618e3b66..4d16119e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java @@ -199,8 +199,7 @@ public class AppManagerActivity extends AbstractGBFragmentActivity { static synchronized ArrayList getUuidsFromFile(String filename) { ArrayList uuids = new ArrayList<>(); - try { - FileReader fileReader = new FileReader(FileUtils.getExternalFilesDir() + "/" + filename); + try (FileReader fileReader = new FileReader(FileUtils.getExternalFilesDir() + "/" + filename)) { BufferedReader in = new BufferedReader(fileReader); String line; while ((line = in.readLine()) != null) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java index 2d6dc678..a3b7f5dd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java @@ -133,57 +133,57 @@ public final class HPlusConstants { public static final Map transliterateMap = new HashMap(){ { //These are missing - put('ó', new Byte((byte) 111)); - put('Ó', new Byte((byte) 79)); - put('í', new Byte((byte) 105)); - put('Í', new Byte((byte) 73)); - put('ú', new Byte((byte) 117)); - put('Ú', new Byte((byte) 85)); + put('ó', (byte) 111); + put('Ó', (byte) 79); + put('í', (byte) 105); + put('Í', (byte) 73); + put('ú', (byte) 117); + put('Ú', (byte) 85); //These mostly belong to the extended ASCII table - put('Ç', new Byte((byte) 128)); - put('ü', new Byte((byte) 129)); - put('é', new Byte((byte) 130)); - put('â', new Byte((byte) 131)); - put('ä', new Byte((byte) 132)); - put('à', new Byte((byte) 133)); - put('ã', new Byte((byte) 134)); - put('ç', new Byte((byte) 135)); - put('ê', new Byte((byte) 136)); - put('ë', new Byte((byte) 137)); - put('è', new Byte((byte) 138)); - put('Ï', new Byte((byte) 139)); - put('Î', new Byte((byte) 140)); - put('Ì', new Byte((byte) 141)); - put('Ã', new Byte((byte) 142)); - put('Ä', new Byte((byte) 143)); - put('É', new Byte((byte) 144)); - put('æ', new Byte((byte) 145)); - put('Æ', new Byte((byte) 146)); - put('ô', new Byte((byte) 147)); - put('ö', new Byte((byte) 148)); - put('ò', new Byte((byte) 149)); - put('û', new Byte((byte) 150)); - put('ù', new Byte((byte) 151)); - put('ÿ', new Byte((byte) 152)); - put('Ö', new Byte((byte) 153)); - put('Ü', new Byte((byte) 154)); - put('¢', new Byte((byte) 155)); - put('£', new Byte((byte) 156)); - put('¥', new Byte((byte) 157)); - put('ƒ', new Byte((byte) 159)); - put('á', new Byte((byte) 160)); - put('ñ', new Byte((byte) 164)); - put('Ñ', new Byte((byte) 165)); - put('ª', new Byte((byte) 166)); - put('º', new Byte((byte) 167)); - put('¿', new Byte((byte) 168)); - put('¬', new Byte((byte) 170)); - put('½', new Byte((byte) 171)); - put('¼', new Byte((byte) 172)); - put('¡', new Byte((byte) 173)); - put('«', new Byte((byte) 174)); - put('»', new Byte((byte) 175)); + put('Ç', (byte) 128); + put('ü', (byte) 129); + put('é', (byte) 130); + put('â', (byte) 131); + put('ä', (byte) 132); + put('à', (byte) 133); + put('ã', (byte) 134); + put('ç', (byte) 135); + put('ê', (byte) 136); + put('ë', (byte) 137); + put('Ï', (byte) 139); + put('è', (byte) 138); + put('Î', (byte) 140); + put('Ì', (byte) 141); + put('Ã', (byte) 142); + put('Ä', (byte) 143); + put('É', (byte) 144); + put('æ', (byte) 145); + put('Æ', (byte) 146); + put('ô', (byte) 147); + put('ö', (byte) 148); + put('ò', (byte) 149); + put('û', (byte) 150); + put('ù', (byte) 151); + put('ÿ', (byte) 152); + put('Ö', (byte) 153); + put('Ü', (byte) 154); + put('¢', (byte) 155); + put('£', (byte) 156); + put('¥', (byte) 157); + put('ƒ', (byte) 159); + put('á', (byte) 160); + put('ñ', (byte) 164); + put('Ñ', (byte) 165); + put('ª', (byte) 166); + put('º', (byte) 167); + put('¿', (byte) 168); + put('¬', (byte) 170); + put('½', (byte) 171); + put('¼', (byte) 172); + put('¡', (byte) 173); + put('«', (byte) 174); + put('»', (byte) 175); } }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/MusicSpec.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/MusicSpec.java index 83b410cb..7d0ff8ef 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/MusicSpec.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/MusicSpec.java @@ -62,6 +62,16 @@ public class MusicSpec { this.duration == musicSpec.duration && this.trackCount == musicSpec.trackCount && this.trackNr == musicSpec.trackNr; + } + @Override + public int hashCode() { + int result = artist != null ? artist.hashCode() : 0; + result = 31 * result + (album != null ? album.hashCode() : 0); + result = 31 * result + (track != null ? track.hashCode() : 0); + result = 31 * result + duration; + result = 31 * result + trackCount; + result = 31 * result + trackNr; + return result; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java index 5c3e856c..e9246c94 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java @@ -39,8 +39,8 @@ public enum NotificationType { GENERIC_ALARM_CLOCK(PebbleIconID.ALARM_CLOCK, PebbleColor.Red); // Note: if you add any more constants, update all clients as well - public int icon; - public byte color; + public final int icon; + public final byte color; NotificationType(int icon, byte color) { this.icon = icon; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/ValueDecoder.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/ValueDecoder.java index f093bb12..f5fd359c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/ValueDecoder.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/ValueDecoder.java @@ -30,7 +30,7 @@ public class ValueDecoder { int percent = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); if (percent > 100 || percent < 0) { LOG.warn("Unexpected percent value: " + percent + ": " + GattCharacteristic.toString(characteristic)); - percent = Math.max(100, Math.min(0, percent)); + percent = Math.min(100, Math.max(0, percent)); } return percent; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/liveview/LiveviewIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/liveview/LiveviewIoThread.java index 47cab85e..0d811aa1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/liveview/LiveviewIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/liveview/LiveviewIoThread.java @@ -197,8 +197,6 @@ public class LiveviewIoThread extends GBDeviceIoThread { break; case HEADER_LEN: int headerSize = 0xff & incoming[0]; - if (headerSize < 0) - throw new IOException(); state = ReaderState.HEADER; incoming = new byte[headerSize]; break; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java index 2f849a43..41f6311e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java @@ -810,7 +810,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } private void handleButtonPressed(byte[] value) { - LOG.info("Button pressed: " + value); + LOG.info("Button pressed"); logMessageContent(value); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/FetchActivityOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/FetchActivityOperation.java index 5260a28c..160ce8cf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/FetchActivityOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/FetchActivityOperation.java @@ -216,7 +216,7 @@ public class FetchActivityOperation extends AbstractMiBand2Operation { int len = value.length; if (len % 4 != 1) { - throw new AssertionError("Unexpected activity array size: " + value); + throw new AssertionError("Unexpected activity array size: " + len); } for (int i = 1; i < len; i+=4) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerZalewszczak.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerZalewszczak.java index 9c8e4103..399686c4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerZalewszczak.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerZalewszczak.java @@ -69,8 +69,8 @@ class AppMessageHandlerZalewszczak extends AppMessageHandler { } ArrayList> pairs = new ArrayList<>(2); - pairs.add(new Pair<>(KEY_TEMP, (Object) (Math.round(weatherSpec.currentTemp - 273) + "C"))); - pairs.add(new Pair<>(KEY_ICON, (Object) (getIconForConditionCode(weatherSpec.currentConditionCode)))); + pairs.add(new Pair(KEY_TEMP, weatherSpec.currentTemp - 273 + "C")); + pairs.add(new Pair(KEY_ICON, getIconForConditionCode(weatherSpec.currentConditionCode))); byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs); ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionAnalytics.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionAnalytics.java index 80659c5d..4fbb3111 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionAnalytics.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionAnalytics.java @@ -31,15 +31,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB; class DatalogSessionAnalytics extends DatalogSession { private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionAnalytics.class); private GBDeviceEventBatteryInfo mGBDeviceEventBatteryInfo = new GBDeviceEventBatteryInfo(); - private GBDevice mGBDevice; DatalogSessionAnalytics(byte id, UUID uuid, int timestamp, int tag, byte itemType, short itemSize, GBDevice device) { super(id, uuid, timestamp, tag, itemType, itemSize); - if (mGBDevice == null || !device.equals(mGBDevice)) { //prevent showing information of other pebble watches when switching devices - mGBDevice = device; - mGBDeviceEventBatteryInfo.state = BatteryState.UNKNOWN; - } - // The default notification should not be too bad (one per hour) but we can override this if needed //mGBDevice.setBatteryThresholdPercent((short) 5); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/CheckSums.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/CheckSums.java index e7679301..e47e023f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/CheckSums.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/CheckSums.java @@ -71,16 +71,17 @@ public class CheckSums { } } - public static byte[] readAll(InputStream in, long maxLen) throws IOException { + // copy&paste of FileUtils.readAll() to have it free from Android dependencies + private static byte[] readAll(InputStream in, long maxLen) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(8192, in.available())); byte[] buf = new byte[8192]; - int read = 0; + int read; long totalRead = 0; while ((read = in.read(buf)) > 0) { out.write(buf, 0, read); totalRead += read; if (totalRead > maxLen) { - throw new IOException("Too much data to read into memory. Got already " + totalRead + buf); + throw new IOException("Too much data to read into memory. Got already " + totalRead); } } return out.toByteArray(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java index b01198a9..ba6150f0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java @@ -54,7 +54,9 @@ public class FileUtils { if (!sourceFile.exists()) { throw new IOException("Does not exist: " + sourceFile.getAbsolutePath()); } - copyFile(new FileInputStream(sourceFile), new FileOutputStream(destFile)); + try (FileInputStream in = new FileInputStream(sourceFile); FileOutputStream out = new FileOutputStream(destFile)) { + copyFile(in, out); + } } private static void copyFile(FileInputStream sourceStream, FileOutputStream destStream) throws IOException { @@ -229,13 +231,13 @@ public class FileUtils { public static byte[] readAll(InputStream in, long maxLen) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(8192, in.available())); byte[] buf = new byte[8192]; - int read = 0; + int read; long totalRead = 0; while ((read = in.read(buf)) > 0) { out.write(buf, 0, read); totalRead += read; if (totalRead > maxLen) { - throw new IOException("Too much data to read into memory. Got already " + totalRead + buf); + throw new IOException("Too much data to read into memory. Got already " + totalRead); } } return out.toByteArray(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java index c1db22ec..df0efe2c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java @@ -61,4 +61,9 @@ public class Version implements Comparable { return false; return this.compareTo((Version) that) == 0; } + + @Override + public int hashCode() { + return version.hashCode(); + } } \ No newline at end of file