blob: 2c4354b953df6259fc45c5d6a056bd1069554e9a [file] [log] [blame]
Wink Savillef8458ff2014-06-25 16:08:02 -07001/*
2 * Copyright (c) 2013 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
17package com.android.ims;
18
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070022import android.telecom.VideoProfile;
Wink Savillef8458ff2014-06-25 16:08:02 -070023
Jing Zhaoe647a012014-08-19 12:41:23 -050024import com.android.internal.telephony.PhoneConstants;
25
Wink Savillef8458ff2014-06-25 16:08:02 -070026/**
27 * Parcelable object to handle IMS call profile.
28 * It is created from GSMA IR.92/IR.94, 3GPP TS 24.229/TS 26.114/TS26.111.
29 * It provides the service and call type, the additional information related to the call.
30 *
31 * @hide
32 */
33public class ImsCallProfile implements Parcelable {
34 private static final String TAG = "ImsCallProfile";
35
36 /**
37 * Service types
38 */
39 /**
40 * It is for a special case. It helps that the application can make a call
41 * without IMS connection (not registered).
42 * In the moment of the call initiation, the device try to connect to the IMS network
43 * and initiates the call.
44 */
45 public static final int SERVICE_TYPE_NONE = 0;
46 /**
47 * It is a default type and can be selected when the device is connected to the IMS network.
48 */
49 public static final int SERVICE_TYPE_NORMAL = 1;
50 /**
51 * It is for an emergency call.
52 */
53 public static final int SERVICE_TYPE_EMERGENCY = 2;
54
55 /**
56 * Call types
57 */
58 /**
59 * IMSPhone to support IR.92 & IR.94 (voice + video upgrade/downgrade)
60 */
61 public static final int CALL_TYPE_VOICE_N_VIDEO = 1;
62 /**
63 * IR.92 (Voice only)
64 */
65 public static final int CALL_TYPE_VOICE = 2;
66 /**
67 * VT to support IR.92 & IR.94 (voice + video upgrade/downgrade)
68 */
69 public static final int CALL_TYPE_VIDEO_N_VOICE = 3;
70 /**
71 * Video Telephony (audio / video two way)
72 */
73 public static final int CALL_TYPE_VT = 4;
74 /**
75 * Video Telephony (audio two way / video TX one way)
76 */
77 public static final int CALL_TYPE_VT_TX = 5;
78 /**
79 * Video Telephony (audio two way / video RX one way)
80 */
81 public static final int CALL_TYPE_VT_RX = 6;
82 /**
83 * Video Telephony (audio two way / video inactive)
84 */
85 public static final int CALL_TYPE_VT_NODIR = 7;
86 /**
87 * VideoShare (video two way)
88 */
89 public static final int CALL_TYPE_VS = 8;
90 /**
91 * VideoShare (video TX one way)
92 */
93 public static final int CALL_TYPE_VS_TX = 9;
94 /**
95 * VideoShare (video RX one way)
96 */
97 public static final int CALL_TYPE_VS_RX = 10;
98
99 /**
100 * Extra properties for IMS call.
101 */
102 /**
103 * Boolean extra properties - "true" / "false"
104 * conference : Indicates if the session is for the conference call or not.
105 * e_call : Indicates if the session is for the emergency call or not.
106 * vms : Indicates if the session is connected to the voice mail system or not.
107 * call_mode_changeable : Indicates if the session is able to upgrade/downgrade
108 * the video during voice call.
109 * conference_avail : Indicates if the session can be extended to the conference.
110 */
111 public static final String EXTRA_CONFERENCE = "conference";
112 public static final String EXTRA_E_CALL = "e_call";
113 public static final String EXTRA_VMS = "vms";
114 public static final String EXTRA_CALL_MODE_CHANGEABLE = "call_mode_changeable";
115 public static final String EXTRA_CONFERENCE_AVAIL = "conference_avail";
116
Shriram Ganesh482e6da2014-10-13 11:31:50 -0700117 // Extra string for internal use only. OEMs should not use
118 // this for packing extras.
119 public static final String EXTRA_OEM_EXTRAS = "OemCallExtras";
120
Wink Savillef8458ff2014-06-25 16:08:02 -0700121 /**
122 * Integer extra properties
123 * oir : Rule for originating identity (number) presentation, MO/MT.
124 * {@link ImsCallProfile#OIR_DEFAULT}
125 * {@link ImsCallProfile#OIR_PRESENTATION_RESTRICTED}
126 * {@link ImsCallProfile#OIR_PRESENTATION_NOT_RESTRICTED}
127 * cnap : Rule for calling name presentation
128 * {@link ImsCallProfile#OIR_DEFAULT}
129 * {@link ImsCallProfile#OIR_PRESENTATION_RESTRICTED}
130 * {@link ImsCallProfile#OIR_PRESENTATION_NOT_RESTRICTED}
131 * dialstring : To identify the Ims call type, MO
132 * {@link ImsCallProfile#DIALSTRING_NORMAL_CALL}
133 * {@link ImsCallProfile#DIALSTRING_SS_CONF}
134 * {@link ImsCallProfile#DIALSTRING_USSD}
135 */
136 public static final String EXTRA_OIR = "oir";
137 public static final String EXTRA_CNAP = "cnap";
138 public static final String EXTRA_DIALSTRING = "dialstring";
139
140 /**
141 * Values for EXTRA_OIR / EXTRA_CNAP
142 */
143 public static final int OIR_DEFAULT = 0; // "user subscription default value"
144 public static final int OIR_PRESENTATION_RESTRICTED = 1;
145 public static final int OIR_PRESENTATION_NOT_RESTRICTED = 2;
Shriram Ganeshef0cde82015-03-05 16:43:03 +0530146 public static final int OIR_PRESENTATION_UNKNOWN = 3;
147 public static final int OIR_PRESENTATION_PAYPHONE = 4;
Wink Savillef8458ff2014-06-25 16:08:02 -0700148
149 /**
150 * Values for EXTRA_DIALSTRING
151 */
152 // default (normal call)
153 public static final int DIALSTRING_NORMAL = 0;
154 // Call for SIP-based user configuration
155 public static final int DIALSTRING_SS_CONF = 1;
156 // Call for USSD message
157 public static final int DIALSTRING_USSD = 2;
158
159 /**
Shriram Ganesh482e6da2014-10-13 11:31:50 -0700160 * Values for causes that restrict call types
161 */
162 // Default cause not restricted at peer and HD is supported
163 public static final int CALL_RESTRICT_CAUSE_NONE = 0;
164 // Service not supported by RAT at peer
165 public static final int CALL_RESTRICT_CAUSE_RAT = 1;
166 // Service Disabled at peer
167 public static final int CALL_RESTRICT_CAUSE_DISABLED = 2;
168 // HD is not supported
169 public static final int CALL_RESTRICT_CAUSE_HD = 3;
170
171 /**
Wink Savillef8458ff2014-06-25 16:08:02 -0700172 * String extra properties
173 * oi : Originating identity (number), MT only
174 * cna : Calling name
175 * ussd : For network-initiated USSD, MT only
176 * remote_uri : Connected user identity (it can be used for the conference)
177 */
178 public static final String EXTRA_OI = "oi";
179 public static final String EXTRA_CNA = "cna";
180 public static final String EXTRA_USSD = "ussd";
181 public static final String EXTRA_REMOTE_URI = "remote_uri";
182
183 public int mServiceType;
184 public int mCallType;
Shriram Ganesh482e6da2014-10-13 11:31:50 -0700185 public int mRestrictCause = CALL_RESTRICT_CAUSE_NONE;
Wink Savillef8458ff2014-06-25 16:08:02 -0700186 public Bundle mCallExtras;
187 public ImsStreamMediaProfile mMediaProfile;
188
Wink Savillef8458ff2014-06-25 16:08:02 -0700189 public ImsCallProfile(Parcel in) {
190 readFromParcel(in);
191 }
192
193 public ImsCallProfile() {
194 mServiceType = SERVICE_TYPE_NORMAL;
195 mCallType = CALL_TYPE_VOICE_N_VIDEO;
196 mCallExtras = new Bundle();
197 mMediaProfile = new ImsStreamMediaProfile();
198 }
199
200 public ImsCallProfile(int serviceType, int callType) {
201 mServiceType = serviceType;
202 mCallType = callType;
203 mCallExtras = new Bundle();
204 mMediaProfile = new ImsStreamMediaProfile();
205 }
206
207 public String getCallExtra(String name) {
208 return getCallExtra(name, "");
209 }
210
211 public String getCallExtra(String name, String defaultValue) {
212 if (mCallExtras == null) {
213 return defaultValue;
214 }
215
216 return mCallExtras.getString(name, defaultValue);
217 }
218
219 public boolean getCallExtraBoolean(String name) {
220 return getCallExtraBoolean(name, false);
221 }
222
223 public boolean getCallExtraBoolean(String name, boolean defaultValue) {
224 if (mCallExtras == null) {
225 return defaultValue;
226 }
227
228 return mCallExtras.getBoolean(name, defaultValue);
229 }
230
231 public int getCallExtraInt(String name) {
232 return getCallExtraInt(name, -1);
233 }
234
235 public int getCallExtraInt(String name, int defaultValue) {
236 if (mCallExtras == null) {
237 return defaultValue;
238 }
239
240 return mCallExtras.getInt(name, defaultValue);
241 }
242
243 public void setCallExtra(String name, String value) {
244 if (mCallExtras != null) {
245 mCallExtras.putString(name, value);
246 }
247 }
248
249 public void setCallExtraBoolean(String name, boolean value) {
250 if (mCallExtras != null) {
251 mCallExtras.putBoolean(name, value);
252 }
253 }
254
255 public void setCallExtraInt(String name, int value) {
256 if (mCallExtras != null) {
257 mCallExtras.putInt(name, value);
258 }
259 }
260
261 public void updateCallType(ImsCallProfile profile) {
262 mCallType = profile.mCallType;
263 }
264
265 public void updateCallExtras(ImsCallProfile profile) {
266 mCallExtras.clear();
267 mCallExtras = (Bundle) profile.mCallExtras.clone();
268 }
269
270 @Override
271 public String toString() {
272 return "{ serviceType=" + mServiceType +
273 ", callType=" + mCallType +
Etan Cohendb45a012014-12-10 10:08:20 -0800274 ", restrictCause=" + mRestrictCause +
Wink Savillef8458ff2014-06-25 16:08:02 -0700275 ", mediaProfile=" + mMediaProfile.toString() + " }";
276 }
277
278 @Override
279 public int describeContents() {
280 return 0;
281 }
282
283 @Override
284 public void writeToParcel(Parcel out, int flags) {
285 out.writeInt(mServiceType);
286 out.writeInt(mCallType);
287 out.writeParcelable(mCallExtras, 0);
288 out.writeParcelable(mMediaProfile, 0);
289 }
290
291 private void readFromParcel(Parcel in) {
292 mServiceType = in.readInt();
293 mCallType = in.readInt();
294 mCallExtras = in.readParcelable(null);
295 mMediaProfile = in.readParcelable(null);
296 }
297
298 public static final Creator<ImsCallProfile> CREATOR = new Creator<ImsCallProfile>() {
299 @Override
300 public ImsCallProfile createFromParcel(Parcel in) {
301 return new ImsCallProfile(in);
302 }
303
304 @Override
305 public ImsCallProfile[] newArray(int size) {
306 return new ImsCallProfile[size];
307 }
308 };
Tyler Gunnaa07df82014-07-17 07:50:22 -0700309
310 /**
311 * Converts from the call types defined in {@link com.android.ims.ImsCallProfile} to the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700312 * video state values defined in {@link VideoProfile}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700313 *
314 * @param callType The call type.
315 * @return The video state.
316 */
Rekha Kumar07366812015-03-24 16:42:31 -0700317 public static int getVideoStateFromImsCallProfile(ImsCallProfile callProfile) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700318 int videostate = VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700319 switch (callProfile.mCallType) {
Tyler Gunnaa07df82014-07-17 07:50:22 -0700320 case CALL_TYPE_VT_TX:
Tyler Gunn87b73f32015-06-03 10:09:59 -0700321 videostate = VideoProfile.STATE_TX_ENABLED;
Rekha Kumar07366812015-03-24 16:42:31 -0700322 break;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700323 case CALL_TYPE_VT_RX:
Tyler Gunn87b73f32015-06-03 10:09:59 -0700324 videostate = VideoProfile.STATE_RX_ENABLED;
Rekha Kumar07366812015-03-24 16:42:31 -0700325 break;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700326 case CALL_TYPE_VT:
Tyler Gunn87b73f32015-06-03 10:09:59 -0700327 videostate = VideoProfile.STATE_BIDIRECTIONAL;
Rekha Kumar07366812015-03-24 16:42:31 -0700328 break;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700329 case CALL_TYPE_VOICE:
Tyler Gunn87b73f32015-06-03 10:09:59 -0700330 videostate = VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700331 break;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700332 default:
Tyler Gunn87b73f32015-06-03 10:09:59 -0700333 videostate = VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700334 break;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700335 }
Tyler Gunnbc6f12e2015-06-09 14:34:11 -0700336 if (callProfile.isVideoPaused() && !VideoProfile.isAudioOnly(videostate)) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700337 videostate |= VideoProfile.STATE_PAUSED;
Rekha Kumar07366812015-03-24 16:42:31 -0700338 } else {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700339 videostate &= ~VideoProfile.STATE_PAUSED;
Rekha Kumar07366812015-03-24 16:42:31 -0700340 }
341 return videostate;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700342 }
343
344 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700345 * Converts from the video state values defined in {@link VideoProfile}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700346 * to the call types defined in {@link ImsCallProfile}.
347 *
348 * @param videoState The video state.
349 * @return The call type.
350 */
351 public static int getCallTypeFromVideoState(int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700352 boolean videoTx = isVideoStateSet(videoState, VideoProfile.STATE_TX_ENABLED);
353 boolean videoRx = isVideoStateSet(videoState, VideoProfile.STATE_RX_ENABLED);
354 boolean isPaused = isVideoStateSet(videoState, VideoProfile.STATE_PAUSED);
Tyler Gunnaa07df82014-07-17 07:50:22 -0700355 if (isPaused) {
356 return ImsCallProfile.CALL_TYPE_VT_NODIR;
357 } else if (videoTx && !videoRx) {
358 return ImsCallProfile.CALL_TYPE_VT_TX;
359 } else if (!videoTx && videoRx) {
360 return ImsCallProfile.CALL_TYPE_VT_RX;
361 } else if (videoTx && videoRx) {
362 return ImsCallProfile.CALL_TYPE_VT;
363 }
364 return ImsCallProfile.CALL_TYPE_VOICE;
365 }
366
367 /**
Jing Zhaoe647a012014-08-19 12:41:23 -0500368 * Translate presentation value to OIR value
369 * @param presentation
370 * @return OIR valuse
371 */
372 public static int presentationToOIR(int presentation) {
373 switch (presentation) {
374 case PhoneConstants.PRESENTATION_RESTRICTED:
375 return ImsCallProfile.OIR_PRESENTATION_RESTRICTED;
376 case PhoneConstants.PRESENTATION_ALLOWED:
377 return ImsCallProfile.OIR_PRESENTATION_NOT_RESTRICTED;
Shriram Ganeshef0cde82015-03-05 16:43:03 +0530378 case PhoneConstants.PRESENTATION_PAYPHONE:
379 return ImsCallProfile.OIR_PRESENTATION_PAYPHONE;
380 case PhoneConstants.PRESENTATION_UNKNOWN:
381 return ImsCallProfile.OIR_PRESENTATION_UNKNOWN;
Jing Zhaoe647a012014-08-19 12:41:23 -0500382 default:
383 return ImsCallProfile.OIR_DEFAULT;
384 }
385 }
386
387 /**
388 * Translate OIR value to presentation value
389 * @param oir value
390 * @return presentation value
391 */
392 public static int OIRToPresentation(int oir) {
393 switch(oir) {
394 case ImsCallProfile.OIR_PRESENTATION_RESTRICTED:
395 return PhoneConstants.PRESENTATION_RESTRICTED;
396 case ImsCallProfile.OIR_PRESENTATION_NOT_RESTRICTED:
397 return PhoneConstants.PRESENTATION_ALLOWED;
Shriram Ganeshef0cde82015-03-05 16:43:03 +0530398 case ImsCallProfile.OIR_PRESENTATION_PAYPHONE:
399 return PhoneConstants.PRESENTATION_PAYPHONE;
400 case ImsCallProfile.OIR_PRESENTATION_UNKNOWN:
401 return PhoneConstants.PRESENTATION_UNKNOWN;
Jing Zhaoe647a012014-08-19 12:41:23 -0500402 default:
403 return PhoneConstants.PRESENTATION_UNKNOWN;
404 }
405 }
406
407 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700408 * Checks if video call is paused
409 * @return true if call is video paused
410 */
411 public boolean isVideoPaused() {
412 return mMediaProfile.mVideoDirection == ImsStreamMediaProfile.DIRECTION_INACTIVE;
413 }
414
415 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700416 * Determines if a video state is set in a video state bit-mask.
417 *
418 * @param videoState The video state bit mask.
419 * @param videoStateToCheck The particular video state to check.
420 * @return True if the video state is set in the bit-mask.
421 */
422 private static boolean isVideoStateSet(int videoState, int videoStateToCheck) {
423 return (videoState & videoStateToCheck) == videoStateToCheck;
424 }
Wink Savillef8458ff2014-06-25 16:08:02 -0700425}