From 5a8c9a9180cddbe552c158ed650330f682b53fe6 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 11 Aug 2015 12:04:45 +0200 Subject: [PATCH] Pebble: cache installed pbw files on sdcard if force untested option is set This will be needed for FW 3.x on demand installations. --- .../activities/FwAppInstallerActivity.java | 1 + .../activities/InstallActivity.java | 4 +-- .../gadgetbridge/devices/InstallHandler.java | 5 ++++ .../miband/MiBandFWInstallHandler.java | 5 ++++ .../devices/pebble/PBWInstallHandler.java | 30 +++++++++++++++++++ .../devices/pebble/PBWReader.java | 4 +++ 6 files changed, 47 insertions(+), 2 deletions(-) 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 1dff9039..d4e64ea5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -98,6 +98,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity installButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + installHandler.onStartInstall(); Intent startIntent = new Intent(FwAppInstallerActivity.this, DeviceCommunicationService.class); startIntent.setAction(DeviceCommunicationService.ACTION_INSTALL); startIntent.putExtra("uri", uri); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/InstallActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/InstallActivity.java index 38bf4c17..6559f2a0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/InstallActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/InstallActivity.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.activities; public interface InstallActivity { - public void setInfoText(String text); - public void setInstallEnabled(boolean enable); + void setInfoText(String text); + void setInstallEnabled(boolean enable); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java index 572fbc6b..1d42a2bb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java @@ -26,4 +26,9 @@ public interface InstallHandler { * @param device the device to which the element shall be installed */ void validateInstallation(InstallActivity installActivity, GBDevice device); + + /** + * Allows device specivic code to be execute just before the installation starts + */ + void onStartInstall(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWInstallHandler.java index 6d041bf6..6697b387 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWInstallHandler.java @@ -52,6 +52,11 @@ public class MiBandFWInstallHandler implements InstallHandler { installActivity.setInstallEnabled(true); } + @Override + public void onStartInstall() { + + } + public boolean isValid() { return helper != null; } 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 13f69fa1..99abfbbe 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 @@ -1,14 +1,21 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble; import android.content.Context; +import android.content.SharedPreferences; import android.net.Uri; +import android.preference.PreferenceManager; +import java.io.File; +import java.io.IOException; + +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; public class PBWInstallHandler implements InstallHandler { @@ -51,7 +58,30 @@ public class PBWInstallHandler implements InstallHandler { } } + @Override + public void onStartInstall() { + if (mPBWReader.isFirmware()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext()); + if (!sharedPrefs.getBoolean("pebble_force_untested", false)) { + return; + } + + GBDeviceApp app = mPBWReader.getGBDeviceApp(); + File pbwFile = new File(mPBWReader.getUri().getPath()); + try { + File destDir = new File(FileUtils.getExternalFilesDir() + "/pbw-cache"); + destDir.mkdirs(); + FileUtils.copyFile(pbwFile, new File(destDir + "/" + app.getUUID().toString() + ".pbw")); + } catch (IOException e) { + e.printStackTrace(); + } + } + public boolean isValid() { return mPBWReader.isValid(); } + } \ 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 a84531de..c7b625ef 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 @@ -200,4 +200,8 @@ public class PBWReader { public String getHWRevision() { return hwRevision; } + + public Uri getUri() { + return uri; + } } \ No newline at end of file