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 | 85936b9 | 2012-10-24 11:23:53 -0400 | [diff] [blame] | 33 | import android.os.Parcelable; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 34 | import android.os.Parcel; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 35 | import android.os.RemoteException; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | import java.util.ArrayList; |
| 38 | |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 39 | import com.savoirfairelinux.sflphone.service.ISipService; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 40 | import com.savoirfairelinux.sflphone.client.CallActivity; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 41 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 42 | public class SipCall |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 43 | { |
| 44 | final static String TAG = "SipCall"; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 45 | public static CallElementList mCallElementList = null; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 46 | private static CallActivity mCallActivity = null; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 47 | public CallInfo mCallInfo; |
| 48 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 49 | public static int CALL_STATE_INVALID = 0; // The call is not existent in SFLphone service |
| 50 | public static int CALL_STATE_NULL = 1; // Before any action performed |
| 51 | public static int CALL_STATE_CALLING = 2; // After INVITE is sent |
| 52 | public static int CALL_STATE_INCOMING = 3; // After INVITE is received |
| 53 | public static int CALL_STATE_EARLY = 4; // After response with To tag |
| 54 | public static int CALL_STATE_CONNECTING = 5; // After 2xx is sent/received |
| 55 | public static int CALL_STATE_CONFIRMED = 6; // After ACK is sent/received |
| 56 | public static int CALL_STATE_DISCONNECTED = 7; // Session is terminated |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 57 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 58 | public static int MEDIA_STATE_NONE = 0; // No media currently |
| 59 | public static int MEDIA_STATE_ACTIVE = 1; // Media is active |
| 60 | public static int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user |
| 61 | public static int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer |
| 62 | public static int MEDIA_STATE_ERROR = 4; // Media is in error state |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 63 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 64 | public static class CallInfo implements Parcelable |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 65 | { |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 66 | public String mCallID = ""; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 67 | public String mDisplayName = ""; |
| 68 | public String mPhone = ""; |
| 69 | public String mEmail = ""; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 70 | public String mRemoteContact = ""; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 71 | public int mCallState = CALL_STATE_NULL; |
| 72 | public int mMediaState = MEDIA_STATE_NONE; |
| 73 | |
| 74 | @Override |
| 75 | public int describeContents() { |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void writeToParcel(Parcel out, int flags) { |
| 81 | ArrayList<String> list = new ArrayList<String>(); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 82 | |
| 83 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 84 | list.add(mCallID); |
| 85 | list.add(mDisplayName); |
| 86 | list.add(mPhone); |
| 87 | list.add(mEmail); |
| 88 | list.add(mRemoteContact); |
| 89 | |
| 90 | out.writeStringList(list); |
| 91 | out.writeInt(mCallState); |
| 92 | out.writeInt(mMediaState); |
| 93 | } |
| 94 | |
| 95 | public static final Parcelable.Creator<CallInfo> CREATOR |
| 96 | = new Parcelable.Creator<CallInfo>() { |
| 97 | public CallInfo createFromParcel(Parcel in) { |
| 98 | return new CallInfo(in); |
| 99 | } |
| 100 | |
| 101 | public CallInfo[] newArray(int size) { |
| 102 | return new CallInfo[size]; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | public CallInfo() {} |
| 107 | |
| 108 | private CallInfo(Parcel in) { |
| 109 | ArrayList<String> list = in.createStringArrayList(); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 110 | |
| 111 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 112 | mCallID = list.get(0); |
| 113 | mDisplayName = list.get(1); |
| 114 | mPhone = list.get(2); |
| 115 | mEmail = list.get(3); |
| 116 | mRemoteContact = list.get(4); |
| 117 | |
| 118 | mCallState = in.readInt(); |
| 119 | mMediaState = in.readInt(); |
| 120 | } |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 121 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 122 | |
| 123 | public SipCall() |
| 124 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 125 | mCallInfo = new CallInfo(); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 128 | public SipCall(CallInfo info) |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 129 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 130 | mCallInfo = info; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 133 | public static void setCallElementList(CallElementList list) |
| 134 | { |
| 135 | mCallElementList = list; |
| 136 | } |
| 137 | |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 138 | public void placeCall() |
| 139 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 140 | if(mCallElementList != null) |
| 141 | mCallElementList.addCall(this); |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 142 | // mManager.callmanagerJNI.placeCall("IP2IP", "CALL1234", "192.168.40.35"); |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 145 | public void answer() |
| 146 | { |
| 147 | |
| 148 | } |
| 149 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 150 | /** |
| 151 | * Perform hangup action without sending request to the service |
| 152 | */ |
| 153 | public void hangup() { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 154 | Log.i(TAG, "Hangup call " + mCallInfo.mCallID); |
| 155 | |
| 156 | if(mCallElementList != null) |
| 157 | mCallElementList.removeCall(this); |
| 158 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 159 | if(mCallActivity != null) |
| 160 | mCallActivity.finish(); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Perform hangup action and send request to the service |
| 165 | */ |
| 166 | public void notifyServiceHangup(ISipService service) |
| 167 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 168 | try { |
| 169 | service.hangUp(mCallInfo.mCallID); |
| 170 | } catch (RemoteException e) { |
| 171 | Log.e(TAG, "Cannot call service method", e); |
| 172 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 173 | } |
Alexandre Savard | aef9d80 | 2012-09-20 17:31:32 -0400 | [diff] [blame] | 174 | |
| 175 | public void addToConference() |
| 176 | { |
| 177 | Log.i(TAG, "Add call to conference"); |
| 178 | } |
| 179 | |
| 180 | public void sendTextMessage() |
| 181 | { |
| 182 | Log.i(TAG, "Send text message"); |
| 183 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 184 | } |