Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 4 | * Author: Alexandre Savard <alexandre.savard@gmail.com> |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 5 | * |
| 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 | */ |
| 31 | package com.savoirfairelinux.sflphone.client; |
| 32 | |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
| 35 | import android.os.Bundle; |
Alexandre Savard | 85936b9 | 2012-10-24 11:23:53 -0400 | [diff] [blame] | 36 | import android.os.Parcelable; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 37 | import android.os.Parcel; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 38 | import android.os.RemoteException; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 39 | import android.util.Log; |
| 40 | import java.util.ArrayList; |
| 41 | |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 42 | import com.savoirfairelinux.sflphone.service.ISipService; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 43 | import com.savoirfairelinux.sflphone.client.CallActivity; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 44 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 45 | public class SipCall |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 46 | { |
| 47 | final static String TAG = "SipCall"; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 48 | public static CallElementList mCallElementList = null; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 49 | public CallInfo mCallInfo; |
| 50 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 51 | 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 Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 55 | 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 Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 60 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 61 | 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 Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 65 | public static int MEDIA_STATE_ERROR = 5; // Media is in error state |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 66 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 67 | public static class CallInfo implements Parcelable |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 68 | { |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 69 | public String mCallID = ""; |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 70 | public String mAccountID = ""; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 71 | public String mDisplayName = ""; |
| 72 | public String mPhone = ""; |
| 73 | public String mEmail = ""; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 74 | public String mRemoteContact = ""; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 75 | 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 Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 86 | |
| 87 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 88 | list.add(mCallID); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 89 | list.add(mAccountID); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 90 | 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 Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 115 | |
| 116 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 117 | mCallID = list.get(0); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 118 | 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 Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 123 | |
| 124 | mCallState = in.readInt(); |
| 125 | mMediaState = in.readInt(); |
| 126 | } |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 127 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 128 | |
| 129 | public SipCall() |
| 130 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 131 | mCallInfo = new CallInfo(); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 134 | public SipCall(CallInfo info) |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 135 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 136 | mCallInfo = info; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 139 | public static void setCallElementList(CallElementList list) |
| 140 | { |
| 141 | mCallElementList = list; |
| 142 | } |
| 143 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 144 | public void setCallID(String callID) { |
| 145 | mCallInfo.mCallID = callID; |
| 146 | } |
| 147 | |
| 148 | public String getCallId() { |
| 149 | return mCallInfo.mCallID; |
| 150 | } |
| 151 | |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 152 | public void setAccountID(String accountID) { |
| 153 | mCallInfo.mAccountID = accountID; |
| 154 | } |
| 155 | |
| 156 | public String getAccountID() { |
| 157 | return mCallInfo.mAccountID; |
| 158 | } |
| 159 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 160 | 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 Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 208 | public void placeCall() |
| 209 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 210 | if(mCallElementList != null) |
| 211 | mCallElementList.addCall(this); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 212 | } |
| 213 | |
| 214 | public void receiveCall() |
| 215 | { |
| 216 | if(mCallElementList != null) |
| 217 | mCallElementList.addCall(this); |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 220 | public void answer() |
| 221 | { |
| 222 | |
| 223 | } |
| 224 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 225 | /** |
| 226 | * Perform hangup action without sending request to the service |
| 227 | */ |
| 228 | public void hangup() { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 229 | Log.i(TAG, "Hangup call " + mCallInfo.mCallID); |
| 230 | |
| 231 | if(mCallElementList != null) |
| 232 | mCallElementList.removeCall(this); |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Perform hangup action and send request to the service |
| 237 | */ |
| 238 | public void notifyServiceHangup(ISipService service) |
| 239 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 240 | try { |
| 241 | service.hangUp(mCallInfo.mCallID); |
| 242 | } catch (RemoteException e) { |
| 243 | Log.e(TAG, "Cannot call service method", e); |
| 244 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 245 | } |
Alexandre Savard | aef9d80 | 2012-09-20 17:31:32 -0400 | [diff] [blame] | 246 | |
| 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 Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 256 | |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame^] | 257 | 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 Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 267 | 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 Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 276 | } |