diff --git a/CHANGELOG.md b/CHANGELOG.md index e791a222c..5449fe2ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ####Next Version * Pebble: fix regression in 0.6.7 when installing pbw/pbz files from content providers (eg. download manager) * Pebble: fix installation of pbw files on firmware 3.x when using content providers (eg. download manager) +* Pebble: fix crash on firmware 3.x when pebble requests a pbw that is not in Gadgetbridge's cache + Treat Signal notifications as chat notifications * Fix crash when contacts cannot be read on Android 6.0 (non-granted pemissions) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java index 820e00046..0c0252aee 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; @@ -53,7 +54,14 @@ public class PBWInstallHandler implements InstallHandler { platformName = "aplite"; } - mPBWReader = new PBWReader(mUri, mContext, platformName); + try { + mPBWReader = new PBWReader(mUri, mContext, platformName); + } catch (FileNotFoundException e) { + installActivity.setInfoText("file not found"); + installActivity.setInstallEnabled(false); + return; + } + if (!mPBWReader.isValid()) { installActivity.setInfoText("pbw/pbz is broken or incompatible with your Hardware or Firmware."); installActivity.setInstallEnabled(false); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java index 8de371c64..70c033ed1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWReader.java @@ -48,7 +48,7 @@ public class PBWReader { private final Uri uri; private final ContentResolver cr; private GBDeviceApp app; - private ArrayList pebbleInstallables; + private ArrayList pebbleInstallables = null; private boolean isFirmware = false; private boolean isLanguage = false; private boolean isValid = false; @@ -58,17 +58,11 @@ public class PBWReader { private int mIconId; private int mFlags; - public PBWReader(Uri uri, Context context, String platform) { + public PBWReader(Uri uri, Context context, String platform) throws FileNotFoundException { this.uri = uri; cr = context.getContentResolver(); - InputStream fin; - try { - fin = new BufferedInputStream(cr.openInputStream(uri)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return; - } + InputStream fin = new BufferedInputStream(cr.openInputStream(uri)); if (uri.toString().endsWith(".pbl") && platform.equals("aplite")) { STM32CRC stm32crc = new STM32CRC(); @@ -104,14 +98,7 @@ public class PBWReader { if (platform.equals("aplite")) { boolean hasApliteDir = false; - InputStream afin; - - try { - afin = new BufferedInputStream(cr.openInputStream(uri)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return; - } + InputStream afin = new BufferedInputStream(cr.openInputStream(uri)); ZipInputStream zis = new ZipInputStream(afin); ZipEntry ze; @@ -289,6 +276,9 @@ public class PBWReader { } public PebbleInstallable[] getPebbleInstallables() { + if (pebbleInstallables == null) { + return null; + } return pebbleInstallables.toArray(new PebbleInstallable[pebbleInstallables.size()]); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index 63e2121fe..3678b2bce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -18,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -551,7 +552,13 @@ public class PebbleIoThread extends GBDeviceIoThread { platformName = "aplite"; } - mPBWReader = new PBWReader(uri, getContext(), platformName); + try { + mPBWReader = new PBWReader(uri, getContext(), platformName); + } catch (FileNotFoundException e) { + LOG.warn("file not found!"); + return; + } + mPebbleInstallables = mPBWReader.getPebbleInstallables(); mCurrentInstallableIndex = 0;