blob: 10548cee2dbb09dd40b82e99d9faa8cf736c14fa [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 Lision5f144b82014-02-11 09:59:36 -050059
60 public boolean isSecured() {
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050061 return false;
Alexandre Lision5f144b82014-02-11 09:59:36 -050062 }
Alexandre Lision945e4612014-01-15 17:40:31 -050063 /**
64 * *********************
alisionfde875f2013-05-28 17:01:54 -040065 * Construtors
Alexandre Lision945e4612014-01-15 17:40:31 -050066 * *********************
67 */
Alexandre Savard557a5742012-10-24 13:54:53 -040068
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050069 protected SipCall(Parcel in) {
Alexandre Savard557a5742012-10-24 13:54:53 -040070
Alexandre Lisiond5686032013-10-29 11:09:21 -040071 mCallID = in.readString();
Alexandre Lision3ee516e2013-10-07 17:32:15 -040072 mAccount = in.readParcelable(Account.class.getClassLoader());
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050073 mContact = in.readParcelable(CallContact.class.getClassLoader());
alisiondf1dac92013-06-27 17:35:53 -040074 isRecording = in.readByte() == 1;
alisionfde875f2013-05-28 17:01:54 -040075 mCallType = in.readInt();
76 mCallState = in.readInt();
Alexandre Lision945e4612014-01-15 17:40:31 -050077 timestampStart_ = in.readLong();
78 timestampEnd_ = in.readLong();
79 }
Alexandre Savard4a19d752012-09-19 13:19:24 -040080
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050081 public SipCall(Bundle args) {
82 mCallID = args.getString(ID);
83 mAccount = args.getParcelable(ACCOUNT);
84 mCallType = args.getInt(TYPE);
85 mCallState = args.getInt(STATE);
86 mContact = args.getParcelable(CONTACT);
Alexandre Savard4a19d752012-09-19 13:19:24 -040087 }
88
Alexandre Lision945e4612014-01-15 17:40:31 -050089 public long getTimestampEnd_() {
90 return timestampEnd_;
91 }
92
93 public String getRecordPath() {
94 return "";
95 }
96
Alexandre Lision183bf452014-01-17 11:21:59 -050097 public int getCallType() {
98 return mCallType;
99 }
100
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500101 public Bundle getBundle() {
102 Bundle args = new Bundle();
103 args.putString(SipCall.ID, mCallID);
104 args.putParcelable(SipCall.ACCOUNT, mAccount);
105 args.putInt(SipCall.STATE, mCallState);
106 args.putInt(SipCall.TYPE, mCallType);
107 args.putParcelable(SipCall.CONTACT, mContact);
108 return args;
Alexandre Lision5f144b82014-02-11 09:59:36 -0500109 }
110
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500111
Alexandre Lision67c70b42014-01-16 13:57:15 -0500112 public interface direction {
alisionfde875f2013-05-28 17:01:54 -0400113 public static final int CALL_TYPE_INCOMING = 1;
114 public static final int CALL_TYPE_OUTGOING = 2;
Alexandre Lision67c70b42014-01-16 13:57:15 -0500115 }
alisionfde875f2013-05-28 17:01:54 -0400116
Alexandre Lision67c70b42014-01-16 13:57:15 -0500117 public interface state {
alisionfde875f2013-05-28 17:01:54 -0400118 public static final int CALL_STATE_NONE = 0;
alisionfde875f2013-05-28 17:01:54 -0400119 public static final int CALL_STATE_RINGING = 2;
120 public static final int CALL_STATE_CURRENT = 3;
121 public static final int CALL_STATE_HUNGUP = 4;
122 public static final int CALL_STATE_BUSY = 5;
123 public static final int CALL_STATE_FAILURE = 6;
124 public static final int CALL_STATE_HOLD = 7;
125 public static final int CALL_STATE_UNHOLD = 8;
Alexandre Savard4a19d752012-09-19 13:19:24 -0400126 }
127
alisionfde875f2013-05-28 17:01:54 -0400128 @Override
129 public int describeContents() {
130 return 0;
131 }
132
133 @Override
134 public void writeToParcel(Parcel out, int flags) {
alisionfde875f2013-05-28 17:01:54 -0400135
Alexandre Lisiond5686032013-10-29 11:09:21 -0400136 out.writeString(mCallID);
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400137 out.writeParcelable(mAccount, 0);
138
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500139 out.writeParcelable(mContact, 0);
alisiondf1dac92013-06-27 17:35:53 -0400140 out.writeByte((byte) (isRecording ? 1 : 0));
alisionfde875f2013-05-28 17:01:54 -0400141 out.writeInt(mCallType);
142 out.writeInt(mCallState);
Alexandre Lision945e4612014-01-15 17:40:31 -0500143 out.writeLong(timestampStart_);
144 out.writeLong(timestampEnd_);
alisionfde875f2013-05-28 17:01:54 -0400145 }
146
147 public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() {
148 public SipCall createFromParcel(Parcel in) {
149 return new SipCall(in);
150 }
151
152 public SipCall[] newArray(int size) {
153 return new SipCall[size];
154 }
155 };
156
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400157 public void setCallID(String callID) {
alisionfde875f2013-05-28 17:01:54 -0400158 mCallID = callID;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400159 }
160
161 public String getCallId() {
alisionfde875f2013-05-28 17:01:54 -0400162 return mCallID;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400163 }
164
Alexandre Lision945e4612014-01-15 17:40:31 -0500165 public long getTimestampStart_() {
166 return timestampStart_;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400167 }
168
Alexandre Lision945e4612014-01-15 17:40:31 -0500169 public void setTimestampStart_(long timestampStart_) {
170 this.timestampStart_ = timestampStart_;
171 }
172
173 public void setTimestampEnd_(long timestampEnd_) {
174 this.timestampEnd_ = timestampEnd_;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400175 }
176
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400177 public void setAccount(Account account) {
178 mAccount = account;
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400179 }
180
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400181 public Account getAccount() {
182 return mAccount;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400183 }
184
alision85704182013-05-29 15:23:03 -0400185 public String getCallTypeString() {
186 switch (mCallType) {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500187 case direction.CALL_TYPE_INCOMING:
Alexandre Lision945e4612014-01-15 17:40:31 -0500188 return "CALL_TYPE_INCOMING";
Alexandre Lision67c70b42014-01-16 13:57:15 -0500189 case direction.CALL_TYPE_OUTGOING:
Alexandre Lision945e4612014-01-15 17:40:31 -0500190 return "CALL_TYPE_OUTGOING";
191 default:
192 return "CALL_TYPE_UNDETERMINED";
alision85704182013-05-29 15:23:03 -0400193 }
194 }
195
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400196 public void setCallState(int callState) {
alisionfde875f2013-05-28 17:01:54 -0400197 mCallState = callState;
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400198 }
199
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500200 public CallContact getmContact() {
201 return mContact;
alisionfde875f2013-05-28 17:01:54 -0400202 }
203
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500204 public void setmContact(CallContact contacts) {
205 mContact = contacts;
alisionfde875f2013-05-28 17:01:54 -0400206 }
207
Alexandre Savarddf544262012-10-25 14:24:08 -0400208 public String getCallStateString() {
Alexandre Savarddf544262012-10-25 14:24:08 -0400209
alisionfde875f2013-05-28 17:01:54 -0400210 String text_state;
211
212 switch (mCallState) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500213 case state.CALL_STATE_RINGING:
214 text_state = "RINGING";
215 break;
216 case state.CALL_STATE_CURRENT:
217 text_state = "CURRENT";
218 break;
219 case state.CALL_STATE_HUNGUP:
220 text_state = "HUNGUP";
221 break;
222 case state.CALL_STATE_BUSY:
223 text_state = "BUSY";
224 break;
225 case state.CALL_STATE_FAILURE:
226 text_state = "FAILURE";
227 break;
228 case state.CALL_STATE_HOLD:
229 text_state = "HOLD";
230 break;
231 case state.CALL_STATE_UNHOLD:
232 text_state = "UNHOLD";
233 break;
234 default:
235 text_state = "NULL";
Alexandre Savarddf544262012-10-25 14:24:08 -0400236 }
237
alisionfde875f2013-05-28 17:01:54 -0400238 return text_state;
Alexandre Savarddf544262012-10-25 14:24:08 -0400239 }
240
alisiondf1dac92013-06-27 17:35:53 -0400241 public boolean isRecording() {
242 return isRecording;
243 }
244
245 public void setRecording(boolean isRecording) {
246 this.isRecording = isRecording;
247 }
248
alision85704182013-05-29 15:23:03 -0400249 public void printCallInfo() {
250 Log.i(TAG, "CallInfo: CallID: " + mCallID);
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400251 Log.i(TAG, " AccountID: " + mAccount.getAccountID());
alision85704182013-05-29 15:23:03 -0400252 Log.i(TAG, " CallState: " + mCallState);
253 Log.i(TAG, " CallType: " + mCallType);
254 }
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400255
alision5f899632013-04-22 17:26:56 -0400256 /**
257 * Compare sip calls based on call ID
258 */
259 @Override
alision11e8e162013-05-28 10:33:14 -0400260 public boolean equals(Object c) {
alision465ceba2013-07-04 09:24:30 -0400261 if (c instanceof SipCall && ((SipCall) c).mCallID.contentEquals((mCallID))) {
alision5f899632013-04-22 17:26:56 -0400262 return true;
263 }
264 return false;
alision11e8e162013-05-28 10:33:14 -0400265
alision5f899632013-04-22 17:26:56 -0400266 }
alision7f18fc82013-05-01 09:37:33 -0400267
alision85704182013-05-29 15:23:03 -0400268 public boolean isOutGoing() {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500269 if (mCallType == direction.CALL_TYPE_OUTGOING)
alision85704182013-05-29 15:23:03 -0400270 return true;
alision85704182013-05-29 15:23:03 -0400271 return false;
272 }
273
274 public boolean isRinging() {
275 if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE)
276 return true;
277
278 return false;
279 }
280
281 public boolean isIncoming() {
Alexandre Lision67c70b42014-01-16 13:57:15 -0500282 if (mCallType == direction.CALL_TYPE_INCOMING)
alision85704182013-05-29 15:23:03 -0400283 return true;
284
285 return false;
286 }
287
288 public void setCallState(String newState) {
Alexandre Lision707f9082014-01-16 15:09:07 -0500289 if (newState.equals("RINGING")) {
alision85704182013-05-29 15:23:03 -0400290 setCallState(SipCall.state.CALL_STATE_RINGING);
291 } else if (newState.equals("CURRENT")) {
292 setCallState(SipCall.state.CALL_STATE_CURRENT);
293 } else if (newState.equals("HUNGUP")) {
294 setCallState(SipCall.state.CALL_STATE_HUNGUP);
295 } else if (newState.equals("BUSY")) {
296 setCallState(SipCall.state.CALL_STATE_BUSY);
297 } else if (newState.equals("FAILURE")) {
298 setCallState(SipCall.state.CALL_STATE_FAILURE);
299 } else if (newState.equals("HOLD")) {
300 setCallState(SipCall.state.CALL_STATE_HOLD);
301 } else if (newState.equals("UNHOLD")) {
302 setCallState(SipCall.state.CALL_STATE_CURRENT);
303 } else {
304 setCallState(SipCall.state.CALL_STATE_NONE);
305 }
alision907bde72013-06-20 14:40:37 -0400306
alision85704182013-05-29 15:23:03 -0400307 }
308
309 public boolean isOngoing() {
alision907bde72013-06-20 14:40:37 -0400310 if (mCallState == state.CALL_STATE_RINGING || mCallState == state.CALL_STATE_NONE || mCallState == state.CALL_STATE_FAILURE
311 || mCallState == state.CALL_STATE_BUSY || mCallState == state.CALL_STATE_HUNGUP)
alision85704182013-05-29 15:23:03 -0400312 return false;
313
314 return true;
315 }
alision04a00182013-05-10 17:05:29 -0400316
alisiondf1dac92013-06-27 17:35:53 -0400317 public boolean isOnHold() {
318 return mCallState == state.CALL_STATE_HOLD;
319 }
320
Alexandre Lision6ae652d2013-09-26 16:39:20 -0400321 public boolean isCurrent() {
322 return mCallState == state.CALL_STATE_CURRENT;
323 }
Alexandre Lision5f144b82014-02-11 09:59:36 -0500324
Alexandre Lision5f144b82014-02-11 09:59:36 -0500325
Alexandre Savard4a19d752012-09-19 13:19:24 -0400326}