summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2012-02-13 18:34:01 -0800
committerJake Hamby <jhamby@google.com>2012-03-13 16:48:21 -0700
commit00b87064abfb9d254fbbf72110643d2e626365e6 (patch)
treee5e540eec2dd2990d407bd7f2f6d443a619f58d2 /tests
parent95903862da74128bbab5c81d782c5ff277172498 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-00b87064abfb9d254fbbf72110643d2e626365e6.tar.gz
android_packages_apps_CellBroadcastReceiver-00b87064abfb9d254fbbf72110643d2e626365e6.tar.bz2
android_packages_apps_CellBroadcastReceiver-00b87064abfb9d254fbbf72110643d2e626365e6.zip
Add CMAS over CDMA support to CellBroadcastReceiver app.
Add support for CMAS warning notifications over CDMA to CellBroadcastReceiver app. The framework code now sends cell broadcasts in a radio-technology independent form by passing the new Parcelable android.telephony.SmsCbMessage class as the "message" intent of the SMS_CB_RECEIVED_ACTION or SMS_EMERGENCY_CB_RECEIVED_ACTION, instead of as a GSM/UMTS "pdu" byte array. The database version has also been upgraded to encompass metadata for ETWS and CMAS emergency broadcasts, as well as CDMA format broadcasts. Bug: 5856308 Change-Id: I1b10d35d8aa6f0134260116980e4c326f86d2fe7
Diffstat (limited to 'tests')
-rw-r--r--tests/res/layout/test_buttons.xml55
-rw-r--r--tests/res/values/strings.xml6
-rw-r--r--tests/src/com/android/cellbroadcastreceiver/DialogSmsDisplayTests.java37
-rw-r--r--tests/src/com/android/cellbroadcastreceiver/tests/SendCdmaCmasMessages.java176
-rw-r--r--tests/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java81
-rw-r--r--tests/src/com/android/cellbroadcastreceiver/tests/SendTestMessages.java112
6 files changed, 368 insertions, 99 deletions
diff --git a/tests/res/layout/test_buttons.xml b/tests/res/layout/test_buttons.xml
index 5ea2ed11..2dd3849c 100644
--- a/tests/res/layout/test_buttons.xml
+++ b/tests/res/layout/test_buttons.xml
@@ -25,10 +25,17 @@
android:layout_height="match_parent"
android:orientation="vertical">
+ <CheckBox android:id="@+id/button_delay_broadcast"
+ android:text="@string/button_delay_broadcast"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <!-- ETWS Alerts -->
<Button android:id="@+id/button_etws_normal_type"
android:text="@string/button_etws_normal_type"
android:layout_marginLeft="20dp"
- android:layout_marginTop="20dp"
+ android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@@ -44,9 +51,43 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+ <!-- CDMA CMAS Alerts -->
+ <Button android:id="@+id/button_cmas_pres_alert"
+ android:text="@string/button_cmas_pres_alert"
+ android:layout_marginLeft="20dp"
+ android:layout_marginTop="10dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <Button android:id="@+id/button_cmas_extreme_alert"
+ android:text="@string/button_cmas_extreme_alert"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <Button android:id="@+id/button_cmas_severe_alert"
+ android:text="@string/button_cmas_severe_alert"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <Button android:id="@+id/button_cmas_amber_alert"
+ android:text="@string/button_cmas_amber_alert"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <Button android:id="@+id/button_cmas_monthly_test"
+ android:text="@string/button_cmas_monthly_test"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <!-- Other Alerts -->
<Button android:id="@+id/button_gsm_7bit_type"
android:text="@string/button_gsm_7bit_type"
android:layout_marginLeft="20dp"
+ android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@@ -86,6 +127,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+ <Button android:id="@+id/button_gsm_7bit_with_language_body_gsm_type"
+ android:text="@string/button_gsm_7bit_with_language_body_gsm_type"
+ android:layout_marginLeft="20dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
<Button android:id="@+id/button_gsm_7bit_with_language_body_umts_type"
android:text="@string/button_gsm_7bit_with_language_body_umts_type"
android:layout_marginLeft="20dp"
@@ -122,12 +169,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
- <CheckBox android:id="@+id/button_delay_broadcast"
- android:text="@string/button_delay_broadcast"
- android:layout_marginLeft="20dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
</LinearLayout>
</ScrollView>
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
index 16fbb7b3..5968e1c9 100644
--- a/tests/res/values/strings.xml
+++ b/tests/res/values/strings.xml
@@ -19,6 +19,11 @@
<string name="button_etws_normal_type">Send ETWS Normal Broadcast</string>
<string name="button_etws_cancel_type">Send ETWS Cancel Broadcast</string>
<string name="button_etws_test_type">Send ETWS Test Broadcast</string>
+ <string name="button_cmas_pres_alert">Send CMAS Presidential Alert</string>
+ <string name="button_cmas_extreme_alert">Send CMAS Extreme Alert</string>
+ <string name="button_cmas_severe_alert">Send CMAS Severe Alert</string>
+ <string name="button_cmas_amber_alert">Send CMAS AMBER Alert</string>
+ <string name="button_cmas_monthly_test">Send CMAS Monthly Test Alert</string>
<string name="button_gsm_7bit_type">Send GSM 7 Bit Test Broadcast</string>
<string name="button_gsm_7bit_umts_type">Send UMTS 7 Bit Test Broadcast</string>
<string name="button_gsm_7bit_nopadding_type">Send GSM 7 Bit Full Length Broadcast</string>
@@ -26,6 +31,7 @@
<string name="button_gsm_7bit_multipage_type">Send GSM 7 Bit Multi Page Broadcast</string>
<string name="button_gsm_7bit_multipage_umts_type">Send UMTS 7 Bit Multi Page Broadcast</string>
<string name="button_gsm_7bit_with_language_type">Send GSM 7 Bit With Language</string>
+ <string name="button_gsm_7bit_with_language_body_gsm_type">Send GSM 7 Bit With Language In Body</string>
<string name="button_gsm_7bit_with_language_body_umts_type">Send UMTS 7 Bit With Language</string>
<string name="button_gsm_ucs2_type">Send GSM UCS-2 Test Broadcast</string>
<string name="button_gsm_ucs2_umts_type">Send UMTS UCS-2 Test Broadcast</string>
diff --git a/tests/src/com/android/cellbroadcastreceiver/DialogSmsDisplayTests.java b/tests/src/com/android/cellbroadcastreceiver/DialogSmsDisplayTests.java
index f7df27ad..095ce062 100644
--- a/tests/src/com/android/cellbroadcastreceiver/DialogSmsDisplayTests.java
+++ b/tests/src/com/android/cellbroadcastreceiver/DialogSmsDisplayTests.java
@@ -20,12 +20,15 @@ import java.io.UnsupportedEncodingException;
import android.content.Intent;
import android.provider.Telephony.Sms.Intents;
+import android.telephony.SmsCbLocation;
+import android.telephony.SmsCbMessage;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.android.internal.telephony.EncodeException;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.gsm.GsmSmsCbMessage;
/**
* Various instrumentation tests for CellBroadcastReceiver.
@@ -106,45 +109,49 @@ public class DialogSmsDisplayTests
}
}
+ private static final SmsCbLocation sEmptyLocation = new SmsCbLocation();
+
+ private static SmsCbMessage createFromPdu(byte[] pdu) {
+ try {
+ byte[][] pdus = new byte[1][];
+ pdus[0] = pdu;
+ return GsmSmsCbMessage.createSmsCbMessage(sEmptyLocation, pdus);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
public void testSendMessage7bit() throws Exception {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = encodeCellBroadcast(0, 0, DCS_7BIT_ENGLISH, "Hello in GSM 7 bit");
- intent.putExtra("pdus", pdus);
+ byte[] pdu = encodeCellBroadcast(0, 0, DCS_7BIT_ENGLISH, "Hello in GSM 7 bit");
+ intent.putExtra("message", createFromPdu(pdu));
getActivity().sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public void testSendMessageUCS2() throws Exception {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = encodeCellBroadcast(0, 0, DCS_16BIT_UCS2, "Hello in UCS2");
- intent.putExtra("pdus", pdus);
+ byte[] pdu = encodeCellBroadcast(0, 0, DCS_16BIT_UCS2, "Hello in UCS2");
+ intent.putExtra("message", createFromPdu(pdu));
getActivity().sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public void testSendEtwsMessageNormal() throws Exception {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageNormal;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageNormal));
getActivity().sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}
public void testSendEtwsMessageCancel() throws Exception {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageCancel;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageCancel));
getActivity().sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}
public void testSendEtwsMessageTest() throws Exception {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageTest;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageTest));
getActivity().sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}
diff --git a/tests/src/com/android/cellbroadcastreceiver/tests/SendCdmaCmasMessages.java b/tests/src/com/android/cellbroadcastreceiver/tests/SendCdmaCmasMessages.java
new file mode 100644
index 00000000..17f76cb4
--- /dev/null
+++ b/tests/src/com/android/cellbroadcastreceiver/tests/SendCdmaCmasMessages.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2012 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.cellbroadcastreceiver.tests;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Parcel;
+import android.provider.Telephony;
+import android.telephony.SmsCbCmasInfo;
+import android.telephony.SmsCbLocation;
+import android.telephony.SmsCbMessage;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.cdma.sms.BearerData;
+import com.android.internal.telephony.cdma.sms.CdmaSmsAddress;
+import com.android.internal.telephony.cdma.sms.SmsEnvelope;
+import com.android.internal.telephony.cdma.sms.UserData;
+import com.android.internal.util.BitwiseOutputStream;
+
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * Send some test CDMA CMAS warning notifications.
+ */
+public class SendCdmaCmasMessages {
+
+ private static final String TEST_TEXT = "This is a test CDMA cell broadcast message..."
+ + "678901234567890123456789012345678901234567890";
+
+ private static final String PRES_ALERT =
+ "THE PRESIDENT HAS ISSUED AN EMERGENCY ALERT. CHECK LOCAL MEDIA FOR MORE DETAILS";
+
+ private static final String EXTREME_ALERT = "FLASH FLOOD WARNING FOR SOUTH COCONINO COUNTY"
+ + " - NORTH CENTRAL ARIZONA UNTIL 415 PM MST";
+
+ private static final String SEVERE_ALERT = "SEVERE WEATHER WARNING FOR SOMERSET COUNTY"
+ + " - NEW JERSEY UNTIL 415 PM MST";
+
+ private static final String AMBER_ALERT =
+ "AMBER ALERT:Mountain View,CA VEH'07 Blue Honda Civic CA LIC 5ABC123";
+
+ private static final String MONTHLY_TEST_ALERT = "This is a test of the emergency alert system."
+ + " This is only a test. 89012345678901234567890";
+
+ private static final String IS91_TEXT = "IS91 SHORT MSG"; // max length 14 chars
+
+ public static void testSendCmasPresAlert(Activity activity) {
+ SmsCbMessage cbMessage = createCmasSmsMessage(
+ SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT, 12345, "en",
+ PRES_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_GEO,
+ SmsCbCmasInfo.CMAS_RESPONSE_TYPE_PREPARE, SmsCbCmasInfo.CMAS_SEVERITY_EXTREME,
+ SmsCbCmasInfo.CMAS_URGENCY_EXPECTED, SmsCbCmasInfo.CMAS_CERTAINTY_LIKELY);
+
+ Intent intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("message", cbMessage);
+ activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
+ }
+
+ public static void testSendCmasExtremeAlert(Activity activity) {
+ SmsCbMessage cbMessage = createCmasSmsMessage(
+ SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, 23456, "en",
+ EXTREME_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_MET,
+ SmsCbCmasInfo.CMAS_RESPONSE_TYPE_PREPARE, SmsCbCmasInfo.CMAS_SEVERITY_EXTREME,
+ SmsCbCmasInfo.CMAS_URGENCY_EXPECTED, SmsCbCmasInfo.CMAS_CERTAINTY_OBSERVED);
+
+ Intent intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("message", cbMessage);
+ activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
+ }
+
+ public static void testSendCmasSevereAlert(Activity activity) {
+ SmsCbMessage cbMessage = createCmasSmsMessage(
+ SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT, 34567, "en",
+ SEVERE_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_HEALTH,
+ SmsCbCmasInfo.CMAS_RESPONSE_TYPE_AVOID, SmsCbCmasInfo.CMAS_SEVERITY_SEVERE,
+ SmsCbCmasInfo.CMAS_URGENCY_IMMEDIATE, SmsCbCmasInfo.CMAS_CERTAINTY_LIKELY);
+
+ Intent intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("message", cbMessage);
+ activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
+ }
+
+ public static void testSendCmasAmberAlert(Activity activity) {
+ SmsCbMessage cbMessage = createCmasSmsMessage(
+ SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY, 45678, "en",
+ AMBER_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_UNKNOWN,
+ SmsCbCmasInfo.CMAS_RESPONSE_TYPE_UNKNOWN, SmsCbCmasInfo.CMAS_SEVERITY_UNKNOWN,
+ SmsCbCmasInfo.CMAS_URGENCY_UNKNOWN, SmsCbCmasInfo.CMAS_CERTAINTY_UNKNOWN);
+
+ Intent intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("message", cbMessage);
+ activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
+ }
+
+ public static void testSendCmasMonthlyTest(Activity activity) {
+ SmsCbMessage cbMessage = createCmasSmsMessage(
+ SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE, 56789, "en",
+ MONTHLY_TEST_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_UNKNOWN,
+ SmsCbCmasInfo.CMAS_RESPONSE_TYPE_UNKNOWN, SmsCbCmasInfo.CMAS_SEVERITY_UNKNOWN,
+ SmsCbCmasInfo.CMAS_URGENCY_UNKNOWN, SmsCbCmasInfo.CMAS_CERTAINTY_UNKNOWN);
+
+ Intent intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("message", cbMessage);
+ activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
+ }
+
+ /**
+ * Create a new SmsCbMessage for testing CDMA CMAS support.
+ * @param serviceCategory the CDMA service category
+ * @param messageId the 16-bit message identifier
+ * @param language message language code
+ * @param body message body
+ * @param cmasCategory CMAS category (or -1 to skip adding CMAS type 1 elements record)
+ * @param responseType CMAS response type
+ * @param severity CMAS severity
+ * @param urgency CMAS urgency
+ * @param certainty CMAS certainty
+ * @return the newly created SmsMessage object
+ */
+ private static SmsCbMessage createCmasSmsMessage(int serviceCategory, int messageId,
+ String language, String body, int cmasCategory, int responseType, int severity,
+ int urgency, int certainty) {
+ int cmasMessageClass = serviceCategoryToCmasMessageClass(serviceCategory);
+ SmsCbCmasInfo cmasInfo = new SmsCbCmasInfo(cmasMessageClass, cmasCategory, responseType,
+ severity, urgency, certainty);
+ return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP2,
+ SmsCbMessage.GEOGRAPHICAL_SCOPE_PLMN_WIDE, messageId, new SmsCbLocation("123456"),
+ serviceCategory, language, body, SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, null,
+ cmasInfo);
+ }
+
+ /**
+ * Convert CDMA service category to CMAS message class. Copied from {@code BearerData}.
+ * @param serviceCategory CDMA service category
+ * @return CMAS message class
+ */
+ private static int serviceCategoryToCmasMessageClass(int serviceCategory) {
+ switch (serviceCategory) {
+ case SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT:
+ return SmsCbCmasInfo.CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT;
+
+ case SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT:
+ return SmsCbCmasInfo.CMAS_CLASS_EXTREME_THREAT;
+
+ case SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT:
+ return SmsCbCmasInfo.CMAS_CLASS_SEVERE_THREAT;
+
+ case SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY:
+ return SmsCbCmasInfo.CMAS_CLASS_CHILD_ABDUCTION_EMERGENCY;
+
+ case SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE:
+ return SmsCbCmasInfo.CMAS_CLASS_REQUIRED_MONTHLY_TEST;
+
+ default:
+ return SmsCbCmasInfo.CMAS_CLASS_UNKNOWN;
+ }
+ }
+}
diff --git a/tests/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java b/tests/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java
index 7727863e..0e731010 100644
--- a/tests/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java
+++ b/tests/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java
@@ -20,7 +20,6 @@ import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -102,6 +101,71 @@ public class SendTestBroadcastActivity extends Activity {
}
});
+ /* Send a CMAS presidential alert to app. */
+ Button cmasPresAlertButton = (Button) findViewById(R.id.button_cmas_pres_alert);
+ cmasPresAlertButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendCdmaCmasMessages.testSendCmasPresAlert(SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
+ /* Send a CMAS extreme alert to app. */
+ Button cmasExtremeAlertButton = (Button) findViewById(R.id.button_cmas_extreme_alert);
+ cmasExtremeAlertButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendCdmaCmasMessages.testSendCmasExtremeAlert(SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
+ /* Send a CMAS severe alert to app. */
+ Button cmasSevereAlertButton = (Button) findViewById(R.id.button_cmas_severe_alert);
+ cmasSevereAlertButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendCdmaCmasMessages.testSendCmasSevereAlert(SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
+ /* Send a CMAS AMBER alert to app. */
+ Button cmasAmberAlertButton = (Button) findViewById(R.id.button_cmas_amber_alert);
+ cmasAmberAlertButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendCdmaCmasMessages.testSendCmasAmberAlert(SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
+ /* Send a CMAS monthly test alert to app. */
+ Button cmasMonthlyTestButton = (Button) findViewById(R.id.button_cmas_monthly_test);
+ cmasMonthlyTestButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendCdmaCmasMessages.testSendCmasMonthlyTest(SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
/* Send a GSM 7-bit broadcast message to app. */
Button gsm7bitTypeButton = (Button) findViewById(R.id.button_gsm_7bit_type);
gsm7bitTypeButton.setOnClickListener(new OnClickListener() {
@@ -197,6 +261,21 @@ public class SendTestBroadcastActivity extends Activity {
}
});
+ /* Send a GSM 7-bit broadcast message with language to app. */
+ Button gsm7bitWithLanguageInBodyButton =
+ (Button) findViewById(R.id.button_gsm_7bit_with_language_body_gsm_type);
+ gsm7bitWithLanguageInBodyButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (mDelayBeforeSending && v != null) {
+ mPendingButtonClick = this;
+ mDelayHandler.sendEmptyMessageDelayed(0, DELAY_BEFORE_SENDING_MSEC);
+ } else {
+ SendTestMessages.testSendMessage7bitWithLanguageInBody(
+ SendTestBroadcastActivity.this);
+ }
+ }
+ });
+
/* Send a UMTS 7-bit broadcast message with language to app. */
Button gsm7bitWithLanguageUmtsButton =
(Button) findViewById(R.id.button_gsm_7bit_with_language_body_umts_type);
diff --git a/tests/src/com/android/cellbroadcastreceiver/tests/SendTestMessages.java b/tests/src/com/android/cellbroadcastreceiver/tests/SendTestMessages.java
index 893d03a3..a8496ff0 100644
--- a/tests/src/com/android/cellbroadcastreceiver/tests/SendTestMessages.java
+++ b/tests/src/com/android/cellbroadcastreceiver/tests/SendTestMessages.java
@@ -16,17 +16,19 @@
package com.android.cellbroadcastreceiver.tests;
-import java.io.UnsupportedEncodingException;
-
import android.app.Activity;
import android.content.Intent;
import android.provider.Telephony.Sms.Intents;
-import android.test.ActivityInstrumentationTestCase2;
+import android.telephony.SmsCbLocation;
+import android.telephony.SmsCbMessage;
import android.util.Log;
import com.android.internal.telephony.EncodeException;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.gsm.GsmSmsCbMessage;
+
+import java.io.UnsupportedEncodingException;
/**
* Send test messages.
@@ -381,64 +383,47 @@ public class SendTestMessages {
(byte)0x50
};
- static byte[] encodeCellBroadcast(int serialNumber, int messageId, int dcs, String message) {
- byte[] pdu = new byte[88];
- pdu[0] = (byte) ((serialNumber >> 8) & 0xff);
- pdu[1] = (byte) (serialNumber & 0xff);
- pdu[2] = (byte) ((messageId >> 8) & 0xff);
- pdu[3] = (byte) (messageId & 0xff);
- pdu[4] = (byte) (dcs & 0xff);
- pdu[5] = 0x11; // single page message
+ private static final SmsCbLocation sEmptyLocation = new SmsCbLocation();
+
+ private static SmsCbMessage createFromPdu(byte[] pdu) {
try {
- byte[] encodedString;
- if (dcs == DCS_16BIT_UCS2) {
- encodedString = message.getBytes("UTF-16");
- System.arraycopy(encodedString, 0, pdu, 6, encodedString.length);
- } else {
- // byte 0 of encodedString is the length in septets (don't copy)
- encodedString = GsmAlphabet.stringToGsm7BitPacked(message);
- System.arraycopy(encodedString, 1, pdu, 6, encodedString.length-1);
- }
- return pdu;
- } catch (EncodeException e) {
- Log.e(TAG, "Encode Exception");
+ byte[][] pdus = new byte[1][];
+ pdus[0] = pdu;
+ return GsmSmsCbMessage.createSmsCbMessage(sEmptyLocation, pdus);
+ } catch (IllegalArgumentException e) {
return null;
- } catch (UnsupportedEncodingException e) {
- Log.e(TAG, "Unsupported encoding exception for UTF-16");
+ }
+ }
+
+ private static SmsCbMessage createFromPdus(byte[][] pdus) {
+ try {
+ return GsmSmsCbMessage.createSmsCbMessage(sEmptyLocation, pdus);
+ } catch (IllegalArgumentException e) {
return null;
}
}
public static void testSendMessage7bit(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTest;
-// pdus[0] = encodeCellBroadcast(0, 0, DCS_7BIT_ENGLISH, "Hello in GSM 7 bit");
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTest));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitNoPadding(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestNoPadding;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestNoPadding));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitNoPaddingUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestNoPaddingUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestNoPaddingUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
@@ -447,106 +432,81 @@ public class SendTestMessages {
byte[][] pdus = new byte[2][];
pdus[0] = gsm7BitTestMultipage1;
pdus[1] = gsm7BitTestMultipage2;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdus(pdus));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitMultipageUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestMultipageUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestMultipageUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitWithLanguage(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestWithLanguage;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguage));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitWithLanguageInBody(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestWithLanguageInBody;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguageInBody));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessage7bitWithLanguageInBodyUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsm7BitTestWithLanguageInBodyUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguageInBodyUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessageUcs2(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsmUcs2Test;
-// pdus[0] = encodeCellBroadcast(0, 0, DCS_16BIT_UCS2, "Hello in UCS2");
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsmUcs2Test));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessageUcs2Umts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsmUcs2TestUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsmUcs2TestUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessageUcs2MultipageUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsmUcs2TestMultipageUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsmUcs2TestMultipageUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessageUcs2WithLanguageInBody(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsmUcs2TestWithLanguageInBody;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsmUcs2TestWithLanguageInBody));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendMessageUcs2WithLanguageUmts(Activity activity) {
Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = gsmUcs2TestWithLanguageInBodyUmts;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(gsmUcs2TestWithLanguageInBodyUmts));
activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
}
public static void testSendEtwsMessageNormal(Activity activity) {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageNormal;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageNormal));
activity.sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}
public static void testSendEtwsMessageCancel(Activity activity) {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageCancel;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageCancel));
activity.sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}
public static void testSendEtwsMessageTest(Activity activity) {
Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
- byte[][] pdus = new byte[1][];
- pdus[0] = etwsMessageTest;
- intent.putExtra("pdus", pdus);
+ intent.putExtra("message", createFromPdu(etwsMessageTest));
activity.sendOrderedBroadcast(intent,
"android.permission.RECEIVE_EMERGENCY_BROADCAST");
}