blob: 3ef82656acd386e7561861985b2c76b86765f27e [file] [log] [blame]
Alexandre Savard4a19d752012-09-19 13:19:24 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
Alexandre Savarda1404652012-09-20 13:34:08 -04004 * Author: Alexandre Savard <alexandre.savard@gmail.com>
Alexandre Savard4a19d752012-09-19 13:19:24 -04005 *
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 */
31package com.savoirfairelinux.sflphone.client;
32
Alexandre Savard3bdce7b2012-10-24 18:27:45 -040033import android.content.Context;
34import android.content.Intent;
35import android.os.Bundle;
Alexandre Savard85936b92012-10-24 11:23:53 -040036import android.os.Parcelable;
Alexandre Savard557a5742012-10-24 13:54:53 -040037import android.os.Parcel;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040038import android.os.RemoteException;
Alexandre Savard4a19d752012-09-19 13:19:24 -040039import android.util.Log;
40import java.util.ArrayList;
41
Alexandre Savard74c1cad2012-10-24 16:39:00 -040042import com.savoirfairelinux.sflphone.service.ISipService;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040043import com.savoirfairelinux.sflphone.client.CallActivity;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040044
Alexandre Savard557a5742012-10-24 13:54:53 -040045public class SipCall
Alexandre Savard4a19d752012-09-19 13:19:24 -040046{
47 final static String TAG = "SipCall";
Alexandre Savard74c1cad2012-10-24 16:39:00 -040048 public static CallElementList mCallElementList = null;
Alexandre Savard7a46f542012-09-20 11:23:33 -040049 public CallInfo mCallInfo;
50
Alexandre Savardc58c0fd2012-10-25 10:44:08 -040051 public static int CALL_STATE_NULL = 0;
52 public static int CALL_STATE_INCOMING = 1;
53 public static int CALL_STATE_RINGING = 2;
54 public static int CALL_STATE_CURRENT = 3;
Alexandre Savard73bc56f2012-10-25 13:35:54 -040055 public static int CALL_STATE_HUNGUP = 4;
56 public static int CALL_STATE_BUSY = 5;
57 public static int CALL_STATE_FAILURE = 6;
58 public static int CALL_STATE_HOLD = 7;
59 public static int CALL_STATE_UNHOLD = 8;
Alexandre Savard2b01c822012-09-20 15:00:37 -040060
Alexandre Savard557a5742012-10-24 13:54:53 -040061 public static int MEDIA_STATE_NONE = 0; // No media currently
62 public static int MEDIA_STATE_ACTIVE = 1; // Media is active
63 public static int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user
64 public static int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer
Alexandre Savard3bdce7b2012-10-24 18:27:45 -040065 public static int MEDIA_STATE_ERROR = 5; // Media is in error state
Alexandre Savard2b01c822012-09-20 15:00:37 -040066
Alexandre Savard557a5742012-10-24 13:54:53 -040067 public static class CallInfo implements Parcelable
Alexandre Savard7a46f542012-09-20 11:23:33 -040068 {
Alexandre Savard2b01c822012-09-20 15:00:37 -040069 public String mCallID = "";
Alexandre Savard73bc56f2012-10-25 13:35:54 -040070 public String mAccountID = "";
Alexandre Savard7a46f542012-09-20 11:23:33 -040071 public String mDisplayName = "";
72 public String mPhone = "";
73 public String mEmail = "";
Alexandre Savard2b01c822012-09-20 15:00:37 -040074 public String mRemoteContact = "";
Alexandre Savard557a5742012-10-24 13:54:53 -040075 public int mCallState = CALL_STATE_NULL;
76 public int mMediaState = MEDIA_STATE_NONE;
77
78 @Override
79 public int describeContents() {
80 return 0;
81 }
82
83 @Override
84 public void writeToParcel(Parcel out, int flags) {
85 ArrayList<String> list = new ArrayList<String>();
Alexandre Savard74c1cad2012-10-24 16:39:00 -040086
87 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -040088 list.add(mCallID);
Alexandre Savard73bc56f2012-10-25 13:35:54 -040089 list.add(mAccountID);
Alexandre Savard557a5742012-10-24 13:54:53 -040090 list.add(mDisplayName);
91 list.add(mPhone);
92 list.add(mEmail);
93 list.add(mRemoteContact);
94
95 out.writeStringList(list);
96 out.writeInt(mCallState);
97 out.writeInt(mMediaState);
98 }
99
100 public static final Parcelable.Creator<CallInfo> CREATOR
101 = new Parcelable.Creator<CallInfo>() {
102 public CallInfo createFromParcel(Parcel in) {
103 return new CallInfo(in);
104 }
105
106 public CallInfo[] newArray(int size) {
107 return new CallInfo[size];
108 }
109 };
110
111 public CallInfo() {}
112
113 private CallInfo(Parcel in) {
114 ArrayList<String> list = in.createStringArrayList();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400115
116 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -0400117 mCallID = list.get(0);
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400118 mAccountID = list.get(1);
119 mDisplayName = list.get(2);
120 mPhone = list.get(3);
121 mEmail = list.get(4);
122 mRemoteContact = list.get(5);
Alexandre Savard557a5742012-10-24 13:54:53 -0400123
124 mCallState = in.readInt();
125 mMediaState = in.readInt();
126 }
Alexandre Savard7a46f542012-09-20 11:23:33 -0400127 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400128
129 public SipCall()
130 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400131 mCallInfo = new CallInfo();
Alexandre Savard4a19d752012-09-19 13:19:24 -0400132 }
133
Alexandre Savard7a46f542012-09-20 11:23:33 -0400134 public SipCall(CallInfo info)
Alexandre Savard4a19d752012-09-19 13:19:24 -0400135 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400136 mCallInfo = info;
Alexandre Savard4a19d752012-09-19 13:19:24 -0400137 }
138
Alexandre Savarda1404652012-09-20 13:34:08 -0400139 public static void setCallElementList(CallElementList list)
140 {
141 mCallElementList = list;
142 }
143
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400144 public void setCallID(String callID) {
145 mCallInfo.mCallID = callID;
146 }
147
148 public String getCallId() {
149 return mCallInfo.mCallID;
150 }
151
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400152 public void setAccountID(String accountID) {
153 mCallInfo.mAccountID = accountID;
154 }
155
156 public String getAccountID() {
157 return mCallInfo.mAccountID;
158 }
159
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400160 public void setDisplayName(String displayName) {
161 mCallInfo.mDisplayName = displayName;
162 }
163
164 public String getDisplayName() {
165 return mCallInfo.mDisplayName;
166 }
167
168 public void setPhone(String phone) {
169 mCallInfo.mPhone = phone;
170 }
171
172 public String getPhone() {
173 return mCallInfo.mPhone;
174 }
175
176 public void setEmail(String email) {
177 mCallInfo.mEmail = email;
178 }
179
180 public String getEmail() {
181 return mCallInfo.mEmail;
182 }
183
184 public void setRemoteContact(String remoteContact) {
185 mCallInfo.mRemoteContact = remoteContact;
186 }
187
188 public String getRemoteContact() {
189 return mCallInfo.mRemoteContact;
190 }
191
192 public void setCallState(int callState) {
193 mCallInfo.mCallState = callState;
194 }
195
196 public int getCallState() {
197 return mCallInfo.mCallState;
198 }
199
200 public void setMediaState(int mediaState) {
201 mCallInfo.mMediaState = mediaState;
202 }
203
204 public int getMediaState() {
205 return mCallInfo.mMediaState;
206 }
207
Alexandre Savard23240c12012-09-19 18:23:44 -0400208 public void placeCall()
209 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400210 if(mCallElementList != null)
211 mCallElementList.addCall(this);
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400212 }
213
214 public void receiveCall()
215 {
216 if(mCallElementList != null)
217 mCallElementList.addCall(this);
Alexandre Savard23240c12012-09-19 18:23:44 -0400218 }
219
Alexandre Savard4a19d752012-09-19 13:19:24 -0400220 public void answer()
221 {
222
223 }
224
Alexandre Savard4f42ade2012-10-24 18:03:31 -0400225 /**
226 * Perform hangup action without sending request to the service
227 */
228 public void hangup() {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400229 Log.i(TAG, "Hangup call " + mCallInfo.mCallID);
230
231 if(mCallElementList != null)
232 mCallElementList.removeCall(this);
Alexandre Savard4f42ade2012-10-24 18:03:31 -0400233 }
234
235 /**
236 * Perform hangup action and send request to the service
237 */
238 public void notifyServiceHangup(ISipService service)
239 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400240 try {
241 service.hangUp(mCallInfo.mCallID);
242 } catch (RemoteException e) {
243 Log.e(TAG, "Cannot call service method", e);
244 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400245 }
Alexandre Savardaef9d802012-09-20 17:31:32 -0400246
247 public void addToConference()
248 {
249 Log.i(TAG, "Add call to conference");
250 }
251
252 public void sendTextMessage()
253 {
254 Log.i(TAG, "Send text message");
255 }
Alexandre Savard3bdce7b2012-10-24 18:27:45 -0400256
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400257 public void printCallInfo()
258 {
259 Log.i(TAG, "CallInfo: CallID: " + mCallInfo.mCallID);
260 Log.i(TAG, " AccountID: " + mCallInfo.mAccountID);
261 Log.i(TAG, " Display Name: " + mCallInfo.mDisplayName);
262 Log.i(TAG, " Phone: " + mCallInfo.mPhone);
263 Log.i(TAG, " Email: " + mCallInfo.mEmail);
264 Log.i(TAG, " Contact: " + mCallInfo.mRemoteContact);
265 }
266
Alexandre Savard3bdce7b2012-10-24 18:27:45 -0400267 public void launchCallActivity(Context context)
268 {
269 Log.i(TAG, "Launch Call Activity");
270 Bundle bundle = new Bundle();
271 bundle.putParcelable("CallInfo", mCallInfo);
272 Intent intent = new Intent().setClass(context, CallActivity.class);
273 intent.putExtras(bundle);
274 context.startActivity(intent);
275 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400276}