1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-02-24 08:21:15 +01:00

persist metadata in class, move validity check to isValid() function

This commit is contained in:
MPeter 2022-09-01 22:15:35 +02:00
parent c7841b4947
commit 96f87cf913

View File

@ -43,7 +43,8 @@ public class PineTimeInstallHandler implements InstallHandler {
private static final Logger LOG = LoggerFactory.getLogger(PineTimeInstallHandler.class); private static final Logger LOG = LoggerFactory.getLogger(PineTimeInstallHandler.class);
private final Context context; private final Context context;
private boolean valid = false;
private InfiniTimeDFUPackage dfuPackageManifest;
private String version = "(Unknown version)"; private String version = "(Unknown version)";
public PineTimeInstallHandler(Uri uri, Context context) { public PineTimeInstallHandler(Uri uri, Context context) {
@ -71,17 +72,6 @@ public class PineTimeInstallHandler implements InstallHandler {
} catch (Exception e) { } catch (Exception e) {
LOG.error("Unknown error occurred.", e); LOG.error("Unknown error occurred.", e);
} }
if (metadata != null &&
metadata.manifest != null &&
metadata.manifest.application != null &&
metadata.manifest.application.bin_file != null) {
valid = true;
version = metadata.manifest.application.bin_file;
} else {
valid = false;
LOG.error("Somehow metadata was found, but some data was missing");
}
} }
@Override @Override
@ -103,7 +93,7 @@ public class PineTimeInstallHandler implements InstallHandler {
return; return;
} }
if (!valid) { if (!isValid()) {
LOG.error("Firmware cannot be installed (not valid)"); LOG.error("Firmware cannot be installed (not valid)");
installActivity.setInfoText("Firmware cannot be installed (not valid)"); installActivity.setInfoText("Firmware cannot be installed (not valid)");
installActivity.setInstallEnabled(false); installActivity.setInstallEnabled(false);
@ -126,6 +116,9 @@ public class PineTimeInstallHandler implements InstallHandler {
@Override @Override
public boolean isValid() { public boolean isValid() {
return valid; return dfuPackageManifest != null &&
dfuPackageManifest.manifest != null &&
dfuPackageManifest.manifest.application != null &&
dfuPackageManifest.manifest.application.bin_file != null;
} }
} }