Loading core/java/android/provider/Telephony.java +24 −4 Original line number Diff line number Diff line Loading @@ -596,8 +596,8 @@ public final class Telephony { * values:</p> * * <ul> * <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * <li><em>message</em> - An SmsCbMessage object containing the broadcast message * data. This is not an emergency alert, so ETWS and CMAS data will be null.</li> * </ul> * * <p>The extra values can be extracted using Loading @@ -616,8 +616,8 @@ public final class Telephony { * values:</p> * * <ul> * <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * <li><em>message</em> - An SmsCbMessage object containing the broadcast message * data, including ETWS or CMAS warning notification info if present.</li> * </ul> * * <p>The extra values can be extracted using Loading @@ -630,6 +630,26 @@ public final class Telephony { public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED"; /** * Broadcast Action: A new CDMA SMS has been received containing Service Category * Program Data (updates the list of enabled broadcast channels). The intent will * have the following extra values:</p> * * <ul> * <li><em>operations</em> - An array of CdmaSmsCbProgramData objects containing * the service category operations (add/delete/clear) to perform.</li> * </ul> * * <p>The extra values can be extracted using * {@link #getMessagesFromIntent(Intent)}.</p> * * <p>If a BroadcastReceiver encounters an error while processing * this intent it should set the result code appropriately.</p> */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION = "android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED"; /** * Broadcast Action: The SIM storage for SMS messages is full. If * space is not freed, messages targeted for the SIM (class 2) may Loading core/java/com/android/internal/util/BitwiseOutputStream.java +1 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ public class BitwiseOutputStream { byte[] newBuf = new byte[(mPos + bits) >>> 2]; System.arraycopy(mBuf, 0, newBuf, 0, mEnd >>> 3); mBuf = newBuf; mEnd = newBuf.length << 3; } /** Loading core/tests/coretests/src/com/android/internal/util/BitwiseStreamsTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -133,4 +133,25 @@ public class BitwiseStreamsTest extends AndroidTestCase { long end = android.os.SystemClock.elapsedRealtime(); Log.d(LOG_TAG, "repeated encode-decode took " + (end - start) + " ms"); } @SmallTest public void testExpandArray() throws Exception { Random random = new Random(); int iterations = 10000; int[] sizeArr = new int[iterations]; int[] valueArr = new int[iterations]; BitwiseOutputStream outStream = new BitwiseOutputStream(8); for (int i = 0; i < iterations; i++) { int x = random.nextInt(); int size = (x & 0x07) + 1; int value = x & (-1 >>> (32 - size)); sizeArr[i] = size; valueArr[i] = value; outStream.write(size, value); } BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray()); for (int i = 0; i < iterations; i++) { assertEquals(valueArr[i], inStream.read(sizeArr[i])); } } } telephony/java/android/telephony/SmsCbCmasInfo.java 0 → 100644 +308 −0 Original line number Diff line number Diff line /* * 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 android.telephony; import android.os.Parcel; import android.os.Parcelable; /** * Contains CMAS warning notification Type 1 elements for a {@link SmsCbMessage}. * Supported values for each element are defined in TIA-1149-0-1 (CMAS over CDMA) and * 3GPP TS 23.041 (for GSM/UMTS). * * {@hide} */ public class SmsCbCmasInfo implements Parcelable { // CMAS message class (in GSM/UMTS message identifier or CDMA service category). /** Presidential-level alert (Korean Public Alert System Class 0 message). */ public static final int CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT = 0x00; /** Extreme threat to life and property (Korean Public Alert System Class 1 message). */ public static final int CMAS_CLASS_EXTREME_THREAT = 0x01; /** Severe threat to life and property (Korean Public Alert System Class 1 message). */ public static final int CMAS_CLASS_SEVERE_THREAT = 0x02; /** Child abduction emergency (AMBER Alert). */ public static final int CMAS_CLASS_CHILD_ABDUCTION_EMERGENCY = 0x03; /** CMAS test message. */ public static final int CMAS_CLASS_REQUIRED_MONTHLY_TEST = 0x04; /** CMAS exercise. */ public static final int CMAS_CLASS_CMAS_EXERCISE = 0x05; /** CMAS category for operator defined use. */ public static final int CMAS_CLASS_OPERATOR_DEFINED_USE = 0x06; /** CMAS category for warning types that are reserved for future extension. */ public static final int CMAS_CLASS_UNKNOWN = -1; // CMAS alert category (in CDMA type 1 elements record). /** CMAS alert category: Geophysical including landslide. */ public static final int CMAS_CATEGORY_GEO = 0x00; /** CMAS alert category: Meteorological including flood. */ public static final int CMAS_CATEGORY_MET = 0x01; /** CMAS alert category: General emergency and public safety. */ public static final int CMAS_CATEGORY_SAFETY = 0x02; /** CMAS alert category: Law enforcement, military, homeland/local/private security. */ public static final int CMAS_CATEGORY_SECURITY = 0x03; /** CMAS alert category: Rescue and recovery. */ public static final int CMAS_CATEGORY_RESCUE = 0x04; /** CMAS alert category: Fire suppression and rescue. */ public static final int CMAS_CATEGORY_FIRE = 0x05; /** CMAS alert category: Medical and public health. */ public static final int CMAS_CATEGORY_HEALTH = 0x06; /** CMAS alert category: Pollution and other environmental. */ public static final int CMAS_CATEGORY_ENV = 0x07; /** CMAS alert category: Public and private transportation. */ public static final int CMAS_CATEGORY_TRANSPORT = 0x08; /** CMAS alert category: Utility, telecom, other non-transport infrastructure. */ public static final int CMAS_CATEGORY_INFRA = 0x09; /** CMAS alert category: Chem, bio, radiological, nuclear, high explosive threat or attack. */ public static final int CMAS_CATEGORY_CBRNE = 0x0a; /** CMAS alert category: Other events. */ public static final int CMAS_CATEGORY_OTHER = 0x0b; /** * CMAS alert category is unknown. The category is only available for CDMA broadcasts * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown. */ public static final int CMAS_CATEGORY_UNKNOWN = -1; // CMAS response type (in CDMA type 1 elements record). /** CMAS response type: Take shelter in place. */ public static final int CMAS_RESPONSE_TYPE_SHELTER = 0x00; /** CMAS response type: Evacuate (Relocate). */ public static final int CMAS_RESPONSE_TYPE_EVACUATE = 0x01; /** CMAS response type: Make preparations. */ public static final int CMAS_RESPONSE_TYPE_PREPARE = 0x02; /** CMAS response type: Execute a pre-planned activity. */ public static final int CMAS_RESPONSE_TYPE_EXECUTE = 0x03; /** CMAS response type: Attend to information sources. */ public static final int CMAS_RESPONSE_TYPE_MONITOR = 0x04; /** CMAS response type: Avoid hazard. */ public static final int CMAS_RESPONSE_TYPE_AVOID = 0x05; /** CMAS response type: Evaluate the information in this message (not for public warnings). */ public static final int CMAS_RESPONSE_TYPE_ASSESS = 0x06; /** CMAS response type: No action recommended. */ public static final int CMAS_RESPONSE_TYPE_NONE = 0x07; /** * CMAS response type is unknown. The response type is only available for CDMA broadcasts * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown. */ public static final int CMAS_RESPONSE_TYPE_UNKNOWN = -1; // 4-bit CMAS severity (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS severity type: Extraordinary threat to life or property. */ public static final int CMAS_SEVERITY_EXTREME = 0x0; /** CMAS severity type: Significant threat to life or property. */ public static final int CMAS_SEVERITY_SEVERE = 0x1; /** * CMAS alert severity is unknown. The severity is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_SEVERITY_UNKNOWN = -1; // CMAS urgency (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS urgency type: Responsive action should be taken immediately. */ public static final int CMAS_URGENCY_IMMEDIATE = 0x0; /** CMAS urgency type: Responsive action should be taken within the next hour. */ public static final int CMAS_URGENCY_EXPECTED = 0x1; /** * CMAS alert urgency is unknown. The urgency is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_URGENCY_UNKNOWN = -1; // CMAS certainty (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS certainty type: Determined to have occurred or to be ongoing. */ public static final int CMAS_CERTAINTY_OBSERVED = 0x0; /** CMAS certainty type: Likely (probability > ~50%). */ public static final int CMAS_CERTAINTY_LIKELY = 0x1; /** * CMAS alert certainty is unknown. The certainty is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_CERTAINTY_UNKNOWN = -1; /** CMAS message class. */ private final int mMessageClass; /** CMAS category. */ private final int mCategory; /** CMAS response type. */ private final int mResponseType; /** CMAS severity. */ private final int mSeverity; /** CMAS urgency. */ private final int mUrgency; /** CMAS certainty. */ private final int mCertainty; /** Create a new SmsCbCmasInfo object with the specified values. */ public SmsCbCmasInfo(int messageClass, int category, int responseType, int severity, int urgency, int certainty) { mMessageClass = messageClass; mCategory = category; mResponseType = responseType; mSeverity = severity; mUrgency = urgency; mCertainty = certainty; } /** Create a new SmsCbCmasInfo object from a Parcel. */ SmsCbCmasInfo(Parcel in) { mMessageClass = in.readInt(); mCategory = in.readInt(); mResponseType = in.readInt(); mSeverity = in.readInt(); mUrgency = in.readInt(); mCertainty = in.readInt(); } /** * Flatten this object into a Parcel. * * @param dest The Parcel in which the object should be written. * @param flags Additional flags about how the object should be written (ignored). */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mMessageClass); dest.writeInt(mCategory); dest.writeInt(mResponseType); dest.writeInt(mSeverity); dest.writeInt(mUrgency); dest.writeInt(mCertainty); } /** * Returns the CMAS message class, e.g. {@link #CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT}. * @return one of the {@code CMAS_CLASS} values */ public int getMessageClass() { return mMessageClass; } /** * Returns the CMAS category, e.g. {@link #CMAS_CATEGORY_GEO}. * @return one of the {@code CMAS_CATEGORY} values */ public int getCategory() { return mCategory; } /** * Returns the CMAS response type, e.g. {@link #CMAS_RESPONSE_TYPE_SHELTER}. * @return one of the {@code CMAS_RESPONSE_TYPE} values */ public int getResponseType() { return mResponseType; } /** * Returns the CMAS severity, e.g. {@link #CMAS_SEVERITY_EXTREME}. * @return one of the {@code CMAS_SEVERITY} values */ public int getSeverity() { return mSeverity; } /** * Returns the CMAS urgency, e.g. {@link #CMAS_URGENCY_IMMEDIATE}. * @return one of the {@code CMAS_URGENCY} values */ public int getUrgency() { return mUrgency; } /** * Returns the CMAS certainty, e.g. {@link #CMAS_CERTAINTY_OBSERVED}. * @return one of the {@code CMAS_CERTAINTY} values */ public int getCertainty() { return mCertainty; } @Override public String toString() { return "SmsCbCmasInfo{messageClass=" + mMessageClass + ", category=" + mCategory + ", responseType=" + mResponseType + ", severity=" + mSeverity + ", urgency=" + mUrgency + ", certainty=" + mCertainty + '}'; } /** * Describe the kinds of special objects contained in the marshalled representation. * @return a bitmask indicating this Parcelable contains no special objects */ @Override public int describeContents() { return 0; } /** Creator for unparcelling objects. */ public static final Parcelable.Creator<SmsCbCmasInfo> CREATOR = new Parcelable.Creator<SmsCbCmasInfo>() { public SmsCbCmasInfo createFromParcel(Parcel in) { return new SmsCbCmasInfo(in); } public SmsCbCmasInfo[] newArray(int size) { return new SmsCbCmasInfo[size]; } }; } telephony/java/android/telephony/SmsCbEtwsInfo.java 0 → 100644 +206 −0 Original line number Diff line number Diff line /* * 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 android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.text.format.Time; import com.android.internal.telephony.IccUtils; import java.util.Arrays; /** * Contains information elements for a GSM or UMTS ETWS warning notification. * Supported values for each element are defined in 3GPP TS 23.041. * * {@hide} */ public class SmsCbEtwsInfo implements Parcelable { /** ETWS warning type for earthquake. */ public static final int ETWS_WARNING_TYPE_EARTHQUAKE = 0x00; /** ETWS warning type for tsunami. */ public static final int ETWS_WARNING_TYPE_TSUNAMI = 0x01; /** ETWS warning type for earthquake and tsunami. */ public static final int ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI = 0x02; /** ETWS warning type for test messages. */ public static final int ETWS_WARNING_TYPE_TEST_MESSAGE = 0x03; /** ETWS warning type for other emergency types. */ public static final int ETWS_WARNING_TYPE_OTHER_EMERGENCY = 0x04; /** Unknown ETWS warning type. */ public static final int ETWS_WARNING_TYPE_UNKNOWN = -1; /** One of the ETWS warning type constants defined in this class. */ private final int mWarningType; /** Whether or not to activate the emergency user alert tone and vibration. */ private final boolean mEmergencyUserAlert; /** Whether or not to activate a popup alert. */ private final boolean mActivatePopup; /** * 50-byte security information (ETWS primary notification for GSM only). As of Release 10, * 3GPP TS 23.041 states that the UE shall ignore the ETWS primary notification timestamp * and digital signature if received. Therefore it is treated as a raw byte array and * parceled with the broadcast intent if present, but the timestamp is only computed if an * application asks for the individual components. */ private final byte[] mWarningSecurityInformation; /** Create a new SmsCbEtwsInfo object with the specified values. */ public SmsCbEtwsInfo(int warningType, boolean emergencyUserAlert, boolean activatePopup, byte[] warningSecurityInformation) { mWarningType = warningType; mEmergencyUserAlert = emergencyUserAlert; mActivatePopup = activatePopup; mWarningSecurityInformation = warningSecurityInformation; } /** Create a new SmsCbEtwsInfo object from a Parcel. */ SmsCbEtwsInfo(Parcel in) { mWarningType = in.readInt(); mEmergencyUserAlert = (in.readInt() != 0); mActivatePopup = (in.readInt() != 0); mWarningSecurityInformation = in.createByteArray(); } /** * Flatten this object into a Parcel. * * @param dest The Parcel in which the object should be written. * @param flags Additional flags about how the object should be written (ignored). */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mWarningType); dest.writeInt(mEmergencyUserAlert ? 1 : 0); dest.writeInt(mActivatePopup ? 1 : 0); dest.writeByteArray(mWarningSecurityInformation); } /** * Returns the ETWS warning type. * @return a warning type such as {@link #ETWS_WARNING_TYPE_EARTHQUAKE} */ public int getWarningType() { return mWarningType; } /** * Returns the ETWS emergency user alert flag. * @return true to notify terminal to activate emergency user alert; false otherwise */ public boolean isEmergencyUserAlert() { return mEmergencyUserAlert; } /** * Returns the ETWS activate popup flag. * @return true to notify terminal to activate display popup; false otherwise */ public boolean isPopupAlert() { return mActivatePopup; } /** * Returns the Warning-Security-Information timestamp (GSM primary notifications only). * As of Release 10, 3GPP TS 23.041 states that the UE shall ignore this value if received. * @return a UTC timestamp in System.currentTimeMillis() format, or 0 if not present */ public long getPrimaryNotificationTimestamp() { if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 7) { return 0; } int year = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[0]); int month = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[1]); int day = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[2]); int hour = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[3]); int minute = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[4]); int second = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[5]); // For the timezone, the most significant bit of the // least significant nibble is the sign byte // (meaning the max range of this field is 79 quarter-hours, // which is more than enough) byte tzByte = mWarningSecurityInformation[6]; // Mask out sign bit. int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08))); timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset; Time time = new Time(Time.TIMEZONE_UTC); // We only need to support years above 2000. time.year = year + 2000; time.month = month - 1; time.monthDay = day; time.hour = hour; time.minute = minute; time.second = second; // Timezone offset is in quarter hours. return time.toMillis(true) - (long) (timezoneOffset * 15 * 60 * 1000); } /** * Returns the digital signature (GSM primary notifications only). As of Release 10, * 3GPP TS 23.041 states that the UE shall ignore this value if received. * @return a byte array containing a copy of the primary notification digital signature */ public byte[] getPrimaryNotificationSignature() { if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 50) { return null; } return Arrays.copyOfRange(mWarningSecurityInformation, 7, 50); } @Override public String toString() { return "SmsCbEtwsInfo{warningType=" + mWarningType + ", emergencyUserAlert=" + mEmergencyUserAlert + ", activatePopup=" + mActivatePopup + '}'; } /** * Describe the kinds of special objects contained in the marshalled representation. * @return a bitmask indicating this Parcelable contains no special objects */ @Override public int describeContents() { return 0; } /** Creator for unparcelling objects. */ public static final Creator<SmsCbEtwsInfo> CREATOR = new Creator<SmsCbEtwsInfo>() { public SmsCbEtwsInfo createFromParcel(Parcel in) { return new SmsCbEtwsInfo(in); } public SmsCbEtwsInfo[] newArray(int size) { return new SmsCbEtwsInfo[size]; } }; } Loading
core/java/android/provider/Telephony.java +24 −4 Original line number Diff line number Diff line Loading @@ -596,8 +596,8 @@ public final class Telephony { * values:</p> * * <ul> * <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * <li><em>message</em> - An SmsCbMessage object containing the broadcast message * data. This is not an emergency alert, so ETWS and CMAS data will be null.</li> * </ul> * * <p>The extra values can be extracted using Loading @@ -616,8 +616,8 @@ public final class Telephony { * values:</p> * * <ul> * <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs * that make up the message.</li> * <li><em>message</em> - An SmsCbMessage object containing the broadcast message * data, including ETWS or CMAS warning notification info if present.</li> * </ul> * * <p>The extra values can be extracted using Loading @@ -630,6 +630,26 @@ public final class Telephony { public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED"; /** * Broadcast Action: A new CDMA SMS has been received containing Service Category * Program Data (updates the list of enabled broadcast channels). The intent will * have the following extra values:</p> * * <ul> * <li><em>operations</em> - An array of CdmaSmsCbProgramData objects containing * the service category operations (add/delete/clear) to perform.</li> * </ul> * * <p>The extra values can be extracted using * {@link #getMessagesFromIntent(Intent)}.</p> * * <p>If a BroadcastReceiver encounters an error while processing * this intent it should set the result code appropriately.</p> */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION = "android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED"; /** * Broadcast Action: The SIM storage for SMS messages is full. If * space is not freed, messages targeted for the SIM (class 2) may Loading
core/java/com/android/internal/util/BitwiseOutputStream.java +1 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ public class BitwiseOutputStream { byte[] newBuf = new byte[(mPos + bits) >>> 2]; System.arraycopy(mBuf, 0, newBuf, 0, mEnd >>> 3); mBuf = newBuf; mEnd = newBuf.length << 3; } /** Loading
core/tests/coretests/src/com/android/internal/util/BitwiseStreamsTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -133,4 +133,25 @@ public class BitwiseStreamsTest extends AndroidTestCase { long end = android.os.SystemClock.elapsedRealtime(); Log.d(LOG_TAG, "repeated encode-decode took " + (end - start) + " ms"); } @SmallTest public void testExpandArray() throws Exception { Random random = new Random(); int iterations = 10000; int[] sizeArr = new int[iterations]; int[] valueArr = new int[iterations]; BitwiseOutputStream outStream = new BitwiseOutputStream(8); for (int i = 0; i < iterations; i++) { int x = random.nextInt(); int size = (x & 0x07) + 1; int value = x & (-1 >>> (32 - size)); sizeArr[i] = size; valueArr[i] = value; outStream.write(size, value); } BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray()); for (int i = 0; i < iterations; i++) { assertEquals(valueArr[i], inStream.read(sizeArr[i])); } } }
telephony/java/android/telephony/SmsCbCmasInfo.java 0 → 100644 +308 −0 Original line number Diff line number Diff line /* * 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 android.telephony; import android.os.Parcel; import android.os.Parcelable; /** * Contains CMAS warning notification Type 1 elements for a {@link SmsCbMessage}. * Supported values for each element are defined in TIA-1149-0-1 (CMAS over CDMA) and * 3GPP TS 23.041 (for GSM/UMTS). * * {@hide} */ public class SmsCbCmasInfo implements Parcelable { // CMAS message class (in GSM/UMTS message identifier or CDMA service category). /** Presidential-level alert (Korean Public Alert System Class 0 message). */ public static final int CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT = 0x00; /** Extreme threat to life and property (Korean Public Alert System Class 1 message). */ public static final int CMAS_CLASS_EXTREME_THREAT = 0x01; /** Severe threat to life and property (Korean Public Alert System Class 1 message). */ public static final int CMAS_CLASS_SEVERE_THREAT = 0x02; /** Child abduction emergency (AMBER Alert). */ public static final int CMAS_CLASS_CHILD_ABDUCTION_EMERGENCY = 0x03; /** CMAS test message. */ public static final int CMAS_CLASS_REQUIRED_MONTHLY_TEST = 0x04; /** CMAS exercise. */ public static final int CMAS_CLASS_CMAS_EXERCISE = 0x05; /** CMAS category for operator defined use. */ public static final int CMAS_CLASS_OPERATOR_DEFINED_USE = 0x06; /** CMAS category for warning types that are reserved for future extension. */ public static final int CMAS_CLASS_UNKNOWN = -1; // CMAS alert category (in CDMA type 1 elements record). /** CMAS alert category: Geophysical including landslide. */ public static final int CMAS_CATEGORY_GEO = 0x00; /** CMAS alert category: Meteorological including flood. */ public static final int CMAS_CATEGORY_MET = 0x01; /** CMAS alert category: General emergency and public safety. */ public static final int CMAS_CATEGORY_SAFETY = 0x02; /** CMAS alert category: Law enforcement, military, homeland/local/private security. */ public static final int CMAS_CATEGORY_SECURITY = 0x03; /** CMAS alert category: Rescue and recovery. */ public static final int CMAS_CATEGORY_RESCUE = 0x04; /** CMAS alert category: Fire suppression and rescue. */ public static final int CMAS_CATEGORY_FIRE = 0x05; /** CMAS alert category: Medical and public health. */ public static final int CMAS_CATEGORY_HEALTH = 0x06; /** CMAS alert category: Pollution and other environmental. */ public static final int CMAS_CATEGORY_ENV = 0x07; /** CMAS alert category: Public and private transportation. */ public static final int CMAS_CATEGORY_TRANSPORT = 0x08; /** CMAS alert category: Utility, telecom, other non-transport infrastructure. */ public static final int CMAS_CATEGORY_INFRA = 0x09; /** CMAS alert category: Chem, bio, radiological, nuclear, high explosive threat or attack. */ public static final int CMAS_CATEGORY_CBRNE = 0x0a; /** CMAS alert category: Other events. */ public static final int CMAS_CATEGORY_OTHER = 0x0b; /** * CMAS alert category is unknown. The category is only available for CDMA broadcasts * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown. */ public static final int CMAS_CATEGORY_UNKNOWN = -1; // CMAS response type (in CDMA type 1 elements record). /** CMAS response type: Take shelter in place. */ public static final int CMAS_RESPONSE_TYPE_SHELTER = 0x00; /** CMAS response type: Evacuate (Relocate). */ public static final int CMAS_RESPONSE_TYPE_EVACUATE = 0x01; /** CMAS response type: Make preparations. */ public static final int CMAS_RESPONSE_TYPE_PREPARE = 0x02; /** CMAS response type: Execute a pre-planned activity. */ public static final int CMAS_RESPONSE_TYPE_EXECUTE = 0x03; /** CMAS response type: Attend to information sources. */ public static final int CMAS_RESPONSE_TYPE_MONITOR = 0x04; /** CMAS response type: Avoid hazard. */ public static final int CMAS_RESPONSE_TYPE_AVOID = 0x05; /** CMAS response type: Evaluate the information in this message (not for public warnings). */ public static final int CMAS_RESPONSE_TYPE_ASSESS = 0x06; /** CMAS response type: No action recommended. */ public static final int CMAS_RESPONSE_TYPE_NONE = 0x07; /** * CMAS response type is unknown. The response type is only available for CDMA broadcasts * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown. */ public static final int CMAS_RESPONSE_TYPE_UNKNOWN = -1; // 4-bit CMAS severity (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS severity type: Extraordinary threat to life or property. */ public static final int CMAS_SEVERITY_EXTREME = 0x0; /** CMAS severity type: Significant threat to life or property. */ public static final int CMAS_SEVERITY_SEVERE = 0x1; /** * CMAS alert severity is unknown. The severity is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_SEVERITY_UNKNOWN = -1; // CMAS urgency (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS urgency type: Responsive action should be taken immediately. */ public static final int CMAS_URGENCY_IMMEDIATE = 0x0; /** CMAS urgency type: Responsive action should be taken within the next hour. */ public static final int CMAS_URGENCY_EXPECTED = 0x1; /** * CMAS alert urgency is unknown. The urgency is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_URGENCY_UNKNOWN = -1; // CMAS certainty (in GSM/UMTS message identifier or CDMA type 1 elements record). /** CMAS certainty type: Determined to have occurred or to be ongoing. */ public static final int CMAS_CERTAINTY_OBSERVED = 0x0; /** CMAS certainty type: Likely (probability > ~50%). */ public static final int CMAS_CERTAINTY_LIKELY = 0x1; /** * CMAS alert certainty is unknown. The certainty is available for CDMA warning alerts * containing a type 1 elements record and for all GSM and UMTS alerts except for the * Presidential-level alert class (Korean Public Alert System Class 0). */ public static final int CMAS_CERTAINTY_UNKNOWN = -1; /** CMAS message class. */ private final int mMessageClass; /** CMAS category. */ private final int mCategory; /** CMAS response type. */ private final int mResponseType; /** CMAS severity. */ private final int mSeverity; /** CMAS urgency. */ private final int mUrgency; /** CMAS certainty. */ private final int mCertainty; /** Create a new SmsCbCmasInfo object with the specified values. */ public SmsCbCmasInfo(int messageClass, int category, int responseType, int severity, int urgency, int certainty) { mMessageClass = messageClass; mCategory = category; mResponseType = responseType; mSeverity = severity; mUrgency = urgency; mCertainty = certainty; } /** Create a new SmsCbCmasInfo object from a Parcel. */ SmsCbCmasInfo(Parcel in) { mMessageClass = in.readInt(); mCategory = in.readInt(); mResponseType = in.readInt(); mSeverity = in.readInt(); mUrgency = in.readInt(); mCertainty = in.readInt(); } /** * Flatten this object into a Parcel. * * @param dest The Parcel in which the object should be written. * @param flags Additional flags about how the object should be written (ignored). */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mMessageClass); dest.writeInt(mCategory); dest.writeInt(mResponseType); dest.writeInt(mSeverity); dest.writeInt(mUrgency); dest.writeInt(mCertainty); } /** * Returns the CMAS message class, e.g. {@link #CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT}. * @return one of the {@code CMAS_CLASS} values */ public int getMessageClass() { return mMessageClass; } /** * Returns the CMAS category, e.g. {@link #CMAS_CATEGORY_GEO}. * @return one of the {@code CMAS_CATEGORY} values */ public int getCategory() { return mCategory; } /** * Returns the CMAS response type, e.g. {@link #CMAS_RESPONSE_TYPE_SHELTER}. * @return one of the {@code CMAS_RESPONSE_TYPE} values */ public int getResponseType() { return mResponseType; } /** * Returns the CMAS severity, e.g. {@link #CMAS_SEVERITY_EXTREME}. * @return one of the {@code CMAS_SEVERITY} values */ public int getSeverity() { return mSeverity; } /** * Returns the CMAS urgency, e.g. {@link #CMAS_URGENCY_IMMEDIATE}. * @return one of the {@code CMAS_URGENCY} values */ public int getUrgency() { return mUrgency; } /** * Returns the CMAS certainty, e.g. {@link #CMAS_CERTAINTY_OBSERVED}. * @return one of the {@code CMAS_CERTAINTY} values */ public int getCertainty() { return mCertainty; } @Override public String toString() { return "SmsCbCmasInfo{messageClass=" + mMessageClass + ", category=" + mCategory + ", responseType=" + mResponseType + ", severity=" + mSeverity + ", urgency=" + mUrgency + ", certainty=" + mCertainty + '}'; } /** * Describe the kinds of special objects contained in the marshalled representation. * @return a bitmask indicating this Parcelable contains no special objects */ @Override public int describeContents() { return 0; } /** Creator for unparcelling objects. */ public static final Parcelable.Creator<SmsCbCmasInfo> CREATOR = new Parcelable.Creator<SmsCbCmasInfo>() { public SmsCbCmasInfo createFromParcel(Parcel in) { return new SmsCbCmasInfo(in); } public SmsCbCmasInfo[] newArray(int size) { return new SmsCbCmasInfo[size]; } }; }
telephony/java/android/telephony/SmsCbEtwsInfo.java 0 → 100644 +206 −0 Original line number Diff line number Diff line /* * 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 android.telephony; import android.os.Parcel; import android.os.Parcelable; import android.text.format.Time; import com.android.internal.telephony.IccUtils; import java.util.Arrays; /** * Contains information elements for a GSM or UMTS ETWS warning notification. * Supported values for each element are defined in 3GPP TS 23.041. * * {@hide} */ public class SmsCbEtwsInfo implements Parcelable { /** ETWS warning type for earthquake. */ public static final int ETWS_WARNING_TYPE_EARTHQUAKE = 0x00; /** ETWS warning type for tsunami. */ public static final int ETWS_WARNING_TYPE_TSUNAMI = 0x01; /** ETWS warning type for earthquake and tsunami. */ public static final int ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI = 0x02; /** ETWS warning type for test messages. */ public static final int ETWS_WARNING_TYPE_TEST_MESSAGE = 0x03; /** ETWS warning type for other emergency types. */ public static final int ETWS_WARNING_TYPE_OTHER_EMERGENCY = 0x04; /** Unknown ETWS warning type. */ public static final int ETWS_WARNING_TYPE_UNKNOWN = -1; /** One of the ETWS warning type constants defined in this class. */ private final int mWarningType; /** Whether or not to activate the emergency user alert tone and vibration. */ private final boolean mEmergencyUserAlert; /** Whether or not to activate a popup alert. */ private final boolean mActivatePopup; /** * 50-byte security information (ETWS primary notification for GSM only). As of Release 10, * 3GPP TS 23.041 states that the UE shall ignore the ETWS primary notification timestamp * and digital signature if received. Therefore it is treated as a raw byte array and * parceled with the broadcast intent if present, but the timestamp is only computed if an * application asks for the individual components. */ private final byte[] mWarningSecurityInformation; /** Create a new SmsCbEtwsInfo object with the specified values. */ public SmsCbEtwsInfo(int warningType, boolean emergencyUserAlert, boolean activatePopup, byte[] warningSecurityInformation) { mWarningType = warningType; mEmergencyUserAlert = emergencyUserAlert; mActivatePopup = activatePopup; mWarningSecurityInformation = warningSecurityInformation; } /** Create a new SmsCbEtwsInfo object from a Parcel. */ SmsCbEtwsInfo(Parcel in) { mWarningType = in.readInt(); mEmergencyUserAlert = (in.readInt() != 0); mActivatePopup = (in.readInt() != 0); mWarningSecurityInformation = in.createByteArray(); } /** * Flatten this object into a Parcel. * * @param dest The Parcel in which the object should be written. * @param flags Additional flags about how the object should be written (ignored). */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mWarningType); dest.writeInt(mEmergencyUserAlert ? 1 : 0); dest.writeInt(mActivatePopup ? 1 : 0); dest.writeByteArray(mWarningSecurityInformation); } /** * Returns the ETWS warning type. * @return a warning type such as {@link #ETWS_WARNING_TYPE_EARTHQUAKE} */ public int getWarningType() { return mWarningType; } /** * Returns the ETWS emergency user alert flag. * @return true to notify terminal to activate emergency user alert; false otherwise */ public boolean isEmergencyUserAlert() { return mEmergencyUserAlert; } /** * Returns the ETWS activate popup flag. * @return true to notify terminal to activate display popup; false otherwise */ public boolean isPopupAlert() { return mActivatePopup; } /** * Returns the Warning-Security-Information timestamp (GSM primary notifications only). * As of Release 10, 3GPP TS 23.041 states that the UE shall ignore this value if received. * @return a UTC timestamp in System.currentTimeMillis() format, or 0 if not present */ public long getPrimaryNotificationTimestamp() { if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 7) { return 0; } int year = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[0]); int month = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[1]); int day = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[2]); int hour = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[3]); int minute = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[4]); int second = IccUtils.gsmBcdByteToInt(mWarningSecurityInformation[5]); // For the timezone, the most significant bit of the // least significant nibble is the sign byte // (meaning the max range of this field is 79 quarter-hours, // which is more than enough) byte tzByte = mWarningSecurityInformation[6]; // Mask out sign bit. int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08))); timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset; Time time = new Time(Time.TIMEZONE_UTC); // We only need to support years above 2000. time.year = year + 2000; time.month = month - 1; time.monthDay = day; time.hour = hour; time.minute = minute; time.second = second; // Timezone offset is in quarter hours. return time.toMillis(true) - (long) (timezoneOffset * 15 * 60 * 1000); } /** * Returns the digital signature (GSM primary notifications only). As of Release 10, * 3GPP TS 23.041 states that the UE shall ignore this value if received. * @return a byte array containing a copy of the primary notification digital signature */ public byte[] getPrimaryNotificationSignature() { if (mWarningSecurityInformation == null || mWarningSecurityInformation.length < 50) { return null; } return Arrays.copyOfRange(mWarningSecurityInformation, 7, 50); } @Override public String toString() { return "SmsCbEtwsInfo{warningType=" + mWarningType + ", emergencyUserAlert=" + mEmergencyUserAlert + ", activatePopup=" + mActivatePopup + '}'; } /** * Describe the kinds of special objects contained in the marshalled representation. * @return a bitmask indicating this Parcelable contains no special objects */ @Override public int describeContents() { return 0; } /** Creator for unparcelling objects. */ public static final Creator<SmsCbEtwsInfo> CREATOR = new Creator<SmsCbEtwsInfo>() { public SmsCbEtwsInfo createFromParcel(Parcel in) { return new SmsCbEtwsInfo(in); } public SmsCbEtwsInfo[] newArray(int size) { return new SmsCbEtwsInfo[size]; } }; }