diff options
author | Christopher Tate <ctate@google.com> | 2014-06-09 19:50:00 -0700 |
---|---|---|
committer | Christopher Tate <ctate@google.com> | 2014-06-10 12:51:55 -0700 |
commit | 7060b04f6d92351b67222e636ab378a0273bf3e7 (patch) | |
tree | 82fce1e04dd58a5d79895d0869b3b0adeffbb417 /tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp | |
parent | 6d7a25f317be60ae8a4d8806e517052be2398753 (diff) | |
download | frameworks_base-7060b04f6d92351b67222e636ab378a0273bf3e7.zip frameworks_base-7060b04f6d92351b67222e636ab378a0273bf3e7.tar.gz frameworks_base-7060b04f6d92351b67222e636ab378a0273bf3e7.tar.bz2 |
Out with the old; in with the new
Switch to the official "JobScheduler" etc naming.
Bug 14997851
Change-Id: I73a61aaa9af0740c114d08188bd97c52f3ac86b7
Diffstat (limited to 'tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp')
-rw-r--r-- | tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java | 26 | ||||
-rw-r--r-- | tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java | 48 |
2 files changed, 33 insertions, 41 deletions
diff --git a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java index 393c594..15050ef 100644 --- a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java +++ b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java @@ -17,8 +17,8 @@ package com.android.demo.jobSchedulerApp; import android.app.Activity; -import android.app.task.Task; -import android.app.task.TaskParams; +import android.app.job.JobInfo; +import android.app.job.JobParameters; import android.content.ComponentName; import android.content.Intent; import android.content.res.Resources; @@ -80,10 +80,10 @@ public class MainActivity extends Activity { RadioButton mWiFiConnectivityRadioButton; RadioButton mAnyConnectivityRadioButton; ComponentName mServiceComponent; - /** Service object to interact scheduled tasks. */ + /** Service object to interact scheduled jobs. */ TestJobService mTestService; - private static int kTaskId = 0; + private static int kJobId = 0; Handler mHandler = new Handler(/* default looper */) { @Override @@ -112,7 +112,7 @@ public class MainActivity extends Activity { } /** - * UI onclick listener to schedule a task. What this task is is defined in + * UI onclick listener to schedule a job. What this job is is defined in * TestJobService#scheduleJob() */ public void scheduleJob(View v) { @@ -120,7 +120,7 @@ public class MainActivity extends Activity { return; } - Task.Builder builder = new Task.Builder(kTaskId++, mServiceComponent); + JobInfo.Builder builder = new JobInfo.Builder(kJobId++, mServiceComponent); String delay = mDelayEditText.getText().toString(); if (delay != null && !TextUtils.isEmpty(delay)) { @@ -133,9 +133,9 @@ public class MainActivity extends Activity { boolean requiresUnmetered = mWiFiConnectivityRadioButton.isSelected(); boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isSelected(); if (requiresUnmetered) { - builder.setRequiredNetworkCapabilities(Task.NetworkType.UNMETERED); + builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED); } else if (requiresAnyConnectivity) { - builder.setRequiredNetworkCapabilities(Task.NetworkType.ANY); + builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.ANY); } mTestService.scheduleJob(builder.build()); @@ -143,24 +143,24 @@ public class MainActivity extends Activity { } /** - * UI onclick listener to call taskFinished() in our service. + * UI onclick listener to call jobFinished() in our service. */ public void finishJob(View v) { if (!ensureTestService()) { return; } - mTestService.callTaskFinished(); + mTestService.callJobFinished(); mParamsTextView.setText(""); } - public void onReceivedStartTask(TaskParams params) { + public void onReceivedStartJob(JobParameters params) { mShowStartView.setBackgroundColor(startJobColor); Message m = Message.obtain(mHandler, MSG_UNCOLOUR_START); mHandler.sendMessageDelayed(m, 1000L); // uncolour in 1 second. - mParamsTextView.setText("Executing: " + params.getTaskId() + " " + params.getExtras()); + mParamsTextView.setText("Executing: " + params.getJobId() + " " + params.getExtras()); } - public void onReceivedStopTask() { + public void onReceivedStopJob() { mShowStopView.setBackgroundColor(stopJobColor); Message m = Message.obtain(mHandler, MSG_UNCOLOUR_STOP); mHandler.sendMessageDelayed(m, 2000L); // uncolour in 1 second. diff --git a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java index 7dd3cf1..bf8e887 100644 --- a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java +++ b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java @@ -16,28 +16,20 @@ package com.android.demo.jobSchedulerApp.service; -import android.app.Service; -import android.app.task.Task; -import android.app.task.TaskManager; -import android.app.task.TaskParams; -import android.app.task.TaskService; -import android.content.ComponentName; +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.app.job.JobParameters; +import android.app.job.JobService; import android.content.Context; import android.content.Intent; -import android.os.Binder; -import android.os.IBinder; import android.os.Message; import android.os.Messenger; -import android.os.PersistableBundle; import android.os.RemoteException; import android.util.Log; import com.android.demo.jobSchedulerApp.MainActivity; -import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedList; -import java.util.List; /** @@ -52,7 +44,7 @@ import java.util.List; * lifecycle of our and provide a handle to said SyncAdapter to the OS on * request. */ -public class TestJobService extends TaskService { +public class TestJobService extends JobService { private static final String TAG = "SyncService"; @Override @@ -82,44 +74,44 @@ public class TestJobService extends TaskService { } @Override - public boolean onStartTask(TaskParams params) { - taskParamsMap.add(params); + public boolean onStartJob(JobParameters params) { + jobParamsMap.add(params); if (mActivity != null) { - mActivity.onReceivedStartTask(params); + mActivity.onReceivedStartJob(params); } - Log.i(TAG, "on start task: " + params.getTaskId()); + Log.i(TAG, "on start job: " + params.getJobId()); return true; } @Override - public boolean onStopTask(TaskParams params) { - taskParamsMap.remove(params); - mActivity.onReceivedStopTask(); - Log.i(TAG, "on stop task: " + params.getTaskId()); + public boolean onStopJob(JobParameters params) { + jobParamsMap.remove(params); + mActivity.onReceivedStopJob(); + Log.i(TAG, "on stop job: " + params.getJobId()); return true; } MainActivity mActivity; - private final LinkedList<TaskParams> taskParamsMap = new LinkedList<TaskParams>(); + private final LinkedList<JobParameters> jobParamsMap = new LinkedList<JobParameters>(); public void setUiCallback(MainActivity activity) { mActivity = activity; } /** Send job to the JobScheduler. */ - public void scheduleJob(Task t) { + public void scheduleJob(JobInfo t) { Log.d(TAG, "Scheduling job"); - TaskManager tm = - (TaskManager) getSystemService(Context.TASK_SERVICE); + JobScheduler tm = + (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); tm.schedule(t); } - public boolean callTaskFinished() { - TaskParams params = taskParamsMap.poll(); + public boolean callJobFinished() { + JobParameters params = jobParamsMap.poll(); if (params == null) { return false; } else { - taskFinished(params, false); + jobFinished(params, false); return true; } } |