blob: e8d6ac3fc2c2f86df72fed73a0e3d6dd4788f8f8 [file] [log] [blame]
Alexandre Savard4a19d752012-09-19 13:19:24 -04001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Savard4a19d752012-09-19 13:19:24 -04003 *
Alexandre Lision68855472013-10-10 16:20:46 -04004 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux>
5 * Alexandre Savard <alexandre.savard@gmail.com>
Alexandre Savard4a19d752012-09-19 13:19:24 -04006 *
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 Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.model;
Alexandre Savard4a19d752012-09-19 13:19:24 -040033
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050034import android.os.Bundle;
Alexandre Savard557a5742012-10-24 13:54:53 -040035import android.os.Parcel;
alisiona4325152013-04-19 11:10:03 -040036import android.os.Parcelable;
Alexandre Savard4a19d752012-09-19 13:19:24 -040037import android.util.Log;
Alexandre Savard4a19d752012-09-19 13:19:24 -040038
alisionfde875f2013-05-28 17:01:54 -040039public class SipCall implements Parcelable {
alision371b77e2013-04-23 14:51:26 -040040
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050041 public static String ID = "id";
42 public static String ACCOUNT = "account";
43 public static String CONTACT = "contcat";
44 public static String TYPE = "type";
45 public static String STATE = "state";
46
alisionfde875f2013-05-28 17:01:54 -040047 private static final String TAG = SipCall.class.getSimpleName();
Alexandre Savard2f1ae542012-10-26 17:05:00 -040048
alisionfde875f2013-05-28 17:01:54 -040049 private String mCallID = "";
Alexandre Lision3ee516e2013-10-07 17:32:15 -040050 private Account mAccount = null;
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050051 private CallContact mContact = null;
alisiondf1dac92013-06-27 17:35:53 -040052 private boolean isRecording = false;
Alexandre Lision945e4612014-01-15 17:40:31 -050053 private long timestampStart_ = 0;
54 private long timestampEnd_ = 0;
55
Alexandre Lision67c70b42014-01-16 13:57:15 -050056 private int mCallType;
alisionfde875f2013-05-28 17:01:54 -040057 private int mCallState = state.CALL_STATE_NONE;
Alexandre Savard2b01c822012-09-20 15:00:37 -040058
Alexandre Lision8162f4c2014-02-14 16:45:49 -050059 public SipCall(SipCall call) {
60 mCallID = call.mCallID;
61 mAccount = call.mAccount;
62 mContact = call.mContact;
63 isRecording = call.isRecording;
64 timestampStart_ = call.timestampStart_;
65 timestampEnd_ = call.timestampEnd_;
66 mCallType = call.mCallType;
67 mCallState = call.mCallState;
68 }
69
Alexandre Lision945e4612014-01-15 17:40:31 -050070 /**
71 * *********************
alisionfde875f2013-05-28 17:01:54 -040072 * Construtors
Alexandre Lision945e4612014-01-15 17:40:31 -050073 * *********************
74 */
Alexandre Savard557a5742012-10-24 13:54:53 -040075
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050076 protected SipCall(Parcel in) {
Alexandre Savard557a5742012-10-24 13:54:53 -040077
Alexandre Lisiond5686032013-10-29 11:09:21 -040078 mCallID = in.readString();
Alexandre Lision3ee516e2013-10-07 17:32:15 -040079 mAccount = in.readParcelable(Account.class.getClassLoader());
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050080 mContact = in.readParcelable(CallContact.class.getClassLoader());
alisiondf1dac92013-06-27 17:35:53 -040081 isRecording = in.readByte() == 1;
alisionfde875f2013-05-28 17:01:54 -040082 mCallType = in.readInt();
83 mCallState = in.readInt();
Alexandre Lision945e4612014-01-15 17:40:31 -050084 timestampStart_ = in.readLong();
85 timestampEnd_ = in.readLong();
86 }
Alexandre Savard4a19d752012-09-19 13:19:24 -040087
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050088 public SipCall(Bundle args) {
89 mCallID = args.getString(ID);
90 mAccount = args.getParcelable(ACCOUNT);
91 mCallType = args.getInt(TYPE);
92 mCallState = args.getInt(STATE);
93 mContact = args.getParcelable(CONTACT);
Alexandre Savard4a19d752012-09-19 13:19:24 -040094 }
95
Alexandre Lision945e4612014-01-15 17:40:31 -050096 public long getTimestampEnd_() {
97 return timestampEnd_;
98 }
99
100 public String getRecordPath() {
101 return "";
102 }
103
Alexandre Lision183bf452014-01-17 11:21:59 -0500104 public int getCallType() {
105 return mCallType;
106 }
107
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500108 public Bundle getBundle() {
109 Bundle args = new Bundle();
110 args.putString(SipCall.ID, mCallID);
111 args.putParcelable(SipCall.ACCOUNT, mAccount);
112 args.putInt(SipCall.STATE, mCallState);
113 args.putInt(SipCall.TYPE, mCallType);
114 args.putParcelable(SipCall.CONTACT, mContact);
115 return args;
Alexandre Lision5f144b82014-02-11 09:59:36 -0500116 }
117
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500118
Alexandre Lision67c70b42014-01-16 13:57:15 -0500119 public interface direction {
alisionfde875f2013-05-28 17:01:54 -0400120 public static final int CALL_TYPE_INCOMING = 1;
121 public static final int CALL_TYPE_OUTGOING = 2;
Alexandre Lision67c70b42014-01-16 13:57:15 -0500122 }
alisionfde875f2013-05-28 17:01:54 -0400123
Alexandre Lision67c70b42014-01-16 13:57:15 -0500124 public interface state {
alisionfde875f2013-05-28 17:01:54 -0400125 public static final int CALL_STATE_NONE = 0;
alisionfde875f2013-05-28 17:01:54 -0400126 public static final int CALL_STATE_RINGING = 2;
127 public static final int CALL_STATE_CURRENT = 3;
128 public static final int CALL_STATE_HUNGUP = 4;
129 public static final int CALL_STATE_BUSY = 5;
130 public static final int CALL_STATE_FAILURE = 6;
131 public static final int CALL_STATE_HOLD = 7;
132 public static final int CALL_STATE_UNHOLD = 8;
Alexandre Savard4a19d752012-09-19 13:19:24 -0400133 }
134
alisionfde875f2013-05-28 17:01:54 -0400135 @Override
136 public int describeContents() {
137 return 0;
138 }
139
140 @Override
141 public void writeToParcel(Parcel out, int flags) {
alisionfde875f2013-05-28 17:01:54 -0400142
Alexandre Lisiond5686032013-10-29 11:09:21 -0400143 out.writeString(mCallID);
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400144 out.writeParcelable(mAccount, 0);
145
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500146 out.writeParcelable(mContact, 0);
alisiondf1dac92013-06-27 17:35:53 -0400147 out.writeByte((byte) (isRecording ? 1 : 0));
alisionfde875f2013-05-28 17:01:54 -0400148 out.writeInt(mCallType);
149 out.writeInt(mCallState);
Alexandre Lision945e4612014-01-15 17:40:31 -0500150 out.writeLong(timestampStart_);
151 out.writeLong(timestampEnd_);
alisionfde875f2013-05-28 17:01:54 -0400152 }
153
154 public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() {
155 public SipCall createFromParcel(Parcel in) {
156 return new SipCall(in);
157 }
158
159 public SipCall[] newArray(int size) {
160 return new SipCall[size];
161 }
162 };
163
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400164 public void setCallID(String callID) {
alisionfde875f2013-05-28 17:01:54 -0400165 mCallID = callID;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400166 }
167
168 public String getCallId() {
alisionfde875f2013-05-28 17:01:54 -0400169 return mCallID;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400170 }
171
Alexandre Lision945e4612014-01-15 17:40:31 -0500172 public long getTimestampStart_() {
173 return timestampStart_;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400174 }
175
Alexandre Lision945e4612014-01-15 17:40:31 -0500176 public void setTimestampStart_(long timestampStart_) {
177 this.timestampStart_ = timestampStart_;
178 }
179
180 public void setTimestampEnd_(long timestampEnd_) {
181 this.timestampEnd_ = timestampEnd_;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400182 }
183
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400184 public void setAccount(Account account) {
185 mAccount = account;
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400186 }
187
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400188 public Account getAccount() {
189 return mAccount;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400190 }
191
alision85704182013-05-29 15:23:03 -0400192 public String getCallTypeString() {
193 switch (mCallType) {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500194 case direction.CALL_TYPE_INCOMING:
Alexandre Lision945e4612014-01-15 17:40:31 -0500195 return "CALL_TYPE_INCOMING";
Alexandre Lision67c70b42014-01-16 13:57:15 -0500196 case direction.CALL_TYPE_OUTGOING:
Alexandre Lision945e4612014-01-15 17:40:31 -0500197 return "CALL_TYPE_OUTGOING";
198 default:
199 return "CALL_TYPE_UNDETERMINED";
alision85704182013-05-29 15:23:03 -0400200 }
201 }
202
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400203 public void setCallState(int callState) {
alisionfde875f2013-05-28 17:01:54 -0400204 mCallState = callState;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400205 }
206
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500207 public CallContact getmContact() {
208 return mContact;
alisionfde875f2013-05-28 17:01:54 -0400209 }
210
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500211 public void setmContact(CallContact contacts) {
212 mContact = contacts;
alisionfde875f2013-05-28 17:01:54 -0400213 }
214
Alexandre Savarddf544262012-10-25 14:24:08 -0400215 public String getCallStateString() {
Alexandre Savarddf544262012-10-25 14:24:08 -0400216
alisionfde875f2013-05-28 17:01:54 -0400217 String text_state;
218
219 switch (mCallState) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500220 case state.CALL_STATE_RINGING:
221 text_state = "RINGING";
222 break;
223 case state.CALL_STATE_CURRENT:
224 text_state = "CURRENT";
225 break;
226 case state.CALL_STATE_HUNGUP:
227 text_state = "HUNGUP";
228 break;
229 case state.CALL_STATE_BUSY:
230 text_state = "BUSY";
231 break;
232 case state.CALL_STATE_FAILURE:
233 text_state = "FAILURE";
234 break;
235 case state.CALL_STATE_HOLD:
236 text_state = "HOLD";
237 break;
238 case state.CALL_STATE_UNHOLD:
239 text_state = "UNHOLD";
240 break;
241 default:
242 text_state = "NULL";
Alexandre Savarddf544262012-10-25 14:24:08 -0400243 }
244
alisionfde875f2013-05-28 17:01:54 -0400245 return text_state;
Alexandre Savarddf544262012-10-25 14:24:08 -0400246 }
247
alisiondf1dac92013-06-27 17:35:53 -0400248 public boolean isRecording() {
249 return isRecording;
250 }
251
252 public void setRecording(boolean isRecording) {
253 this.isRecording = isRecording;
254 }
255
alision85704182013-05-29 15:23:03 -0400256 public void printCallInfo() {
257 Log.i(TAG, "CallInfo: CallID: " + mCallID);
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400258 Log.i(TAG, " AccountID: " + mAccount.getAccountID());
alision85704182013-05-29 15:23:03 -0400259 Log.i(TAG, " CallState: " + mCallState);
260 Log.i(TAG, " CallType: " + mCallType);
261 }
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400262
alision5f899632013-04-22 17:26:56 -0400263 /**
264 * Compare sip calls based on call ID
265 */
266 @Override
alision11e8e162013-05-28 10:33:14 -0400267 public boolean equals(Object c) {
alision465ceba2013-07-04 09:24:30 -0400268 if (c instanceof SipCall && ((SipCall) c).mCallID.contentEquals((mCallID))) {
alision5f899632013-04-22 17:26:56 -0400269 return true;
270 }
271 return false;
alision11e8e162013-05-28 10:33:14 -0400272
alision5f899632013-04-22 17:26:56 -0400273 }
alision7f18fc82013-05-01 09:37:33 -0400274
alision85704182013-05-29 15:23:03 -0400275 public boolean isOutGoing() {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500276 if (mCallType == direction.CALL_TYPE_OUTGOING)
alision85704182013-05-29 15:23:03 -0400277 return true;
alision85704182013-05-29 15:23:03 -0400278 return false;
279 }
280
281 public boolean isRinging() {
282 if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE)
283 return true;
284
285 return false;
286 }
287
288 public boolean isIncoming() {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500289 if (mCallType == direction.CALL_TYPE_INCOMING)
alision85704182013-05-29 15:23:03 -0400290 return true;
291
292 return false;
293 }
294
295 public void setCallState(String newState) {
Alexandre Lision707f9082014-01-16 15:09:07 -0500296 if (newState.equals("RINGING")) {
alision85704182013-05-29 15:23:03 -0400297 setCallState(SipCall.state.CALL_STATE_RINGING);
298 } else if (newState.equals("CURRENT")) {
299 setCallState(SipCall.state.CALL_STATE_CURRENT);
300 } else if (newState.equals("HUNGUP")) {
301 setCallState(SipCall.state.CALL_STATE_HUNGUP);
302 } else if (newState.equals("BUSY")) {
303 setCallState(SipCall.state.CALL_STATE_BUSY);
304 } else if (newState.equals("FAILURE")) {
305 setCallState(SipCall.state.CALL_STATE_FAILURE);
306 } else if (newState.equals("HOLD")) {
307 setCallState(SipCall.state.CALL_STATE_HOLD);
308 } else if (newState.equals("UNHOLD")) {
309 setCallState(SipCall.state.CALL_STATE_CURRENT);
310 } else {
311 setCallState(SipCall.state.CALL_STATE_NONE);
312 }
alision907bde72013-06-20 14:40:37 -0400313
alision85704182013-05-29 15:23:03 -0400314 }
315
316 public boolean isOngoing() {
alision907bde72013-06-20 14:40:37 -0400317 if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE || mCallState == state.CALL_STATE_FAILURE
318 || mCallState == state.CALL_STATE_BUSY || mCallState == state.CALL_STATE_HUNGUP)
alision85704182013-05-29 15:23:03 -0400319 return false;
320
321 return true;
322 }
alision04a00182013-05-10 17:05:29 -0400323
alisiondf1dac92013-06-27 17:35:53 -0400324 public boolean isOnHold() {
325 return mCallState == state.CALL_STATE_HOLD;
326 }
327
Alexandre Lision6ae652d2013-09-26 16:39:20 -0400328 public boolean isCurrent() {
329 return mCallState == state.CALL_STATE_CURRENT;
330 }
Alexandre Lision5f144b82014-02-11 09:59:36 -0500331
Alexandre Lision5f144b82014-02-11 09:59:36 -0500332
Alexandre Savard4a19d752012-09-19 13:19:24 -0400333}