From 09efecaeadc0ff3f02aff0366ab79787966fc1f7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 24 Oct 2017 23:58:37 +0900 Subject: [PATCH] Fix crash related to usage reporting update (fixes #978) --- .../syncthingandroid/activities/MainActivity.java | 4 ++-- .../syncthingandroid/activities/SettingsActivity.java | 4 ++-- .../com/nutomic/syncthingandroid/model/Options.java | 11 +++-------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index c58d452f..526cc3fb 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -109,7 +109,7 @@ public class MainActivity extends StateDialogActivity mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); mDrawerFragment.requestGuiUpdate(); if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY && - getApi().getOptions().getUsageReportValue() == Options.USAGE_REPORTING_UNDECIDED) { + getApi().getOptions().isUsageReportingAccepted()) { showUsageReportingDialog(); } break; @@ -452,7 +452,7 @@ public class MainActivity extends StateDialogActivity Options options = getApi().getOptions(); switch (which) { case DialogInterface.BUTTON_POSITIVE: - options.urAccepted = Options.USAGE_REPORTING_ACCEPTED; + options.urAccepted = options.urVersionMax; break; case DialogInterface.BUTTON_NEGATIVE: options.urAccepted = Options.USAGE_REPORTING_DENIED; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index 95332f0c..3a706480 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -234,7 +234,7 @@ public class SettingsActivity extends SyncthingActivity { mRelaysEnabled.setChecked(mOptions.relaysEnabled); mGlobalAnnounceServers.setText(joiner.join(mOptions.globalAnnounceServers)); mAddress.setText(mGui.address); - mUrAccepted.setChecked(mOptions.getUsageReportValue() == Options.USAGE_REPORTING_ACCEPTED); + mUrAccepted.setChecked(mOptions.isUsageReportingAccepted()); } @Override @@ -277,7 +277,7 @@ public class SettingsActivity extends SyncthingActivity { case "address": mGui.address = (String) o; break; case "urAccepted": mOptions.urAccepted = ((boolean) o) - ? Options.USAGE_REPORTING_ACCEPTED + ? mOptions.urVersionMax : Options.USAGE_REPORTING_DENIED; break; default: throw new InvalidParameterException(); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java b/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java index 1752e465..b4131310 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java @@ -18,6 +18,7 @@ public class Options { public int natRenewalMinutes; public int natTimeoutSeconds; public int urAccepted; + public int urVersionMax; public String urUniqueId; public String urURL; public boolean urPostInsecurely; @@ -36,15 +37,9 @@ public class Options { public int tempIndexMinBlocks; public static final int USAGE_REPORTING_UNDECIDED = 0; - public static final int USAGE_REPORTING_ACCEPTED = 2; public static final int USAGE_REPORTING_DENIED = -1; - public int getUsageReportValue() { - if (urAccepted > USAGE_REPORTING_ACCEPTED) - throw new RuntimeException("Inalid usage reporting value"); - - return (urAccepted == USAGE_REPORTING_ACCEPTED || urAccepted == USAGE_REPORTING_DENIED) - ? urAccepted - : USAGE_REPORTING_UNDECIDED; + public boolean isUsageReportingAccepted() { + return urAccepted == urVersionMax; } }