Skip to content

Commit

Permalink
use preference to check remote verification state
Browse files Browse the repository at this point in the history
This is more efficient than checking if the job is scheduled and avoids
showing it disabled if the user does something like manually cancelling
the job. The app knows how to restore the missing job, so it's not what
determines if this is enabled anymore.
  • Loading branch information
thestinger committed Jun 8, 2019
1 parent 730952d commit 23a6b33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ public boolean onCreateOptionsMenu(final Menu menu) {

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
final boolean isRemoteVerifyScheduled = RemoteVerifyJob.isScheduled(this);
final boolean isRemoteVerifyEnabled = RemoteVerifyJob.isEnabled(this);
menu.findItem(R.id.action_enable_remote_verify)
.setEnabled(isSupportedAuditee && !isRemoteVerifyScheduled);
menu.findItem(R.id.action_disable_remote_verify).setEnabled(isRemoteVerifyScheduled);
.setEnabled(isSupportedAuditee && !isRemoteVerifyEnabled);
menu.findItem(R.id.action_disable_remote_verify).setEnabled(isRemoteVerifyEnabled);
menu.findItem(R.id.action_submit_sample).setEnabled(canSubmitSample &&
!SubmitSampleJob.isScheduled(this));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ public class RemoteVerifyJob extends JobService {

private RemoteVerifyTask task;

static boolean isEnabled(final Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).contains(KEY_USER_ID);
}

static boolean isScheduled(final Context context) {
return context.getSystemService(JobScheduler.class).getPendingJob(PERIODIC_JOB_ID) != null;
}

static void restore(final Context context) {
if (!PreferenceManager.getDefaultSharedPreferences(context).contains(KEY_USER_ID)) {
return;
}
if (!isScheduled(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);
Expand Down

0 comments on commit 23a6b33

Please sign in to comment.