mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-15 04:07:32 +01:00
Remove redundant null checks
This commit is contained in:
parent
100ed9f50c
commit
c1de677448
@ -636,14 +636,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
byte attributes_count = 0;
|
byte attributes_count = 0;
|
||||||
|
|
||||||
int length = 21 + 10 + actions_length;
|
int length = 21 + 10 + actions_length;
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attributes_count++;
|
|
||||||
length += (3 + s.getBytes().length);
|
|
||||||
}
|
}
|
||||||
|
attributes_count++;
|
||||||
|
length += (3 + s.getBytes().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode Prefix
|
// Encode Prefix
|
||||||
@ -667,19 +665,17 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
byte attribute_id = 0;
|
byte attribute_id = 0;
|
||||||
// Encode Pascal-Style Strings
|
// Encode Pascal-Style Strings
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
attribute_id++;
|
||||||
attribute_id++;
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int partlength = s.getBytes().length;
|
|
||||||
if (partlength > 255) partlength = 255;
|
|
||||||
buf.put(attribute_id);
|
|
||||||
buf.putShort((short) partlength);
|
|
||||||
buf.put(s.getBytes(), 0, partlength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int partlength = s.getBytes().length;
|
||||||
|
if (partlength > 255) partlength = 255;
|
||||||
|
buf.put(attribute_id);
|
||||||
|
buf.putShort((short) partlength);
|
||||||
|
buf.put(s.getBytes(), 0, partlength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -981,14 +977,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
byte attributes_count = 2; // icon
|
byte attributes_count = 2; // icon
|
||||||
short attributes_length = (short) (11 + actions_length);
|
short attributes_length = (short) (11 + actions_length);
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attributes_count++;
|
|
||||||
attributes_length += (3 + s.getBytes().length);
|
|
||||||
}
|
}
|
||||||
|
attributes_count++;
|
||||||
|
attributes_length += (3 + s.getBytes().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length);
|
short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length);
|
||||||
@ -1013,19 +1007,17 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
byte attribute_id = 0;
|
byte attribute_id = 0;
|
||||||
// Encode Pascal-Style Strings
|
// Encode Pascal-Style Strings
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
attribute_id++;
|
||||||
attribute_id++;
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int partlength = s.getBytes().length;
|
|
||||||
if (partlength > 512) partlength = 512;
|
|
||||||
buf.put(attribute_id);
|
|
||||||
buf.putShort((short) partlength);
|
|
||||||
buf.put(s.getBytes(), 0, partlength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int partlength = s.getBytes().length;
|
||||||
|
if (partlength > 512) partlength = 512;
|
||||||
|
buf.put(attribute_id);
|
||||||
|
buf.putShort((short) partlength);
|
||||||
|
buf.put(s.getBytes(), 0, partlength);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.put((byte) 4); // icon
|
buf.put((byte) 4); // icon
|
||||||
@ -1116,14 +1108,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
byte attributes_count = 3;
|
byte attributes_count = 3;
|
||||||
short attributes_length = (short) (21 + actions_length);
|
short attributes_length = (short) (21 + actions_length);
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attributes_count++;
|
|
||||||
attributes_length += (3 + s.getBytes().length);
|
|
||||||
}
|
}
|
||||||
|
attributes_count++;
|
||||||
|
attributes_length += (3 + s.getBytes().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = UUID.fromString("61b22bc8-1e29-460d-a236-3fe409a43901");
|
UUID uuid = UUID.fromString("61b22bc8-1e29-460d-a236-3fe409a43901");
|
||||||
@ -1150,27 +1140,25 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
byte attribute_id = 0;
|
byte attribute_id = 0;
|
||||||
// Encode Pascal-Style Strings
|
// Encode Pascal-Style Strings
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
attribute_id++;
|
||||||
attribute_id++;
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int partlength = s.getBytes().length;
|
|
||||||
if (partlength > 512) partlength = 512;
|
|
||||||
if (attribute_id == 4) {
|
|
||||||
buf.put((byte) 11);
|
|
||||||
} else if (attribute_id == 5) {
|
|
||||||
buf.put((byte) 25);
|
|
||||||
} else if (attribute_id == 6) {
|
|
||||||
buf.put((byte) 26);
|
|
||||||
} else {
|
|
||||||
buf.put(attribute_id);
|
|
||||||
}
|
|
||||||
buf.putShort((short) partlength);
|
|
||||||
buf.put(s.getBytes(), 0, partlength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int partlength = s.getBytes().length;
|
||||||
|
if (partlength > 512) partlength = 512;
|
||||||
|
if (attribute_id == 4) {
|
||||||
|
buf.put((byte) 11);
|
||||||
|
} else if (attribute_id == 5) {
|
||||||
|
buf.put((byte) 25);
|
||||||
|
} else if (attribute_id == 6) {
|
||||||
|
buf.put((byte) 26);
|
||||||
|
} else {
|
||||||
|
buf.put(attribute_id);
|
||||||
|
}
|
||||||
|
buf.putShort((short) partlength);
|
||||||
|
buf.put(s.getBytes(), 0, partlength);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.put((byte) 4); // icon
|
buf.put((byte) 4); // icon
|
||||||
@ -1254,13 +1242,11 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
// Calculate length first
|
// Calculate length first
|
||||||
short attributes_length = 0;
|
short attributes_length = 0;
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attributes_length += (2 + s.getBytes().length);
|
|
||||||
}
|
}
|
||||||
|
attributes_length += (2 + s.getBytes().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
short pin_length = (short) (WEATHER_FORECAST_LENGTH + attributes_length);
|
short pin_length = (short) (WEATHER_FORECAST_LENGTH + attributes_length);
|
||||||
@ -1280,17 +1266,15 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
buf.putShort(attributes_length);
|
buf.putShort(attributes_length);
|
||||||
|
|
||||||
// Encode Pascal-Style Strings
|
// Encode Pascal-Style Strings
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int partlength = s.getBytes().length;
|
|
||||||
if (partlength > 512) partlength = 512;
|
|
||||||
buf.putShort((short) partlength);
|
|
||||||
buf.put(s.getBytes(), 0, partlength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int partlength = s.getBytes().length;
|
||||||
|
if (partlength > 512) partlength = 512;
|
||||||
|
buf.putShort((short) partlength);
|
||||||
|
buf.put(s.getBytes(), 0, partlength);
|
||||||
}
|
}
|
||||||
|
|
||||||
return encodeBlobdb(UUID_LOCATION, BLOBDB_INSERT, BLOBDB_WEATHER, buf.array());
|
return encodeBlobdb(UUID_LOCATION, BLOBDB_INSERT, BLOBDB_WEATHER, buf.array());
|
||||||
@ -1434,14 +1418,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
} else {
|
} else {
|
||||||
// Calculate length first
|
// Calculate length first
|
||||||
int length = LENGTH_PREFIX + 9;
|
int length = LENGTH_PREFIX + 9;
|
||||||
if (parts != null) {
|
for (String s : parts) {
|
||||||
for (String s : parts) {
|
if (s == null || s.equals("")) {
|
||||||
if (s == null || s.equals("")) {
|
length++; // encode null or empty strings as 0x00 later
|
||||||
length++; // encode null or empty strings as 0x00 later
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
length += (1 + s.getBytes().length);
|
|
||||||
}
|
}
|
||||||
|
length += (1 + s.getBytes().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode Prefix
|
// Encode Prefix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user