diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-03 23:10:39 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-03 23:10:39 +0000 |
commit | d67f1627521b174f12e0c247f154c7c93c5e408e (patch) | |
tree | 1a45d60921e293c6088efeaf4d9c408456f3e0e2 /java/com/android/voicemail/impl/scheduling/BaseTask.java | |
parent | 010981b798fbc6b8e6a00c3ea507f00c3e77c371 (diff) | |
parent | 8369df095a73a77b3715f8ae7ba06089cebca4ce (diff) |
This change reflects the Dialer V10 RC00 branch.
am: 8369df095a
Change-Id: I6820870feb74cba010ac3039e4da41325b3005f9
Diffstat (limited to 'java/com/android/voicemail/impl/scheduling/BaseTask.java')
-rw-r--r-- | java/com/android/voicemail/impl/scheduling/BaseTask.java | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/java/com/android/voicemail/impl/scheduling/BaseTask.java b/java/com/android/voicemail/impl/scheduling/BaseTask.java index 4cc6dd59e..0144e346f 100644 --- a/java/com/android/voicemail/impl/scheduling/BaseTask.java +++ b/java/com/android/voicemail/impl/scheduling/BaseTask.java @@ -18,12 +18,14 @@ package com.android.voicemail.impl.scheduling; import android.content.Context; import android.content.Intent; +import android.os.Bundle; import android.os.SystemClock; import android.support.annotation.CallSuper; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.WorkerThread; import android.telecom.PhoneAccountHandle; +import com.android.dialer.proguard.UsedByReflection; import com.android.voicemail.impl.Assert; import com.android.voicemail.impl.NeededForTesting; import java.util.ArrayList; @@ -33,10 +35,15 @@ import java.util.List; * Provides common utilities for task implementations, such as execution time and managing {@link * Policy} */ +@UsedByReflection(value = "Tasks.java") public abstract class BaseTask implements Task { private static final String EXTRA_PHONE_ACCOUNT_HANDLE = "extra_phone_account_handle"; + private static final String EXTRA_EXECUTION_TIME = "extra_execution_time"; + + private Bundle mExtras; + private Context mContext; private int mId; @@ -58,7 +65,7 @@ public abstract class BaseTask implements Task { /** * Modify the task ID to prevent arbitrary task from executing. Can only be called before {@link - * #onCreate(Context, Intent, int, int)} returns. + * #onCreate(Context, Bundle)} returns. */ @MainThread public void setId(int id) { @@ -86,8 +93,7 @@ public abstract class BaseTask implements Task { return mPhoneAccountHandle; } /** - * Should be call in the constructor or {@link Policy#onCreate(BaseTask, Intent, int, int)} will - * be missed. + * Should be call in the constructor or {@link Policy#onCreate(BaseTask, Bundle)} will be missed. */ @MainThread public BaseTask addPolicy(Policy policy) { @@ -107,6 +113,7 @@ public abstract class BaseTask implements Task { mHasFailed = true; } + /** @param timeMillis the time since epoch, in milliseconds. */ @MainThread public void setExecutionTime(long timeMillis) { Assert.isMainThread(); @@ -131,7 +138,7 @@ public abstract class BaseTask implements Task { */ public static Intent createIntent( Context context, Class<? extends BaseTask> task, PhoneAccountHandle phoneAccountHandle) { - Intent intent = TaskSchedulerService.createIntent(context, task); + Intent intent = Tasks.createIntent(context, task); intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); return intent; } @@ -142,12 +149,27 @@ public abstract class BaseTask implements Task { } @Override + public Bundle toBundle() { + mExtras.putLong(EXTRA_EXECUTION_TIME, mExecutionTime); + return mExtras; + } + + @Override @CallSuper - public void onCreate(Context context, Intent intent, int flags, int startId) { + public void onCreate(Context context, Bundle extras) { mContext = context; - mPhoneAccountHandle = intent.getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE); + mExtras = extras; + mPhoneAccountHandle = extras.getParcelable(EXTRA_PHONE_ACCOUNT_HANDLE); for (Policy policy : mPolicies) { - policy.onCreate(this, intent, flags, startId); + policy.onCreate(this, extras); + } + } + + @Override + @CallSuper + public void onRestore(Bundle extras) { + if (mExtras.containsKey(EXTRA_EXECUTION_TIME)) { + mExecutionTime = extras.getLong(EXTRA_EXECUTION_TIME); } } |