Merge "Added ETWS primary message default message support"

This commit is contained in:
Jack Yu
2017-03-21 07:38:20 +00:00
committed by Android (Google) Code Review
3 changed files with 69 additions and 23 deletions

View File

@@ -392,7 +392,7 @@
This indicates that a work profile has been deleted. [CHAR LIMIT=NONE]-->
<string name="work_profile_deleted_description_dpm_wipe">Your work profile is no longer available on this device.</string>
<!-- Content title for a notification. This notification indicates that the device is managed
<!-- Content title for a notification. This notification indicates that the device is managed
and network logging was activated by a device owner. [CHAR LIMIT=NONE]-->
<string name="network_logging_notification_title">Device is managed</string>
<!-- Content text for a notification. Tapping opens a dialog with more information on device management and network
@@ -4588,4 +4588,18 @@
<!-- Label for the type of data being saved for autofill when it represents a credit card [CHAR LIMIT=NONE] -->
<string name="autofill_save_type_credit_card">credit card</string>
<!-- Primary ETWS (Earthquake and Tsunami Warning System) default message for earthquake -->
<string name="etws_primary_default_message_earthquake">Stay calm and seek shelter nearby.</string>
<!-- Primary ETWS (Earthquake and Tsunami Warning System) default message for Tsunami -->
<string name="etws_primary_default_message_tsunami">Evacuate immediately from coastal regions and riverside areas to a safer place such as high ground.</string>
<!-- Primary ETWS (Earthquake and Tsunami Warning System) default message for earthquake and Tsunami -->
<string name="etws_primary_default_message_earthquake_and_tsunami">Stay calm and seek shelter nearby.</string>
<!-- Primary ETWS (Earthquake and Tsunami Warning System) default message for test -->
<string name="etws_primary_default_message_test">Emergency messages test</string>
<!-- Primary ETWS (Earthquake and Tsunami Warning System) default message for others -->
<string name="etws_primary_default_message_others"></string>
</resources>

View File

@@ -2919,4 +2919,14 @@
<java-symbol type="string" name="notification_channel_retail_mode" />
<java-symbol type="string" name="notification_channel_usb" />
<!-- ETWS primary messages -->
<java-symbol type="string" name="etws_primary_default_message_earthquake" />
<java-symbol type="string" name="etws_primary_default_message_tsunami" />
<java-symbol type="string" name="etws_primary_default_message_earthquake_and_tsunami" />
<java-symbol type="string" name="etws_primary_default_message_test" />
<java-symbol type="string" name="etws_primary_default_message_others" />
</resources>

View File

@@ -16,10 +16,19 @@
package com.android.internal.telephony.gsm;
import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_EARTHQUAKE;
import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI;
import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_OTHER_EMERGENCY;
import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_TEST_MESSAGE;
import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_TSUNAMI;
import android.content.Context;
import android.content.res.Resources;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.util.Pair;
import com.android.internal.R;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.SmsConstants;
@@ -54,24 +63,50 @@ public class GsmSmsCbMessage {
/** Utility class with only static methods. */
private GsmSmsCbMessage() { }
/**
* Get built-in ETWS primary messages by category. ETWS primary message does not contain text,
* so we have to show the pre-built messages to the user.
*
* @param context Device context
* @param category ETWS message category defined in SmsCbConstants
* @return ETWS text message in string. Return an empty string if no match.
*/
private static String getEtwsPrimaryMessage(Context context, int category) {
final Resources r = context.getResources();
switch (category) {
case ETWS_WARNING_TYPE_EARTHQUAKE:
return r.getString(R.string.etws_primary_default_message_earthquake);
case ETWS_WARNING_TYPE_TSUNAMI:
return r.getString(R.string.etws_primary_default_message_tsunami);
case ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI:
return r.getString(R.string.etws_primary_default_message_earthquake_and_tsunami);
case ETWS_WARNING_TYPE_TEST_MESSAGE:
return r.getString(R.string.etws_primary_default_message_test);
case ETWS_WARNING_TYPE_OTHER_EMERGENCY:
return r.getString(R.string.etws_primary_default_message_others);
default:
return "";
}
}
/**
* Create a new SmsCbMessage object from a header object plus one or more received PDUs.
*
* @param pdus PDU bytes
*/
public static SmsCbMessage createSmsCbMessage(SmsCbHeader header, SmsCbLocation location,
byte[][] pdus) throws IllegalArgumentException {
public static SmsCbMessage createSmsCbMessage(Context context, SmsCbHeader header,
SmsCbLocation location, byte[][] pdus)
throws IllegalArgumentException {
if (header.isEtwsPrimaryNotification()) {
// ETSI TS 23.041 ETWS Primary Notification message
// ETWS primary message only contains 4 fields including serial number,
// message identifier, warning type, and warning security information.
// There is no field for the content/text. We hardcode "ETWS" in the
// text body so the user won't see an empty dialog without any text.
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP,
header.getGeographicalScope(), header.getSerialNumber(),
location, header.getServiceCategory(),
null, "ETWS", SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY,
header.getEtwsInfo(), header.getCmasInfo());
// There is no field for the content/text so we get the text from the resources.
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP, header.getGeographicalScope(),
header.getSerialNumber(), location, header.getServiceCategory(), null,
getEtwsPrimaryMessage(context, header.getEtwsInfo().getWarningType()),
SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, header.getEtwsInfo(),
header.getCmasInfo());
} else {
String language = null;
StringBuilder sb = new StringBuilder();
@@ -90,19 +125,6 @@ public class GsmSmsCbMessage {
}
}
/**
* Create a new SmsCbMessage object from one or more received PDUs. This is used by some
* CellBroadcastReceiver test cases, because SmsCbHeader is now package local.
*
* @param location the location (geographical scope) for the message
* @param pdus PDU bytes
*/
public static SmsCbMessage createSmsCbMessage(SmsCbLocation location, byte[][] pdus)
throws IllegalArgumentException {
SmsCbHeader header = new SmsCbHeader(pdus[0]);
return createSmsCbMessage(header, location, pdus);
}
/**
* Parse and unpack the body text according to the encoding in the DCS.
* After completing successfully this method will have assigned the body