Modify CTS tests for AlarmClock to include testing for
CompleteVoiceRequest and AbortVoiceRequest hanlding by whatever
Clock app is included (DeskClock in stock Android case).
There are 3 CTS tests: one for each of the intents: SET_ALARM, DISMISS_ALARM, SNOOZE_ALARM
Design details
==============
1. The various activities/services involved are:
1.1. CTS_Test starts TestStartActivity
1.2. That starts VoiceInteractionMain
1.3. That starts MainInteractionService (the voice_interaction_service)
1.4. That starts MainInteractionSession
1.5. which fires an intent, based on the given test case type, to handle one of the intents: SET_ALARM, DISMISS_ALARM, SNOOZE_ALARM
2. Each of the 3 tests is a separate CTS test - so for each of the
tests, the above chain is started and is terminated at tne end of the
test.
3, DISMISS_ALARM test first sets an alarm to be dismissed. So, it really
is a set of 2 tests: first one is to set the alarm and next one is to
dismiss it.
Change-Id: I61e2d14d28c65eb8c37ec5cb2a414d3e5c15c9b3
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 8e0d83d..dfb4225 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -70,6 +70,7 @@
cts_support_packages := \
CtsAccelerationTestStubs \
+ CtsAlarmClockService \
CtsAppTestStubs \
CtsAtraceTestApp \
CtsCertInstallerApp \
diff --git a/tests/tests/alarmclock/Android.mk b/tests/tests/alarmclock/Android.mk
index c99f953..6c30bc7 100644
--- a/tests/tests/alarmclock/Android.mk
+++ b/tests/tests/alarmclock/Android.mk
@@ -21,7 +21,7 @@
# and when built explicitly put it in the data partition
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ctsdeviceutil
+LOCAL_STATIC_JAVA_LIBRARIES := CtsAlarmClockCommon ctstestrunner ctsdeviceutil
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/alarmclock/AndroidManifest.xml b/tests/tests/alarmclock/AndroidManifest.xml
index 88bb91d..c0193dd 100644
--- a/tests/tests/alarmclock/AndroidManifest.xml
+++ b/tests/tests/alarmclock/AndroidManifest.xml
@@ -22,9 +22,15 @@
<application>
<uses-library android:name="android.test.runner" />
- <activity android:name="TestActivity"
- android:label="The Target Activity for alarmClock Intents Test">
+
+ <activity android:name="TestStartActivity"
+ android:label="The Target Activity for AlarmClock CTS Test">
<intent-filter>
+ <action android:name="android.intent.action.TEST_START_ACTIVITY_DISMISS_ALARM" />
+ <action android:name="android.intent.action.TEST_START_ACTIVITY_SET_ALARM" />
+ <action android:name=
+ "android.intent.action.TEST_START_ACTIVITY_SET_ALARM_FOR_DISMISSAL" />
+ <action android:name="android.intent.action.TEST_START_ACTIVITY_SNOOZE_ALARM" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
diff --git a/tests/tests/alarmclock/AndroidTest.xml b/tests/tests/alarmclock/AndroidTest.xml
new file mode 100644
index 0000000..1cdd7f4
--- /dev/null
+++ b/tests/tests/alarmclock/AndroidTest.xml
@@ -0,0 +1,23 @@
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for AlarmClock">
+ <include name="common-config" />
+ <option name="cts-apk-installer:test-file-name" value="CtsAlarmClockService.apk" />
+ <option name="run-command:run-command"
+ value="settings put secure voice_interaction_service android.alarmclock.service/.MainInteractionService" />
+ <option name="run-command:teardown-command"
+ value="settings put secure voice_interaction_service com.google.android.googlequicksearchbox/com.google.android.voiceinteraction.GsaVoiceInteractionService" />
+ <option name="cts-apk-installer:test-file-name" value="CtsAlarmClockTestCases.apk" />
+</configuration>
diff --git a/tests/tests/alarmclock/common/Android.mk b/tests/tests/alarmclock/common/Android.mk
new file mode 100644
index 0000000..d460ade
--- /dev/null
+++ b/tests/tests/alarmclock/common/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+# and when built explicitly put it in the data partition
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := CtsAlarmClockCommon
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/tests/tests/alarmclock/common/src/android/alarmclock/common/Utils.java b/tests/tests/alarmclock/common/src/android/alarmclock/common/Utils.java
new file mode 100644
index 0000000..d469592
--- /dev/null
+++ b/tests/tests/alarmclock/common/src/android/alarmclock/common/Utils.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.alarmclock.common;
+
+import android.os.Bundle;
+
+public class Utils {
+ // private constructor - so it can't be instantiated.
+ private Utils() {
+ }
+
+ public enum TestcaseType {
+ DISMISS_ALARM,
+ SET_ALARM,
+ SET_ALARM_FOR_DISMISSAL,
+ SNOOZE_ALARM,
+ }
+ public static final String TESTCASE_TYPE = "Testcase_type";
+ public static final String BROADCAST_INTENT =
+ "android.intent.action.FROM_ALARMCLOCK_CTS_TEST_";
+ public static final String TEST_RESULT = "test_result";
+ public static final String COMPLETION_RESULT = "completion";
+ public static final String ABORT_RESULT = "abort";
+
+ public static final String toBundleString(Bundle bundle) {
+ if (bundle == null) {
+ return "*** Bundle is null ****";
+ }
+ StringBuilder buf = new StringBuilder();
+ if (bundle != null) {
+ buf.append("extras: ");
+ for (String s : bundle.keySet()) {
+ buf.append("(" + s + " = " + bundle.get(s) + "), ");
+ }
+ }
+ return buf.toString();
+ }
+}
diff --git a/tests/tests/alarmclock/res/xml/interaction_service.xml b/tests/tests/alarmclock/res/xml/interaction_service.xml
new file mode 100644
index 0000000..e37017c
--- /dev/null
+++ b/tests/tests/alarmclock/res/xml/interaction_service.xml
@@ -0,0 +1,20 @@
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:sessionService="android.alarmclock.service.MainInteractionSessionService"
+ android:recognitionService="android.alarmclock.service.MainRecognitionService"
+ android:settingsActivity="android.alarmclock.service.SettingsActivity"
+ android:supportsAssist="false" />
diff --git a/tests/tests/alarmclock/service/Android.mk b/tests/tests/alarmclock/service/Android.mk
new file mode 100644
index 0000000..53dc564
--- /dev/null
+++ b/tests/tests/alarmclock/service/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+# and when built explicitly put it in the data partition
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_STATIC_JAVA_LIBRARIES := CtsAlarmClockCommon ctstestrunner ctsdeviceutil
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsAlarmClockService
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/tests/alarmclock/service/AndroidManifest.xml b/tests/tests/alarmclock/service/AndroidManifest.xml
new file mode 100644
index 0000000..074df26
--- /dev/null
+++ b/tests/tests/alarmclock/service/AndroidManifest.xml
@@ -0,0 +1,64 @@
+<!--
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.alarmclock.service">
+ <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <service android:name=".MainInteractionService"
+ android:label="CTS test voice interaction service"
+ android:permission="android.permission.BIND_VOICE_INTERACTION"
+ android:process=":interactor"
+ android:exported="true">
+ <meta-data android:name="android.voice_interaction"
+ android:resource="@xml/interaction_service" />
+ <intent-filter>
+ <action android:name="android.service.voice.VoiceInteractionService" />
+ </intent-filter>
+ </service>
+ <activity android:name=".VoiceInteractionMain" >
+ <intent-filter>
+ <action android:name="android.intent.action.VIMAIN_DISMISS_ALARM" />
+ <action android:name="android.intent.action.VIMAIN_SET_ALARM" />
+ <action android:name="android.intent.action.VIMAIN_SET_ALARM_FOR_DISMISSAL" />
+ <action android:name="android.intent.action.VIMAIN_SNOOZE_ALARM" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ <activity android:name=".SettingsActivity"
+ android:label="Voice Interaction Settings">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ <service android:name=".MainInteractionSessionService"
+ android:permission="android.permission.BIND_VOICE_INTERACTION"
+ android:process=":session">
+ </service>
+ <service android:name=".MainRecognitionService"
+ android:label="CTS Voice Recognition Service">
+ <intent-filter>
+ <action android:name="android.speech.RecognitionService" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="android.speech" android:resource="@xml/recognition_service" />
+ </service>
+ </application>
+</manifest>
+
diff --git a/tests/tests/alarmclock/service/res/xml/interaction_service.xml b/tests/tests/alarmclock/service/res/xml/interaction_service.xml
new file mode 100644
index 0000000..e37017c
--- /dev/null
+++ b/tests/tests/alarmclock/service/res/xml/interaction_service.xml
@@ -0,0 +1,20 @@
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:sessionService="android.alarmclock.service.MainInteractionSessionService"
+ android:recognitionService="android.alarmclock.service.MainRecognitionService"
+ android:settingsActivity="android.alarmclock.service.SettingsActivity"
+ android:supportsAssist="false" />
diff --git a/tests/tests/alarmclock/service/res/xml/recognition_service.xml b/tests/tests/alarmclock/service/res/xml/recognition_service.xml
new file mode 100644
index 0000000..132c987
--- /dev/null
+++ b/tests/tests/alarmclock/service/res/xml/recognition_service.xml
@@ -0,0 +1,17 @@
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<recognition-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:settingsActivity="android.alarmclock.service.SettingsActivity" />
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionService.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionService.java
new file mode 100644
index 0000000..f96140e
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionService.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.alarmclock.common.Utils;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+import android.service.voice.VoiceInteractionService;
+import android.util.Log;
+
+public class MainInteractionService extends VoiceInteractionService {
+ static final String TAG = "MainInteractionService";
+ private Intent mIntent;
+ private boolean mReady = false;
+
+ @Override
+ public void onReady() {
+ super.onReady();
+ mReady = true;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.i(TAG, "onStartCommand received");
+ mIntent = intent;
+ Log.i(TAG, "received_testcasetype = " + mIntent.getStringExtra(Utils.TESTCASE_TYPE));
+ maybeStart();
+ return START_NOT_STICKY;
+ }
+
+ private void maybeStart() {
+ if (mIntent == null || !mReady) {
+ Log.wtf(TAG, "Can't start session because either intent is null or onReady() "
+ + "is not called yet. mIntent = " + mIntent + ", mReady = " + mReady);
+ } else {
+ Log.i(TAG,
+ "Yay! about to start MainInteractionSession as the voice_interaction_service");
+ if (isActiveService(this, new ComponentName(this, getClass()))) {
+ Bundle args = new Bundle();
+ args.putString(Utils.TESTCASE_TYPE, mIntent.getStringExtra(Utils.TESTCASE_TYPE));
+ Log.i(TAG, "xferring_testcasetype = " + args.getString(Utils.TESTCASE_TYPE));
+ showSession(args, 0);
+ } else {
+ Log.wtf(TAG, "**** Not starting MainInteractionService because" +
+ " it is not set as the current voice_interaction_service");
+ }
+ }
+ }
+}
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSession.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSession.java
new file mode 100644
index 0000000..ede762a
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSession.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.alarmclock.common.Utils;
+import android.alarmclock.common.Utils.TestcaseType;
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.provider.AlarmClock;
+import android.service.voice.VoiceInteractionSession;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MainInteractionSession extends VoiceInteractionSession {
+ static final String TAG = "MainInteractionSession";
+
+ private List<MyTask> mUsedTasks = new ArrayList<MyTask>();
+ private Context mContext;
+ private TestcaseType mTestType;
+ private String mTestResult = "";
+
+ MainInteractionSession(Context context) {
+ super(context);
+ mContext = context;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ }
+
+ @Override
+ public void onDestroy() {
+ Log.i(TAG, "Canceling the Asynctasks in onDestroy()");
+ for (MyTask t : mUsedTasks) {
+ t.cancel(true);
+ }
+ super.onDestroy();
+ }
+
+ @Override
+ public void onShow(Bundle args, int showFlags) {
+ super.onShow(args, showFlags);
+ String testCaseType = args.getString(Utils.TESTCASE_TYPE);
+ Log.i(TAG, "received_testcasetype = " + testCaseType);
+ try {
+ mTestType = TestcaseType.valueOf(testCaseType);
+ } catch (IllegalArgumentException e) {
+ Log.wtf(TAG, e);
+ return;
+ } catch (NullPointerException e) {
+ Log.wtf(TAG, e);
+ return;
+ }
+ Intent intent;
+ switch(mTestType) {
+ case DISMISS_ALARM:
+ intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
+ intent.putExtra(AlarmClock.EXTRA_ALARM_SEARCH_MODE,
+ AlarmClock.ALARM_SEARCH_MODE_NEXT);
+ break;
+
+ case SET_ALARM_FOR_DISMISSAL:
+ case SET_ALARM:
+ intent = new Intent(AlarmClock.ACTION_SET_ALARM);
+ intent.putExtra(AlarmClock.EXTRA_HOUR, 14);
+ break;
+
+ case SNOOZE_ALARM:
+ intent = new Intent(AlarmClock.ACTION_SNOOZE_ALARM);
+ break;
+
+ default:
+ Log.e(TAG, "Unexpected value");
+ return;
+ }
+ Log.i(TAG, "starting_voiceactivity: " + intent.toString());
+ startVoiceActivity(intent);
+ }
+
+ @Override
+ public void onTaskFinished(Intent intent, int taskId) {
+ // extras contain the info on what the activity started above did.
+ // we probably could verify this also.
+ Bundle extras = intent.getExtras();
+ Log.i(TAG, "in onTaskFinished: testcasetype = " + mTestType + ", intent: " +
+ intent.toString() + Utils.toBundleString(extras));
+ Intent broadcastIntent = new Intent(Utils.BROADCAST_INTENT + mTestType.toString());
+ broadcastIntent.putExtra(Utils.TEST_RESULT, mTestResult);
+ broadcastIntent.putExtra(Utils.TESTCASE_TYPE, mTestType.toString());
+ Log.i(TAG, "sending_broadcast for testcase+type = " +
+ broadcastIntent.getStringExtra(Utils.TESTCASE_TYPE) +
+ ", test_result = " + broadcastIntent.getStringExtra(Utils.TEST_RESULT));
+ mContext.sendBroadcast(broadcastIntent);
+ }
+
+ synchronized MyTask newTask() {
+ MyTask t = new MyTask();
+ mUsedTasks.add(t);
+ return t;
+ }
+
+ @Override
+ public void onRequestCompleteVoice(CompleteVoiceRequest request) {
+ mTestResult = Utils.COMPLETION_RESULT;
+ CharSequence prompt = request.getVoicePrompt().getVoicePromptAt(0);
+ Log.i(TAG, "in Session testcasetype = " + mTestType +
+ ", onRequestCompleteVoice recvd. message = " + prompt);
+ AsyncTaskArg asyncTaskArg = new AsyncTaskArg().setRequest(request).setCompleteReq(true);
+ newTask().execute(asyncTaskArg);
+ }
+
+ @Override
+ public void onRequestAbortVoice(AbortVoiceRequest request) {
+ mTestResult = Utils.ABORT_RESULT;
+ AsyncTaskArg asyncTaskArg = new AsyncTaskArg().setRequest(request).setCompleteReq(false);
+ Log.i(TAG, "in Session sending sendAbortResult for testcasetype = " + mTestType);
+ newTask().execute(asyncTaskArg);
+ }
+
+ private class AsyncTaskArg {
+ CompleteVoiceRequest mCompReq;
+ AbortVoiceRequest mAbortReq;
+ boolean isCompleteRequest = true;
+
+ AsyncTaskArg setRequest(CompleteVoiceRequest r) {
+ mCompReq = r;
+ return this;
+ }
+
+ AsyncTaskArg setRequest(AbortVoiceRequest r) {
+ mAbortReq = r;
+ return this;
+ }
+
+ AsyncTaskArg setCompleteReq(boolean flag) {
+ isCompleteRequest = flag;
+ return this;
+ }
+ }
+
+ private class MyTask extends AsyncTask<AsyncTaskArg, Void, Void> {
+ @Override
+ protected Void doInBackground(AsyncTaskArg... params) {
+ AsyncTaskArg arg = params[0];
+ Log.i(TAG, "in MyTask - doInBackground: testType = " +
+ MainInteractionSession.this.mTestType);
+ if (arg.isCompleteRequest) {
+ arg.mCompReq.sendCompleteResult(new Bundle());
+ } else {
+ arg.mAbortReq.sendAbortResult(new Bundle());
+ }
+ return null;
+ }
+ }
+}
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSessionService.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSessionService.java
new file mode 100644
index 0000000..a83c115
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainInteractionSessionService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.os.Bundle;
+import android.service.voice.VoiceInteractionSession;
+import android.service.voice.VoiceInteractionSessionService;
+
+public class MainInteractionSessionService extends VoiceInteractionSessionService {
+ @Override
+ public VoiceInteractionSession onNewSession(Bundle args) {
+ return new MainInteractionSession(this);
+ }
+}
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/MainRecognitionService.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainRecognitionService.java
new file mode 100644
index 0000000..15a32d4
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/MainRecognitionService.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.content.Intent;
+import android.speech.RecognitionService;
+import android.util.Log;
+
+/**
+ * Stub recognition service needed to be a complete voice interactor.
+ */
+public class MainRecognitionService extends RecognitionService {
+ private static final String TAG = "MainRecognitionService";
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ Log.i(TAG, "onCreate");
+ }
+
+ @Override
+ protected void onStartListening(Intent recognizerIntent, Callback listener) {
+ Log.i(TAG, "onStartListening");
+ }
+
+ @Override
+ protected void onCancel(Callback listener) {
+ Log.i(TAG, "onCancel");
+ }
+
+ @Override
+ protected void onStopListening(Callback listener) {
+ Log.i(TAG, "onStopListening");
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log.i(TAG, "onDestroy");
+ }
+}
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/SettingsActivity.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/SettingsActivity.java
new file mode 100644
index 0000000..0c4d289
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/SettingsActivity.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Stub activity to test out settings selection for voice interactor.
+ */
+public class SettingsActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+}
diff --git a/tests/tests/alarmclock/service/src/android/alarmclock/service/VoiceInteractionMain.java b/tests/tests/alarmclock/service/src/android/alarmclock/service/VoiceInteractionMain.java
new file mode 100644
index 0000000..c1f23a0
--- /dev/null
+++ b/tests/tests/alarmclock/service/src/android/alarmclock/service/VoiceInteractionMain.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.service;
+
+import android.alarmclock.common.Utils;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.os.Bundle;
+import android.util.Log;
+
+public class VoiceInteractionMain extends Activity {
+ static final String TAG = "VoiceInteractionMain";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Intent intent = new Intent();
+ String testCaseType = getIntent().getStringExtra(Utils.TESTCASE_TYPE);
+ Log.i(TAG, "received_testcasetype = " + testCaseType);
+ intent.putExtra(Utils.TESTCASE_TYPE, testCaseType);
+ intent.setComponent(new ComponentName(this, MainInteractionService.class));
+ ComponentName serviceName = startService(intent);
+ Log.i(TAG, "Started service: " + serviceName);
+ }
+}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockIntentsTest.java b/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockIntentsTest.java
deleted file mode 100644
index 33ac546..0000000
--- a/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockIntentsTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.alarmclock.cts;
-
-import android.app.AlarmManager;
-import android.app.AlarmManager.AlarmClockInfo;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.provider.AlarmClock;
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
-
-import java.util.Calendar;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class AlarmClockIntentsTest extends ActivityInstrumentationTestCase2<TestActivity> {
- static final String TAG = "AlarmClockIntentsTest";
- static final int ALARM_TEST_WINDOW_MINS = 2;
- private static final int TIMEOUT_MS = 20 * 1000;
-
- private TestActivity mActivity;
- private AlarmManager mAlarmManager;
- private NextAlarmReceiver mReceiver = new NextAlarmReceiver();
- private final CountDownLatch mLatch = new CountDownLatch(1);
- private Context mContext;
-
- public AlarmClockIntentsTest() {
- super(TestActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mContext = getInstrumentation().getTargetContext();
- mActivity = getActivity();
- mAlarmManager = (AlarmManager) mActivity.getSystemService(Context.ALARM_SERVICE);
- IntentFilter filter = new IntentFilter(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
- filter.addAction(AlarmClock.ACTION_SET_ALARM);
- mContext.registerReceiver(mReceiver, filter);
- }
-
- @Override
- protected void tearDown() throws Exception {
- mContext.unregisterReceiver(mReceiver);
- super.tearDown();
- }
-
- public void testSetAlarm() throws Exception {
- // set an alarm for ALARM_TEST_WINDOW millisec from now.
- // Assume the next alarm is NOT within the next ALARM_TEST_WINDOW millisec
- // TODO: fix this assumption
- AlarmTime expected = getAlarmTime();
-
- // set the alarm
- assertNotNull(mActivity);
- assertTrue(mActivity.setAlarm(expected));
-
- // wait for the alarm to be set
- if (!mLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
- fail("Failed to receive broadcast in " + (TIMEOUT_MS / 1000) + "sec");
- }
-
- // verify the next alarm
- assertTrue(isNextAlarmSameAs(expected));
- }
-
- public void testDismissAlarm() throws Exception {
- assertTrue(mActivity.cancelAlarm(getAlarmTime()));
- }
-
- public void testSnoozeAlarm() throws Exception {
- assertTrue(mActivity.snoozeAlarm());
- }
-
- private AlarmTime getAlarmTime() {
- Calendar now = Calendar.getInstance();
- now.add(Calendar.MINUTE, ALARM_TEST_WINDOW_MINS);
- long nextAlarmTime = now.getTimeInMillis();
- return new AlarmTime(nextAlarmTime);
- }
-
- private boolean isNextAlarmSameAs(AlarmTime expected) {
- AlarmClockInfo alarmInfo = mAlarmManager.getNextAlarmClock();
- if (alarmInfo == null) {
- return false;
- }
- AlarmTime next = new AlarmTime(alarmInfo.getTriggerTime());
- if (expected.mIsPm != next.mIsPm ||
- expected.mHour != next.mHour ||
- expected.mMinute != next.mMinute) {
- Log.i(TAG, "Next Alarm time is not same expected time: " +
- "next = " + next + ", expected = " + expected);
- return false;
- }
- return true;
- }
-
- class NextAlarmReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
- Log.i(TAG, "received broadcast");
- mLatch.countDown();
- }
- }
- }
-
- static class AlarmTime {
- int mHour;
- int mMinute;
- boolean mIsPm;
-
- AlarmTime(long l) {
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(l);
- mHour = cal.get(Calendar.HOUR);
- mMinute = cal.get(Calendar.MINUTE);
- mIsPm = cal.get(Calendar.AM_PM) == 1;
- Log.i(TAG, "Calendar converted is: " + cal);
- }
-
- AlarmTime(int hour, int minute, boolean isPM) {
- mHour = hour;
- mMinute = minute;
- mIsPm = isPM;
- }
-
- @Override
- public String toString() {
- String isPmString = (mIsPm) ? "pm" : "am";
- return mHour + ":" + mMinute + isPmString;
- }
- }
-}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java b/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java
new file mode 100644
index 0000000..0089e69
--- /dev/null
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/AlarmClockTestBase.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.cts;
+
+import android.alarmclock.common.Utils;
+import android.alarmclock.common.Utils.TestcaseType;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class AlarmClockTestBase extends ActivityInstrumentationTestCase2<TestStartActivity> {
+ static final String TAG = "AlarmClockTestBase";
+ protected static final int TIMEOUT_MS = 20 * 1000;
+
+ private Context mContext;
+ private String mTestResult;
+ private CountDownLatch mLatch;
+ private ActivityDoneReceiver mActivityDoneReceiver = null;
+ private TestStartActivity mActivity;
+ private TestcaseType mTestCaseType;
+
+ public AlarmClockTestBase() {
+ super(TestStartActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContext = getInstrumentation().getTargetContext();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mContext.unregisterReceiver(mActivityDoneReceiver);
+ super.tearDown();
+ }
+
+ private void registerBroadcastReceiver(TestcaseType testCaseType) throws Exception {
+ mTestCaseType = testCaseType;
+ mLatch = new CountDownLatch(1);
+ if (mActivityDoneReceiver != null) {
+ mContext.unregisterReceiver(mActivityDoneReceiver);
+ }
+ mActivityDoneReceiver = new ActivityDoneReceiver();
+ mContext.registerReceiver(mActivityDoneReceiver,
+ new IntentFilter(Utils.BROADCAST_INTENT + testCaseType.toString()));
+ }
+
+ protected String runTest(TestcaseType testCaseType) throws Exception {
+ Log.i(TAG, "Begin Testing: " + testCaseType);
+ if (!startTestActivity(testCaseType)) {
+ fail("test activity start failed for testcase = " + testCaseType);
+ return "";
+ }
+
+ registerBroadcastReceiver(testCaseType);
+ mActivity.startTest(testCaseType.toString());
+ if (!mLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
+ fail("Failed to receive broadcast in " + TIMEOUT_MS + "msec");
+ return "";
+ }
+ return mTestResult;
+ }
+
+ private boolean startTestActivity(TestcaseType testCaseType) {
+ Log.i(TAG, "Starting test activity for test: " + testCaseType);
+ Intent intent = new Intent();
+ intent.setAction("android.intent.action.TEST_START_ACTIVITY_" + testCaseType.toString());
+ intent.setComponent(new ComponentName(getInstrumentation().getContext(),
+ TestStartActivity.class));
+ setActivityIntent(intent);
+ mActivity = getActivity();
+ return mActivity != null;
+ }
+
+ class ActivityDoneReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(
+ Utils.BROADCAST_INTENT + AlarmClockTestBase.this.mTestCaseType.toString())) {
+ AlarmClockTestBase.this.mTestResult = intent.getStringExtra(Utils.TEST_RESULT);
+ Log.i(TAG, "received_broadcast for testcase_type = " +
+ Utils.BROADCAST_INTENT + AlarmClockTestBase.this.mTestCaseType +
+ ", test_result = " + AlarmClockTestBase.this.mTestResult);
+ mLatch.countDown();
+ }
+ }
+ }
+}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/DismissAlarmTest.java b/tests/tests/alarmclock/src/android/alarmclock/cts/DismissAlarmTest.java
new file mode 100644
index 0000000..64ecf86
--- /dev/null
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/DismissAlarmTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.cts;
+
+import android.alarmclock.common.Utils;
+import android.alarmclock.common.Utils.TestcaseType;
+
+public class DismissAlarmTest extends AlarmClockTestBase {
+ public DismissAlarmTest() {
+ super();
+ }
+
+ public void testAll() throws Exception {
+ assertEquals(Utils.COMPLETION_RESULT, runTest(TestcaseType.SET_ALARM_FOR_DISMISSAL));
+ assertEquals(Utils.COMPLETION_RESULT, runTest(TestcaseType.DISMISS_ALARM));
+ }
+}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/SetAlarmTest.java b/tests/tests/alarmclock/src/android/alarmclock/cts/SetAlarmTest.java
new file mode 100644
index 0000000..a95a1dd
--- /dev/null
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/SetAlarmTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.cts;
+
+import android.alarmclock.common.Utils;
+import android.alarmclock.common.Utils.TestcaseType;
+
+public class SetAlarmTest extends AlarmClockTestBase {
+ public SetAlarmTest() {
+ super();
+ }
+
+ public void testAll() throws Exception {
+ assertEquals(Utils.COMPLETION_RESULT, runTest(TestcaseType.SET_ALARM));
+ }
+}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/SnoozeAlarmTest.java b/tests/tests/alarmclock/src/android/alarmclock/cts/SnoozeAlarmTest.java
new file mode 100644
index 0000000..b67a7cf
--- /dev/null
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/SnoozeAlarmTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.cts;
+
+import android.alarmclock.common.Utils;
+import android.alarmclock.common.Utils.TestcaseType;
+
+public class SnoozeAlarmTest extends AlarmClockTestBase {
+ public SnoozeAlarmTest() {
+ super();
+ }
+
+ public void testAll() throws Exception {
+ String result = runTest(TestcaseType.SNOOZE_ALARM);
+ // Since there is no way to figure out if there is a currently-firing alarm,
+ // we should expect either of the 2 results:
+ // Utils.COMPLETION_RESULT
+ // Utils.ABORT_RESULT
+ // For CTS test purposes, all we can do is to know that snooze-alarm intent
+ // was picked up and processed by the voice_interaction_service and the associated app.
+ // The above call to runTest() would have failed the test otherwise.
+ assertTrue(result.equals(Utils.ABORT_RESULT) || result.equals(Utils.COMPLETION_RESULT));
+ }
+}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/TestActivity.java b/tests/tests/alarmclock/src/android/alarmclock/cts/TestActivity.java
deleted file mode 100644
index 9ec33ae..0000000
--- a/tests/tests/alarmclock/src/android/alarmclock/cts/TestActivity.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.alarmclock.cts;
-
-import android.app.Activity;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.os.Bundle;
-import android.provider.AlarmClock;
-import android.util.Log;
-
-import java.util.Calendar;
-
-public class TestActivity extends Activity {
- static final String TAG = "TestActivity";
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Log.i(TAG, " in onCreate");
- }
-
- private void setParams(int hour, int minute, boolean isPM, Intent intent) {
- intent.putExtra(AlarmClock.EXTRA_ALARM_SEARCH_MODE, AlarmClock.ALARM_SEARCH_MODE_TIME);
- intent.putExtra(AlarmClock.EXTRA_IS_PM, isPM);
- intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
- intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
- }
-
- private boolean start(Intent intent) {
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException e) {
- Log.wtf(TAG, e);
- return false;
- }
- return true;
- }
-
- public boolean cancelAlarm(AlarmClockIntentsTest.AlarmTime time) {
- Intent intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
- setParams(time.mHour, time.mMinute, time.mIsPm, intent);
- Log.i(TAG, "sending DISMISS_ALARM intent for: " + time + ", Intent = " + intent);
- return start(intent);
- }
-
- public boolean setAlarm(AlarmClockIntentsTest.AlarmTime time) {
- Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
- int hour = time.mHour;
- if (time.mIsPm) {
- hour += 12;
- }
- setParams(hour, time.mMinute, time.mIsPm, intent);
- Log.i(TAG, "Setting alarm: " + hour + ":" + time.mMinute + ", Intent = " + intent);
- return start(intent);
- }
-
- public boolean snoozeAlarm() {
- Intent intent = new Intent(AlarmClock.ACTION_SNOOZE_ALARM);
- Log.i(TAG, "sending SNOOZE_ALARM intent." + intent);
- return start(intent);
- }
-}
diff --git a/tests/tests/alarmclock/src/android/alarmclock/cts/TestStartActivity.java b/tests/tests/alarmclock/src/android/alarmclock/cts/TestStartActivity.java
new file mode 100644
index 0000000..1a3c4eb
--- /dev/null
+++ b/tests/tests/alarmclock/src/android/alarmclock/cts/TestStartActivity.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.alarmclock.cts;
+
+import android.alarmclock.common.Utils;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.os.Bundle;
+import android.util.Log;
+
+public class TestStartActivity extends Activity {
+ static final String TAG = "TestStartActivity";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.i(TAG, " in onCreate");
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Log.i(TAG, " in onResume");
+ }
+
+ void startTest(String testCaseType) {
+ Intent intent = new Intent();
+ Log.i(TAG, "received_testcasetype = " + testCaseType);
+ intent.putExtra(Utils.TESTCASE_TYPE, testCaseType);
+ intent.setAction("android.intent.action.VIMAIN_" + testCaseType);
+ intent.setComponent(new ComponentName("android.alarmclock.service",
+ "android.alarmclock.service.VoiceInteractionMain"));
+ startActivity(intent);
+ }
+
+ @Override
+ protected void onPause() {
+ Log.i(TAG, " in onPause");
+ super.onPause();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ Log.i(TAG, " in onStart");
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ Log.i(TAG, " in onRestart");
+ }
+
+ @Override
+ protected void onStop() {
+ Log.i(TAG, " in onStop");
+ super.onStop();
+ }
+
+ @Override
+ protected void onDestroy() {
+ Log.i(TAG, " in onDestroy");
+ super.onDestroy();
+ }
+}