Skip to content

Commit

Permalink
handle invalid intervals gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Jun 8, 2019
1 parent 23a6b33 commit 750a313
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public void onActivityResult(final int requestCode, final int resultCode, final
try {
RemoteVerifyJob.schedule(this, Integer.parseInt(values[3]));
snackbar.setText(R.string.enable_remote_verify).show();
} catch (final RemoteVerifyJob.InvalidInterval | NumberFormatException e) {
} catch (final NumberFormatException e) {
snackbar.setText(R.string.scanned_invalid_account_qr_code).show();
}
} else {
Expand Down
25 changes: 9 additions & 16 deletions app/src/main/java/app/attestation/auditor/RemoteVerifyJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,17 @@ static boolean isScheduled(final Context context) {
static void restore(final Context context) {
if (isEnabled(context) && !isScheduled(context)) {
Log.d(TAG, "remote attestation is enabled but job was not scheduled, rescheduling it");
try {
schedule(context, DEFAULT_INTERVAL);
} catch (final InvalidInterval e) {
throw new RuntimeException(e);
}
}
}

static class InvalidInterval extends Exception {
InvalidInterval() {
super("invalid interval");
schedule(context, DEFAULT_INTERVAL);
}
}

static void schedule(final Context context, final int interval) throws InvalidInterval {
if (interval < MIN_INTERVAL || interval > MAX_INTERVAL) {
throw new InvalidInterval();
static void schedule(final Context context, int interval) {
if (interval < MIN_INTERVAL) {
interval = MIN_INTERVAL;
Log.e(TAG, "invalid interval " + interval + " clamped to MIN_INTERVAL " + MIN_INTERVAL);
} else if (interval > MAX_INTERVAL) {
interval = MAX_INTERVAL;
Log.e(TAG, "invalid interval " + interval + " clamped to MAX_INTERVAL " + MAX_INTERVAL);
}
final JobScheduler scheduler = context.getSystemService(JobScheduler.class);
final JobInfo jobInfo = scheduler.getPendingJob(PERIODIC_JOB_ID);
Expand Down Expand Up @@ -184,8 +178,7 @@ protected Boolean doInBackground(final Void... params) {
}
throw new IOException("response code: " + responseCode);
}
} catch (final GeneralSecurityException | IOException | InvalidInterval |
NumberFormatException e) {
} catch (final GeneralSecurityException | IOException | NumberFormatException e) {
Log.e(TAG, "remote verify failure", e);
failure = true;
} finally {
Expand Down

0 comments on commit 750a313

Please sign in to comment.