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