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.SystemApi;
22 import android.annotation.UnsupportedAppUsage;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * Provides the call forward information for the supplementary service configuration.
31  *
32  * @hide
33  */
34 @SystemApi
35 public final class ImsCallForwardInfo implements Parcelable {
36 
37     /**
38      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for unconditional call
39      * forwarding. See TC 27.007
40      */
41     public static final int CDIV_CF_REASON_UNCONDITIONAL = 0;
42 
43     /**
44      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for call forwarding
45      * when the user is busy.
46      */
47     public static final int CDIV_CF_REASON_BUSY = 1;
48 
49     /**
50      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for call forwarding
51      * when there is no reply from the user.
52      */
53     public static final int CDIV_CF_REASON_NO_REPLY = 2;
54 
55     /**
56      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for call forwarding
57      * when the user is not reachable.
58      */
59     public static final int CDIV_CF_REASON_NOT_REACHABLE = 3;
60 
61     /**
62      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for setting all call
63      * forwarding reasons simultaneously (i.e. unconditional, busy, no reply, and not reachable).
64      */
65     public static final int CDIV_CF_REASON_ALL = 4;
66 
67     /**
68      * CDIV (Communication Diversion, 3GPP TS 24.604) call forwarding reason for setting all
69      * conditional call forwarding reasons simultaneously (i.e. if busy, if no reply, and if not
70      * reachable).
71      */
72     public static final int CDIV_CF_REASON_ALL_CONDITIONAL = 5;
73 
74     /**
75      * CDIV (Communication Diversion) IMS only call forwarding reason for call forwarding when the
76      * user is not logged in.
77      */
78     public static final int CDIV_CF_REASON_NOT_LOGGED_IN = 6;
79 
80     /**@hide*/
81     @IntDef(prefix = {"CDIV_CF_REASON_"}, value = {
82             CDIV_CF_REASON_UNCONDITIONAL,
83             CDIV_CF_REASON_BUSY,
84             CDIV_CF_REASON_NO_REPLY,
85             CDIV_CF_REASON_NOT_REACHABLE,
86             CDIV_CF_REASON_ALL,
87             CDIV_CF_REASON_ALL_CONDITIONAL,
88             CDIV_CF_REASON_NOT_LOGGED_IN})
89     @Retention(RetentionPolicy.SOURCE)
90     public @interface CallForwardReasons{}
91 
92     /**
93      * Call forwarding is not active for any service class.
94      */
95     public static final int STATUS_NOT_ACTIVE = 0;
96 
97     /**
98      * Call forwarding is active for one or more service classes.
99      */
100     public static final int STATUS_ACTIVE = 1;
101 
102     /**@hide*/
103     @IntDef(prefix = {"STATUS_"}, value = {
104             STATUS_NOT_ACTIVE,
105             STATUS_ACTIVE})
106     @Retention(RetentionPolicy.SOURCE)
107     public @interface CallForwardStatus{}
108 
109     /**
110      * The address defined in {@link #getNumber()} is in an unknown format.
111      *
112      * See TS 27.007, section 7.11 for more information.
113      */
114     public static final int TYPE_OF_ADDRESS_UNKNOWN = 0x81;
115     /**
116      * The address defined in {@link #getNumber()} is in E.164 international format, which includes
117      * international access code "+".
118      *
119      * See TS 27.007, section 7.11 for more information.
120      */
121     public static final int TYPE_OF_ADDRESS_INTERNATIONAL = 0x91;
122 
123     /**@hide*/
124     @IntDef(prefix = {"TYPE_OF_ADDRESS_"}, value = {
125             TYPE_OF_ADDRESS_INTERNATIONAL,
126             TYPE_OF_ADDRESS_UNKNOWN})
127     @Retention(RetentionPolicy.SOURCE)
128     public @interface TypeOfAddress{}
129 
130     /**@hide*/
131     @UnsupportedAppUsage
132     public @CallForwardReasons int mCondition;
133     /** @hide */
134     @UnsupportedAppUsage
135     public @CallForwardStatus int mStatus;
136     /** @hide */
137     @UnsupportedAppUsage
138     public @TypeOfAddress int mToA;
139     /** @hide */
140     @UnsupportedAppUsage
141     public @ImsSsData.ServiceClassFlags int mServiceClass;
142     /** @hide */
143     @UnsupportedAppUsage
144     public String mNumber;
145     /** @hide */
146     @UnsupportedAppUsage
147     public int mTimeSeconds;
148 
149     /** @hide */
150     @UnsupportedAppUsage
ImsCallForwardInfo()151     public ImsCallForwardInfo() {
152     }
153 
154     /**
155      * IMS Call Forward Information.
156      */
ImsCallForwardInfo(@allForwardReasons int reason, @CallForwardStatus int status, @TypeOfAddress int toA, @ImsSsData.ServiceClassFlags int serviceClass, @NonNull String number, int replyTimerSec)157     public ImsCallForwardInfo(@CallForwardReasons int reason, @CallForwardStatus int status,
158             @TypeOfAddress int toA, @ImsSsData.ServiceClassFlags int serviceClass,
159             @NonNull String number, int replyTimerSec) {
160         mCondition = reason;
161         mStatus = status;
162         mToA = toA;
163         mServiceClass = serviceClass;
164         mNumber = number;
165         mTimeSeconds = replyTimerSec;
166     }
167 
168     /** @hide */
ImsCallForwardInfo(Parcel in)169     public ImsCallForwardInfo(Parcel in) {
170         readFromParcel(in);
171     }
172 
173     @Override
describeContents()174     public int describeContents() {
175         return 0;
176     }
177 
178     @Override
writeToParcel(Parcel out, int flags)179     public void writeToParcel(Parcel out, int flags) {
180         out.writeInt(mCondition);
181         out.writeInt(mStatus);
182         out.writeInt(mToA);
183         out.writeString(mNumber);
184         out.writeInt(mTimeSeconds);
185         out.writeInt(mServiceClass);
186     }
187 
188     @Override
toString()189     public String toString() {
190         return super.toString() + ", Condition: " + mCondition
191             + ", Status: " + ((mStatus == 0) ? "disabled" : "enabled")
192             + ", ToA: " + mToA
193             + ", Service Class: " + mServiceClass
194             + ", Number=" + mNumber
195             + ", Time (seconds): " + mTimeSeconds;
196     }
197 
readFromParcel(Parcel in)198     private void readFromParcel(Parcel in) {
199         mCondition = in.readInt();
200         mStatus = in.readInt();
201         mToA = in.readInt();
202         mNumber = in.readString();
203         mTimeSeconds = in.readInt();
204         mServiceClass = in.readInt();
205     }
206 
207     public static final @android.annotation.NonNull Creator<ImsCallForwardInfo> CREATOR =
208             new Creator<ImsCallForwardInfo>() {
209         @Override
210         public ImsCallForwardInfo createFromParcel(Parcel in) {
211             return new ImsCallForwardInfo(in);
212         }
213 
214         @Override
215         public ImsCallForwardInfo[] newArray(int size) {
216             return new ImsCallForwardInfo[size];
217         }
218     };
219 
220     /**
221      * @return the condition of call forwarding for the service classes specified.
222      */
getCondition()223     public @CallForwardReasons int getCondition() {
224         return mCondition;
225     }
226 
227     /**
228      * @return The call forwarding status.
229      */
getStatus()230     public @CallForwardStatus int getStatus() {
231         return mStatus;
232     }
233 
234     /**
235      * @return the type of address (ToA) for the number.
236      * @see #getNumber()
237      */
getToA()238     public @TypeOfAddress int getToA() {
239         return mToA;
240     }
241 
242     /**
243      * @return a bitfield containing the service classes that are enabled for call forwarding.
244      */
getServiceClass()245     public @ImsSsData.ServiceClassFlags int getServiceClass() {
246         return mServiceClass;
247     }
248 
249     /**
250      * @return the call forwarding number associated with call forwarding, with a number type
251      * defined by {@link #getToA()}.
252      */
getNumber()253     public String getNumber() {
254         return mNumber;
255     }
256 
257     /**
258      * @return the number in seconds to wait before the call is forwarded for call forwarding
259      * condition {@link #CDIV_CF_REASON_NO_REPLY}
260      */
getTimeSeconds()261     public int getTimeSeconds() {
262         return mTimeSeconds;
263     }
264 }
265