diff options
author | Matthew Williams <mjwilliams@google.com> | 2014-06-18 18:52:47 -0700 |
---|---|---|
committer | Matthew Williams <mjwilliams@google.com> | 2014-06-18 18:52:47 -0700 |
commit | f7c4fddf44dd94162d26635bbd703ffeb392c675 (patch) | |
tree | 161048a7ef65e6482b2bc13cee5a997f74124953 /tests/JobSchedulerTestApp | |
parent | d7e16851285e19cb412fc14635a9f3f74bc07e0c (diff) | |
download | frameworks_base-f7c4fddf44dd94162d26635bbd703ffeb392c675.zip frameworks_base-f7c4fddf44dd94162d26635bbd703ffeb392c675.tar.gz frameworks_base-f7c4fddf44dd94162d26635bbd703ffeb392c675.tar.bz2 |
Flesh out job scheduler test app
adds the rest of the constraints - charging, idle, and allows you
to cancel all.
Change-Id: I43b7cac94446f6860ca0387440b3c8f995a2c0f3
Diffstat (limited to 'tests/JobSchedulerTestApp')
3 files changed, 97 insertions, 39 deletions
diff --git a/tests/JobSchedulerTestApp/res/layout/activity_main.xml b/tests/JobSchedulerTestApp/res/layout/activity_main.xml index 7f4961b..d3429ff 100644 --- a/tests/JobSchedulerTestApp/res/layout/activity_main.xml +++ b/tests/JobSchedulerTestApp/res/layout/activity_main.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> @@ -54,6 +54,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/constraints" + android:layout_margin="15dp" android:textSize="18dp"/> <LinearLayout android:layout_width="match_parent" @@ -83,43 +84,81 @@ </RadioGroup> </LinearLayout> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content"> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/timing"/> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginLeft="15dp" - android:textSize="17dp" - android:text="@string/delay"/> - <EditText - android:id="@+id/delay_time" - android:layout_width="60dp" - android:layout_height="wrap_content" - android:inputType="number"/> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/deadline" - android:textSize="17dp"/> - <EditText - android:id="@+id/deadline_time" - android:layout_width="60dp" - android:layout_height="wrap_content" - android:inputType="number"/> - </LinearLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/timing"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="15dp" + android:textSize="17dp" + android:text="@string/delay"/> + <EditText + android:id="@+id/delay_time" + android:layout_width="60dp" + android:layout_height="wrap_content" + android:inputType="number"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/deadline" + android:textSize="17dp"/> + <EditText + android:id="@+id/deadline_time" + android:layout_width="60dp" + android:layout_height="wrap_content" + android:inputType="number"/> + </LinearLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/charging_caption" + android:layout_marginRight="15dp"/> + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/checkbox_charging" + android:text="@string/charging_text"/> + </LinearLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/idle_caption" + android:layout_marginRight="15dp"/> + <CheckBox + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/checkbox_idle" + android:text="@string/idle_mode_text"/> + </LinearLayout> </LinearLayout> <Button android:id="@+id/schedule_button" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="40dp" + android:layout_marginTop="20dp" + android:layout_marginLeft="40dp" + android:layout_marginRight="40dp" android:onClick="scheduleJob" android:text="@string/schedule_job_button_text"/> + <Button + android:id="@+id/cancel_button" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="40dp" + android:layout_marginRight="40dp" + android:onClick="cancelAllJobs" + android:text="@string/cancel_all_jobs_button_text"/> </LinearLayout> -</LinearLayout> +</ScrollView> diff --git a/tests/JobSchedulerTestApp/res/values/strings.xml b/tests/JobSchedulerTestApp/res/values/strings.xml index 824d4b1..eebfb19 100644 --- a/tests/JobSchedulerTestApp/res/values/strings.xml +++ b/tests/JobSchedulerTestApp/res/values/strings.xml @@ -20,9 +20,13 @@ limitations under the License. <string name="onstarttask">onStartTask</string> <string name="defaultparamtext">task params will show up here.</string> <string name="schedule_job_button_text">Schedule Job</string> + <string name="cancel_all_jobs_button_text">Cancel all</string> <string name="app_name">Job Scheduler Test</string> <string name="finish_job_button_text">taskFinished</string> - <string name="manual_sync_text">Manual Sync</string> + <string name="idle_mode_text">Requires device in idle mode.</string> + <string name="charging_caption">Charging:</string> + <string name="charging_text">Requires device plugged in.</string> + <string name="idle_caption">Idle:</string> <string name="constraints">Constraints</string> <string name="connectivity">Connectivity:</string> <string name="any">Any</string> diff --git a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java index 15050ef..e15929d 100644 --- a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java +++ b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/MainActivity.java @@ -19,7 +19,9 @@ package com.android.demo.jobSchedulerApp; import android.app.Activity; import android.app.job.JobInfo; import android.app.job.JobParameters; +import android.app.job.JobScheduler; import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; @@ -28,6 +30,7 @@ import android.os.Message; import android.os.Messenger; import android.text.TextUtils; import android.view.View; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; @@ -60,7 +63,8 @@ public class MainActivity extends Activity { mDeadlineEditText = (EditText) findViewById(R.id.deadline_time); mWiFiConnectivityRadioButton = (RadioButton) findViewById(R.id.checkbox_unmetered); mAnyConnectivityRadioButton = (RadioButton) findViewById(R.id.checkbox_any); - + mRequiresChargingCheckBox = (CheckBox) findViewById(R.id.checkbox_charging); + mRequiresIdleCheckbox = (CheckBox) findViewById(R.id.checkbox_idle); mServiceComponent = new ComponentName(this, TestJobService.class); // Start service and provide it a way to communicate with us. Intent startServiceIntent = new Intent(this, TestJobService.class); @@ -79,6 +83,9 @@ public class MainActivity extends Activity { EditText mDeadlineEditText; RadioButton mWiFiConnectivityRadioButton; RadioButton mAnyConnectivityRadioButton; + CheckBox mRequiresChargingCheckBox; + CheckBox mRequiresIdleCheckbox; + ComponentName mServiceComponent; /** Service object to interact scheduled jobs. */ TestJobService mTestService; @@ -124,24 +131,32 @@ public class MainActivity extends Activity { String delay = mDelayEditText.getText().toString(); if (delay != null && !TextUtils.isEmpty(delay)) { - builder.setMinimumLatency(Long.valueOf(delay)); + builder.setMinimumLatency(Long.valueOf(delay) * 1000); } String deadline = mDeadlineEditText.getText().toString(); if (deadline != null && !TextUtils.isEmpty(deadline)) { - builder.setOverrideDeadline(Long.valueOf(deadline)); + builder.setOverrideDeadline(Long.valueOf(deadline) * 1000); } - boolean requiresUnmetered = mWiFiConnectivityRadioButton.isSelected(); - boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isSelected(); + boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked(); + boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isChecked(); if (requiresUnmetered) { builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED); } else if (requiresAnyConnectivity) { builder.setRequiredNetworkCapabilities(JobInfo.NetworkType.ANY); } + builder.setRequiresDeviceIdle(mRequiresIdleCheckbox.isChecked()); + builder.setRequiresCharging(mRequiresChargingCheckBox.isChecked()); mTestService.scheduleJob(builder.build()); } + public void cancelAllJobs(View v) { + JobScheduler tm = + (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + tm.cancelAll(); + } + /** * UI onclick listener to call jobFinished() in our service. */ |