Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b981e2a5 authored by Jack Yu's avatar Jack Yu
Browse files

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
Merged-In: I0bd0a6655bc4a327124b2a145fa3892c177c4fdb
Change-Id: I0bd0a6655bc4a327124b2a145fa3892c177c4fdb
parent 93fc20f2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import android.os.Message;
import android.telephony.CellLocation;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;

import com.android.internal.telephony.CellBroadcastHandler;
import com.android.internal.telephony.Phone;
@@ -185,7 +185,7 @@ public class GsmCellBroadcastHandler extends CellBroadcastHandler {
                }
            }

            return GsmSmsCbMessage.createSmsCbMessage(header, location, pdus);
            return GsmSmsCbMessage.createSmsCbMessage(mContext, header, location, pdus);

        } catch (RuntimeException e) {
            loge("Error in decoding SMS CB pdu", e);
+44 −22
Original line number Diff line number Diff line
@@ -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
+3 −3
Original line number Diff line number Diff line
@@ -38,18 +38,18 @@ public class GsmSmsCbTest extends AndroidTestCase {

    private static final SmsCbLocation sTestLocation = new SmsCbLocation("94040", 1234, 5678);

    private static SmsCbMessage createFromPdu(byte[] pdu) {
    private SmsCbMessage createFromPdu(byte[] pdu) {
        try {
            SmsCbHeader header = new SmsCbHeader(pdu);
            byte[][] pdus = new byte[1][];
            pdus[0] = pdu;
            return GsmSmsCbMessage.createSmsCbMessage(header, sTestLocation, pdus);
            return GsmSmsCbMessage.createSmsCbMessage(getContext(), header, sTestLocation, pdus);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    private static void doTestGeographicalScopeValue(byte[] pdu, byte b, int expectedGs) {
    private void doTestGeographicalScopeValue(byte[] pdu, byte b, int expectedGs) {
        pdu[0] = b;
        SmsCbMessage msg = createFromPdu(pdu);