1 /*
2  * Copyright (C) 2020 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.Nullable;
22 import android.annotation.SuppressLint;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import com.android.telephony.Rlog;
27 
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 import java.util.Objects;
31 
32 /**
33  * Defines the call forwarding information.
34  * @hide
35  */
36 public final class CallForwardingInfo implements Parcelable {
37     private static final String TAG = "CallForwardingInfo";
38 
39     /**
40      * Indicates the call forwarding status is inactive.
41      *
42      * @hide
43      */
44     public static final int STATUS_INACTIVE = 0;
45 
46     /**
47      * Indicates the call forwarding status is active.
48      *
49      * @hide
50      */
51     public static final int STATUS_ACTIVE = 1;
52 
53     /**
54      * Indicates the call forwarding could not be enabled because the recipient is not on
55      * Fixed Dialing Number (FDN) list.
56      *
57      * @hide
58      */
59     public static final int STATUS_FDN_CHECK_FAILURE = 2;
60 
61     /**
62      * Indicates the call forwarding status is with an unknown error.
63      *
64      * @hide
65      */
66     public static final int STATUS_UNKNOWN_ERROR = 3;
67 
68     /**
69      * Indicates the call forwarding is not supported (e.g. called via CDMA).
70      *
71      * @hide
72      */
73     public static final int STATUS_NOT_SUPPORTED = 4;
74 
75     /**
76      * Indicates the call forwarding reason is "unconditional".
77      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
78      *            and conditions +CCFC
79      * @hide
80      */
81     public static final int REASON_UNCONDITIONAL = 0;
82 
83     /**
84      * Indicates the call forwarding status is "busy".
85      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
86      *            and conditions +CCFC
87      * @hide
88      */
89     public static final int REASON_BUSY = 1;
90 
91     /**
92      * Indicates the call forwarding reason is "no reply".
93      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
94      *            and conditions +CCFC
95      * @hide
96      */
97     public static final int REASON_NO_REPLY = 2;
98 
99     /**
100      * Indicates the call forwarding reason is "not reachable".
101      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
102      *            and conditions +CCFC
103      * @hide
104      */
105     public static final int REASON_NOT_REACHABLE = 3;
106 
107     /**
108      * Indicates the call forwarding reason is "all", for setting all call forwarding reasons
109      * simultaneously (unconditional, busy, no reply, and not reachable).
110      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
111      *            and conditions +CCFC
112      * @hide
113      */
114     public static final int REASON_ALL = 4;
115 
116     /**
117      * Indicates the call forwarding reason is "all_conditional", for setting all conditional call
118      * forwarding reasons simultaneously (busy, no reply, and not reachable).
119      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
120      *            and conditions +CCFC
121      * @hide
122      */
123     public static final int REASON_ALL_CONDITIONAL = 5;
124 
125     /**
126      * Call forwarding function status
127      */
128     @IntDef(prefix = { "STATUS_" }, value = {
129         STATUS_ACTIVE,
130         STATUS_INACTIVE,
131         STATUS_UNKNOWN_ERROR,
132         STATUS_NOT_SUPPORTED,
133         STATUS_FDN_CHECK_FAILURE
134     })
135     @Retention(RetentionPolicy.SOURCE)
136     public @interface CallForwardingStatus {
137     }
138 
139     /**
140      * Call forwarding reason types
141      */
142     @IntDef(flag = true, prefix = { "REASON_" }, value = {
143         REASON_UNCONDITIONAL,
144         REASON_BUSY,
145         REASON_NO_REPLY,
146         REASON_NOT_REACHABLE,
147         REASON_ALL,
148         REASON_ALL_CONDITIONAL
149     })
150     @Retention(RetentionPolicy.SOURCE)
151     public @interface CallForwardingReason {
152     }
153 
154     /**
155      * The call forwarding status.
156      */
157     private int mStatus;
158 
159     /**
160      * The call forwarding reason indicates the condition under which calls will be forwarded.
161      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
162      *            and conditions +CCFC
163      */
164     private int mReason;
165 
166     /**
167      * The phone number to which calls will be forwarded.
168      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
169      *            and conditions +CCFC
170      */
171     private String mNumber;
172 
173     /**
174      * Gets the timeout (in seconds) before the forwarding is attempted.
175      */
176     private int mTimeSeconds;
177 
178     /**
179      * Construct a CallForwardingInfo.
180      *
181      * @param status the call forwarding status
182      * @param reason the call forwarding reason
183      * @param number the phone number to which calls will be forwarded
184      * @param timeSeconds the timeout (in seconds) before the forwarding is attempted
185      * @hide
186      */
CallForwardingInfo(@allForwardingStatus int status, @CallForwardingReason int reason, @Nullable String number, int timeSeconds)187     public CallForwardingInfo(@CallForwardingStatus int status, @CallForwardingReason int reason,
188             @Nullable String number, int timeSeconds) {
189         mStatus = status;
190         mReason = reason;
191         mNumber = number;
192         mTimeSeconds = timeSeconds;
193     }
194 
195     /**
196      * Returns the call forwarding status.
197      *
198      * @return the call forwarding status.
199      *
200      * @hide
201      */
getStatus()202     public @CallForwardingStatus int getStatus() {
203         return mStatus;
204     }
205 
206     /**
207      * Returns the call forwarding reason. The call forwarding reason indicates the condition
208      * under which calls will be forwarded.  For example, {@link #REASON_NO_REPLY} indicates
209      * that calls will be forward to {@link #getNumber()} when the user fails to answer the call.
210      *
211      * @return the call forwarding reason.
212      *
213      * @hide
214      */
getReason()215     public @CallForwardingReason int getReason() {
216         return mReason;
217     }
218 
219     /**
220      * Returns the phone number to which calls will be forwarded.
221      *
222      * @return the number calls will be forwarded to, or {@code null} if call forwarding
223      * is being disabled.
224      *
225      * @hide
226      */
227     @Nullable
getNumber()228     public String getNumber() {
229         return mNumber;
230     }
231 
232     /**
233      * Gets the timeout (in seconds) before the forwarding is attempted. For example,
234      * if {@link #REASON_NO_REPLY} is the call forwarding reason, the device will wait this
235      * duration of time before forwarding the call to {@link #getNumber()}.
236      *
237      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10
238      *            7.11 Call forwarding number and conditions +CCFC
239      *
240      * @return the timeout (in seconds) before the forwarding is attempted.
241      *
242      * @hide
243      */
244     @SuppressLint("MethodNameUnits")
getTimeoutSeconds()245     public int getTimeoutSeconds() {
246         return mTimeSeconds;
247     }
248 
249     @Override
describeContents()250     public int describeContents() {
251         return 0;
252     }
253 
254     /**
255      * @hide
256      */
257     @Override
writeToParcel(Parcel out, int flags)258     public void writeToParcel(Parcel out, int flags) {
259         out.writeString(mNumber);
260         out.writeInt(mStatus);
261         out.writeInt(mReason);
262         out.writeInt(mTimeSeconds);
263     }
264 
CallForwardingInfo(Parcel in)265     private CallForwardingInfo(Parcel in) {
266         mNumber = in.readString();
267         mStatus = in.readInt();
268         mReason = in.readInt();
269         mTimeSeconds = in.readInt();
270     }
271 
272     /**
273      * @hide
274      */
275     @Override
equals(Object o)276     public boolean equals(Object o) {
277         if (this == o) return true;
278 
279         if (!(o instanceof CallForwardingInfo)) {
280             return false;
281         }
282 
283         CallForwardingInfo other = (CallForwardingInfo) o;
284         return mStatus == other.mStatus
285                 && mNumber == other.mNumber
286                 && mReason == other.mReason
287                 && mTimeSeconds == other.mTimeSeconds;
288     }
289 
290     /**
291      * @hide
292      */
293     @Override
hashCode()294     public int hashCode() {
295         return Objects.hash(mStatus, mNumber, mReason, mTimeSeconds);
296     }
297 
298     public static final @NonNull Parcelable.Creator<CallForwardingInfo> CREATOR =
299             new Parcelable.Creator<CallForwardingInfo>() {
300                 @Override
301                 public CallForwardingInfo createFromParcel(Parcel in) {
302                     return new CallForwardingInfo(in);
303                 }
304 
305                 @Override
306                 public CallForwardingInfo[] newArray(int size) {
307                     return new CallForwardingInfo[size];
308                 }
309             };
310 
311     /**
312      * @hide
313      */
314     @Override
toString()315     public String toString() {
316         return "[CallForwardingInfo: status=" + mStatus
317                 + ", reason= " + mReason
318                 + ", timeSec= " + mTimeSeconds + " seconds"
319                 + ", number=" + Rlog.pii(TAG, mNumber) + "]";
320     }
321 }
322