From faaa04b6709f085618a54caede2e4fb5f4a9db83 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 20 Aug 2015 18:55:22 +0200 Subject: [PATCH] App Installation: various improvements - make FwAppInstallerActivity wait for a completely initialized device - check basalt/aplite compatibility with pbw to be installed and report intead of crashing - fix crash when trying to install pbw with all app slots full --- app/src/main/AndroidManifest.xml | 3 +-- .../activities/FwAppInstallerActivity.java | 2 +- .../devices/pebble/PBWInstallHandler.java | 13 ++++++++++--- .../gadgetbridge/devices/pebble/PBWReader.java | 1 - .../service/devices/pebble/PebbleIoThread.java | 10 ++++++---- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 957a6be6..27d00cd9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,9 +5,8 @@ - diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java index 9f85914d..87dc334e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -47,7 +47,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity } else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) { device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); if (device != null) { - if (!device.isConnected()) { + if (!device.isInitialized()) { setInstallEnabled(false); if (mayConnect) { GB.toast(FwAppInstallerActivity.this, getString(R.string.connecting), Toast.LENGTH_SHORT, GB.INFO); 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 f7043c10..cae52c63 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 @@ -17,12 +17,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; public class PBWInstallHandler implements InstallHandler { private final Context mContext; - private final PBWReader mPBWReader; + private PBWReader mPBWReader; private final Uri mUri; public PBWInstallHandler(Uri uri, Context context) { mContext = context; - mPBWReader = new PBWReader(uri, context, ""); // FIXME: we should know the platform here mUri = uri; } @@ -34,6 +33,13 @@ public class PBWInstallHandler implements InstallHandler { return; } + mPBWReader = new PBWReader(mUri, mContext, device.getHardwareVersion().equals("dvt") ? "basalt" : "aplite"); + if (!mPBWReader.isValid()) { + installActivity.setInfoText("pbw/pbz is broken or incompatible with your Hardware or Firmware."); + installActivity.setInstallEnabled(false); + return; + } + if (mPBWReader.isFirmware()) { String hwRevision = mPBWReader.getHWRevision(); if (hwRevision != null && hwRevision.equals(device.getHardwareVersion())) { @@ -77,7 +83,8 @@ public class PBWInstallHandler implements InstallHandler { } public boolean isValid() { - return mPBWReader.isValid(); + // always pretend it is valid, as we cant know yet about hw/fw version + return true; } } \ No newline at end of file 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 4c97bfdb..b9f85a67 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 @@ -147,7 +147,6 @@ public class PBWReader { if (appName != null && appCreator != null && appVersion != null) { // FIXME: dont assume WATCHFACE app = new GBDeviceApp(uuid, appName, appCreator, appVersion, GBDeviceApp.Type.WATCHFACE); - isValid = true; } } catch (JSONException e) { 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 44a113c6..68758bf2 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 @@ -480,10 +480,12 @@ public class PebbleIoThread extends GBDeviceIoThread { mPBWReader = null; mIsInstalling = false; - try { - mZis.close(); - } catch (IOException e) { - // ignore + if (mZis != null) { + try { + mZis.close(); + } catch (IOException e) { + // ignore + } } mZis = null; mAppInstallToken = -1;