summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java60
-rw-r--r--tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java77
-rw-r--r--tests/UsesFeature2Test/AndroidManifest.xml1
3 files changed, 129 insertions, 9 deletions
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 bf8e887..e2c3be0 100644
--- a/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java
+++ b/tests/JobSchedulerTestApp/src/com/android/demo/jobSchedulerApp/service/TestJobService.java
@@ -20,16 +20,21 @@ import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.app.job.JobParameters;
import android.app.job.JobService;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;
+import android.util.SparseArray;
import com.android.demo.jobSchedulerApp.MainActivity;
+import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Random;
/**
@@ -75,39 +80,76 @@ public class TestJobService extends JobService {
@Override
public boolean onStartJob(JobParameters params) {
- jobParamsMap.add(params);
+ Log.i(TAG, "on start job: " + params.getJobId());
+ currentId++;
+ jobParamsMap.put(currentId, params);
+ final int currId = this.currentId;
+ Log.d(TAG, "putting :" + currId + " for " + params.toString());
+ Log.d(TAG, " pulled: " + jobParamsMap.get(currId));
if (mActivity != null) {
mActivity.onReceivedStartJob(params);
}
- Log.i(TAG, "on start job: " + params.getJobId());
+
+ // Spin off a new task on a separate thread for a couple seconds.
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... voids) {
+ try {
+ Log.d(TAG, "Sleeping for 3 seconds.");
+ Thread.sleep(3000L);
+ } catch (InterruptedException e) {}
+ final JobParameters params = jobParamsMap.get(currId);
+ Log.d(TAG, "Pulled :" + currId + " " + params);
+ jobFinished(params, false);
+
+ Log.d(TAG, "Rescheduling new job: " + params.getJobId());
+ scheduleJob(
+ new JobInfo.Builder(params.getJobId(),
+ new ComponentName(getBaseContext(), TestJobService.class))
+ .setMinimumLatency(2000L)
+ .setOverrideDeadline(3000L)
+ .setRequiresCharging(true)
+ .build()
+ );
+
+ return null;
+ }
+ }.execute();
return true;
}
+
@Override
public boolean onStopJob(JobParameters params) {
- jobParamsMap.remove(params);
- mActivity.onReceivedStopJob();
Log.i(TAG, "on stop job: " + params.getJobId());
+ int ind = jobParamsMap.indexOfValue(params);
+ jobParamsMap.remove(ind);
+ mActivity.onReceivedStopJob();
return true;
}
+ static int currentId = 0;
MainActivity mActivity;
- private final LinkedList<JobParameters> jobParamsMap = new LinkedList<JobParameters>();
+ private final SparseArray<JobParameters> jobParamsMap = new SparseArray<JobParameters>();
+
public void setUiCallback(MainActivity activity) {
mActivity = activity;
}
/** Send job to the JobScheduler. */
- public void scheduleJob(JobInfo t) {
- Log.d(TAG, "Scheduling job");
+ public void scheduleJob(JobInfo job) {
+ Log.d(TAG, "Scheduling job " + job);
JobScheduler tm =
(JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
- tm.schedule(t);
+ tm.schedule(job);
}
public boolean callJobFinished() {
- JobParameters params = jobParamsMap.poll();
+ if (jobParamsMap.size() == 0) {
+ return false;
+ }
+ JobParameters params = jobParamsMap.valueAt(0);
if (params == null) {
return false;
} else {
diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
index 5d32c66..4372ff9 100644
--- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
+++ b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
@@ -17,7 +17,10 @@
package android.hardware.soundtrigger;
import android.hardware.soundtrigger.SoundTrigger;
+import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
+import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent;
+import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
import android.hardware.soundtrigger.SoundTrigger.RecognitionEvent;
import android.os.Parcel;
@@ -253,4 +256,78 @@ public class SoundTriggerTest extends InstrumentationTestCase {
// Verify that they are the same
assertEquals(re, unparceled);
}
+
+ @SmallTest
+ public void testKeyphraseRecognitionEventParcelUnparcel_noKeyphrases() throws Exception {
+ KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
+ SoundTrigger.RECOGNITION_STATUS_SUCCESS, 1, true, 2, 3, 4, null, false, null);
+
+ // Write to a parcel
+ Parcel parcel = Parcel.obtain();
+ re.writeToParcel(parcel, 0);
+
+ // Read from it
+ parcel.setDataPosition(0);
+ KeyphraseRecognitionEvent unparceled =
+ KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
+
+ // Verify that they are the same
+ assertEquals(re, unparceled);
+ }
+
+ @SmallTest
+ public void testKeyphraseRecognitionEventParcelUnparcel_zeroData() throws Exception {
+ KeyphraseRecognitionExtra[] kpExtra = new KeyphraseRecognitionExtra[0];
+ KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
+ SoundTrigger.RECOGNITION_STATUS_FAILURE, 2, true, 2, 3, 4, new byte[1],
+ true, kpExtra);
+
+ // Write to a parcel
+ Parcel parcel = Parcel.obtain();
+ re.writeToParcel(parcel, 0);
+
+ // Read from it
+ parcel.setDataPosition(0);
+ KeyphraseRecognitionEvent unparceled =
+ KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
+
+ // Verify that they are the same
+ assertEquals(re, unparceled);
+ }
+
+ @LargeTest
+ public void testKeyphraseRecognitionEventParcelUnparcel_largeData() throws Exception {
+ byte[] data = new byte[200 * 1024];
+ mRandom.nextBytes(data);
+ KeyphraseRecognitionExtra[] kpExtra = new KeyphraseRecognitionExtra[4];
+ ConfidenceLevel cl1 = new ConfidenceLevel(1, 90);
+ ConfidenceLevel cl2 = new ConfidenceLevel(2, 30);
+ kpExtra[0] = new KeyphraseRecognitionExtra(1,
+ SoundTrigger.RECOGNITION_MODE_USER_IDENTIFICATION,
+ new ConfidenceLevel[] {cl1, cl2});
+ kpExtra[1] = new KeyphraseRecognitionExtra(1,
+ SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER,
+ new ConfidenceLevel[] {cl2});
+ kpExtra[2] = new KeyphraseRecognitionExtra(1,
+ SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER, null);
+ kpExtra[3] = new KeyphraseRecognitionExtra(1,
+ SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER,
+ new ConfidenceLevel[0]);
+
+ KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
+ SoundTrigger.RECOGNITION_STATUS_FAILURE, 1, true, 2, 3, 4, data,
+ false, kpExtra);
+
+ // Write to a parcel
+ Parcel parcel = Parcel.obtain();
+ re.writeToParcel(parcel, 0);
+
+ // Read from it
+ parcel.setDataPosition(0);
+ KeyphraseRecognitionEvent unparceled =
+ KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
+
+ // Verify that they are the same
+ assertEquals(re, unparceled);
+ }
}
diff --git a/tests/UsesFeature2Test/AndroidManifest.xml b/tests/UsesFeature2Test/AndroidManifest.xml
index 724d186..6b6c4da 100644
--- a/tests/UsesFeature2Test/AndroidManifest.xml
+++ b/tests/UsesFeature2Test/AndroidManifest.xml
@@ -30,6 +30,7 @@
</feature-group>
<feature-group android:label="@string/gamepad">
<uses-feature android:name="android.hardware.gamepad" />
+ <uses-feature android:name="android.hardware.opengles.aep" />
</feature-group>
<application android:label="@string/app_title">