mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-12 04:59:27 +01:00
Fix some findbugs findings
This commit is contained in:
parent
a77ff03ca5
commit
1a88858c6f
@ -199,8 +199,7 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
|
||||
|
||||
static synchronized ArrayList<UUID> getUuidsFromFile(String filename) {
|
||||
ArrayList<UUID> 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) {
|
||||
|
@ -133,57 +133,57 @@ public final class HPlusConstants {
|
||||
public static final Map<Character, Byte> transliterateMap = new HashMap<Character, Byte>(){
|
||||
{
|
||||
//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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -69,8 +69,8 @@ class AppMessageHandlerZalewszczak extends AppMessageHandler {
|
||||
}
|
||||
|
||||
ArrayList<Pair<Integer, Object>> 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<Integer, Object>(KEY_TEMP, weatherSpec.currentTemp - 273 + "C"));
|
||||
pairs.add(new Pair<Integer, Object>(KEY_ICON, getIconForConditionCode(weatherSpec.currentConditionCode)));
|
||||
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -61,4 +61,9 @@ public class Version implements Comparable<Version> {
|
||||
return false;
|
||||
return this.compareTo((Version) that) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version.hashCode();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user