• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.net.Uri;
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 
32 /**
33  * Parcelable object to handle MultiEndpoint Dialog Event Package Information.
34  * @hide
35  */
36 @SystemApi
37 public final class ImsExternalCallState implements Parcelable {
38 
39     private static final String TAG = "ImsExternalCallState";
40 
41     // Dialog States
42     /**
43      * The external call is in the confirmed dialog state.
44      */
45     public static final int CALL_STATE_CONFIRMED = 1;
46     /**
47      * The external call is in the terminated dialog state.
48      */
49     public static final int CALL_STATE_TERMINATED = 2;
50 
51     /**@hide*/
52     @IntDef(value = {
53                     CALL_STATE_CONFIRMED,
54                     CALL_STATE_TERMINATED
55             },
56             prefix = "CALL_STATE_")
57     @Retention(RetentionPolicy.SOURCE)
58     public @interface ExternalCallState {}
59 
60     /**@hide*/
61     @IntDef(value = {
62                     ImsCallProfile.CALL_TYPE_VOICE,
63                     ImsCallProfile.CALL_TYPE_VT_TX,
64                     ImsCallProfile.CALL_TYPE_VT_RX,
65                     ImsCallProfile.CALL_TYPE_VT
66             },
67             prefix = "CALL_TYPE_")
68     @Retention(RetentionPolicy.SOURCE)
69     public @interface ExternalCallType {}
70 
71 
72 
73     // Dialog Id
74     private int mCallId;
75     // Number
76     private Uri mAddress;
77     private Uri mLocalAddress;
78     private boolean mIsPullable;
79     // CALL_STATE_CONFIRMED / CALL_STATE_TERMINATED
80     private int mCallState;
81     // ImsCallProfile#CALL_TYPE_*
82     private int mCallType;
83     private boolean mIsHeld;
84 
85     /** @hide */
ImsExternalCallState()86     public ImsExternalCallState() {
87     }
88 
89     /**@hide*/
ImsExternalCallState(int callId, Uri address, boolean isPullable, @ExternalCallState int callState, int callType, boolean isCallheld)90     public ImsExternalCallState(int callId, Uri address, boolean isPullable,
91             @ExternalCallState int callState, int callType, boolean isCallheld) {
92         mCallId = callId;
93         mAddress = address;
94         mIsPullable = isPullable;
95         mCallState = callState;
96         mCallType = callType;
97         mIsHeld = isCallheld;
98         Rlog.d(TAG, "ImsExternalCallState = " + this);
99     }
100 
101     /**@hide*/
ImsExternalCallState(int callId, Uri address, Uri localAddress, boolean isPullable, @ExternalCallState int callState, int callType, boolean isCallheld)102     public ImsExternalCallState(int callId, Uri address, Uri localAddress,
103             boolean isPullable, @ExternalCallState int callState, int callType,
104             boolean isCallheld) {
105         mCallId = callId;
106         mAddress = address;
107         mLocalAddress = localAddress;
108         mIsPullable = isPullable;
109         mCallState = callState;
110         mCallType = callType;
111         mIsHeld = isCallheld;
112         Rlog.d(TAG, "ImsExternalCallState = " + this);
113     }
114 
115     /**
116      * Create a new ImsExternalCallState instance to contain Multiendpoint Dialog information.
117      * @param callId The unique ID of the call, which will be used to identify this external
118      *               connection.
119      * @param address A {@link Uri} containing the remote address of this external connection.
120      * @param localAddress A {@link Uri} containing the local address information.
121      * @param isPullable A flag determining if this external connection can be pulled to the current
122      *         device.
123      * @param callState The state of the external call.
124      * @param callType The type of external call.
125      * @param isCallheld A flag determining if the external connection is currently held.
126      */
ImsExternalCallState(@onNull String callId, @NonNull Uri address, @Nullable Uri localAddress, boolean isPullable, @ExternalCallState int callState, @ExternalCallType int callType, boolean isCallheld)127     public ImsExternalCallState(@NonNull String callId, @NonNull Uri address,
128             @Nullable Uri localAddress, boolean isPullable, @ExternalCallState int callState,
129             @ExternalCallType int callType, boolean isCallheld) {
130         mCallId = getIdForString(callId);
131         mAddress = address;
132         mLocalAddress = localAddress;
133         mIsPullable = isPullable;
134         mCallState = callState;
135         mCallType = callType;
136         mIsHeld = isCallheld;
137         Rlog.d(TAG, "ImsExternalCallState = " + this);
138     }
139 
140     /** @hide */
ImsExternalCallState(Parcel in)141     public ImsExternalCallState(Parcel in) {
142         mCallId = in.readInt();
143         ClassLoader classLoader = ImsExternalCallState.class.getClassLoader();
144         mAddress = in.readParcelable(classLoader);
145         mLocalAddress = in.readParcelable(classLoader);
146         mIsPullable = (in.readInt() != 0);
147         mCallState = in.readInt();
148         mCallType = in.readInt();
149         mIsHeld = (in.readInt() != 0);
150         Rlog.d(TAG, "ImsExternalCallState const = " + this);
151     }
152 
153     @Override
describeContents()154     public int describeContents() {
155         return 0;
156     }
157 
158     @Override
writeToParcel(Parcel out, int flags)159     public void writeToParcel(Parcel out, int flags) {
160         out.writeInt(mCallId);
161         out.writeParcelable(mAddress, 0);
162         out.writeParcelable(mLocalAddress, 0);
163         out.writeInt(mIsPullable ? 1 : 0);
164         out.writeInt(mCallState);
165         out.writeInt(mCallType);
166         out.writeInt(mIsHeld ? 1 : 0);
167         Rlog.d(TAG, "ImsExternalCallState writeToParcel = " + out.toString());
168     }
169 
170     public static final @android.annotation.NonNull Parcelable.Creator<ImsExternalCallState> CREATOR =
171             new Parcelable.Creator<ImsExternalCallState>() {
172         @Override
173         public ImsExternalCallState createFromParcel(Parcel in) {
174             return new ImsExternalCallState(in);
175         }
176 
177         @Override
178         public ImsExternalCallState[] newArray(int size) {
179             return new ImsExternalCallState[size];
180         }
181     };
182 
getCallId()183     public int getCallId() {
184         return mCallId;
185     }
186 
getAddress()187     public @NonNull Uri getAddress() {
188         return mAddress;
189     }
190 
191     /**
192      * @return A {@link Uri} containing the local address from the Multiendpoint Dialog Information.
193      */
getLocalAddress()194     public @Nullable Uri getLocalAddress() {
195         return mLocalAddress;
196     }
197 
isCallPullable()198     public boolean isCallPullable() {
199         return mIsPullable;
200     }
201 
getCallState()202     public @ExternalCallState int getCallState() {
203         return mCallState;
204     }
205 
getCallType()206     public @ExternalCallType int getCallType() {
207         return mCallType;
208     }
209 
isCallHeld()210     public boolean isCallHeld() {
211         return mIsHeld;
212     }
213 
214     @NonNull
215     @Override
toString()216     public String toString() {
217         return "ImsExternalCallState { mCallId = " + mCallId +
218                 ", mAddress = " + Rlog.pii(TAG, mAddress) +
219                 ", mLocalAddress = " + Rlog.pii(TAG, mLocalAddress) +
220                 ", mIsPullable = " + mIsPullable +
221                 ", mCallState = " + mCallState +
222                 ", mCallType = " + mCallType +
223                 ", mIsHeld = " + mIsHeld + "}";
224     }
225 
getIdForString(String idString)226     private int getIdForString(String idString) {
227         try {
228             return Integer.parseInt(idString);
229         } catch (NumberFormatException e) {
230             // In the case that there are alphanumeric characters, we will create a hash of the
231             // String value as a backup.
232             // TODO: Modify call IDs to use Strings as keys instead of integers in telephony/telecom
233             return idString.hashCode();
234         }
235     }
236 }
237