Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.ims; |
| 18 | |
| 19 | import android.os.Bundle; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 22 | import android.telecom.VideoProfile; |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 23 | |
Jing Zhao | e647a01 | 2014-08-19 12:41:23 -0500 | [diff] [blame] | 24 | import com.android.internal.telephony.PhoneConstants; |
| 25 | |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 26 | /** |
| 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 | */ |
| 33 | public 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 Ganesh | 482e6da | 2014-10-13 11:31:50 -0700 | [diff] [blame] | 117 | // 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 Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 121 | /** |
| 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; |
| 146 | |
| 147 | /** |
| 148 | * Values for EXTRA_DIALSTRING |
| 149 | */ |
| 150 | // default (normal call) |
| 151 | public static final int DIALSTRING_NORMAL = 0; |
| 152 | // Call for SIP-based user configuration |
| 153 | public static final int DIALSTRING_SS_CONF = 1; |
| 154 | // Call for USSD message |
| 155 | public static final int DIALSTRING_USSD = 2; |
| 156 | |
| 157 | /** |
Shriram Ganesh | 482e6da | 2014-10-13 11:31:50 -0700 | [diff] [blame] | 158 | * Values for causes that restrict call types |
| 159 | */ |
| 160 | // Default cause not restricted at peer and HD is supported |
| 161 | public static final int CALL_RESTRICT_CAUSE_NONE = 0; |
| 162 | // Service not supported by RAT at peer |
| 163 | public static final int CALL_RESTRICT_CAUSE_RAT = 1; |
| 164 | // Service Disabled at peer |
| 165 | public static final int CALL_RESTRICT_CAUSE_DISABLED = 2; |
| 166 | // HD is not supported |
| 167 | public static final int CALL_RESTRICT_CAUSE_HD = 3; |
| 168 | |
| 169 | /** |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 170 | * String extra properties |
| 171 | * oi : Originating identity (number), MT only |
| 172 | * cna : Calling name |
| 173 | * ussd : For network-initiated USSD, MT only |
| 174 | * remote_uri : Connected user identity (it can be used for the conference) |
| 175 | */ |
| 176 | public static final String EXTRA_OI = "oi"; |
| 177 | public static final String EXTRA_CNA = "cna"; |
| 178 | public static final String EXTRA_USSD = "ussd"; |
| 179 | public static final String EXTRA_REMOTE_URI = "remote_uri"; |
| 180 | |
| 181 | public int mServiceType; |
| 182 | public int mCallType; |
Shriram Ganesh | 482e6da | 2014-10-13 11:31:50 -0700 | [diff] [blame] | 183 | public int mRestrictCause = CALL_RESTRICT_CAUSE_NONE; |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 184 | public Bundle mCallExtras; |
| 185 | public ImsStreamMediaProfile mMediaProfile; |
| 186 | |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 187 | public ImsCallProfile(Parcel in) { |
| 188 | readFromParcel(in); |
| 189 | } |
| 190 | |
| 191 | public ImsCallProfile() { |
| 192 | mServiceType = SERVICE_TYPE_NORMAL; |
| 193 | mCallType = CALL_TYPE_VOICE_N_VIDEO; |
| 194 | mCallExtras = new Bundle(); |
| 195 | mMediaProfile = new ImsStreamMediaProfile(); |
| 196 | } |
| 197 | |
| 198 | public ImsCallProfile(int serviceType, int callType) { |
| 199 | mServiceType = serviceType; |
| 200 | mCallType = callType; |
| 201 | mCallExtras = new Bundle(); |
| 202 | mMediaProfile = new ImsStreamMediaProfile(); |
| 203 | } |
| 204 | |
| 205 | public String getCallExtra(String name) { |
| 206 | return getCallExtra(name, ""); |
| 207 | } |
| 208 | |
| 209 | public String getCallExtra(String name, String defaultValue) { |
| 210 | if (mCallExtras == null) { |
| 211 | return defaultValue; |
| 212 | } |
| 213 | |
| 214 | return mCallExtras.getString(name, defaultValue); |
| 215 | } |
| 216 | |
| 217 | public boolean getCallExtraBoolean(String name) { |
| 218 | return getCallExtraBoolean(name, false); |
| 219 | } |
| 220 | |
| 221 | public boolean getCallExtraBoolean(String name, boolean defaultValue) { |
| 222 | if (mCallExtras == null) { |
| 223 | return defaultValue; |
| 224 | } |
| 225 | |
| 226 | return mCallExtras.getBoolean(name, defaultValue); |
| 227 | } |
| 228 | |
| 229 | public int getCallExtraInt(String name) { |
| 230 | return getCallExtraInt(name, -1); |
| 231 | } |
| 232 | |
| 233 | public int getCallExtraInt(String name, int defaultValue) { |
| 234 | if (mCallExtras == null) { |
| 235 | return defaultValue; |
| 236 | } |
| 237 | |
| 238 | return mCallExtras.getInt(name, defaultValue); |
| 239 | } |
| 240 | |
| 241 | public void setCallExtra(String name, String value) { |
| 242 | if (mCallExtras != null) { |
| 243 | mCallExtras.putString(name, value); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | public void setCallExtraBoolean(String name, boolean value) { |
| 248 | if (mCallExtras != null) { |
| 249 | mCallExtras.putBoolean(name, value); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | public void setCallExtraInt(String name, int value) { |
| 254 | if (mCallExtras != null) { |
| 255 | mCallExtras.putInt(name, value); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | public void updateCallType(ImsCallProfile profile) { |
| 260 | mCallType = profile.mCallType; |
| 261 | } |
| 262 | |
| 263 | public void updateCallExtras(ImsCallProfile profile) { |
| 264 | mCallExtras.clear(); |
| 265 | mCallExtras = (Bundle) profile.mCallExtras.clone(); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public String toString() { |
| 270 | return "{ serviceType=" + mServiceType + |
| 271 | ", callType=" + mCallType + |
Etan Cohen | db45a01 | 2014-12-10 10:08:20 -0800 | [diff] [blame] | 272 | ", restrictCause=" + mRestrictCause + |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 273 | ", mediaProfile=" + mMediaProfile.toString() + " }"; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public int describeContents() { |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public void writeToParcel(Parcel out, int flags) { |
| 283 | out.writeInt(mServiceType); |
| 284 | out.writeInt(mCallType); |
| 285 | out.writeParcelable(mCallExtras, 0); |
| 286 | out.writeParcelable(mMediaProfile, 0); |
| 287 | } |
| 288 | |
| 289 | private void readFromParcel(Parcel in) { |
| 290 | mServiceType = in.readInt(); |
| 291 | mCallType = in.readInt(); |
| 292 | mCallExtras = in.readParcelable(null); |
| 293 | mMediaProfile = in.readParcelable(null); |
| 294 | } |
| 295 | |
| 296 | public static final Creator<ImsCallProfile> CREATOR = new Creator<ImsCallProfile>() { |
| 297 | @Override |
| 298 | public ImsCallProfile createFromParcel(Parcel in) { |
| 299 | return new ImsCallProfile(in); |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public ImsCallProfile[] newArray(int size) { |
| 304 | return new ImsCallProfile[size]; |
| 305 | } |
| 306 | }; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 307 | |
| 308 | /** |
| 309 | * Converts from the call types defined in {@link com.android.ims.ImsCallProfile} to the |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 310 | * video state values defined in {@link VideoProfile}. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 311 | * |
| 312 | * @param callType The call type. |
| 313 | * @return The video state. |
| 314 | */ |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 315 | public static int getVideoStateFromImsCallProfile(ImsCallProfile callProfile) { |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 316 | int videostate = VideoProfile.STATE_AUDIO_ONLY; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 317 | switch (callProfile.mCallType) { |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 318 | case CALL_TYPE_VT_TX: |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 319 | videostate = VideoProfile.STATE_TX_ENABLED; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 320 | break; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 321 | case CALL_TYPE_VT_RX: |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 322 | videostate = VideoProfile.STATE_RX_ENABLED; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 323 | break; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 324 | case CALL_TYPE_VT: |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 325 | videostate = VideoProfile.STATE_BIDIRECTIONAL; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 326 | break; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 327 | case CALL_TYPE_VOICE: |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 328 | videostate = VideoProfile.STATE_AUDIO_ONLY; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 329 | break; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 330 | default: |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 331 | videostate = VideoProfile.STATE_AUDIO_ONLY; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 332 | break; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 333 | } |
Tyler Gunn | bc6f12e | 2015-06-09 14:34:11 -0700 | [diff] [blame] | 334 | if (callProfile.isVideoPaused() && !VideoProfile.isAudioOnly(videostate)) { |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 335 | videostate |= VideoProfile.STATE_PAUSED; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 336 | } else { |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 337 | videostate &= ~VideoProfile.STATE_PAUSED; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 338 | } |
| 339 | return videostate; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 343 | * Converts from the video state values defined in {@link VideoProfile} |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 344 | * to the call types defined in {@link ImsCallProfile}. |
| 345 | * |
| 346 | * @param videoState The video state. |
| 347 | * @return The call type. |
| 348 | */ |
| 349 | public static int getCallTypeFromVideoState(int videoState) { |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 350 | boolean videoTx = isVideoStateSet(videoState, VideoProfile.STATE_TX_ENABLED); |
| 351 | boolean videoRx = isVideoStateSet(videoState, VideoProfile.STATE_RX_ENABLED); |
| 352 | boolean isPaused = isVideoStateSet(videoState, VideoProfile.STATE_PAUSED); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 353 | if (isPaused) { |
| 354 | return ImsCallProfile.CALL_TYPE_VT_NODIR; |
| 355 | } else if (videoTx && !videoRx) { |
| 356 | return ImsCallProfile.CALL_TYPE_VT_TX; |
| 357 | } else if (!videoTx && videoRx) { |
| 358 | return ImsCallProfile.CALL_TYPE_VT_RX; |
| 359 | } else if (videoTx && videoRx) { |
| 360 | return ImsCallProfile.CALL_TYPE_VT; |
| 361 | } |
| 362 | return ImsCallProfile.CALL_TYPE_VOICE; |
| 363 | } |
| 364 | |
| 365 | /** |
Jing Zhao | e647a01 | 2014-08-19 12:41:23 -0500 | [diff] [blame] | 366 | * Translate presentation value to OIR value |
| 367 | * @param presentation |
| 368 | * @return OIR valuse |
| 369 | */ |
| 370 | public static int presentationToOIR(int presentation) { |
| 371 | switch (presentation) { |
| 372 | case PhoneConstants.PRESENTATION_RESTRICTED: |
| 373 | return ImsCallProfile.OIR_PRESENTATION_RESTRICTED; |
| 374 | case PhoneConstants.PRESENTATION_ALLOWED: |
| 375 | return ImsCallProfile.OIR_PRESENTATION_NOT_RESTRICTED; |
| 376 | default: |
| 377 | return ImsCallProfile.OIR_DEFAULT; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Translate OIR value to presentation value |
| 383 | * @param oir value |
| 384 | * @return presentation value |
| 385 | */ |
| 386 | public static int OIRToPresentation(int oir) { |
| 387 | switch(oir) { |
| 388 | case ImsCallProfile.OIR_PRESENTATION_RESTRICTED: |
| 389 | return PhoneConstants.PRESENTATION_RESTRICTED; |
| 390 | case ImsCallProfile.OIR_PRESENTATION_NOT_RESTRICTED: |
| 391 | return PhoneConstants.PRESENTATION_ALLOWED; |
| 392 | default: |
| 393 | return PhoneConstants.PRESENTATION_UNKNOWN; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 398 | * Checks if video call is paused |
| 399 | * @return true if call is video paused |
| 400 | */ |
| 401 | public boolean isVideoPaused() { |
| 402 | return mMediaProfile.mVideoDirection == ImsStreamMediaProfile.DIRECTION_INACTIVE; |
| 403 | } |
| 404 | |
| 405 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 406 | * Determines if a video state is set in a video state bit-mask. |
| 407 | * |
| 408 | * @param videoState The video state bit mask. |
| 409 | * @param videoStateToCheck The particular video state to check. |
| 410 | * @return True if the video state is set in the bit-mask. |
| 411 | */ |
| 412 | private static boolean isVideoStateSet(int videoState, int videoStateToCheck) { |
| 413 | return (videoState & videoStateToCheck) == videoStateToCheck; |
| 414 | } |
Wink Saville | f8458ff | 2014-06-25 16:08:02 -0700 | [diff] [blame] | 415 | } |