Merge change 21813 into donut
* changes:
CTS: Fix console search for test packages
diff --git a/tests/tests/dpi/Android.mk b/tests/tests/dpi/Android.mk
new file mode 100644
index 0000000..e104290
--- /dev/null
+++ b/tests/tests/dpi/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2009 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_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsDpiTestCases
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/dpi/AndroidManifest.xml b/tests/tests/dpi/AndroidManifest.xml
new file mode 100644
index 0000000..7206d00
--- /dev/null
+++ b/tests/tests/dpi/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2009 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.cts.dpi">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.cts.dpi"
+ android:label="CTS tests for DPI"/>
+</manifest>
diff --git a/tests/tests/dpi/src/com/android/cts/dpi/ConfigurationTest.java b/tests/tests/dpi/src/com/android/cts/dpi/ConfigurationTest.java
new file mode 100644
index 0000000..e59b860
--- /dev/null
+++ b/tests/tests/dpi/src/com/android/cts/dpi/ConfigurationTest.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2009 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.dpi.cts;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.test.AndroidTestCase;
+import android.view.Display;
+import android.view.WindowManager;
+import android.util.DisplayMetrics;
+
+import java.lang.Integer;
+import java.util.EnumSet;
+
+/**
+ * This is verifyin that the device under test is running a supported
+ * resolution, and is being classified as the right Screen Layout
+ * Size.
+ */
+public class ConfigurationTest extends AndroidTestCase {
+
+ private enum Density {
+ // It is important to keep these sorted
+ INVALID_LOW(Integer.MIN_VALUE, 99),
+ LOW (100, 140),
+ MEDIUM (141, 190),
+ HIGH (191, 250),
+ INVALID_HIGH(251, Integer.MAX_VALUE);
+
+ private int low;
+ private int high;
+
+ Density(int low, int high) {
+ this.low = low;
+ this.high = high;
+ }
+
+ public static Density findDensity(int value) {
+ Density density = INVALID_LOW;
+ for (Density d : EnumSet.range(Density.INVALID_LOW, Density.INVALID_HIGH)) {
+ if (value >= d.low && value <= d.high) {
+ density = d;
+ break;
+ }
+ }
+ return density;
+ }
+ };
+
+ /**
+ * Holds information on the current active screen's configuration.
+ */
+ private static class ActiveScreenConfiguration {
+ private final int width;
+ private final int height;
+ private final Density density;
+
+ /**
+ * Create a new ActiveScreenConfiguration.
+ *
+ * @param width the width of the screen
+ * @param height the height of the screen
+ * @param density the scaling factor for DIP from standard
+ * density (160.0)
+ */
+ public ActiveScreenConfiguration(int width,
+ int height,
+ float density) {
+ // 160 DIP is the "standard" density
+ this(width, height, Density.findDensity((int) (160.0f * density)));
+ }
+
+ protected ActiveScreenConfiguration(int width,
+ int height,
+ Density density) {
+ this.width = width;
+ this.height = height;
+ this.density = density;
+ }
+
+ public Density getDensity() {
+ return density;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+ }
+
+ private static class ScreenConfiguration extends ActiveScreenConfiguration {
+ private final int screenLayout;
+ private final boolean isWide;
+
+ public ScreenConfiguration(int width,
+ int height,
+ Density density,
+ int screenLayout,
+ boolean isWide) {
+ super(width, height, density);
+ this.screenLayout = screenLayout;
+ this.isWide = isWide;
+ }
+
+ public ScreenConfiguration(int width,
+ int height,
+ Density density,
+ int screenLayout) {
+ this(width, height, density, screenLayout, false);
+ }
+
+ public int getScreenLayout() {
+ return screenLayout;
+ }
+
+ public boolean isWide() {
+ return isWide;
+ }
+ };
+
+ private static boolean areConfigsEqual(ActiveScreenConfiguration active,
+ ScreenConfiguration screenConfig) {
+ if (screenConfig.isWide()) {
+ // For widescreen configs, the height is fixed but the
+ // width only specifies a minimum. But since the device
+ // can be both landscape and portrait, we have to search
+ // for which way it is.
+ if (active.getHeight() == screenConfig.getHeight()) {
+ // active height matches config height. Make sure
+ // that the active width is at least the config width.
+ return active.getWidth() >= screenConfig.getWidth();
+ } else if (active.getWidth() == screenConfig.getHeight()) {
+ // directions are swapped
+ return active.getHeight() >= screenConfig.getWidth();
+ } else {
+ return false;
+ }
+ } else {
+ if (active.getWidth() == screenConfig.getWidth() &&
+ active.getHeight() == screenConfig.getHeight() &&
+ active.getDensity().equals(screenConfig.getDensity())) {
+ return true;
+ }
+ // It is also possible that the device is in landscape
+ // mode, which flips the active w/h.
+ if (active.getHeight() == screenConfig.getWidth() &&
+ active.getWidth() == screenConfig.getHeight() &&
+ active.getDensity().equals(screenConfig.getDensity())) {
+ return true;
+ }
+ // nope.
+ return false;
+ }
+ }
+
+ /**
+ * Here's the current configuration table:
+ *
+ * Resoluion | Density | Size
+ * QVGA | low (100-140) | small
+ * WQVGA | low (100-140) | normal
+ * HVGA | medium (141-190) | normal
+ * WVGA | high (191-250) | normal
+ * FWVGA | high (191-250) | normal
+
+ * VGA | medium (141-190) | large
+ * WVGA | medium (141-190) | large
+ * FWVGA | medium (141-190) | large
+ *
+ * Any changes to allow additional resolutions will need to update this table
+ */
+
+ private static final ScreenConfiguration[] SUPPORTED_SCREEN_CONFIGS = {
+ // QVGA | low (100-140) | small
+ new ScreenConfiguration(240, 320, Density.LOW, Configuration.SCREENLAYOUT_SIZE_SMALL),
+ // WQVGA | low (100-140) | normal
+ new ScreenConfiguration(240, 320, Density.LOW, Configuration.SCREENLAYOUT_SIZE_SMALL, true),
+ // HVGA | medium (141-190) | normal
+ new ScreenConfiguration(480, 320, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_NORMAL),
+ new ScreenConfiguration(640, 240, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_NORMAL),
+ // WVGA | high (191-250) | normal
+ new ScreenConfiguration(640, 480, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_NORMAL, true),
+ // FWVGA | high (191-250) | normal
+ new ScreenConfiguration(864, 480, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_NORMAL),
+
+ // VGA | medium (141-190) | large
+ new ScreenConfiguration(640, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE),
+ // WVGA | medium (141-190) | large
+ new ScreenConfiguration(640, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE, true),
+ // FWVGA | medium (141-190) | large
+ new ScreenConfiguration(864, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE),
+
+ };
+
+ private ActiveScreenConfiguration getCurrentScreenConfig() {
+ WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ DisplayMetrics dm = new DisplayMetrics();
+ display.getMetrics(dm);
+ return new ActiveScreenConfiguration(display.getWidth(),
+ display.getHeight(),
+ dm.density);
+ }
+
+ /**
+ * Get the current screen configuration, make sure it is a
+ * supported screen configuration and that the screenlayout size
+ * is being set correctly according to the compatibility
+ * definition.
+ */
+ public void testScreenLayoutSize() {
+ ActiveScreenConfiguration currentScreenConfig = getCurrentScreenConfig();
+ // Make sure we have a valid density for the current screent.
+ assertFalse(Density.INVALID_LOW.equals(currentScreenConfig.getDensity()));
+ assertFalse(Density.INVALID_HIGH.equals(currentScreenConfig.getDensity()));
+
+ // Look up the ScreenConfig in the supported table and make
+ // sure we find a match.
+ for (ScreenConfiguration screenConfig: SUPPORTED_SCREEN_CONFIGS) {
+ if (areConfigsEqual(currentScreenConfig, screenConfig)) {
+ Configuration config = getContext().getResources().getConfiguration();
+ int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
+ if (screenConfig.getScreenLayout() == size) {
+ // we have a match, this is a supported device.
+ return;
+ }
+ }
+ }
+ fail("Current screen configuration is not supported.");
+ }
+}
diff --git a/tests/tests/permission2/src/android/permission2/cts/NoReceiveGsmSmsPermissionTest.java b/tests/tests/permission2/src/android/permission2/cts/NoReceiveGsmSmsPermissionTest.java
new file mode 100644
index 0000000..9b20d1d
--- /dev/null
+++ b/tests/tests/permission2/src/android/permission2/cts/NoReceiveGsmSmsPermissionTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009 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.permission2.cts;
+
+import android.app.PendingIntent;
+import android.telephony.gsm.SmsManager;
+
+/**
+ * Verify Sms and Mms cannot be received without required permissions.
+ * Uses {@link android.telephony.gsm.SmsManager}.
+ */
+@SuppressWarnings("deprecation")
+public class NoReceiveGsmSmsPermissionTest extends NoReceiveSmsPermissionTest {
+
+ protected void sendSms(PendingIntent sentIntent, PendingIntent deliveryIntent,
+ String currentNumber) {
+ SmsManager.getDefault().sendTextMessage(currentNumber, null, "test message",
+ sentIntent, deliveryIntent);
+ }
+}
diff --git a/tests/tests/permission2/src/android/permission2/cts/NoReceiveSmsPermissionTest.java b/tests/tests/permission2/src/android/permission2/cts/NoReceiveSmsPermissionTest.java
index d8eca3b..7b14db7 100755
--- a/tests/tests/permission2/src/android/permission2/cts/NoReceiveSmsPermissionTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/NoReceiveSmsPermissionTest.java
@@ -22,13 +22,14 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.telephony.gsm.SmsManager;
+import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
import android.util.Log;
/**
* Verify Sms and Mms cannot be received without required permissions.
+ * Uses {@link android.telephony.SmsManager}.
*/
public class NoReceiveSmsPermissionTest extends AndroidTestCase {
@@ -86,9 +87,13 @@
// get current phone number
String currentNumber = telephony.getLine1Number();
Log.i(LOG_TAG, String.format("Sending SMS to self: %s", currentNumber));
- // TODO: change this to use android.telephony.SmsManager once its made public
- SmsManager.getDefault().sendTextMessage(currentNumber, null, "test message",
- sentIntent, deliveryIntent);
+ sendSms(currentNumber, "test message", sentIntent, deliveryIntent);
+ }
+
+ protected void sendSms(String currentNumber, String text, PendingIntent sentIntent,
+ PendingIntent deliveryIntent) {
+ SmsManager.getDefault().sendTextMessage(currentNumber, null, text, sentIntent,
+ deliveryIntent);
}
/**
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
new file mode 100644
index 0000000..889b114
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2009 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.telephony.cts;
+
+import java.util.ArrayList;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.telephony.TelephonyManager;
+import android.telephony.SmsManager;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+/**
+ * Tests for {@link android.telephony.SmsManager}.
+ *
+ * Structured so tests can be reused to test {@link android.telephony.gsm.SmsManager}
+ */
+@TestTargetClass(SmsManager.class)
+public class SmsManagerTest extends AndroidTestCase {
+
+ private static final int NUM_TEXT_PARTS = 3;
+ private static final String LONG_TEXT =
+ "This is a very long text. This text should be broken into three " +
+ "separate messages.This is a very long text. This text should be broken into " +
+ "three separate messages.This is a very long text. This text should be broken " +
+ "into three separate messages.This is a very long text. This text should be " +
+ "broken into three separate messages.";;
+
+ private static final String SMS_SEND_ACTION = "CTS_SMS_SEND_ACTION";
+ private static final String SMS_DELIVERY_ACTION = "CTS_SMS_DELIVERY_ACTION";
+
+ private String mDestAddr;
+ private String mText;
+ private SmsBroadcastReceiver mSendReceiver;
+ private SmsBroadcastReceiver mDeliveryReceiver;
+ private PendingIntent mSentIntent;
+ private PendingIntent mDeliveredIntent;
+ private Intent mSendIntent;
+ private Intent mDeliveryIntent;
+
+ private static final int TIME_OUT = 1000 * 60 * 4;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ TelephonyManager tm =
+ (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
+ mDestAddr = tm.getLine1Number();
+ mText = "This is a test message";
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "divideMessage",
+ args = {String.class}
+ )
+ public void testDivideMessage() {
+ ArrayList<String> dividedMessages = divideMessage(LONG_TEXT);
+ assertNotNull(dividedMessages);
+ assertEquals(NUM_TEXT_PARTS, dividedMessages.size());
+ assertEquals(LONG_TEXT,
+ dividedMessages.get(0) + dividedMessages.get(1) + dividedMessages.get(2));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "sendDataMessage",
+ args = {String.class, String.class, short.class, byte[].class,
+ PendingIntent.class, PendingIntent.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "sendTextMessage",
+ args = {String.class, String.class, String.class, PendingIntent.class,
+ PendingIntent.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "sendMultipartTextMessage",
+ args = {String.class, String.class, ArrayList.class, ArrayList.class, ArrayList.class}
+ )
+ })
+ public void testSendMessages() throws InterruptedException {
+
+ mSendIntent = new Intent(SMS_SEND_ACTION);
+ mDeliveryIntent = new Intent(SMS_DELIVERY_ACTION);
+
+ IntentFilter sendIntentFilter = new IntentFilter(SMS_SEND_ACTION);
+ IntentFilter deliveryIntentFilter = new IntentFilter(SMS_DELIVERY_ACTION);
+
+ mSendReceiver = new SmsBroadcastReceiver(SMS_SEND_ACTION);
+ mDeliveryReceiver = new SmsBroadcastReceiver(SMS_DELIVERY_ACTION);
+
+ getContext().registerReceiver(mSendReceiver, sendIntentFilter);
+ getContext().registerReceiver(mDeliveryReceiver, deliveryIntentFilter);
+
+ // send single text sms
+ init();
+ sendTextMessage(mDestAddr, mDestAddr, mDeliveredIntent, mDeliveredIntent);
+ mSendReceiver.waitForCalls(1, TIME_OUT);
+ mDeliveryReceiver.waitForCalls(1, TIME_OUT);
+
+ // send data sms
+ byte[] data = mText.getBytes();
+ short port = 19989;
+
+ init();
+ sendDataMessage(mDestAddr, port, data, mDeliveredIntent, mDeliveredIntent);
+ mSendReceiver.waitForCalls(1, TIME_OUT);
+ mDeliveryReceiver.waitForCalls(1, TIME_OUT);
+
+ // send multi parts text sms
+ init();
+ ArrayList<String> parts = divideMessage(LONG_TEXT);
+ int numParts = parts.size();
+ ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
+ ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
+ for (int i = 0; i < numParts; i++) {
+ sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
+ deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
+ }
+ sendMultiPartTextMessage(mDestAddr, parts, sentIntents, deliveryIntents);
+ mSendReceiver.waitForCalls(numParts, TIME_OUT);
+ mDeliveryReceiver.waitForCalls(numParts, TIME_OUT);
+ }
+
+ private void init() {
+ mSendReceiver.reset();
+ mDeliveryReceiver.reset();
+ mSentIntent = PendingIntent.getBroadcast(getContext(), 0, mSendIntent,
+ PendingIntent.FLAG_ONE_SHOT);
+ mDeliveredIntent = PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent,
+ PendingIntent.FLAG_ONE_SHOT);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDefault",
+ args = {}
+ )
+ public void testGetDefault() {
+ assertNotNull(getSmsManager());
+ }
+
+ protected ArrayList<String> divideMessage(String text) {
+ return getSmsManager().divideMessage(text);
+ }
+
+ private android.telephony.SmsManager getSmsManager() {
+ return android.telephony.SmsManager.getDefault();
+ }
+
+ protected void sendMultiPartTextMessage(String destAddr, ArrayList<String> parts,
+ ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
+ getSmsManager().sendMultipartTextMessage(destAddr, null, parts, sentIntents, deliveryIntents);
+ }
+
+ protected void sendDataMessage(String destAddr,short port, byte[] data, PendingIntent sentIntent, PendingIntent deliveredIntent) {
+ getSmsManager().sendDataMessage(destAddr, null, port, data, sentIntent, deliveredIntent);
+ }
+
+ protected void sendTextMessage(String destAddr, String text, PendingIntent sentIntent, PendingIntent deliveredIntent) {
+ getSmsManager().sendTextMessage(destAddr, null, text, sentIntent, deliveredIntent);
+ }
+
+ private static class SmsBroadcastReceiver extends BroadcastReceiver {
+ private int mCalls;
+ private int mExpectedCalls;
+ private String mAction;
+ private Object mLock;
+
+ SmsBroadcastReceiver(String action) {
+ mAction = action;
+ reset();
+ mLock = new Object();
+ }
+
+ void reset() {
+ mExpectedCalls = Integer.MAX_VALUE;
+ mCalls = 0;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(mAction)) {
+ synchronized (mLock) {
+ mCalls += 1;
+ if (mCalls >= mExpectedCalls) {
+ mLock.notify();
+ }
+ }
+ }
+ }
+
+ public void waitForCalls(int expectedCalls, long timeout) throws InterruptedException {
+ synchronized(mLock) {
+ mExpectedCalls = expectedCalls;
+ if (mCalls < mExpectedCalls) {
+ mLock.wait(timeout);
+ }
+ }
+ }
+ }
+}
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java
new file mode 100644
index 0000000..2d8d35c
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java
@@ -0,0 +1,435 @@
+/*
+ * Copyright (C) 2009 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.telephony.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import android.telephony.SmsMessage;
+import android.test.AndroidTestCase;
+
+@TestTargetClass(SmsMessage.class)
+public class SmsMessageTest extends AndroidTestCase{
+
+ private static final String DISPLAY_MESSAGE_BODY = "test body";
+ private static final String DMB = "{ testBody[^~\\] }";
+ private static final String EMAIL_ADD = "foo@example.com";
+ private static final String EMAIL_FROM = "foo@example.com";
+ private static final String MB = DMB;
+ private static final String MESSAGE_BODY1 = "Test";
+ private static final String MESSAGE_BODY2 = "(Subject)Test";
+ private static final String MESSAGE_BODY3 = "\u2122\u00a9\u00aehello";
+ private static final String MESSAGE_BODY4 = " ";
+ private static final String MESSAGE_BODY5 = " ";
+ private static final String OA = "foo@example.com";
+ private static final String OA1 = "+14154255486";
+ private static final String OA2 = "+15122977683";
+ private static final String OA3 = "_@";
+ private static final String OA4 = "\u0394@";
+ private static final String PSEUDO_SUBJECT = "test subject";
+ private static final String SCA1 = "+16466220020";
+ private static final String SCA2 = "+12063130012";
+ private static final String SCA3 = "+14155551212";
+ private static final String SCA4 = "+14155551212";
+ private static final int NOT_CREATE_FROM_SIM = -1;
+ private static final int NOT_CREATE_FROM_ICC = -1;
+ private static final int PROTOCOL_IDENTIFIER = 0;
+ private static final int SMS_NUMBER1 = 1;
+ private static final int SMS_NUMBER2 = 1;
+ private static final int SMS_NUMBER3 = 1;
+ private static final int STATUS = 0;
+ private static final int STATUS_ON_SIM_DEF = -1;
+ private static final int STATUS_ON_ICC_DEF = -1;
+ private static final int TPLAYER_LENGTH_FOR_PDU = 23;
+ private static final long TIMESTAMP_MILLIS = 1149631383000l;
+
+ @SuppressWarnings("deprecation")
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "createFromPdu",
+ args = {byte[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getServiceCenterAddress",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getOriginatingAddress",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getTPLayerLengthForPDU",
+ args = {String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getMessageBody",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "calculateLength",
+ args = {CharSequence.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "calculateLength",
+ args = {String.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getPdu",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isEmail",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isCphsMwiMessage",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isMwiDontStore",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isReplyPathPresent",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isStatusReportMessage",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getProtocolIdentifier",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getIndexOnSim",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getMessageClass",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStatus",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getStatusOnSim",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getTimestampMillis",
+ args = {}
+ )
+ })
+ public void testCreateFromPdu() throws Exception {
+ String pdu = "07916164260220F0040B914151245584F600006060605130308A04D4F29C0E";
+ SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertEquals(SCA1, sms.getServiceCenterAddress());
+ assertEquals(OA1, sms.getOriginatingAddress());
+ assertEquals(MESSAGE_BODY1, sms.getMessageBody());
+ assertEquals(TPLAYER_LENGTH_FOR_PDU, SmsMessage.getTPLayerLengthForPDU(pdu));
+ int[] result = SmsMessage.calculateLength(sms.getMessageBody(), true);
+ assertEquals(SMS_NUMBER1, result[0]);
+ assertEquals(sms.getMessageBody().length(), result[1]);
+ assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
+ assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
+ assertEquals(pdu, toHexString(sms.getPdu()));
+
+ assertEquals(NOT_CREATE_FROM_SIM, sms.getIndexOnSim());
+ assertEquals(NOT_CREATE_FROM_ICC, sms.getIndexOnIcc());
+ assertEquals(PROTOCOL_IDENTIFIER, sms.getProtocolIdentifier());
+ assertFalse(sms.isEmail());
+ assertFalse(sms.isReplyPathPresent());
+ assertFalse(sms.isStatusReportMessage());
+ assertFalse(sms.isCphsMwiMessage());
+ assertEquals(SmsMessage.MessageClass.UNKNOWN, sms.getMessageClass());
+ assertEquals(STATUS, sms.getStatus());
+ assertEquals(STATUS_ON_SIM_DEF, sms.getStatusOnSim());
+ assertEquals(STATUS_ON_ICC_DEF, sms.getStatusOnIcc());
+ assertEquals(TIMESTAMP_MILLIS, sms.getTimestampMillis());
+
+ // Test create from null Pdu
+ sms = SmsMessage.createFromPdu(null);
+ assertNotNull(sms);
+
+ //Test create from long Pdu
+ pdu = "07912160130310F2040B915121927786F300036060924180008A0DA"
+ + "8695DAC2E8FE9296A794E07";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertEquals(SCA2, sms.getServiceCenterAddress());
+ assertEquals(OA2, sms.getOriginatingAddress());
+ assertEquals(MESSAGE_BODY2, sms.getMessageBody());
+ CharSequence msgBody = (CharSequence) sms.getMessageBody();
+ result = SmsMessage.calculateLength(msgBody, false);
+ assertEquals(SMS_NUMBER2, result[0]);
+ assertEquals(sms.getMessageBody().length(), result[1]);
+ assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
+ assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
+
+ // Test createFromPdu Ucs to Sms
+ pdu = "07912160130300F4040B914151245584"
+ + "F600087010807121352B10212200A900AE00680065006C006C006F";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertEquals(MESSAGE_BODY3, sms.getMessageBody());
+ result = SmsMessage.calculateLength(sms.getMessageBody(), true);
+ assertEquals(SMS_NUMBER3, result[0]);
+ assertEquals(sms.getMessageBody().length(), result[1]);
+ assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
+ assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isReplace",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isMWISetMessage",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isMWIClearMessage",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isMwiDontStore",
+ args = {}
+ )
+ })
+ public void testCPHSVoiceMail() throws Exception {
+ // "set MWI flag"
+ String pdu = "07912160130310F20404D0110041006060627171118A0120";
+ SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertTrue(sms.isReplace());
+ assertEquals(OA3, sms.getOriginatingAddress());
+ assertEquals(MESSAGE_BODY4, sms.getMessageBody());
+ assertTrue(sms.isMWISetMessage());
+
+ // "clear mwi flag"
+ pdu = "07912160130310F20404D0100041006021924193352B0120";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertTrue(sms.isMWIClearMessage());
+
+ // "clear MWI flag"
+ pdu = "07912160130310F20404D0100041006060627161058A0120";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertTrue(sms.isReplace());
+ assertEquals(OA4, sms.getOriginatingAddress());
+ assertEquals(MESSAGE_BODY5, sms.getMessageBody());
+ assertTrue(sms.isMWIClearMessage());
+
+ // "set MWI flag"
+ pdu = "07912180958750F84401800500C87020026195702B06040102000200";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertTrue(sms.isMWISetMessage());
+ assertTrue(sms.isMwiDontStore());
+
+ // "clear mwi flag"
+ pdu = "07912180958750F84401800500C07020027160112B06040102000000";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+
+ assertTrue(sms.isMWIClearMessage());
+ assertTrue(sms.isMwiDontStore());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getUserData",
+ args = {}
+ )
+ })
+ public void testGetUserData() throws Exception {
+ String pdu = "07914140279510F6440A8111110301003BF56080207130138A8C0B05040B8423F"
+ + "000032A02010106276170706C69636174696F6E2F766E642E7761702E6D6D732D"
+ + "6D65737361676500AF848D0185B4848C8298524E453955304A6D7135514141426"
+ + "66C414141414D7741414236514141414141008D908918802B3135313232393737"
+ + "3638332F545950453D504C4D4E008A808E022B918805810306977F83687474703"
+ + "A2F2F36";
+ SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ byte[] userData = sms.getUserData();
+ assertNotNull(userData);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getSubmitPdu",
+ args = {String.class, String.class, String.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getSubmitPdu",
+ args = {String.class, String.class, short.class, byte[].class, boolean.class}
+ )
+ })
+ public void testGetSubmitPdu() throws Exception {
+ String scAddress = null, destinationAddress = null;
+ String message = null;
+ boolean statusReportRequested = false;
+
+ try {
+ // null message, null destination
+ SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException expected) {
+ // expected
+ }
+
+ message = "This is a test message";
+ try {
+ // non-null message
+ SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException expected) {
+ // expected
+ }
+
+ scAddress = "1650253000";
+ destinationAddress = "18004664411";
+ message = "This is a test message";
+ statusReportRequested = false;
+ SmsMessage.SubmitPdu smsPdu =
+ SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
+ assertNotNull(smsPdu);
+
+ smsPdu = SmsMessage.getSubmitPdu(scAddress, destinationAddress, (short)80,
+ message.getBytes(), statusReportRequested);
+ assertNotNull(smsPdu);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getEmailBody",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getEmailFrom",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDisplayMessageBody",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getPseudoSubject",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDisplayOriginatingAddress",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "isEmail",
+ args = {}
+ )
+ })
+ public void testEmailGateway() throws Exception {
+ String pdu = "07914151551512f204038105f300007011103164638a28e6f71b50c687db" +
+ "7076d9357eb7412f7a794e07cdeb6275794c07bde8e5391d247e93f3";
+
+ SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertEquals(SCA4, sms.getServiceCenterAddress());
+ assertTrue(sms.isEmail());
+ assertEquals(EMAIL_ADD, sms.getEmailFrom());
+ assertEquals(EMAIL_ADD, sms.getDisplayOriginatingAddress());
+ assertEquals(PSEUDO_SUBJECT, sms.getPseudoSubject());
+
+ assertEquals(DISPLAY_MESSAGE_BODY, sms.getDisplayMessageBody());
+ assertEquals(DISPLAY_MESSAGE_BODY, sms.getEmailBody());
+
+ pdu = "07914151551512f204038105f400007011103105458a29e6f71b50c687db" +
+ "7076d9357eb741af0d0a442fcfe9c23739bfe16d289bdee6b5f1813629";
+ sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
+ assertEquals(SCA3, sms.getServiceCenterAddress());
+ assertTrue(sms.isEmail());
+ assertEquals(OA, sms.getDisplayOriginatingAddress());
+ assertEquals(EMAIL_FROM, sms.getEmailFrom());
+ assertEquals(DMB, sms.getDisplayMessageBody());
+ assertEquals(MB, sms.getEmailBody());
+ }
+
+ private final static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ public static String toHexString(byte[] array) {
+ int length = array.length;
+ char[] buf = new char[length * 2];
+
+ int bufIndex = 0;
+ for (int i = 0 ; i < length; i++)
+ {
+ byte b = array[i];
+ buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
+ buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
+ }
+
+ return new String(buf);
+ }
+
+ private static int toByte(char c) {
+ if (c >= '0' && c <= '9') return (c - '0');
+ if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
+ if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
+
+ throw new RuntimeException ("Invalid hex char '" + c + "'");
+ }
+
+ private static byte[] hexStringToByteArray(String hexString) {
+ int length = hexString.length();
+ byte[] buffer = new byte[length / 2];
+
+ for (int i = 0 ; i < length ; i += 2) {
+ buffer[i / 2] =
+ (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i+1)));
+ }
+
+ return buffer;
+ }
+}
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsMessage_MessageClassTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsMessage_MessageClassTest.java
new file mode 100644
index 0000000..450b4e3
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsMessage_MessageClassTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 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.telephony.cts;
+
+import junit.framework.TestCase;
+import android.telephony.SmsMessage;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(SmsMessage.MessageClass.class)
+public class SmsMessage_MessageClassTest extends TestCase {
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "valueOf",
+ args = {String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "values",
+ args = {}
+ )
+ })
+ public void testMessageClass() {
+ }
+}
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsMessage_SubmitPduTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsMessage_SubmitPduTest.java
new file mode 100644
index 0000000..6b96468
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsMessage_SubmitPduTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2008 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.telephony.cts;
+
+import android.telephony.SmsMessage;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(SmsMessage.SubmitPdu.class)
+public class SmsMessage_SubmitPduTest extends AndroidTestCase {
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ method = "toString",
+ args = {}
+ )
+ })
+ // SmsMessage.SubmitPdu constructor is not public, so no need to test its methods
+ public void testToString() {
+ }
+}
diff --git a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsManagerTest.java b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsManagerTest.java
index ba02c35..8dc6936 100644
--- a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsManagerTest.java
@@ -19,187 +19,46 @@
import java.util.ArrayList;
import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
-import android.test.AndroidTestCase;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
@SuppressWarnings("deprecation")
@TestTargetClass(SmsManager.class)
-public class SmsManagerTest extends AndroidTestCase {
+public class SmsManagerTest extends android.telephony.cts.SmsManagerTest {
- private static final int NUM_TEXT_PARTS = 3;
- private static final String LONG_TEXT =
- "This is a very long text. This text should be broken into three " +
- "separate messages.This is a very long text. This text should be broken into " +
- "three separate messages.This is a very long text. This text should be broken " +
- "into three separate messages.This is a very long text. This text should be " +
- "broken into three separate messages.";;
-
- private static final String SMS_SEND_ACTION = "CTS_SMS_SEND_ACTION";
- private static final String SMS_DELIVERY_ACTION = "CTS_SMS_DELIVERY_ACTION";
-
- private SmsManager mSms;
- private String mDestAddr;
- private String mText;
- private SmsBroadcastReceiver mSendReceiver;
- private SmsBroadcastReceiver mDeliveryReceiver;
- private PendingIntent mSentIntent;
- private PendingIntent mDeliveredIntent;
- private Intent mSendIntent;
- private Intent mDeliveryIntent;
-
- private static final int TIME_OUT = 1000 * 60 * 4;
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDefault",
+ args = {}
+ )
+ public void testGetDefault() {
+ assertNotNull(getSmsManager());
+ }
@Override
- protected void setUp() throws Exception {
- super.setUp();
- mSms = SmsManager.getDefault();
- TelephonyManager tm =
- (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
- mDestAddr = tm.getLine1Number();
- mText = "This is a test message";
+ protected ArrayList<String> divideMessage(String text) {
+ return getSmsManager().divideMessage(text);
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "divideMessage",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getDefault",
- args = {}
- )
- })
- public void testDivideMessage() {
- // Test getDefault
- assertNotNull(mSms);
-
- // Test divideMessage
- ArrayList<String> dividedMessages = mSms.divideMessage(LONG_TEXT);
- assertNotNull(dividedMessages);
- assertEquals(NUM_TEXT_PARTS, dividedMessages.size());
- assertEquals(LONG_TEXT,
- dividedMessages.get(0) + dividedMessages.get(1) + dividedMessages.get(2));
+ private android.telephony.gsm.SmsManager getSmsManager() {
+ return android.telephony.gsm.SmsManager.getDefault();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "sendDataMessage",
- args = {String.class, String.class, short.class, byte[].class,
- PendingIntent.class, PendingIntent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "sendTextMessage",
- args = {String.class, String.class, String.class, PendingIntent.class,
- PendingIntent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "sendMultipartTextMessage",
- args = {String.class, String.class, ArrayList.class, ArrayList.class, ArrayList.class}
- )
- })
- public void testSendMessages() throws InterruptedException {
-
- mSendIntent = new Intent(SMS_SEND_ACTION);
- mDeliveryIntent = new Intent(SMS_DELIVERY_ACTION);
-
- IntentFilter sendIntentFilter = new IntentFilter(SMS_SEND_ACTION);
- IntentFilter deliveryIntentFilter = new IntentFilter(SMS_DELIVERY_ACTION);
-
- mSendReceiver = new SmsBroadcastReceiver(SMS_SEND_ACTION);
- mDeliveryReceiver = new SmsBroadcastReceiver(SMS_DELIVERY_ACTION);
-
- getContext().registerReceiver(mSendReceiver, sendIntentFilter);
- getContext().registerReceiver(mDeliveryReceiver, deliveryIntentFilter);
-
- // send single text sms
- init();
- mSms.sendTextMessage(mDestAddr, null, mText, mSentIntent, mDeliveredIntent);
- mSendReceiver.waitForCalls(1, TIME_OUT);
- mDeliveryReceiver.waitForCalls(1, TIME_OUT);
-
- // send data sms
- byte[] data = mText.getBytes();
- short port = 19989;
-
- init();
- mSms.sendDataMessage(mDestAddr, null, port, data, mSentIntent, mDeliveredIntent);
- mSendReceiver.waitForCalls(1, TIME_OUT);
- mDeliveryReceiver.waitForCalls(1, TIME_OUT);
-
- // send multi parts text sms
- init();
- ArrayList<String> parts = mSms.divideMessage(LONG_TEXT);
- int numParts = parts.size();
- ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
- ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
- for (int i = 0; i < numParts; i++) {
- sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
- deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
- }
- mSms.sendMultipartTextMessage(mDestAddr, null, parts, sentIntents, deliveryIntents);
- mSendReceiver.waitForCalls(numParts, TIME_OUT);
- mDeliveryReceiver.waitForCalls(numParts, TIME_OUT);
+ @Override
+ protected void sendMultiPartTextMessage(String destAddr, ArrayList<String> parts,
+ ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
+ getSmsManager().sendMultipartTextMessage(destAddr, null, parts, sentIntents, deliveryIntents);
}
- private void init() {
- mSendReceiver.reset();
- mDeliveryReceiver.reset();
- mSentIntent = PendingIntent.getBroadcast(getContext(), 0, mSendIntent,
- PendingIntent.FLAG_ONE_SHOT);
- mDeliveredIntent = PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent,
- PendingIntent.FLAG_ONE_SHOT);
+ @Override
+ protected void sendDataMessage(String destAddr,short port, byte[] data, PendingIntent sentIntent, PendingIntent deliveredIntent) {
+ getSmsManager().sendDataMessage(destAddr, null, port, data, sentIntent, deliveredIntent);
}
- private static class SmsBroadcastReceiver extends BroadcastReceiver {
- private int mCalls;
- private int mExpectedCalls;
- private String mAction;
- private Object mLock;
-
- SmsBroadcastReceiver(String action) {
- mAction = action;
- reset();
- mLock = new Object();
- }
-
- void reset() {
- mExpectedCalls = Integer.MAX_VALUE;
- mCalls = 0;
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(mAction)) {
- synchronized (mLock) {
- mCalls += 1;
- if (mCalls >= mExpectedCalls) {
- mLock.notify();
- }
- }
- }
- }
-
- public void waitForCalls(int expectedCalls, long timeout) throws InterruptedException {
- synchronized(mLock) {
- mExpectedCalls = expectedCalls;
- if (mCalls < mExpectedCalls) {
- mLock.wait(timeout);
- }
- }
- }
+ @Override
+ protected void sendTextMessage(String destAddr, String text, PendingIntent sentIntent, PendingIntent deliveredIntent) {
+ getSmsManager().sendTextMessage(destAddr, null, text, sentIntent, deliveredIntent);
}
-}
+}
\ No newline at end of file
diff --git a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_MessageClassTest.java b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_MessageClassTest.java
index bfa53ef..400bc27 100644
--- a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_MessageClassTest.java
+++ b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_MessageClassTest.java
@@ -24,6 +24,7 @@
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+@SuppressWarnings("deprecation")
@TestTargetClass(SmsMessage.MessageClass.class)
public class SmsMessage_MessageClassTest extends TestCase {
diff --git a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_SubmitPduTest.java b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_SubmitPduTest.java
index e40a7fd..e28d2f6 100644
--- a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_SubmitPduTest.java
+++ b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessage_SubmitPduTest.java
@@ -23,6 +23,7 @@
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+@SuppressWarnings("deprecation")
@TestTargetClass(SmsMessage.SubmitPdu.class)
public class SmsMessage_SubmitPduTest extends AndroidTestCase {
diff --git a/tools/utils/genDefaultTestPlan.sh b/tools/utils/genDefaultTestPlan.sh
index 14f5cee..042be07 100644
--- a/tools/utils/genDefaultTestPlan.sh
+++ b/tools/utils/genDefaultTestPlan.sh
@@ -293,6 +293,7 @@
${TOP_DIR}/cts/tests/tests/performance3/src:\
${TOP_DIR}/cts/tests/tests/performance4/src:\
${TOP_DIR}/cts/tests/tests/performance5/src:\
+${TOP_DIR}/cts/tests/tests/dpi/src:\
${TOP_DIR}/dalvik/libcore/dalvik/src/main/java:\
${TOP_DIR}/dalvik/libcore/junit/src/main/java \
${SOURCES} 1>/dev/null 2>/dev/null