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.annotation.SystemApi;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import com.android.telephony.Rlog;
28 
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 import java.util.Objects;
32 
33 /**
34  * Defines the call forwarding information.
35  * @hide
36  */
37 @SystemApi
38 public final class CallForwardingInfo implements Parcelable {
39     private static final String TAG = "CallForwardingInfo";
40 
41     /**
42      * Indicates that call forwarding reason is "unconditional".
43      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
44      *            and conditions +CCFC
45      */
46     public static final int REASON_UNCONDITIONAL = 0;
47 
48     /**
49      * Indicates the call forwarding status is "busy".
50      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
51      *            and conditions +CCFC
52      */
53     public static final int REASON_BUSY = 1;
54 
55     /**
56      * Indicates the call forwarding reason is "no reply".
57      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
58      *            and conditions +CCFC
59      */
60     public static final int REASON_NO_REPLY = 2;
61 
62     /**
63      * Indicates the call forwarding reason is "not reachable".
64      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
65      *            and conditions +CCFC
66      */
67     public static final int REASON_NOT_REACHABLE = 3;
68 
69     /**
70      * Indicates the call forwarding reason is "all", for setting all call forwarding reasons
71      * simultaneously (unconditional, busy, no reply, and not reachable).
72      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
73      *            and conditions +CCFC
74      */
75     public static final int REASON_ALL = 4;
76 
77     /**
78      * Indicates the call forwarding reason is "all_conditional", for setting all conditional call
79      * forwarding reasons simultaneously (busy, no reply, and not reachable).
80      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
81      *            and conditions +CCFC
82      */
83     public static final int REASON_ALL_CONDITIONAL = 5;
84 
85     /**
86      * Call forwarding reason types
87      * @hide
88      */
89     @IntDef(prefix = { "REASON_" }, value = {
90         REASON_UNCONDITIONAL,
91         REASON_BUSY,
92         REASON_NO_REPLY,
93         REASON_NOT_REACHABLE,
94         REASON_ALL,
95         REASON_ALL_CONDITIONAL
96     })
97     @Retention(RetentionPolicy.SOURCE)
98     public @interface CallForwardingReason {
99     }
100 
101     /**
102      * Whether call forwarding is enabled for this reason.
103      */
104     private boolean mEnabled;
105 
106     /**
107      * The call forwarding reason indicates the condition under which calls will be forwarded.
108      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
109      *            and conditions +CCFC
110      */
111     private int mReason;
112 
113     /**
114      * The phone number to which calls will be forwarded.
115      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10 - 7.11 Call forwarding number
116      *            and conditions +CCFC
117      */
118     private String mNumber;
119 
120     /**
121      * Gets the timeout (in seconds) before the forwarding is attempted.
122      */
123     private int mTimeSeconds;
124 
125     /**
126      * Construct a CallForwardingInfo.
127      *
128      * @param enabled Whether to enable call forwarding for the reason specified
129      *                in {@link #getReason()}.
130      * @param reason the call forwarding reason
131      * @param number the phone number to which calls will be forwarded
132      * @param timeSeconds the timeout (in seconds) before the forwarding is attempted
133      */
CallForwardingInfo(boolean enabled, @CallForwardingReason int reason, @Nullable String number, int timeSeconds)134     public CallForwardingInfo(boolean enabled, @CallForwardingReason int reason,
135             @Nullable String number, int timeSeconds) {
136         mEnabled = enabled;
137         mReason = reason;
138         mNumber = number;
139         mTimeSeconds = timeSeconds;
140     }
141 
142     /**
143      * Whether call forwarding is enabled for the reason from {@link #getReason()}.
144      *
145      * @return {@code true} if enabled, {@code false} otherwise.
146      */
isEnabled()147     public boolean isEnabled() {
148         return mEnabled;
149     }
150 
151     /**
152      * Returns the call forwarding reason. The call forwarding reason indicates the condition
153      * under which calls will be forwarded. For example, {@link #REASON_NO_REPLY} indicates
154      * that calls will be forwarded when the user fails to answer the call.
155      *
156      * @return the call forwarding reason.
157      */
getReason()158     public @CallForwardingReason int getReason() {
159         return mReason;
160     }
161 
162     /**
163      * Returns the phone number to which calls will be forwarded.
164      *
165      * @return the number calls will be forwarded to, or {@code null} if call forwarding
166      *         is disabled.
167      */
168     @Nullable
getNumber()169     public String getNumber() {
170         return mNumber;
171     }
172 
173     /**
174      * Gets the timeout (in seconds) before forwarding is attempted. For example,
175      * if {@link #REASON_NO_REPLY} is the call forwarding reason, the device will wait this
176      * duration of time before forwarding the call to the number returned by {@link #getNumber()}.
177      *
178      * Reference: 3GPP TS 27.007 version 10.3.0 Release 10
179      *            7.11 Call forwarding number and conditions +CCFC
180      *
181      * @return the timeout (in seconds) before the forwarding is attempted.
182      */
183     @SuppressLint("MethodNameUnits")
getTimeoutSeconds()184     public int getTimeoutSeconds() {
185         return mTimeSeconds;
186     }
187 
188     @Override
describeContents()189     public int describeContents() {
190         return 0;
191     }
192 
193     /**
194      * @hide
195      */
196     @Override
writeToParcel(Parcel out, int flags)197     public void writeToParcel(Parcel out, int flags) {
198         out.writeString(mNumber);
199         out.writeBoolean(mEnabled);
200         out.writeInt(mReason);
201         out.writeInt(mTimeSeconds);
202     }
203 
CallForwardingInfo(Parcel in)204     private CallForwardingInfo(Parcel in) {
205         mNumber = in.readString();
206         mEnabled = in.readBoolean();
207         mReason = in.readInt();
208         mTimeSeconds = in.readInt();
209     }
210 
211     /**
212      * @hide
213      */
214     @Override
equals(Object o)215     public boolean equals(Object o) {
216         if (this == o) return true;
217 
218         if (!(o instanceof CallForwardingInfo)) {
219             return false;
220         }
221 
222         CallForwardingInfo other = (CallForwardingInfo) o;
223         return mEnabled == other.mEnabled
224                 && mNumber == other.mNumber
225                 && mReason == other.mReason
226                 && mTimeSeconds == other.mTimeSeconds;
227     }
228 
229     /**
230      * @hide
231      */
232     @Override
hashCode()233     public int hashCode() {
234         return Objects.hash(mEnabled, mNumber, mReason, mTimeSeconds);
235     }
236 
237     public static final @NonNull Parcelable.Creator<CallForwardingInfo> CREATOR =
238             new Parcelable.Creator<CallForwardingInfo>() {
239                 @Override
240                 public CallForwardingInfo createFromParcel(Parcel in) {
241                     return new CallForwardingInfo(in);
242                 }
243 
244                 @Override
245                 public CallForwardingInfo[] newArray(int size) {
246                     return new CallForwardingInfo[size];
247                 }
248             };
249 
250     /**
251      * @hide
252      */
253     @Override
toString()254     public String toString() {
255         return "[CallForwardingInfo: enabled=" + mEnabled
256                 + ", reason= " + mReason
257                 + ", timeSec= " + mTimeSeconds + " seconds"
258                 + ", number=" + Rlog.pii(TAG, mNumber) + "]";
259     }
260 }
261