Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 4 | * Author: Alexandre Savard <alexandre.savard@gmail.com> |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 31 | package com.savoirfairelinux.sflphone.model; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 32 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 33 | import java.util.ArrayList; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 34 | import java.util.Random; |
Tristan Matthews | 1a4962d | 2013-07-18 16:27:10 -0400 | [diff] [blame] | 35 | import java.lang.Math; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 36 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 37 | import android.content.ContentResolver; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 38 | import android.os.Parcel; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 39 | import android.os.Parcelable; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 40 | import android.util.Log; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 41 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 42 | public class SipCall implements Parcelable { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 43 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 44 | private static final String TAG = SipCall.class.getSimpleName(); |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 45 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 46 | private String mCallID = ""; |
| 47 | private String mAccountID = ""; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 48 | private CallContact contact = null; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 49 | private boolean isRecording = false; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 50 | private long timestamp_start = 0; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 51 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 52 | public static final String USER_ID = "user_id"; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 53 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 54 | private int mCallType = state.CALL_TYPE_UNDETERMINED; |
| 55 | private int mCallState = state.CALL_STATE_NONE; |
| 56 | private int mMediaState = state.MEDIA_STATE_NONE; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 57 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 58 | /************************ |
| 59 | * Construtors |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 60 | ***********************/ |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 61 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 62 | private SipCall(Parcel in) { |
| 63 | ArrayList<String> list = in.createStringArrayList(); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 64 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 65 | mCallID = list.get(0); |
| 66 | mAccountID = list.get(1); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 67 | contact = in.readParcelable(CallContact.class.getClassLoader()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 68 | isRecording = in.readByte() == 1; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 69 | mCallType = in.readInt(); |
| 70 | mCallState = in.readInt(); |
| 71 | mMediaState = in.readInt(); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 72 | timestamp_start = in.readLong(); |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 73 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 74 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 75 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 76 | public SipCall(String id, String account, int call_type, int call_state, int media_state, CallContact c) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 77 | mCallID = id; |
| 78 | mAccountID = account; |
| 79 | mCallType = call_type; |
| 80 | mCallState = call_state; |
| 81 | mMediaState = media_state; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 82 | contact = c; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 83 | } |
| 84 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 85 | |
| 86 | public interface state { |
| 87 | public static final int CALL_TYPE_UNDETERMINED = 0; |
| 88 | public static final int CALL_TYPE_INCOMING = 1; |
| 89 | public static final int CALL_TYPE_OUTGOING = 2; |
| 90 | |
| 91 | public static final int CALL_STATE_NONE = 0; |
| 92 | public static final int CALL_STATE_INCOMING = 1; |
| 93 | public static final int CALL_STATE_RINGING = 2; |
| 94 | public static final int CALL_STATE_CURRENT = 3; |
| 95 | public static final int CALL_STATE_HUNGUP = 4; |
| 96 | public static final int CALL_STATE_BUSY = 5; |
| 97 | public static final int CALL_STATE_FAILURE = 6; |
| 98 | public static final int CALL_STATE_HOLD = 7; |
| 99 | public static final int CALL_STATE_UNHOLD = 8; |
| 100 | |
| 101 | public static final int MEDIA_STATE_NONE = 0; // No media currently |
| 102 | public static final int MEDIA_STATE_ACTIVE = 1; // Media is active |
| 103 | public static final int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user |
| 104 | public static final int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer |
| 105 | public static final int MEDIA_STATE_ERROR = 5; // Media is in error state |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 106 | } |
| 107 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 108 | @Override |
| 109 | public int describeContents() { |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void writeToParcel(Parcel out, int flags) { |
| 115 | ArrayList<String> list = new ArrayList<String>(); |
| 116 | |
| 117 | // Don't mess with this order!!! |
| 118 | list.add(mCallID); |
| 119 | list.add(mAccountID); |
| 120 | |
| 121 | out.writeStringList(list); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 122 | out.writeParcelable(contact, 0); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 123 | out.writeByte((byte) (isRecording ? 1 : 0)); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 124 | out.writeInt(mCallType); |
| 125 | out.writeInt(mCallState); |
| 126 | out.writeInt(mMediaState); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 127 | out.writeLong(timestamp_start); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() { |
| 131 | public SipCall createFromParcel(Parcel in) { |
| 132 | return new SipCall(in); |
| 133 | } |
| 134 | |
| 135 | public SipCall[] newArray(int size) { |
| 136 | return new SipCall[size]; |
| 137 | } |
| 138 | }; |
| 139 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 140 | public void setCallID(String callID) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 141 | mCallID = callID; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | public String getCallId() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 145 | return mCallID; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 148 | public long getTimestamp_start() { |
| 149 | return timestamp_start; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | public void setTimestamp_start(long timestamp_start) { |
| 154 | this.timestamp_start = timestamp_start; |
| 155 | } |
| 156 | |
| 157 | |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 158 | public void setAccountID(String accountID) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 159 | mAccountID = accountID; |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | public String getAccountID() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 163 | return mAccountID; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 166 | public void setCallType(int callType) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 167 | mCallType = callType; |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | public int getCallType() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 171 | return mCallType; |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 172 | } |
| 173 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 174 | public String getCallTypeString() { |
| 175 | switch (mCallType) { |
| 176 | case state.CALL_TYPE_INCOMING: |
| 177 | return "CALL_TYPE_INCOMING"; |
| 178 | case state.CALL_TYPE_OUTGOING: |
| 179 | return "CALL_TYPE_OUTGOING"; |
| 180 | default: |
| 181 | return "CALL_TYPE_UNDETERMINED"; |
| 182 | } |
| 183 | } |
| 184 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 185 | public void setCallState(int callState) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 186 | mCallState = callState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 189 | public int getCallStateInt() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 190 | return mCallState; |
| 191 | } |
| 192 | |
| 193 | public String getmCallID() { |
| 194 | return mCallID; |
| 195 | } |
| 196 | |
| 197 | public void setmCallID(String mCallID) { |
| 198 | this.mCallID = mCallID; |
| 199 | } |
| 200 | |
| 201 | public String getmAccountID() { |
| 202 | return mAccountID; |
| 203 | } |
| 204 | |
| 205 | public void setmAccountID(String mAccountID) { |
| 206 | this.mAccountID = mAccountID; |
| 207 | } |
| 208 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 209 | public CallContact getContact() { |
| 210 | return contact; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 211 | } |
| 212 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 213 | public void setContact(CallContact contacts) { |
| 214 | contact = contacts; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | public int getmCallType() { |
| 218 | return mCallType; |
| 219 | } |
| 220 | |
| 221 | public void setmCallType(int mCallType) { |
| 222 | this.mCallType = mCallType; |
| 223 | } |
| 224 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 225 | public int getmMediaState() { |
| 226 | return mMediaState; |
| 227 | } |
| 228 | |
| 229 | public void setmMediaState(int mMediaState) { |
| 230 | this.mMediaState = mMediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 233 | public String getCallStateString() { |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 234 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 235 | String text_state; |
| 236 | |
| 237 | switch (mCallState) { |
| 238 | case state.CALL_STATE_INCOMING: |
| 239 | text_state = "INCOMING"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 240 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 241 | case state.CALL_STATE_RINGING: |
| 242 | text_state = "RINGING"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 243 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 244 | case state.CALL_STATE_CURRENT: |
| 245 | text_state = "CURRENT"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 246 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 247 | case state.CALL_STATE_HUNGUP: |
| 248 | text_state = "HUNGUP"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 249 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 250 | case state.CALL_STATE_BUSY: |
| 251 | text_state = "BUSY"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 252 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 253 | case state.CALL_STATE_FAILURE: |
| 254 | text_state = "FAILURE"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 255 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 256 | case state.CALL_STATE_HOLD: |
| 257 | text_state = "HOLD"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 258 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 259 | case state.CALL_STATE_UNHOLD: |
| 260 | text_state = "UNHOLD"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 261 | break; |
| 262 | default: |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 263 | text_state = "NULL"; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 264 | } |
| 265 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 266 | return text_state; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 269 | public void setMediaState(int mediaState) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 270 | mMediaState = mediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | public int getMediaState() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 274 | return mMediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 275 | } |
| 276 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 277 | public boolean isRecording() { |
| 278 | return isRecording; |
| 279 | } |
| 280 | |
| 281 | public void setRecording(boolean isRecording) { |
| 282 | this.isRecording = isRecording; |
| 283 | } |
| 284 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 285 | public static class SipCallBuilder { |
| 286 | |
| 287 | private String bCallID = ""; |
| 288 | private String bAccountID = ""; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 289 | private CallContact bContact = null; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 290 | |
| 291 | private int bCallType = state.CALL_TYPE_UNDETERMINED; |
| 292 | private int bCallState = state.CALL_STATE_NONE; |
| 293 | private int bMediaState = state.MEDIA_STATE_NONE; |
| 294 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 295 | public SipCallBuilder setCallType(int bCallType) { |
| 296 | this.bCallType = bCallType; |
| 297 | return this; |
| 298 | } |
| 299 | |
| 300 | public SipCallBuilder setMediaState(int state) { |
| 301 | this.bMediaState = state; |
| 302 | return this; |
| 303 | } |
| 304 | |
| 305 | public SipCallBuilder setCallState(int state) { |
| 306 | this.bCallState = state; |
| 307 | return this; |
| 308 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 309 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 310 | private static final String TAG = SipCallBuilder.class.getSimpleName(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 311 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 312 | public SipCallBuilder startCallCreation(String id) { |
| 313 | bCallID = id; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 314 | bCallType = SipCall.state.CALL_TYPE_INCOMING; |
| 315 | return this; |
| 316 | } |
| 317 | |
| 318 | public SipCallBuilder startCallCreation() { |
| 319 | Random random = new Random(); |
Tristan Matthews | 1a4962d | 2013-07-18 16:27:10 -0400 | [diff] [blame] | 320 | bCallID = Integer.toString(Math.abs(random.nextInt())); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 321 | return this; |
| 322 | } |
| 323 | |
| 324 | public SipCallBuilder setAccountID(String h) { |
| 325 | Log.i(TAG, "setAccountID" + h); |
| 326 | bAccountID = h; |
| 327 | return this; |
| 328 | } |
| 329 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 330 | public SipCallBuilder setContact(CallContact c) { |
| 331 | bContact = c; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 332 | return this; |
| 333 | } |
| 334 | |
| 335 | public SipCall build() throws Exception { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 336 | if (bCallID.contentEquals("") || bAccountID.contentEquals("") || bContact == null) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 337 | throw new Exception("SipCallBuilder's parameters missing"); |
| 338 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 339 | return new SipCall(bCallID, bAccountID, bCallType, bCallState, bMediaState, bContact); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | public static SipCallBuilder getInstance() { |
| 343 | return new SipCallBuilder(); |
| 344 | } |
| 345 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 346 | public static SipCall buildMyselfCall(ContentResolver cr, String displayName) { |
| 347 | return new SipCall("default", "default", SipCall.state.CALL_TYPE_UNDETERMINED, state.CALL_STATE_NONE, state.MEDIA_STATE_NONE, |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 348 | CallContact.ContactBuilder.buildUserContact(cr, displayName)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 349 | |
| 350 | } |
| 351 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 352 | } |
| 353 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 354 | public void printCallInfo() { |
| 355 | Log.i(TAG, "CallInfo: CallID: " + mCallID); |
| 356 | Log.i(TAG, " AccountID: " + mAccountID); |
| 357 | Log.i(TAG, " CallState: " + mCallState); |
| 358 | Log.i(TAG, " CallType: " + mCallType); |
| 359 | } |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 360 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 361 | /** |
| 362 | * Compare sip calls based on call ID |
| 363 | */ |
| 364 | @Override |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 365 | public boolean equals(Object c) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 366 | if (c instanceof SipCall && ((SipCall) c).mCallID.contentEquals((mCallID))) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 367 | return true; |
| 368 | } |
| 369 | return false; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 370 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 371 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 372 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 373 | public boolean isOutGoing() { |
| 374 | if (mCallType == state.CALL_TYPE_OUTGOING) |
| 375 | return true; |
| 376 | |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | public boolean isRinging() { |
| 381 | if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE) |
| 382 | return true; |
| 383 | |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | public boolean isIncoming() { |
| 388 | if (mCallType == state.CALL_TYPE_INCOMING) |
| 389 | return true; |
| 390 | |
| 391 | return false; |
| 392 | } |
| 393 | |
| 394 | public void setCallState(String newState) { |
| 395 | if (newState.equals("INCOMING")) { |
| 396 | setCallState(SipCall.state.CALL_STATE_INCOMING); |
| 397 | } else if (newState.equals("RINGING")) { |
| 398 | setCallState(SipCall.state.CALL_STATE_RINGING); |
| 399 | } else if (newState.equals("CURRENT")) { |
| 400 | setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 401 | } else if (newState.equals("HUNGUP")) { |
| 402 | setCallState(SipCall.state.CALL_STATE_HUNGUP); |
| 403 | } else if (newState.equals("BUSY")) { |
| 404 | setCallState(SipCall.state.CALL_STATE_BUSY); |
| 405 | } else if (newState.equals("FAILURE")) { |
| 406 | setCallState(SipCall.state.CALL_STATE_FAILURE); |
| 407 | } else if (newState.equals("HOLD")) { |
| 408 | setCallState(SipCall.state.CALL_STATE_HOLD); |
| 409 | } else if (newState.equals("UNHOLD")) { |
| 410 | setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 411 | } else { |
| 412 | setCallState(SipCall.state.CALL_STATE_NONE); |
| 413 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 414 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 415 | } |
| 416 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 417 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 418 | public boolean isOngoing() { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 419 | if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE || mCallState == state.CALL_STATE_FAILURE |
| 420 | || mCallState == state.CALL_STATE_BUSY || mCallState == state.CALL_STATE_HUNGUP) |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 421 | return false; |
| 422 | |
| 423 | return true; |
| 424 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 425 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 426 | public boolean isOnHold() { |
| 427 | return mCallState == state.CALL_STATE_HOLD; |
| 428 | } |
| 429 | |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 430 | } |