ImsCallProfile.java revision aa07df84f279a87ad6370758c9d792a660f2cebb
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
17package com.android.ims;
18
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.telecomm.VideoCallProfile;
23
24/**
25 * Parcelable object to handle IMS call profile.
26 * It is created from GSMA IR.92/IR.94, 3GPP TS 24.229/TS 26.114/TS26.111.
27 * It provides the service and call type, the additional information related to the call.
28 *
29 * @hide
30 */
31public class ImsCallProfile implements Parcelable {
32    private static final String TAG = "ImsCallProfile";
33
34    /**
35     * Service types
36     */
37    /**
38     * It is for a special case. It helps that the application can make a call
39     * without IMS connection (not registered).
40     * In the moment of the call initiation, the device try to connect to the IMS network
41     * and initiates the call.
42     */
43    public static final int SERVICE_TYPE_NONE = 0;
44    /**
45     * It is a default type and can be selected when the device is connected to the IMS network.
46     */
47    public static final int SERVICE_TYPE_NORMAL = 1;
48    /**
49     * It is for an emergency call.
50     */
51    public static final int SERVICE_TYPE_EMERGENCY = 2;
52
53    /**
54     * Call types
55     */
56    /**
57     * IMSPhone to support IR.92 & IR.94 (voice + video upgrade/downgrade)
58     */
59    public static final int CALL_TYPE_VOICE_N_VIDEO = 1;
60    /**
61     * IR.92 (Voice only)
62     */
63    public static final int CALL_TYPE_VOICE = 2;
64    /**
65     * VT to support IR.92 & IR.94 (voice + video upgrade/downgrade)
66     */
67    public static final int CALL_TYPE_VIDEO_N_VOICE = 3;
68    /**
69     * Video Telephony (audio / video two way)
70     */
71    public static final int CALL_TYPE_VT = 4;
72    /**
73     * Video Telephony (audio two way / video TX one way)
74     */
75    public static final int CALL_TYPE_VT_TX = 5;
76    /**
77     * Video Telephony (audio two way / video RX one way)
78     */
79    public static final int CALL_TYPE_VT_RX = 6;
80    /**
81     * Video Telephony (audio two way / video inactive)
82     */
83    public static final int CALL_TYPE_VT_NODIR = 7;
84    /**
85     * VideoShare (video two way)
86     */
87    public static final int CALL_TYPE_VS = 8;
88    /**
89     * VideoShare (video TX one way)
90     */
91    public static final int CALL_TYPE_VS_TX = 9;
92    /**
93     * VideoShare (video RX one way)
94     */
95    public static final int CALL_TYPE_VS_RX = 10;
96
97    /**
98     * Extra properties for IMS call.
99     */
100    /**
101     * Boolean extra properties - "true" / "false"
102     *  conference : Indicates if the session is for the conference call or not.
103     *  e_call : Indicates if the session is for the emergency call or not.
104     *  vms : Indicates if the session is connected to the voice mail system or not.
105     *  call_mode_changeable : Indicates if the session is able to upgrade/downgrade
106     *      the video during voice call.
107     *  conference_avail : Indicates if the session can be extended to the conference.
108     */
109    public static final String EXTRA_CONFERENCE = "conference";
110    public static final String EXTRA_E_CALL = "e_call";
111    public static final String EXTRA_VMS = "vms";
112    public static final String EXTRA_CALL_MODE_CHANGEABLE = "call_mode_changeable";
113    public static final String EXTRA_CONFERENCE_AVAIL = "conference_avail";
114
115    /**
116     * Integer extra properties
117     *  oir : Rule for originating identity (number) presentation, MO/MT.
118     *      {@link ImsCallProfile#OIR_DEFAULT}
119     *      {@link ImsCallProfile#OIR_PRESENTATION_RESTRICTED}
120     *      {@link ImsCallProfile#OIR_PRESENTATION_NOT_RESTRICTED}
121     *  cnap : Rule for calling name presentation
122     *      {@link ImsCallProfile#OIR_DEFAULT}
123     *      {@link ImsCallProfile#OIR_PRESENTATION_RESTRICTED}
124     *      {@link ImsCallProfile#OIR_PRESENTATION_NOT_RESTRICTED}
125     *  dialstring : To identify the Ims call type, MO
126     *      {@link ImsCallProfile#DIALSTRING_NORMAL_CALL}
127     *      {@link ImsCallProfile#DIALSTRING_SS_CONF}
128     *      {@link ImsCallProfile#DIALSTRING_USSD}
129     */
130    public static final String EXTRA_OIR = "oir";
131    public static final String EXTRA_CNAP = "cnap";
132    public static final String EXTRA_DIALSTRING = "dialstring";
133
134    /**
135     * Values for EXTRA_OIR / EXTRA_CNAP
136     */
137    public static final int OIR_DEFAULT = 0;    // "user subscription default value"
138    public static final int OIR_PRESENTATION_RESTRICTED = 1;
139    public static final int OIR_PRESENTATION_NOT_RESTRICTED = 2;
140
141    /**
142     * Values for EXTRA_DIALSTRING
143     */
144    // default (normal call)
145    public static final int DIALSTRING_NORMAL = 0;
146    // Call for SIP-based user configuration
147    public static final int DIALSTRING_SS_CONF = 1;
148    // Call for USSD message
149    public static final int DIALSTRING_USSD = 2;
150
151    /**
152     * String extra properties
153     *  oi : Originating identity (number), MT only
154     *  cna : Calling name
155     *  ussd : For network-initiated USSD, MT only
156     *  remote_uri : Connected user identity (it can be used for the conference)
157     */
158    public static final String EXTRA_OI = "oi";
159    public static final String EXTRA_CNA = "cna";
160    public static final String EXTRA_USSD = "ussd";
161    public static final String EXTRA_REMOTE_URI = "remote_uri";
162
163    public int mServiceType;
164    public int mCallType;
165    public Bundle mCallExtras;
166    public ImsStreamMediaProfile mMediaProfile;
167
168
169
170    public ImsCallProfile(Parcel in) {
171        readFromParcel(in);
172    }
173
174    public ImsCallProfile() {
175        mServiceType = SERVICE_TYPE_NORMAL;
176        mCallType = CALL_TYPE_VOICE_N_VIDEO;
177        mCallExtras = new Bundle();
178        mMediaProfile = new ImsStreamMediaProfile();
179    }
180
181    public ImsCallProfile(int serviceType, int callType) {
182        mServiceType = serviceType;
183        mCallType = callType;
184        mCallExtras = new Bundle();
185        mMediaProfile = new ImsStreamMediaProfile();
186    }
187
188    public String getCallExtra(String name) {
189        return getCallExtra(name, "");
190    }
191
192    public String getCallExtra(String name, String defaultValue) {
193        if (mCallExtras == null) {
194            return defaultValue;
195        }
196
197        return mCallExtras.getString(name, defaultValue);
198    }
199
200    public boolean getCallExtraBoolean(String name) {
201        return getCallExtraBoolean(name, false);
202    }
203
204    public boolean getCallExtraBoolean(String name, boolean defaultValue) {
205        if (mCallExtras == null) {
206            return defaultValue;
207        }
208
209        return mCallExtras.getBoolean(name, defaultValue);
210    }
211
212    public int getCallExtraInt(String name) {
213        return getCallExtraInt(name, -1);
214    }
215
216    public int getCallExtraInt(String name, int defaultValue) {
217        if (mCallExtras == null) {
218            return defaultValue;
219        }
220
221        return mCallExtras.getInt(name, defaultValue);
222    }
223
224    public void setCallExtra(String name, String value) {
225        if (mCallExtras != null) {
226            mCallExtras.putString(name, value);
227        }
228    }
229
230    public void setCallExtraBoolean(String name, boolean value) {
231        if (mCallExtras != null) {
232            mCallExtras.putBoolean(name, value);
233        }
234    }
235
236    public void setCallExtraInt(String name, int value) {
237        if (mCallExtras != null) {
238            mCallExtras.putInt(name, value);
239        }
240    }
241
242    public void updateCallType(ImsCallProfile profile) {
243        mCallType = profile.mCallType;
244    }
245
246    public void updateCallExtras(ImsCallProfile profile) {
247        mCallExtras.clear();
248        mCallExtras = (Bundle) profile.mCallExtras.clone();
249    }
250
251    @Override
252    public String toString() {
253        return "{ serviceType=" + mServiceType +
254                ", callType=" + mCallType +
255                ", callExtras=" + mCallExtras.toString() +
256                ", mediaProfile=" + mMediaProfile.toString() + " }";
257    }
258
259    @Override
260    public int describeContents() {
261        return 0;
262    }
263
264    @Override
265    public void writeToParcel(Parcel out, int flags) {
266        out.writeInt(mServiceType);
267        out.writeInt(mCallType);
268        out.writeParcelable(mCallExtras, 0);
269        out.writeParcelable(mMediaProfile, 0);
270    }
271
272    private void readFromParcel(Parcel in) {
273        mServiceType = in.readInt();
274        mCallType = in.readInt();
275        mCallExtras = in.readParcelable(null);
276        mMediaProfile = in.readParcelable(null);
277    }
278
279    public static final Creator<ImsCallProfile> CREATOR = new Creator<ImsCallProfile>() {
280        @Override
281        public ImsCallProfile createFromParcel(Parcel in) {
282            return new ImsCallProfile(in);
283        }
284
285        @Override
286        public ImsCallProfile[] newArray(int size) {
287            return new ImsCallProfile[size];
288        }
289    };
290
291    /**
292     * Converts from the call types defined in {@link com.android.ims.ImsCallProfile} to the
293     * video state values defined in {@link android.telecomm.VideoCallProfile}.
294     *
295     * @param callType The call type.
296     * @return The video state.
297     */
298    public static int getVideoStateFromCallType(int callType) {
299        switch (callType) {
300            case CALL_TYPE_VT_NODIR:
301                return VideoCallProfile.VIDEO_STATE_PAUSED |
302                        VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL;
303            case CALL_TYPE_VT_TX:
304                return VideoCallProfile.VIDEO_STATE_TX_ENABLED;
305            case CALL_TYPE_VT_RX:
306                return VideoCallProfile.VIDEO_STATE_RX_ENABLED;
307            case CALL_TYPE_VT:
308                return VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL;
309            case CALL_TYPE_VOICE:
310                return VideoCallProfile.VIDEO_STATE_AUDIO_ONLY;
311            default:
312                return VideoCallProfile.VIDEO_STATE_AUDIO_ONLY;
313        }
314    }
315
316    /**
317     * Converts from the video state values defined in {@link android.telecomm.VideoCallProfile}
318     * to the call types defined in {@link ImsCallProfile}.
319     *
320     * @param videoState The video state.
321     * @return The call type.
322     */
323    public static int getCallTypeFromVideoState(int videoState) {
324        boolean videoTx = isVideoStateSet(videoState, VideoCallProfile.VIDEO_STATE_TX_ENABLED);
325        boolean videoRx = isVideoStateSet(videoState, VideoCallProfile.VIDEO_STATE_RX_ENABLED);
326        boolean isPaused = isVideoStateSet(videoState, VideoCallProfile.VIDEO_STATE_PAUSED);
327        if (isPaused) {
328            return ImsCallProfile.CALL_TYPE_VT_NODIR;
329        } else if (videoTx && !videoRx) {
330            return ImsCallProfile.CALL_TYPE_VT_TX;
331        } else if (!videoTx && videoRx) {
332            return ImsCallProfile.CALL_TYPE_VT_RX;
333        } else if (videoTx && videoRx) {
334            return ImsCallProfile.CALL_TYPE_VT;
335        }
336        return ImsCallProfile.CALL_TYPE_VOICE;
337    }
338
339    /**
340     * Determines if a video state is set in a video state bit-mask.
341     *
342     * @param videoState The video state bit mask.
343     * @param videoStateToCheck The particular video state to check.
344     * @return True if the video state is set in the bit-mask.
345     */
346    private static boolean isVideoStateSet(int videoState, int videoStateToCheck) {
347        return (videoState & videoStateToCheck) == videoStateToCheck;
348    }
349}
350