From e3070ede55652bb00618eadfac9daee64320569f Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 17 Mar 2017 23:21:48 -0700 Subject: [PATCH] Added ETWS primary message default message support ETWS primary message does not contain messagy body. We used to use hardcoded "ETWS" as the body, which is not easy for end users to understand what happened. Added the built-in default messages provided by Japanese government guideline for earthquake, Tsunami, test, and other channels support to enhance the user experience. Test: manual bug: 33595007 Change-Id: I53659298d8ce3b3ba5c751c14c1b36e76d6dc562 --- core/res/res/values/strings.xml | 16 ++++- core/res/res/values/symbols.xml | 10 +++ .../telephony/gsm/GsmSmsCbMessage.java | 66 ++++++++++++------- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 30b27781127b8..a9a7116541372 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -392,7 +392,7 @@ This indicates that a work profile has been deleted. [CHAR LIMIT=NONE]--> Your work profile is no longer available on this device. - Device is managed credit card + + Stay calm and seek shelter nearby. + + + Evacuate immediately from coastal regions and riverside areas to a safer place such as high ground. + + + Stay calm and seek shelter nearby. + + + Emergency messages test + + + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index f6f29d9d36358..6acccd1a71e43 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2919,4 +2919,14 @@ + + + + + + + + + + diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmSmsCbMessage.java b/telephony/java/com/android/internal/telephony/gsm/GsmSmsCbMessage.java index 15ed810988134..6bf22a05beec9 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmSmsCbMessage.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmSmsCbMessage.java @@ -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