1 /*
2  * Copyright (C) 2022 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.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.telephony.Annotation.PreciseCallStates;
24 
25 import java.util.Objects;
26 
27 /**
28  * A Parcelable object to represent the current state of an IMS call that is being tracked
29  * in the ImsService when an SRVCC begins. This information will be delivered to modem.
30  * @see SrvccStartedCallback
31  *
32  * @hide
33  */
34 @SystemApi
35 public final class SrvccCall implements Parcelable {
36     private static final String TAG = "SrvccCall";
37 
38     /** The IMS call profile */
39     private ImsCallProfile mImsCallProfile;
40 
41     /** The IMS call id */
42     private String mCallId;
43 
44     /** The call state */
45     private @PreciseCallStates int mCallState;
46 
SrvccCall(Parcel in)47     private SrvccCall(Parcel in) {
48         readFromParcel(in);
49     }
50 
51     /**
52      * Constructs an instance of SrvccCall.
53      *
54      * @param callId the call ID associated with the IMS call
55      * @param callState the state of this IMS call
56      * @param imsCallProfile the profile associated with this IMS call
57      * @throws IllegalArgumentException if the callId or the imsCallProfile is null
58      */
SrvccCall(@onNull String callId, @PreciseCallStates int callState, @NonNull ImsCallProfile imsCallProfile)59     public SrvccCall(@NonNull String callId, @PreciseCallStates int callState,
60             @NonNull ImsCallProfile imsCallProfile) {
61         if (callId == null) throw new IllegalArgumentException("callId is null");
62         if (imsCallProfile == null) throw new IllegalArgumentException("imsCallProfile is null");
63 
64         mCallId = callId;
65         mCallState = callState;
66         mImsCallProfile = imsCallProfile;
67     }
68 
69     /**
70      * @return the {@link ImsCallProfile} associated with this IMS call,
71      * which will be used to get the address, the name, and the audio direction
72      * including the call in pre-alerting state.
73      */
74     @NonNull
getImsCallProfile()75     public ImsCallProfile getImsCallProfile() {
76         return mImsCallProfile;
77     }
78 
79     /**
80      * @return the call ID associated with this IMS call.
81      *
82      * @see android.telephony.ims.stub.ImsCallSessionImplBase#getCallId().
83      */
84     @NonNull
getCallId()85     public String getCallId() {
86         return mCallId;
87     }
88 
89     /**
90      * @return the call state of the associated IMS call.
91      */
getPreciseCallState()92     public @PreciseCallStates int getPreciseCallState() {
93         return mCallState;
94     }
95 
96     @NonNull
97     @Override
toString()98     public String toString() {
99         return "{ callId=" + mCallId
100                 + ", callState=" + mCallState
101                 + ", imsCallProfile=" + mImsCallProfile
102                 + " }";
103     }
104 
105     @Override
equals(Object o)106     public boolean equals(Object o) {
107         if (this == o) return true;
108         if (o == null || getClass() != o.getClass()) return false;
109         SrvccCall that = (SrvccCall) o;
110         return mImsCallProfile.equals(that.mImsCallProfile)
111                 && mCallId.equals(that.mCallId)
112                 && mCallState == that.mCallState;
113     }
114 
115     @Override
hashCode()116     public int hashCode() {
117         int result = Objects.hash(mImsCallProfile, mCallId);
118         result = 31 * result + mCallState;
119         return result;
120     }
121 
122     @Override
describeContents()123     public int describeContents() {
124         return 0;
125     }
126 
127     @Override
writeToParcel(@onNull Parcel out, int flags)128     public void writeToParcel(@NonNull Parcel out, int flags) {
129         out.writeString(mCallId);
130         out.writeInt(mCallState);
131         out.writeParcelable(mImsCallProfile, 0);
132     }
133 
readFromParcel(Parcel in)134     private void readFromParcel(Parcel in) {
135         mCallId = in.readString();
136         mCallState = in.readInt();
137         mImsCallProfile = in.readParcelable(ImsCallProfile.class.getClassLoader(),
138                 android.telephony.ims.ImsCallProfile.class);
139     }
140 
141     public static final @android.annotation.NonNull Creator<SrvccCall> CREATOR =
142             new Creator<SrvccCall>() {
143         @Override
144         public SrvccCall createFromParcel(Parcel in) {
145             return new SrvccCall(in);
146         }
147 
148         @Override
149         public SrvccCall[] newArray(int size) {
150             return new SrvccCall[size];
151         }
152     };
153 }
154