diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-05-15 23:21:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-05-15 23:21:06 +0000 |
commit | 0c9dbf507b53a12bdf577ff3e55c1686a2e089de (patch) | |
tree | 3849f2add85d7abe11151436b3f03f99783157a8 /java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java | |
parent | e724c7b6376be660abf2113f97c7cbfc34515da8 (diff) | |
parent | c857f90590e7d7fcffa89511982eb33afd34805f (diff) |
Merge "Update Dialer to v10 RC32" into oc-dev
Diffstat (limited to 'java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java')
-rw-r--r-- | java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java index 9bfce0052..107234edc 100644 --- a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java +++ b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java @@ -23,9 +23,11 @@ import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.ComponentName; import android.content.Context; +import android.content.SharedPreferences; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Parcelable; +import android.preference.PreferenceManager; import android.support.annotation.MainThread; import com.android.dialer.constants.ScheduledJobIds; import com.android.voicemail.impl.Assert; @@ -41,11 +43,28 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. private static final String EXTRA_TASK_EXTRAS_ARRAY = "extra_task_extras_array"; + private static final String EXTRA_JOB_ID = "extra_job_id"; + + private static final String EXPECTED_JOB_ID = + "com.android.voicemail.impl.scheduling.TaskSchedulerJobService.EXPECTED_JOB_ID"; + + private static final String NEXT_JOB_ID = + "com.android.voicemail.impl.scheduling.TaskSchedulerJobService.NEXT_JOB_ID"; + private JobParameters jobParameters; @Override @MainThread public boolean onStartJob(JobParameters params) { + int jobId = params.getTransientExtras().getInt(EXTRA_JOB_ID); + int expectedJobId = + PreferenceManager.getDefaultSharedPreferences(this).getInt(EXPECTED_JOB_ID, 0); + if (jobId != expectedJobId) { + VvmLog.e( + TAG, "Job " + jobId + " is not the last scheduled job " + expectedJobId + ", ignoring"); + return false; // nothing more to do. Job not running in background. + } + VvmLog.i(TAG, "starting " + jobId); jobParameters = params; TaskExecutor.createRunningInstance(this); TaskExecutor.getRunningInstance() @@ -97,6 +116,13 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. jobScheduler.cancel(ScheduledJobIds.VVM_TASK_SCHEDULER_JOB); } Bundle extras = new Bundle(); + int jobId = createJobId(context); + extras.putInt(EXTRA_JOB_ID, jobId); + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putInt(EXPECTED_JOB_ID, jobId) + .apply(); + extras.putParcelableArray( EXTRA_TASK_EXTRAS_ARRAY, pendingTasks.toArray(new Bundle[pendingTasks.size()])); JobInfo.Builder builder = @@ -112,7 +138,7 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. VvmLog.i(TAG, "running job instantly."); } jobScheduler.schedule(builder.build()); - VvmLog.i(TAG, "job scheduled"); + VvmLog.i(TAG, "job " + jobId + " scheduled"); } /** @@ -143,4 +169,11 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. } return result; } + + private static int createJobId(Context context) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + int jobId = sharedPreferences.getInt(NEXT_JOB_ID, 0); + sharedPreferences.edit().putInt(NEXT_JOB_ID, jobId + 1).apply(); + return jobId; + } } |