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