summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2015-04-03 11:10:00 -0700
committerSantos Cordon <santoscordon@google.com>2015-04-08 11:01:31 -0700
commitcf08122bfb54b832e0ab8324032b5797e8cc83ba (patch)
treec2cc41e1030ac6914fd18c911a884b65ece015c9 /tests
parentf0d5024e1463d92854280de556aade0a74750431 (diff)
downloadandroid_packages_services_Telephony-cf08122bfb54b832e0ab8324032b5797e8cc83ba.tar.gz
android_packages_services_Telephony-cf08122bfb54b832e0ab8324032b5797e8cc83ba.tar.bz2
android_packages_services_Telephony-cf08122bfb54b832e0ab8324032b5797e8cc83ba.zip
Add test activity to run SIM Activation.
Change-Id: I0c387dbdc461ae2ddd0e9a25010c925a0c849df2
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidManifest.xml3
-rw-r--r--tests/src/com/android/services/telephony/activation/ResponseReceiver.java65
-rw-r--r--tests/src/com/android/services/telephony/activation/SimActivationTest.java73
3 files changed, 141 insertions, 0 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index af3f7e430..890056883 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PERFORM_CDMA_PROVISIONING" />
+ <uses-permission android:name="android.permission.PERFORM_SIM_ACTIVATION" />
<application android:label="@string/app_name">
<uses-library android:name="android.test.runner" />
@@ -56,6 +57,8 @@
<data android:scheme="smsto" />
</intent-filter>
</service>
+
+ <receiver android:name="com.android.services.telephony.activation.ResponseReceiver" />
</application>
<!--
diff --git a/tests/src/com/android/services/telephony/activation/ResponseReceiver.java b/tests/src/com/android/services/telephony/activation/ResponseReceiver.java
new file mode 100644
index 000000000..33e7f0005
--- /dev/null
+++ b/tests/src/com/android/services/telephony/activation/ResponseReceiver.java
@@ -0,0 +1,65 @@
+/*
+ * 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 com.android.services.telephony.activation;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+import com.android.services.telephony.Log;
+
+public class ResponseReceiver extends BroadcastReceiver {
+ volatile public static boolean responseReceived = false;
+ public static final String ACTION_ACTIVATION_RESPONSE =
+ "com.android.services.telephony.ACTIVATION_RESPONSE";
+
+ private final Object mLock;
+ private Context mContext;
+
+ ResponseReceiver(Object lock) {
+ mLock = lock;
+ }
+
+ /** ${inheritDoc} */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!ACTION_ACTIVATION_RESPONSE.equals(intent.getAction())) {
+ Log.e(this, null, "Unexpected intent: " + intent.getAction());
+ return;
+ }
+
+ responseReceived = true;
+ Log.i(this, "received intent");
+
+ if (mLock != null) {
+ synchronized(mLock) {
+ Log.i(this, "notifying");
+ mLock.notify();
+ }
+ }
+ }
+
+ void register(Context context) {
+ context.registerReceiver(this, new IntentFilter(ACTION_ACTIVATION_RESPONSE));
+ mContext = context;
+ }
+
+ void unregister() {
+ mContext.unregisterReceiver(this);
+ }
+}
diff --git a/tests/src/com/android/services/telephony/activation/SimActivationTest.java b/tests/src/com/android/services/telephony/activation/SimActivationTest.java
new file mode 100644
index 000000000..f6060dc64
--- /dev/null
+++ b/tests/src/com/android/services/telephony/activation/SimActivationTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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 com.android.services.telephony.activation;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.services.telephony.Log;
+
+public class SimActivationTest extends AndroidTestCase {
+
+ private static Object mActivationLock = new Object();
+ private ResponseReceiver mResponseReceiver;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mResponseReceiver = new ResponseReceiver(mActivationLock);
+ mResponseReceiver.register(context());
+ }
+
+ /** ${inheritDoc} */
+ @Override
+ protected void tearDown() throws Exception {
+ mResponseReceiver.unregister();
+ super.tearDown();
+ }
+
+ @SmallTest
+ public void testSimActivationResponse() throws Exception {
+ Log.i(this, "Running activation test");
+
+ Intent responseIntent = new Intent(ResponseReceiver.ACTION_ACTIVATION_RESPONSE);
+ responseIntent.setPackage(context().getPackageName());
+ PendingIntent pendingResponse = PendingIntent.getBroadcast(
+ context(), 0, responseIntent, 0);
+
+ Intent intent = new Intent(Intent.ACTION_SIM_ACTIVATION_REQUEST);
+ intent.putExtra(Intent.EXTRA_SIM_ACTIVATION_RESPONSE, pendingResponse);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ Log.i(this, "sent intent");
+ context().startActivity(intent);
+ synchronized (mActivationLock) {
+ Log.i(this, "waiting ");
+ mActivationLock.wait(5000);
+ Log.i(this, "unwaiting");
+ }
+ assertTrue(ResponseReceiver.responseReceived);
+ }
+
+ private Context context() {
+ return getContext();
+ }
+}