1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telephony;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Contains CMAS (Commercial Mobile Alert System) warning notification Type 1 elements for a
30  * {@link SmsCbMessage}.
31  * Supported values for each element are defined in TIA-1149-0-1 (CMAS over CDMA) and
32  * 3GPP TS 23.041 (for GSM/UMTS).
33  *
34  * {@hide}
35  */
36 @SystemApi
37 public final class SmsCbCmasInfo implements Parcelable {
38 
39     // CMAS message class (in GSM/UMTS message identifier or CDMA service category).
40 
41     /** Presidential-level alert (Korean Public Alert System Class 0 message). */
42     public static final int CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT = 0x00;
43 
44     /** Extreme threat to life and property (Korean Public Alert System Class 1 message). */
45     public static final int CMAS_CLASS_EXTREME_THREAT = 0x01;
46 
47     /** Severe threat to life and property (Korean Public Alert System Class 1 message). */
48     public static final int CMAS_CLASS_SEVERE_THREAT = 0x02;
49 
50     /** Child abduction emergency (AMBER Alert). */
51     public static final int CMAS_CLASS_CHILD_ABDUCTION_EMERGENCY = 0x03;
52 
53     /** CMAS test message. */
54     public static final int CMAS_CLASS_REQUIRED_MONTHLY_TEST = 0x04;
55 
56     /** CMAS exercise. */
57     public static final int CMAS_CLASS_CMAS_EXERCISE = 0x05;
58 
59     /** CMAS category for operator defined use. */
60     public static final int CMAS_CLASS_OPERATOR_DEFINED_USE = 0x06;
61 
62     /** CMAS category for warning types that are reserved for future extension. */
63     public static final int CMAS_CLASS_UNKNOWN = -1;
64 
65     /** @hide */
66     @Retention(RetentionPolicy.SOURCE)
67     @IntDef(prefix = {"CMAS_CLASS_"},
68             value = {
69                     CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT,
70                     CMAS_CLASS_EXTREME_THREAT,
71                     CMAS_CLASS_SEVERE_THREAT,
72                     CMAS_CLASS_CHILD_ABDUCTION_EMERGENCY,
73                     CMAS_CLASS_REQUIRED_MONTHLY_TEST,
74                     CMAS_CLASS_CMAS_EXERCISE,
75                     CMAS_CLASS_OPERATOR_DEFINED_USE,
76                     CMAS_CLASS_UNKNOWN,
77             })
78     public @interface Class {}
79 
80     // CMAS alert category (in CDMA type 1 elements record).
81 
82     /** CMAS alert category: Geophysical including landslide. */
83     public static final int CMAS_CATEGORY_GEO = 0x00;
84 
85     /** CMAS alert category: Meteorological including flood. */
86     public static final int CMAS_CATEGORY_MET = 0x01;
87 
88     /** CMAS alert category: General emergency and public safety. */
89     public static final int CMAS_CATEGORY_SAFETY = 0x02;
90 
91     /** CMAS alert category: Law enforcement, military, homeland/local/private security. */
92     public static final int CMAS_CATEGORY_SECURITY = 0x03;
93 
94     /** CMAS alert category: Rescue and recovery. */
95     public static final int CMAS_CATEGORY_RESCUE = 0x04;
96 
97     /** CMAS alert category: Fire suppression and rescue. */
98     public static final int CMAS_CATEGORY_FIRE = 0x05;
99 
100     /** CMAS alert category: Medical and public health. */
101     public static final int CMAS_CATEGORY_HEALTH = 0x06;
102 
103     /** CMAS alert category: Pollution and other environmental. */
104     public static final int CMAS_CATEGORY_ENV = 0x07;
105 
106     /** CMAS alert category: Public and private transportation. */
107     public static final int CMAS_CATEGORY_TRANSPORT = 0x08;
108 
109     /** CMAS alert category: Utility, telecom, other non-transport infrastructure. */
110     public static final int CMAS_CATEGORY_INFRA = 0x09;
111 
112     /** CMAS alert category: Chem, bio, radiological, nuclear, high explosive threat or attack. */
113     public static final int CMAS_CATEGORY_CBRNE = 0x0a;
114 
115     /** CMAS alert category: Other events. */
116     public static final int CMAS_CATEGORY_OTHER = 0x0b;
117 
118     /**
119      * CMAS alert category is unknown. The category is only available for CDMA broadcasts
120      * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown.
121      */
122     public static final int CMAS_CATEGORY_UNKNOWN = -1;
123 
124     /** @hide */
125     @Retention(RetentionPolicy.SOURCE)
126     @IntDef(prefix = {"CMAS_CATEORY_"},
127             value = {
128                     CMAS_CATEGORY_GEO,
129                     CMAS_CATEGORY_MET,
130                     CMAS_CATEGORY_SAFETY,
131                     CMAS_CATEGORY_SECURITY,
132                     CMAS_CATEGORY_RESCUE,
133                     CMAS_CATEGORY_FIRE,
134                     CMAS_CATEGORY_HEALTH,
135                     CMAS_CATEGORY_ENV,
136                     CMAS_CATEGORY_TRANSPORT,
137                     CMAS_CATEGORY_INFRA,
138                     CMAS_CATEGORY_CBRNE,
139                     CMAS_CATEGORY_OTHER,
140                     CMAS_CATEGORY_UNKNOWN,
141             })
142     public @interface Category {}
143 
144     // CMAS response type (in CDMA type 1 elements record).
145 
146     /** CMAS response type: Take shelter in place. */
147     public static final int CMAS_RESPONSE_TYPE_SHELTER = 0x00;
148 
149     /** CMAS response type: Evacuate (Relocate). */
150     public static final int CMAS_RESPONSE_TYPE_EVACUATE = 0x01;
151 
152     /** CMAS response type: Make preparations. */
153     public static final int CMAS_RESPONSE_TYPE_PREPARE = 0x02;
154 
155     /** CMAS response type: Execute a pre-planned activity. */
156     public static final int CMAS_RESPONSE_TYPE_EXECUTE = 0x03;
157 
158     /** CMAS response type: Attend to information sources. */
159     public static final int CMAS_RESPONSE_TYPE_MONITOR = 0x04;
160 
161     /** CMAS response type: Avoid hazard. */
162     public static final int CMAS_RESPONSE_TYPE_AVOID = 0x05;
163 
164     /** CMAS response type: Evaluate the information in this message (not for public warnings). */
165     public static final int CMAS_RESPONSE_TYPE_ASSESS = 0x06;
166 
167     /** CMAS response type: No action recommended. */
168     public static final int CMAS_RESPONSE_TYPE_NONE = 0x07;
169 
170     /**
171      * CMAS response type is unknown. The response type is only available for CDMA broadcasts
172      * containing a type 1 elements record, so GSM and UMTS broadcasts always return unknown.
173      */
174     public static final int CMAS_RESPONSE_TYPE_UNKNOWN = -1;
175 
176     /** @hide */
177     @Retention(RetentionPolicy.SOURCE)
178     @IntDef(prefix = {"CMAS_RESPONSE_TYPE_"},
179             value = {
180                     CMAS_RESPONSE_TYPE_SHELTER,
181                     CMAS_RESPONSE_TYPE_EVACUATE,
182                     CMAS_RESPONSE_TYPE_PREPARE,
183                     CMAS_RESPONSE_TYPE_EXECUTE,
184                     CMAS_RESPONSE_TYPE_MONITOR,
185                     CMAS_RESPONSE_TYPE_AVOID,
186                     CMAS_RESPONSE_TYPE_ASSESS,
187                     CMAS_RESPONSE_TYPE_NONE,
188                     CMAS_RESPONSE_TYPE_UNKNOWN,
189     })
190     public @interface ResponseType {}
191 
192     // 4-bit CMAS severity (in GSM/UMTS message identifier or CDMA type 1 elements record).
193 
194     /** CMAS severity type: Extraordinary threat to life or property. */
195     public static final int CMAS_SEVERITY_EXTREME = 0x0;
196 
197     /** CMAS severity type: Significant threat to life or property. */
198     public static final int CMAS_SEVERITY_SEVERE = 0x1;
199 
200     /**
201      * CMAS alert severity is unknown. The severity is available for CDMA warning alerts
202      * containing a type 1 elements record and for all GSM and UMTS alerts except for the
203      * Presidential-level alert class (Korean Public Alert System Class 0).
204      */
205     public static final int CMAS_SEVERITY_UNKNOWN = -1;
206 
207     /** @hide */
208     @Retention(RetentionPolicy.SOURCE)
209     @IntDef(prefix = {"CMAS_SEVERITY_"},
210             value = {
211                     CMAS_SEVERITY_EXTREME,
212                     CMAS_SEVERITY_SEVERE,
213                     CMAS_SEVERITY_UNKNOWN,
214             })
215     public @interface Severity {}
216 
217     // CMAS urgency (in GSM/UMTS message identifier or CDMA type 1 elements record).
218 
219     /** CMAS urgency type: Responsive action should be taken immediately. */
220     public static final int CMAS_URGENCY_IMMEDIATE = 0x0;
221 
222     /** CMAS urgency type: Responsive action should be taken within the next hour. */
223     public static final int CMAS_URGENCY_EXPECTED = 0x1;
224 
225     /**
226      * CMAS alert urgency is unknown. The urgency is available for CDMA warning alerts
227      * containing a type 1 elements record and for all GSM and UMTS alerts except for the
228      * Presidential-level alert class (Korean Public Alert System Class 0).
229      */
230     public static final int CMAS_URGENCY_UNKNOWN = -1;
231 
232     /** @hide */
233     @Retention(RetentionPolicy.SOURCE)
234     @IntDef(prefix = {"CMAS_URGENCY_"},
235             value = {
236                     CMAS_URGENCY_IMMEDIATE,
237                     CMAS_URGENCY_EXPECTED,
238                     CMAS_URGENCY_UNKNOWN,
239             })
240     public @interface Urgency {}
241 
242     // CMAS certainty (in GSM/UMTS message identifier or CDMA type 1 elements record).
243 
244     /** CMAS certainty type: Determined to have occurred or to be ongoing. */
245     public static final int CMAS_CERTAINTY_OBSERVED = 0x0;
246 
247     /** CMAS certainty type: Likely (probability > ~50%). */
248     public static final int CMAS_CERTAINTY_LIKELY = 0x1;
249 
250     /**
251      * CMAS alert certainty is unknown. The certainty is available for CDMA warning alerts
252      * containing a type 1 elements record and for all GSM and UMTS alerts except for the
253      * Presidential-level alert class (Korean Public Alert System Class 0).
254      */
255     public static final int CMAS_CERTAINTY_UNKNOWN = -1;
256 
257     /** @hide */
258     @Retention(RetentionPolicy.SOURCE)
259     @IntDef(prefix = {"CMAS_CERTAINTY_"},
260             value = {
261                     CMAS_CERTAINTY_OBSERVED,
262                     CMAS_CERTAINTY_LIKELY,
263                     CMAS_CERTAINTY_UNKNOWN,
264             })
265     public @interface Certainty {}
266 
267     /** CMAS message class. */
268     private final @Class int mMessageClass;
269 
270     /** CMAS category. */
271     private final @Category int mCategory;
272 
273     /** CMAS response type. */
274     private final @ResponseType int mResponseType;
275 
276     /** CMAS severity. */
277     private final @Severity int mSeverity;
278 
279     /** CMAS urgency. */
280     private final @Urgency int mUrgency;
281 
282     /** CMAS certainty. */
283     private final @Certainty int mCertainty;
284 
285     /** Create a new SmsCbCmasInfo object with the specified values. */
SmsCbCmasInfo(@lass int messageClass, @Category int category, @ResponseType int responseType, @Severity int severity, @Urgency int urgency, @Certainty int certainty)286     public SmsCbCmasInfo(@Class int messageClass, @Category int category,
287             @ResponseType int responseType,
288             @Severity int severity, @Urgency int urgency, @Certainty int certainty) {
289         mMessageClass = messageClass;
290         mCategory = category;
291         mResponseType = responseType;
292         mSeverity = severity;
293         mUrgency = urgency;
294         mCertainty = certainty;
295     }
296 
297     /** Create a new SmsCbCmasInfo object from a Parcel. */
SmsCbCmasInfo(Parcel in)298     SmsCbCmasInfo(Parcel in) {
299         mMessageClass = in.readInt();
300         mCategory = in.readInt();
301         mResponseType = in.readInt();
302         mSeverity = in.readInt();
303         mUrgency = in.readInt();
304         mCertainty = in.readInt();
305     }
306 
307     /**
308      * Flatten this object into a Parcel.
309      *
310      * @param dest  The Parcel in which the object should be written.
311      * @param flags Additional flags about how the object should be written (ignored).
312      */
313     @Override
writeToParcel(Parcel dest, int flags)314     public void writeToParcel(Parcel dest, int flags) {
315         dest.writeInt(mMessageClass);
316         dest.writeInt(mCategory);
317         dest.writeInt(mResponseType);
318         dest.writeInt(mSeverity);
319         dest.writeInt(mUrgency);
320         dest.writeInt(mCertainty);
321     }
322 
323     /**
324      * Returns the CMAS message class, e.g. {@link #CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT}.
325      * @return one of the {@code CMAS_CLASS} values
326      */
getMessageClass()327     public @Class int getMessageClass() {
328         return mMessageClass;
329     }
330 
331     /**
332      * Returns the CMAS category, e.g. {@link #CMAS_CATEGORY_GEO}.
333      * @return one of the {@code CMAS_CATEGORY} values
334      */
getCategory()335     public @Category int getCategory() {
336         return mCategory;
337     }
338 
339     /**
340      * Returns the CMAS response type, e.g. {@link #CMAS_RESPONSE_TYPE_SHELTER}.
341      * @return one of the {@code CMAS_RESPONSE_TYPE} values
342      */
getResponseType()343     public @ResponseType int getResponseType() {
344         return mResponseType;
345     }
346 
347     /**
348      * Returns the CMAS severity, e.g. {@link #CMAS_SEVERITY_EXTREME}.
349      * @return one of the {@code CMAS_SEVERITY} values
350      */
getSeverity()351     public @Severity int getSeverity() {
352         return mSeverity;
353     }
354 
355     /**
356      * Returns the CMAS urgency, e.g. {@link #CMAS_URGENCY_IMMEDIATE}.
357      * @return one of the {@code CMAS_URGENCY} values
358      */
getUrgency()359     public @Urgency int getUrgency() {
360         return mUrgency;
361     }
362 
363     /**
364      * Returns the CMAS certainty, e.g. {@link #CMAS_CERTAINTY_OBSERVED}.
365      *
366      * @return one of the {@code CMAS_CERTAINTY} values
367      */
getCertainty()368     public @Certainty int getCertainty() {
369         return mCertainty;
370     }
371 
372     @Override
toString()373     public String toString() {
374         return "SmsCbCmasInfo{messageClass=" + mMessageClass + ", category=" + mCategory
375                 + ", responseType=" + mResponseType + ", severity=" + mSeverity
376                 + ", urgency=" + mUrgency + ", certainty=" + mCertainty + '}';
377     }
378 
379     /**
380      * Describe the kinds of special objects contained in the marshalled representation.
381      *
382      * @return a bitmask indicating this Parcelable contains no special objects
383      */
384     @Override
describeContents()385     public int describeContents() {
386         return 0;
387     }
388 
389     /** Creator for unparcelling objects. */
390     @NonNull
391     public static final Parcelable.Creator<SmsCbCmasInfo> CREATOR =
392             new Parcelable.Creator<SmsCbCmasInfo>() {
393         @Override
394         public SmsCbCmasInfo createFromParcel(Parcel in) {
395             return new SmsCbCmasInfo(in);
396         }
397 
398         @Override
399         public SmsCbCmasInfo[] newArray(int size) {
400             return new SmsCbCmasInfo[size];
401         }
402     };
403 }
404