Adding telecom test directory.
Adds a notification-based test CallService + first do-nothing unit-test.
Change-Id: Ifa2725da44305024adced42154d6b458767bd5d0
diff --git a/tests/Android.mk b/tests/Android.mk
new file mode 100644
index 0000000..23b6950
--- /dev/null
+++ b/tests/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2013 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)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_PACKAGE_NAME := TelecommTests
+LOCAL_CERTIFICATE := platform
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_INSTRUMENTATION_FOR := Telecomm
+
+include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
new file mode 100644
index 0000000..5ad1cae
--- /dev/null
+++ b/tests/AndroidManifest.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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="com.android.telecomm.tests">
+ <application android:label="@string/app_name">
+ <uses-library android:name="android.test.runner" />
+
+ <!-- Miscellaneous telecomm app-related test activities. -->
+
+ <service android:name="com.android.telecomm.testcallservice.TestCallServiceProvider">
+ <intent-filter>
+ <action android:name="android.telecomm.ICallServiceProvider" />
+ </intent-filter>
+ </service>
+
+ <activity android:name="com.android.telecomm.testcallservice.TestCallActivity"
+ android:label="@string/testCallActivityLabel">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <receiver android:name="com.android.telecomm.testcallservice.CallNotificationReceiver"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="com.android.telecomm.testcallservice.ACTION_CALL_SERVICE_EXIT"
+ />
+ </intent-filter>
+ </receiver>
+
+ </application>
+
+ <!--
+ The prefered way is to use 'runtest':
+ runtest telecomm-unit
+
+ runtest is a wrapper around 'adb shell'. The low level shell command is:
+ adb shell am instrument -w com.android.telecomm.tests/android.test.InstrumentationTestRunner
+
+ To run a single test case:
+ adb shell am instrument -w com.android.telecomm.tests/android.test.InstrumentationTestRunner
+ -e com.android.telecomm.tests.unit.FooUnitTest
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.telecomm"
+ android:label="Telecomm application tests." />
+</manifest>
diff --git a/tests/res/values/donottranslate_strings.xml b/tests/res/values/donottranslate_strings.xml
new file mode 100644
index 0000000..6e4788f
--- /dev/null
+++ b/tests/res/values/donottranslate_strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<resources>
+ <!-- Application label -->
+ <string name="app_name">TelecommTests</string>
+
+ <!-- String for the TestCallActivity -->
+ <string name="testCallActivityLabel">Test CallService App</string>
+</resources>
diff --git a/tests/src/com/android/telecomm/testcallservice/CallNotificationReceiver.java b/tests/src/com/android/telecomm/testcallservice/CallNotificationReceiver.java
new file mode 100644
index 0000000..8ad4118
--- /dev/null
+++ b/tests/src/com/android/telecomm/testcallservice/CallNotificationReceiver.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.testcallservice;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * This class receives the notification callback intents used to update call states for
+ * {@link TestCallService}.
+ */
+public class CallNotificationReceiver extends BroadcastReceiver {
+
+ /**
+ * Main intent action is sent when the user clicks the main portion of the TestCallService
+ * notification. No-op at the time of this writing.
+ */
+ /* package */ static final String ACTION_CALL_SERVICE_MAIN =
+ "com.android.telecomm.testcallservice.ACTION_CALL_SERVICE_MAIN";
+
+ /**
+ * Exit intent action is sent when the user clicks the "exit" action of the TestCallService
+ * notification. Used to cancel (remove) the notification.
+ */
+ /* package */ static final String ACTION_CALL_SERVICE_EXIT =
+ "com.android.telecomm.testcallservice.ACTION_CALL_SERVICE_EXIT";
+
+ /** {@inheritDoc} */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (ACTION_CALL_SERVICE_EXIT.equals(action)) {
+ CallServiceNotifier.getInstance().cancelNotification(context);
+ }
+ }
+}
diff --git a/tests/src/com/android/telecomm/testcallservice/CallServiceNotifier.java b/tests/src/com/android/telecomm/testcallservice/CallServiceNotifier.java
new file mode 100644
index 0000000..f92d1f2
--- /dev/null
+++ b/tests/src/com/android/telecomm/testcallservice/CallServiceNotifier.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.testcallservice;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+/**
+ * Class used to create, update and cancel the notification used to display and update call state for
+ * {@link TestCallService}.
+ */
+public class CallServiceNotifier {
+ private static final String TAG = CallServiceNotifier.class.getSimpleName();
+
+ private static final CallServiceNotifier INSTANCE = new CallServiceNotifier();
+
+ /**
+ * Static notification id.
+ */
+ private static final int CALL_NOTIFICATION_ID = 1;
+
+ /**
+ * Application context for getting Notification Manager.
+ */
+ private Context mContext;
+
+ /**
+ * Singleton accessor.
+ */
+ public static CallServiceNotifier getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Creates a CallService & initializes notification manager.
+ */
+ private CallServiceNotifier() {
+ }
+
+ /**
+ * Updates the notification in the notification pane.
+ */
+ public void updateNotification(Context context) {
+ Log.i("CallServiceNotifier", "adding the notification ------------");
+ getNotificationManager(context).notify(CALL_NOTIFICATION_ID, getNotification(context));
+ }
+
+ /**
+ * Cancels the notification.
+ */
+ public void cancelNotification(Context context) {
+ Log.i(TAG, "canceling notification");
+ getNotificationManager(context).cancel(CALL_NOTIFICATION_ID);
+ }
+
+ /**
+ * Returns the system's notification manager needed to add/remove notifications.
+ */
+ private NotificationManager getNotificationManager(Context context) {
+ return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+
+ /**
+ * Creates a notification object out of the current calls state.
+ */
+ private Notification getNotification(Context context) {
+ final Notification.Builder builder = new Notification.Builder(context);
+ builder.setOngoing(true);
+ builder.setPriority(Notification.PRIORITY_HIGH);
+
+ final PendingIntent intent = createMainIntent(context);
+ builder.setContentIntent(intent);
+
+ builder.setSmallIcon(android.R.drawable.stat_sys_phone_call);
+ builder.setContentText("Test calls via CallService API");
+ builder.setContentTitle("TestCallService");
+
+ addAddCallAction(builder, context);
+ addExitAction(builder, context);
+
+ return builder.build();
+ }
+
+ /**
+ * Creates the intent issued when the user clicks the notification.
+ */
+ private PendingIntent createMainIntent(Context context) {
+ final Intent intent = new Intent(CallNotificationReceiver.ACTION_CALL_SERVICE_MAIN, null,
+ context, CallNotificationReceiver.class);
+
+ return PendingIntent.getBroadcast(context, 0, intent, 0);
+ }
+
+ /**
+ * Creates the intent to remove the notification.
+ */
+ private PendingIntent createExitIntent(Context context) {
+ final Intent intent = new Intent(CallNotificationReceiver.ACTION_CALL_SERVICE_EXIT, null,
+ context, CallNotificationReceiver.class);
+
+ return PendingIntent.getBroadcast(context, 0, intent, 0);
+ }
+
+ /**
+ * Adds an action to the Notification Builder for adding a call through the CallService.
+ * @param builder The Notification Builder.
+ */
+ private void addAddCallAction(Notification.Builder builder, Context context) {
+ builder.addAction(0, "Add a Call", createMainIntent(context));
+ }
+
+ /**
+ * Adds an action to remove the notification.
+ */
+ private void addExitAction(Notification.Builder builder, Context context) {
+ builder.addAction(0, "Exit", createExitIntent(context));
+ }
+}
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallActivity.java b/tests/src/com/android/telecomm/testcallservice/TestCallActivity.java
new file mode 100644
index 0000000..5c483ef
--- /dev/null
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallActivity.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.testcallservice;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * This activity exists in order to add an icon to the launcher. This activity has no UI of its own
+ * and instead starts the notification for {@link TestCallService} via {@link CallServiceNotifier}.
+ * After triggering a notification update, this activity immediately finishes.
+ */
+public class TestCallActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ CallServiceNotifier.getInstance().updateNotification(this);
+ finish();
+ }
+}
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallService.java b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
new file mode 100644
index 0000000..69e0db0
--- /dev/null
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.testcallservice;
+
+import com.google.android.collect.Lists;
+
+import android.telecomm.CallService;
+import android.telecomm.ICallServiceAdapter;
+import android.util.Log;
+
+/**
+ * Service which provides fake calls to test the ICallService interface.
+ */
+public class TestCallService extends CallService {
+ /** Unique identifying tag used for logging. */
+ private static final String TAG = TestCallService.class.getSimpleName();
+
+ /** {@inheritDoc} */
+ @Override
+ public void setCallServiceAdapter(ICallServiceAdapter callServiceAdapter) {
+ Log.i(TAG, "setCallServiceAdapter()");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void isCompatibleWith(String handle) {
+ Log.i(TAG, "isCompatibleWith(" + handle + ")");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void call(String handle) {
+ Log.i(TAG, "call(" + handle + ")");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void disconnect(String callId) {
+ Log.i(TAG, "disconnect(" + callId + ")");
+ }
+}
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java b/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java
new file mode 100644
index 0000000..d48e759
--- /dev/null
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.testcallservice;
+
+import android.telecomm.CallServiceProvider;
+import android.telecomm.ICallServiceProviderAdapter;
+import android.util.Log;
+
+/**
+ * Service which provides fake calls to test the ICallService interface.
+ */
+public class TestCallServiceProvider extends CallServiceProvider {
+ /** Unique identifying tag used for logging. */
+ private static final String TAG = TestCallServiceProvider.class.getSimpleName();
+
+ /** {@inheritDoc} */
+ @Override
+ public void setCallServiceProviderAdapter(
+ ICallServiceProviderAdapter callServiceProviderAdapter) {
+ Log.i(TAG, "setCallServiceProviderAdapter(" + callServiceProviderAdapter + ")");
+ }
+}
diff --git a/tests/src/com/android/telecomm/tests/unit/ExampleTest.java b/tests/src/com/android/telecomm/tests/unit/ExampleTest.java
new file mode 100644
index 0000000..755267a
--- /dev/null
+++ b/tests/src/com/android/telecomm/tests/unit/ExampleTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 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 com.android.telecomm.tests.unit;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.telecomm.CallActivity;
+
+/**
+ * Unit tests for {@link CallActivity}.
+ */
+@SmallTest
+public class ExampleTest extends AndroidTestCase {
+
+ /**
+ * TODO(santoscordon): Remove once there are real tests which can be used as proper examples.
+ */
+ @SmallTest
+ public void testExample1() throws Exception {
+ CallActivity callActivity = new CallActivity();
+
+ assertNotNull(callActivity);
+ }
+}