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.cdma;
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  * CDMA Service Category Program Data from SCPT (Service Category Programming Teleservice) SMS,
30  * as defined in 3GPP2 C.S0015-B section 4.5.19.
31  * <p>
32  * The CellBroadcastReceiver app receives an Intent with action
33  * {@link android.provider.Telephony.Sms.Intents#SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION}
34  * containing an array of these objects to update its list of cell broadcast service categories
35  * to display.
36  *
37  * {@hide}
38  */
39 @SystemApi
40 public final class CdmaSmsCbProgramData implements Parcelable {
41 
42     /** Delete the specified service category from the list of enabled categories. */
43     public static final int OPERATION_DELETE_CATEGORY   = 0;
44 
45     /** Add the specified service category to the list of enabled categories. */
46     public static final int OPERATION_ADD_CATEGORY      = 1;
47 
48     /** Clear all service categories from the list of enabled categories. */
49     public static final int OPERATION_CLEAR_CATEGORIES  = 2;
50 
51     /** @hide */
52     @Retention(RetentionPolicy.SOURCE)
53     @IntDef(prefix = {"OPERATION_"},
54             value = {
55                     OPERATION_DELETE_CATEGORY,
56                     OPERATION_ADD_CATEGORY,
57                     OPERATION_CLEAR_CATEGORIES,
58             })
59     public @interface Operation {}
60 
61     // CMAS alert service category assignments, see 3GPP2 C.R1001 table 9.3.3-1
62     /** Indicates a presidential-level alert */
63     public static final int CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT  = 0x1000;
64 
65     /** Indicates an extreme threat to life and property */
66     public static final int CATEGORY_CMAS_EXTREME_THREAT            = 0x1001;
67 
68     /** Indicates an severe threat to life and property */
69     public static final int CATEGORY_CMAS_SEVERE_THREAT             = 0x1002;
70 
71     /** Indicates an AMBER child abduction emergency */
72     public static final int CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY = 0x1003;
73 
74     /** Indicates a CMAS test message */
75     public static final int CATEGORY_CMAS_TEST_MESSAGE              = 0x1004;
76 
77     /** The last reserved value of a CMAS service category according to 3GPP C.R1001 table
78      * 9.3.3-1. */
79     public static final int CATEGORY_CMAS_LAST_RESERVED_VALUE       = 0x10ff;
80 
81     /** @hide */
82     @Retention(RetentionPolicy.SOURCE)
83     @IntDef(prefix = {"CATEGORY_"},
84             value = {
85                     CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT,
86                     CATEGORY_CMAS_EXTREME_THREAT,
87                     CATEGORY_CMAS_SEVERE_THREAT,
88                     CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY,
89                     CATEGORY_CMAS_TEST_MESSAGE,
90                     CATEGORY_CMAS_LAST_RESERVED_VALUE,
91             })
92     public @interface Category {}
93 
94     /** Alert option: no alert. @hide */
95     public static final int ALERT_OPTION_NO_ALERT               = 0;
96 
97     /** Alert option: default alert. @hide */
98     public static final int ALERT_OPTION_DEFAULT_ALERT          = 1;
99 
100     /** Alert option: vibrate alert once. @hide */
101     public static final int ALERT_OPTION_VIBRATE_ONCE           = 2;
102 
103     /** Alert option: vibrate alert - repeat. @hide */
104     public static final int ALERT_OPTION_VIBRATE_REPEAT         = 3;
105 
106     /** Alert option: visual alert once. @hide */
107     public static final int ALERT_OPTION_VISUAL_ONCE            = 4;
108 
109     /** Alert option: visual alert - repeat. @hide */
110     public static final int ALERT_OPTION_VISUAL_REPEAT          = 5;
111 
112     /** Alert option: low-priority alert once. @hide */
113     public static final int ALERT_OPTION_LOW_PRIORITY_ONCE      = 6;
114 
115     /** Alert option: low-priority alert - repeat. @hide */
116     public static final int ALERT_OPTION_LOW_PRIORITY_REPEAT    = 7;
117 
118     /** Alert option: medium-priority alert once. @hide */
119     public static final int ALERT_OPTION_MED_PRIORITY_ONCE      = 8;
120 
121     /** Alert option: medium-priority alert - repeat. @hide */
122     public static final int ALERT_OPTION_MED_PRIORITY_REPEAT    = 9;
123 
124     /** Alert option: high-priority alert once. @hide */
125     public static final int ALERT_OPTION_HIGH_PRIORITY_ONCE     = 10;
126 
127     /** Alert option: high-priority alert - repeat. @hide */
128     public static final int ALERT_OPTION_HIGH_PRIORITY_REPEAT   = 11;
129 
130     /** Service category operation (add/delete/clear). */
131     private final int mOperation;
132 
133     /** Service category to modify. */
134     private final int mCategory;
135 
136     /** Language used for service category name (defined in BearerData.LANGUAGE_*). */
137     private final int mLanguage;
138 
139     /** Maximum number of messages to store for this service category. */
140     private final int mMaxMessages;
141 
142     /** Service category alert option. */
143     private final int mAlertOption;
144 
145     /** Name of service category. */
146     private final String mCategoryName;
147 
148     /**
149      * Create a new CdmaSmsCbProgramData object with the specified values.
150      * @hide
151      */
CdmaSmsCbProgramData(@peration int operation, @Category int category, int language, int maxMessages, int alertOption, @NonNull String categoryName)152     public CdmaSmsCbProgramData(@Operation int operation, @Category int category, int language,
153             int maxMessages, int alertOption, @NonNull String categoryName) {
154         mOperation = operation;
155         mCategory = category;
156         mLanguage = language;
157         mMaxMessages = maxMessages;
158         mAlertOption = alertOption;
159         mCategoryName = categoryName;
160     }
161 
162     /**
163      * Create a new CdmaSmsCbProgramData object from a Parcel.
164      * @hide
165      */
CdmaSmsCbProgramData(Parcel in)166     CdmaSmsCbProgramData(Parcel in) {
167         mOperation = in.readInt();
168         mCategory = in.readInt();
169         mLanguage = in.readInt();
170         mMaxMessages = in.readInt();
171         mAlertOption = in.readInt();
172         mCategoryName = in.readString();
173     }
174 
175     /**
176      * Flatten this object into a Parcel.
177      *
178      * @param dest  The Parcel in which the object should be written.
179      * @param flags Additional flags about how the object should be written (ignored).
180      */
181     @Override
writeToParcel(Parcel dest, int flags)182     public void writeToParcel(Parcel dest, int flags) {
183         dest.writeInt(mOperation);
184         dest.writeInt(mCategory);
185         dest.writeInt(mLanguage);
186         dest.writeInt(mMaxMessages);
187         dest.writeInt(mAlertOption);
188         dest.writeString(mCategoryName);
189     }
190 
191     /**
192      * Returns the service category operation, e.g. {@link #OPERATION_ADD_CATEGORY}.
193      *
194      * @return the service category operation
195      */
getOperation()196     public @Operation int getOperation() {
197         return mOperation;
198     }
199 
200     /**
201      * Returns the CDMA service category to modify. See 3GPP2 C.S0015-B section 3.4.3.2 for more
202      * information on the service category. Currently only CMAS service categories 0x1000 through
203      * 0x10FF are supported.
204      *
205      * @return a 16-bit CDMA service category value
206      */
getCategory()207     public @Category int getCategory() {
208         return mCategory;
209     }
210 
211     /**
212      * Returns the CDMA language code for this service category.
213      * @return one of the language values defined in BearerData.LANGUAGE_*
214      * @hide
215      */
getLanguage()216     public int getLanguage() {
217         return mLanguage;
218     }
219 
220     /**
221      * Returns the maximum number of messages to store for this service category.
222      * @return the maximum number of messages to store for this service category
223      * @hide
224      */
getMaxMessages()225     public int getMaxMessages() {
226         return mMaxMessages;
227     }
228 
229     /**
230      * Returns the service category alert option, e.g. {@link #ALERT_OPTION_DEFAULT_ALERT}.
231      * @return one of the {@code ALERT_OPTION_*} values
232      * @hide
233      */
getAlertOption()234     public int getAlertOption() {
235         return mAlertOption;
236     }
237 
238     /**
239      * Returns the service category name, in the language specified by {@link #getLanguage()}.
240      * @return an optional service category name
241      * @hide
242      */
243     @NonNull
getCategoryName()244     public String getCategoryName() {
245         return mCategoryName;
246     }
247 
248     @Override
toString()249     public String toString() {
250         return "CdmaSmsCbProgramData{operation=" + mOperation + ", category=" + mCategory
251                 + ", language=" + mLanguage + ", max messages=" + mMaxMessages
252                 + ", alert option=" + mAlertOption + ", category name=" + mCategoryName + '}';
253     }
254 
255     /**
256      * Describe the kinds of special objects contained in the marshalled representation.
257      * @return a bitmask indicating this Parcelable contains no special objects
258      */
259     @Override
describeContents()260     public int describeContents() {
261         return 0;
262     }
263 
264     /**
265      * Creator for unparcelling objects.
266      */
267     @NonNull
268     public static final Parcelable.Creator<CdmaSmsCbProgramData>
269             CREATOR = new Parcelable.Creator<CdmaSmsCbProgramData>() {
270         @Override
271         public CdmaSmsCbProgramData createFromParcel(Parcel in) {
272             return new CdmaSmsCbProgramData(in);
273         }
274 
275         @Override
276         public CdmaSmsCbProgramData[] newArray(int size) {
277             return new CdmaSmsCbProgramData[size];
278         }
279     };
280 }
281