From 550e6a86f2ae174c93f0995e0fde6f67a7a689a3 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Wed, 25 Sep 2024 15:09:01 +0200 Subject: [PATCH] Pebble: fix NPE in getPlatformName The NPE was triggered by recent changes in the HearthRate Charts (503cd31d917337b8fe2d56715c67cd2ff2736bc3) Since getModel was also affected by the same NPE, the function is now changed as well. --- .../gadgetbridge/util/PebbleUtils.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java index 2a02c7465..32ba6e861 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java @@ -35,36 +35,39 @@ public class PebbleUtils { private static final Logger LOG = LoggerFactory.getLogger(PebbleUtils.class); public static String getPlatformName(String hwRev) { - String platformName; - if (hwRev.startsWith("snowy")) { - platformName = "basalt"; - } else if (hwRev.startsWith("spalding")) { - platformName = "chalk"; - } else if (hwRev.startsWith("silk")) { - platformName = "diorite"; - } else if (hwRev.startsWith("robert")) { - platformName = "emery"; - } else { - platformName = "aplite"; + final String DEFAULT_PLATFORM = "aplite"; + if (hwRev == null || hwRev.isEmpty()) { + return DEFAULT_PLATFORM; } - return platformName; + + if (hwRev.startsWith("snowy")) { + return "basalt"; + } else if (hwRev.startsWith("spalding")) { + return "chalk"; + } else if (hwRev.startsWith("silk")) { + return "diorite"; + } else if (hwRev.startsWith("robert")) { + return "emery"; + } + return DEFAULT_PLATFORM; } public static String getModel(String hwRev) { //TODO: get real data? - String model; - if (hwRev.startsWith("snowy")) { - model = "pebble_time_black"; - } else if (hwRev.startsWith("spalding")) { - model = "pebble_time_round_black_20mm"; - } else if (hwRev.startsWith("silk")) { - model = "pebble2_black"; - } else if (hwRev.startsWith("robert")) { - model = "pebble_time2_black"; - } else { - model = "pebble_black"; + final String DEFAULT_MODEL = "pebble_black"; + if (hwRev == null || hwRev.isEmpty()) { + return DEFAULT_MODEL; } - return model; + if (hwRev.startsWith("snowy")) { + return "pebble_time_black"; + } else if (hwRev.startsWith("spalding")) { + return "pebble_time_round_black_20mm"; + } else if (hwRev.startsWith("silk")) { + return "pebble2_black"; + } else if (hwRev.startsWith("robert")) { + return "pebble_time2_black"; + } + return DEFAULT_MODEL; } public static int getFwMajor(String fwString) {