1 /*
2  * Copyright (C) 2018 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.ims;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.annotation.TestApi;
24 import android.compat.annotation.UnsupportedAppUsage;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 
31 /**
32  * Provides the result to the update operation for the supplementary service configuration.
33  *
34  * Also supports IMS specific Incoming Communication Barring (ICB) as well as Anonymous
35  * Communication Rejection (ACR), as per 3GPP 24.611.
36  *
37  * @see Builder
38  * @hide
39  */
40 @SystemApi
41 @TestApi
42 public final class ImsSsInfo implements Parcelable {
43 
44     /**@hide*/
45     @IntDef(value = {
46             NOT_REGISTERED,
47             DISABLED,
48             ENABLED
49     })
50     @Retention(RetentionPolicy.SOURCE)
51     public @interface ServiceStatus {}
52 
53     /**
54      * For the status of service registration or activation/deactivation.
55      */
56     public static final int NOT_REGISTERED = (-1);
57     public static final int DISABLED = 0;
58     public static final int ENABLED = 1;
59 
60     /**
61      * Provision status of service.
62      * @hide
63      */
64     @IntDef(value = {
65             SERVICE_PROVISIONING_UNKNOWN,
66             SERVICE_NOT_PROVISIONED,
67             SERVICE_PROVISIONED
68     }, prefix = "SERVICE_")
69     @Retention(RetentionPolicy.SOURCE)
70     public @interface ServiceProvisionStatus {}
71 
72     /**
73      * Unknown provision status for the service.
74      */
75     public static final int SERVICE_PROVISIONING_UNKNOWN = (-1);
76 
77     /**
78      * Service is not provisioned.
79      */
80     public static final int SERVICE_NOT_PROVISIONED = 0;
81 
82     /**
83      * Service is provisioned.
84      */
85     public static final int SERVICE_PROVISIONED = 1;
86 
87     /**@hide*/
88     @IntDef(value = {
89             CLIR_OUTGOING_DEFAULT,
90             CLIR_OUTGOING_INVOCATION,
91             CLIR_OUTGOING_SUPPRESSION
92     }, prefix = "CLIR_OUTGOING_")
93     @Retention(RetentionPolicy.SOURCE)
94     public @interface ClirOutgoingState {}
95 
96     /**
97      * Calling line identification restriction (CLIR) is set to the default according to the
98      * subscription of the CLIR service.
99      *
100      * See TS 27.007, section 7.7 for more information.
101      */
102     public static final int CLIR_OUTGOING_DEFAULT = 0;
103     /**
104      * Activate Calling line identification restriction for outgoing calls.
105      *
106      * See TS 27.007, section 7.7 for more information.
107      */
108     public static final int CLIR_OUTGOING_INVOCATION = 1;
109     /**
110      * Deactivate Calling line identification restriction for outgoing calls.
111      *
112      * See TS 27.007, section 7.7 for more information.
113      */
114     public static final int CLIR_OUTGOING_SUPPRESSION = 2;
115 
116     /**
117      * Calling line identification restriction is currently not provisioned.
118      *
119      * See TS 27.007, section 7.7 for more information.
120      */
121     public static final int CLIR_STATUS_NOT_PROVISIONED = 0;
122     /**
123      * Calling line identification restriction is currently provisioned in permanent mode.
124      *
125      * See TS 27.007, section 7.7 for more information.
126      */
127     public static final int CLIR_STATUS_PROVISIONED_PERMANENT = 1;
128     /**
129      * Calling line identification restriction is currently unknown, e.g. no network, etc.
130      *
131      * See TS 27.007, section 7.7 for more information.
132      */
133     public static final int CLIR_STATUS_UNKNOWN = 2;
134     /**
135      * Calling line identification restriction temporary mode, temporarily restricted.
136      *
137      * See TS 27.007, section 7.7 for more information.
138      */
139     public static final int CLIR_STATUS_TEMPORARILY_RESTRICTED = 3;
140     /**
141      * Calling line identification restriction temporary mode, temporarily allowed.
142      *
143      * See TS 27.007, section 7.7 for more information.
144      */
145     public static final int CLIR_STATUS_TEMPORARILY_ALLOWED = 4;
146 
147     /**@hide*/
148     @IntDef(value = {
149             CLIR_STATUS_NOT_PROVISIONED,
150             CLIR_STATUS_PROVISIONED_PERMANENT,
151             CLIR_STATUS_UNKNOWN,
152             CLIR_STATUS_TEMPORARILY_RESTRICTED,
153             CLIR_STATUS_TEMPORARILY_ALLOWED
154     }, prefix = "CLIR_STATUS_")
155     @Retention(RetentionPolicy.SOURCE)
156     public @interface ClirInterrogationStatus {}
157 
158     // 0: disabled, 1: enabled
159     /** @hide */
160     @UnsupportedAppUsage
161     public int mStatus;
162     /** @hide */
163     @UnsupportedAppUsage
164     public String mIcbNum;
165     /** @hide */
166     public int mProvisionStatus = SERVICE_PROVISIONING_UNKNOWN;
167     private int mClirInterrogationStatus = CLIR_STATUS_UNKNOWN;
168     private int mClirOutgoingState = CLIR_OUTGOING_DEFAULT;
169 
170     /**@hide*/
171     @UnsupportedAppUsage
ImsSsInfo()172     public ImsSsInfo() {
173     }
174 
175     /**
176      * Builds {@link ImsSsInfo} instances, which may include optional parameters.
177      */
178     public static final class Builder {
179 
180         private final ImsSsInfo mImsSsInfo;
181 
Builder(@erviceStatus int status)182         public Builder(@ServiceStatus int status) {
183             mImsSsInfo = new ImsSsInfo();
184             mImsSsInfo.mStatus = status;
185         }
186 
187         /**
188          * Set the ICB number for IMS call barring.
189          * @param number The number in E.164 international format.
190          */
setIncomingCommunicationBarringNumber(@onNull String number)191         public @NonNull Builder setIncomingCommunicationBarringNumber(@NonNull String number) {
192             mImsSsInfo.mIcbNum = number;
193             return this;
194         }
195 
196         /**
197          * Set the provisioning status for a Supplementary Service interrogation response.
198          */
setProvisionStatus(@erviceProvisionStatus int provisionStatus)199         public @NonNull Builder setProvisionStatus(@ServiceProvisionStatus int provisionStatus) {
200             mImsSsInfo.mProvisionStatus = provisionStatus;
201             return this;
202         }
203 
204         /**
205          * Set the Calling Line Identification Restriction (CLIR) status for a supplementary service
206          * interrogation response.
207          */
setClirInterrogationStatus(@lirInterrogationStatus int status)208         public @NonNull Builder setClirInterrogationStatus(@ClirInterrogationStatus int status) {
209             mImsSsInfo.mClirInterrogationStatus = status;
210             return this;
211         }
212 
213         /**
214          * Set the Calling line identification Restriction (CLIR) state for outgoing calls.
215          */
setClirOutgoingState(@lirOutgoingState int state)216         public @NonNull Builder setClirOutgoingState(@ClirOutgoingState int state) {
217             mImsSsInfo.mClirOutgoingState = state;
218             return this;
219         }
220 
221         /**
222          * @return a built {@link ImsSsInfo} containing optional the parameters that were set.
223          */
build()224         public @NonNull ImsSsInfo build() {
225             return mImsSsInfo;
226         }
227     }
228 
229     /**
230      *
231      * @param status The status of the service registration of activation/deactiviation.
232      * @param icbNum The Incoming barring number.
233      * @deprecated use {@link ImsSsInfo.Builder} instead.
234      */
235     @Deprecated
ImsSsInfo(@erviceStatus int status, @Nullable String icbNum)236     public ImsSsInfo(@ServiceStatus int status, @Nullable String icbNum) {
237         mStatus = status;
238         mIcbNum = icbNum;
239     }
240 
ImsSsInfo(Parcel in)241     private ImsSsInfo(Parcel in) {
242         readFromParcel(in);
243     }
244 
245     @Override
describeContents()246     public int describeContents() {
247         return 0;
248     }
249 
250     @Override
writeToParcel(Parcel out, int flags)251     public void writeToParcel(Parcel out, int flags) {
252         out.writeInt(mStatus);
253         out.writeString(mIcbNum);
254         out.writeInt(mProvisionStatus);
255         out.writeInt(mClirInterrogationStatus);
256         out.writeInt(mClirOutgoingState);
257     }
258 
259     @NonNull
260     @Override
toString()261     public String toString() {
262         return super.toString() + ", Status: " + ((mStatus == 0) ? "disabled" : "enabled")
263                 + ", ProvisionStatus: " + provisionStatusToString(mProvisionStatus);
264     }
265 
provisionStatusToString(int pStatus)266     private static String provisionStatusToString(int pStatus) {
267         switch (pStatus) {
268             case SERVICE_NOT_PROVISIONED:
269                 return "Service not provisioned";
270              case SERVICE_PROVISIONED:
271                 return "Service provisioned";
272              default:
273                 return "Service provisioning unknown";
274         }
275     }
276 
readFromParcel(Parcel in)277     private void readFromParcel(Parcel in) {
278         mStatus = in.readInt();
279         mIcbNum = in.readString();
280         mProvisionStatus = in.readInt();
281         mClirInterrogationStatus = in.readInt();
282         mClirOutgoingState = in.readInt();
283     }
284 
285     public static final @android.annotation.NonNull Creator<ImsSsInfo> CREATOR =
286             new Creator<ImsSsInfo>() {
287         @Override
288         public ImsSsInfo createFromParcel(Parcel in) {
289             return new ImsSsInfo(in);
290         }
291 
292         @Override
293         public ImsSsInfo[] newArray(int size) {
294             return new ImsSsInfo[size];
295         }
296     };
297 
298     /**
299      * @return Supplementary Service Configuration status.
300      */
getStatus()301     public @ServiceStatus int getStatus() {
302         return mStatus;
303     }
304 
305     /** @deprecated Use {@link #getIncomingCommunicationBarringNumber()} instead.*/
306     @Deprecated
getIcbNum()307     public String getIcbNum() {
308         return mIcbNum;
309     }
310 
311     /**
312      * @return The Incoming Communication Barring (ICB) number.
313      */
getIncomingCommunicationBarringNumber()314     public @Nullable String getIncomingCommunicationBarringNumber() {
315         return mIcbNum;
316     }
317 
318     /**
319      * @return Supplementary Service Provision status.
320      */
getProvisionStatus()321     public @ServiceProvisionStatus int getProvisionStatus() {
322         return mProvisionStatus;
323     }
324 
325     /**
326      * @return the Calling Line Identification Restriction State for outgoing calls with respect to
327      * this subscription. Will be {@link #CLIR_OUTGOING_DEFAULT} if not applicable to this SS info.
328      */
getClirOutgoingState()329     public @ClirOutgoingState int getClirOutgoingState() {
330         return mClirOutgoingState;
331     }
332 
333     /**
334      * @return the calling line identification restriction provisioning status upon interrogation of
335      * the service for this subscription. Will be {@link #CLIR_STATUS_UNKNOWN} if not applicable to
336      * this SS info.
337      */
getClirInterrogationStatus()338     public @ClirInterrogationStatus int getClirInterrogationStatus() {
339         return mClirInterrogationStatus;
340     }
341 
342     /**
343      * Parts of telephony still use the old {m,n} 3GPP definition, so convert to that format.
344      * @hide
345      */
getCompatArray(@msSsData.ServiceType int type)346     public int[] getCompatArray(@ImsSsData.ServiceType int type) {
347         int[] result = new int[2];
348         // Convert ImsSsInfo into a form that telephony can read (as per 3GPP 27.007)
349         // CLIR (section 7.7)
350         if (type == ImsSsData.SS_CLIR) {
351             // Assume there will only be one ImsSsInfo.
352             // contains {"n","m"} parameters
353             result[0] = getClirOutgoingState();
354             result[1] = getClirInterrogationStatus();
355             return result;
356         }
357         // COLR 7.31
358         if (type == ImsSsData.SS_COLR) {
359             result[0] = getProvisionStatus();
360         }
361         // Facility Lock CLCK 7.4 (for call barring), CLIP 7.6, COLP 7.8, as well as any
362         // other result, just return the status for the "n" parameter and provisioning status for
363         // "m" as the default.
364         result[0] = getStatus();
365         result[1] = getProvisionStatus();
366         return result;
367     }
368 }
369