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 | |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 38 | import org.sflphone.service.StringMap; |
| 39 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 41 | import android.os.Parcel; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 42 | import android.os.Parcelable; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 43 | import android.util.Log; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 44 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 45 | public class SipCall implements Parcelable { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 46 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 47 | private static final String TAG = SipCall.class.getSimpleName(); |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 48 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 49 | private String mCallID = ""; |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 50 | private Account mAccount = null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 51 | private CallContact contact = null; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 52 | private boolean isRecording = false; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 53 | private long timestamp_start = 0; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 54 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 55 | public static final String USER_ID = "user_id"; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 56 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 57 | private int mCallType = state.CALL_TYPE_UNDETERMINED; |
| 58 | private int mCallState = state.CALL_STATE_NONE; |
| 59 | private int mMediaState = state.MEDIA_STATE_NONE; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 60 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 61 | /************************ |
| 62 | * Construtors |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 63 | ***********************/ |
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 | private SipCall(Parcel in) { |
| 66 | ArrayList<String> list = in.createStringArrayList(); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 67 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 68 | mCallID = list.get(0); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 69 | mAccount = in.readParcelable(Account.class.getClassLoader()); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 70 | contact = in.readParcelable(CallContact.class.getClassLoader()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 71 | isRecording = in.readByte() == 1; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 72 | mCallType = in.readInt(); |
| 73 | mCallState = in.readInt(); |
| 74 | mMediaState = in.readInt(); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 75 | timestamp_start = in.readLong(); |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 76 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 77 | |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 78 | 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] | 79 | mCallID = id; |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 80 | mAccount = account; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 81 | mCallType = call_type; |
| 82 | mCallState = call_state; |
| 83 | mMediaState = media_state; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 84 | contact = c; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 85 | } |
| 86 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 87 | public interface state { |
| 88 | public static final int CALL_TYPE_UNDETERMINED = 0; |
| 89 | public static final int CALL_TYPE_INCOMING = 1; |
| 90 | public static final int CALL_TYPE_OUTGOING = 2; |
| 91 | |
| 92 | public static final int CALL_STATE_NONE = 0; |
| 93 | public static final int CALL_STATE_INCOMING = 1; |
| 94 | public static final int CALL_STATE_RINGING = 2; |
| 95 | public static final int CALL_STATE_CURRENT = 3; |
| 96 | public static final int CALL_STATE_HUNGUP = 4; |
| 97 | public static final int CALL_STATE_BUSY = 5; |
| 98 | public static final int CALL_STATE_FAILURE = 6; |
| 99 | public static final int CALL_STATE_HOLD = 7; |
| 100 | public static final int CALL_STATE_UNHOLD = 8; |
| 101 | |
| 102 | public static final int MEDIA_STATE_NONE = 0; // No media currently |
| 103 | public static final int MEDIA_STATE_ACTIVE = 1; // Media is active |
| 104 | public static final int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user |
| 105 | public static final int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer |
| 106 | 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] | 107 | } |
| 108 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 109 | @Override |
| 110 | public int describeContents() { |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void writeToParcel(Parcel out, int flags) { |
| 116 | ArrayList<String> list = new ArrayList<String>(); |
| 117 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 118 | list.add(mCallID); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 119 | |
| 120 | out.writeStringList(list); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 121 | out.writeParcelable(mAccount, 0); |
| 122 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 123 | out.writeParcelable(contact, 0); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 124 | out.writeByte((byte) (isRecording ? 1 : 0)); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 125 | out.writeInt(mCallType); |
| 126 | out.writeInt(mCallState); |
| 127 | out.writeInt(mMediaState); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 128 | out.writeLong(timestamp_start); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() { |
| 132 | public SipCall createFromParcel(Parcel in) { |
| 133 | return new SipCall(in); |
| 134 | } |
| 135 | |
| 136 | public SipCall[] newArray(int size) { |
| 137 | return new SipCall[size]; |
| 138 | } |
| 139 | }; |
| 140 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 141 | public void setCallID(String callID) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 142 | mCallID = callID; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | public String getCallId() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 146 | return mCallID; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 149 | public long getTimestamp_start() { |
| 150 | return timestamp_start; |
| 151 | } |
| 152 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 153 | public void setTimestamp_start(long timestamp_start) { |
| 154 | this.timestamp_start = timestamp_start; |
| 155 | } |
| 156 | |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 157 | public void setAccount(Account account) { |
| 158 | mAccount = account; |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 161 | public Account getAccount() { |
| 162 | return mAccount; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 163 | } |
| 164 | |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 165 | public void setCallType(int callType) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 166 | mCallType = callType; |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | public int getCallType() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 170 | return mCallType; |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 171 | } |
| 172 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 173 | public String getCallTypeString() { |
| 174 | switch (mCallType) { |
| 175 | case state.CALL_TYPE_INCOMING: |
| 176 | return "CALL_TYPE_INCOMING"; |
| 177 | case state.CALL_TYPE_OUTGOING: |
| 178 | return "CALL_TYPE_OUTGOING"; |
| 179 | default: |
| 180 | return "CALL_TYPE_UNDETERMINED"; |
| 181 | } |
| 182 | } |
| 183 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 184 | public void setCallState(int callState) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 185 | mCallState = callState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 186 | } |
| 187 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 188 | public int getCallStateInt() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 189 | return mCallState; |
| 190 | } |
| 191 | |
| 192 | public String getmCallID() { |
| 193 | return mCallID; |
| 194 | } |
| 195 | |
| 196 | public void setmCallID(String mCallID) { |
| 197 | this.mCallID = mCallID; |
| 198 | } |
| 199 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 200 | public CallContact getContact() { |
| 201 | return contact; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 202 | } |
| 203 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 204 | public void setContact(CallContact contacts) { |
| 205 | contact = contacts; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | public int getmCallType() { |
| 209 | return mCallType; |
| 210 | } |
| 211 | |
| 212 | public void setmCallType(int mCallType) { |
| 213 | this.mCallType = mCallType; |
| 214 | } |
| 215 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 216 | public int getmMediaState() { |
| 217 | return mMediaState; |
| 218 | } |
| 219 | |
| 220 | public void setmMediaState(int mMediaState) { |
| 221 | this.mMediaState = mMediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 224 | public String getCallStateString() { |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 225 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 226 | String text_state; |
| 227 | |
| 228 | switch (mCallState) { |
| 229 | case state.CALL_STATE_INCOMING: |
| 230 | text_state = "INCOMING"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 231 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 232 | case state.CALL_STATE_RINGING: |
| 233 | text_state = "RINGING"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 234 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 235 | case state.CALL_STATE_CURRENT: |
| 236 | text_state = "CURRENT"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 237 | break; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 238 | case state.CALL_STATE_HUNGUP: |
| 239 | text_state = "HUNGUP"; |
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_BUSY: |
| 242 | text_state = "BUSY"; |
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_FAILURE: |
| 245 | text_state = "FAILURE"; |
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_HOLD: |
| 248 | text_state = "HOLD"; |
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_UNHOLD: |
| 251 | text_state = "UNHOLD"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 252 | break; |
| 253 | default: |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 254 | text_state = "NULL"; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 255 | } |
| 256 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 257 | return text_state; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 258 | } |
| 259 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 260 | public void setMediaState(int mediaState) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 261 | mMediaState = mediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | public int getMediaState() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 265 | return mMediaState; |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 266 | } |
| 267 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 268 | public boolean isRecording() { |
| 269 | return isRecording; |
| 270 | } |
| 271 | |
| 272 | public void setRecording(boolean isRecording) { |
| 273 | this.isRecording = isRecording; |
| 274 | } |
| 275 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 276 | public static class SipCallBuilder { |
| 277 | |
| 278 | private String bCallID = ""; |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 279 | private Account bAccount = null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 280 | private CallContact bContact = null; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 281 | |
| 282 | private int bCallType = state.CALL_TYPE_UNDETERMINED; |
| 283 | private int bCallState = state.CALL_STATE_NONE; |
| 284 | private int bMediaState = state.MEDIA_STATE_NONE; |
| 285 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 286 | public SipCallBuilder setCallType(int bCallType) { |
| 287 | this.bCallType = bCallType; |
| 288 | return this; |
| 289 | } |
| 290 | |
| 291 | public SipCallBuilder setMediaState(int state) { |
| 292 | this.bMediaState = state; |
| 293 | return this; |
| 294 | } |
| 295 | |
| 296 | public SipCallBuilder setCallState(int state) { |
| 297 | this.bCallState = state; |
| 298 | return this; |
| 299 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 300 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 301 | private static final String TAG = SipCallBuilder.class.getSimpleName(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 302 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 303 | public SipCallBuilder startCallCreation(String id) { |
| 304 | bCallID = id; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 305 | bCallType = SipCall.state.CALL_TYPE_INCOMING; |
| 306 | return this; |
| 307 | } |
| 308 | |
| 309 | public SipCallBuilder startCallCreation() { |
| 310 | Random random = new Random(); |
Tristan Matthews | 1a4962d | 2013-07-18 16:27:10 -0400 | [diff] [blame] | 311 | bCallID = Integer.toString(Math.abs(random.nextInt())); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 312 | return this; |
| 313 | } |
| 314 | |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 315 | public SipCallBuilder setAccount(Account a) { |
| 316 | bAccount = a; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 317 | return this; |
| 318 | } |
| 319 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 320 | public SipCallBuilder setContact(CallContact c) { |
| 321 | bContact = c; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 322 | return this; |
| 323 | } |
| 324 | |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 325 | public SipCall build() throws InvalidObjectException { |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 326 | if (bCallID.contentEquals("") || bAccount == null || bContact == null) { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 327 | throw new InvalidObjectException("SipCallBuilder's parameters missing"); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 328 | } |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 329 | return new SipCall(bCallID, bAccount, bCallType, bCallState, bMediaState, bContact); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | public static SipCallBuilder getInstance() { |
| 333 | return new SipCallBuilder(); |
| 334 | } |
| 335 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 336 | public static SipCall buildMyselfCall(ContentResolver cr, String displayName) { |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 337 | return new SipCall("default", null, SipCall.state.CALL_TYPE_UNDETERMINED, state.CALL_STATE_NONE, state.MEDIA_STATE_NONE, |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 338 | CallContact.ContactBuilder.buildUserContact(cr, displayName)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 339 | |
| 340 | } |
| 341 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 342 | } |
| 343 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 344 | public void printCallInfo() { |
| 345 | Log.i(TAG, "CallInfo: CallID: " + mCallID); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 346 | Log.i(TAG, " AccountID: " + mAccount.getAccountID()); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 347 | Log.i(TAG, " CallState: " + mCallState); |
| 348 | Log.i(TAG, " CallType: " + mCallType); |
| 349 | } |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 350 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 351 | /** |
| 352 | * Compare sip calls based on call ID |
| 353 | */ |
| 354 | @Override |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 355 | public boolean equals(Object c) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 356 | if (c instanceof SipCall && ((SipCall) c).mCallID.contentEquals((mCallID))) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 357 | return true; |
| 358 | } |
| 359 | return false; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 360 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 361 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 362 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 363 | public boolean isOutGoing() { |
| 364 | if (mCallType == state.CALL_TYPE_OUTGOING) |
| 365 | return true; |
| 366 | |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | public boolean isRinging() { |
| 371 | if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE) |
| 372 | return true; |
| 373 | |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | public boolean isIncoming() { |
| 378 | if (mCallType == state.CALL_TYPE_INCOMING) |
| 379 | return true; |
| 380 | |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | public void setCallState(String newState) { |
| 385 | if (newState.equals("INCOMING")) { |
| 386 | setCallState(SipCall.state.CALL_STATE_INCOMING); |
| 387 | } else if (newState.equals("RINGING")) { |
| 388 | setCallState(SipCall.state.CALL_STATE_RINGING); |
| 389 | } else if (newState.equals("CURRENT")) { |
| 390 | setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 391 | } else if (newState.equals("HUNGUP")) { |
| 392 | setCallState(SipCall.state.CALL_STATE_HUNGUP); |
| 393 | } else if (newState.equals("BUSY")) { |
| 394 | setCallState(SipCall.state.CALL_STATE_BUSY); |
| 395 | } else if (newState.equals("FAILURE")) { |
| 396 | setCallState(SipCall.state.CALL_STATE_FAILURE); |
| 397 | } else if (newState.equals("HOLD")) { |
| 398 | setCallState(SipCall.state.CALL_STATE_HOLD); |
| 399 | } else if (newState.equals("UNHOLD")) { |
| 400 | setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 401 | } else { |
| 402 | setCallState(SipCall.state.CALL_STATE_NONE); |
| 403 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 404 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | public boolean isOngoing() { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 408 | if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE || mCallState == state.CALL_STATE_FAILURE |
| 409 | || mCallState == state.CALL_STATE_BUSY || mCallState == state.CALL_STATE_HUNGUP) |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 410 | return false; |
| 411 | |
| 412 | return true; |
| 413 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 414 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 415 | public boolean isOnHold() { |
| 416 | return mCallState == state.CALL_STATE_HOLD; |
| 417 | } |
| 418 | |
Alexandre Lision | 6ae652d | 2013-09-26 16:39:20 -0400 | [diff] [blame] | 419 | public boolean isCurrent() { |
| 420 | return mCallState == state.CALL_STATE_CURRENT; |
| 421 | } |
| 422 | |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 423 | } |