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 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 31 | package com.savoirfairelinux.sflphone.model; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 32 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 33 | import java.util.ArrayList; |
| 34 | |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
| 37 | import android.os.Bundle; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 38 | import android.os.Parcel; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 39 | import android.os.Parcelable; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 40 | import android.os.RemoteException; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 41 | import android.util.Log; |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 42 | import android.view.View; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 43 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 44 | import com.savoirfairelinux.sflphone.adapters.CallElementAdapter.CallElementView; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 45 | import com.savoirfairelinux.sflphone.client.CallActivity; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 46 | import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity; |
| 47 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 48 | import com.savoirfairelinux.sflphone.service.ISipService; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 49 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 50 | public class SipCall |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 51 | { |
| 52 | final static String TAG = "SipCall"; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 53 | public CallInfo mCallInfo; |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 54 | // Update UI on actions (answer, hangup) |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 55 | static private CallElementListFragment mCallElementList = null; |
| 56 | static private SFLPhoneHomeActivity mHome = null; |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 57 | private View mRowView = null; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 58 | |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 59 | public static final int CALL_TYPE_UNDETERMINED = 0; |
| 60 | public static final int CALL_TYPE_INCOMING = 1; |
| 61 | public static final int CALL_TYPE_OUTGOING = 2; |
| 62 | |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 63 | public static final int CALL_STATE_NONE = 0; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 64 | public static final int CALL_STATE_INCOMING = 1; |
| 65 | public static final int CALL_STATE_RINGING = 2; |
| 66 | public static final int CALL_STATE_CURRENT = 3; |
| 67 | public static final int CALL_STATE_HUNGUP = 4; |
| 68 | public static final int CALL_STATE_BUSY = 5; |
| 69 | public static final int CALL_STATE_FAILURE = 6; |
| 70 | public static final int CALL_STATE_HOLD = 7; |
| 71 | public static final int CALL_STATE_UNHOLD = 8; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 72 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 73 | public static final int MEDIA_STATE_NONE = 0; // No media currently |
| 74 | public static final int MEDIA_STATE_ACTIVE = 1; // Media is active |
| 75 | public static final int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user |
| 76 | public static final int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer |
| 77 | public static final int MEDIA_STATE_ERROR = 5; // Media is in error state |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 78 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 79 | public static class CallInfo implements Parcelable |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 80 | { |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 81 | public String mCallID = ""; |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 82 | public String mAccountID = ""; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 83 | public String mDisplayName = ""; |
| 84 | public String mPhone = ""; |
| 85 | public String mEmail = ""; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 86 | public String mRemoteContact = ""; |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 87 | public int mCallType = CALL_TYPE_UNDETERMINED; |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 88 | public int mCallState = CALL_STATE_NONE; |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 89 | public int mMediaState = MEDIA_STATE_NONE; |
| 90 | |
| 91 | @Override |
| 92 | public int describeContents() { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void writeToParcel(Parcel out, int flags) { |
| 98 | ArrayList<String> list = new ArrayList<String>(); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 99 | |
| 100 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 101 | list.add(mCallID); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 102 | list.add(mAccountID); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 103 | list.add(mDisplayName); |
| 104 | list.add(mPhone); |
| 105 | list.add(mEmail); |
| 106 | list.add(mRemoteContact); |
| 107 | |
| 108 | out.writeStringList(list); |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 109 | out.writeInt(mCallType); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 110 | out.writeInt(mCallState); |
| 111 | out.writeInt(mMediaState); |
| 112 | } |
| 113 | |
| 114 | public static final Parcelable.Creator<CallInfo> CREATOR |
| 115 | = new Parcelable.Creator<CallInfo>() { |
| 116 | public CallInfo createFromParcel(Parcel in) { |
| 117 | return new CallInfo(in); |
| 118 | } |
| 119 | |
| 120 | public CallInfo[] newArray(int size) { |
| 121 | return new CallInfo[size]; |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | public CallInfo() {} |
| 126 | |
| 127 | private CallInfo(Parcel in) { |
| 128 | ArrayList<String> list = in.createStringArrayList(); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 129 | |
| 130 | // Don't mess with this order!!! |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 131 | mCallID = list.get(0); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 132 | mAccountID = list.get(1); |
| 133 | mDisplayName = list.get(2); |
| 134 | mPhone = list.get(3); |
| 135 | mEmail = list.get(4); |
| 136 | mRemoteContact = list.get(5); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 137 | |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 138 | mCallType = in.readInt(); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 139 | mCallState = in.readInt(); |
| 140 | mMediaState = in.readInt(); |
| 141 | } |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 142 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 143 | |
| 144 | public SipCall() |
| 145 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 146 | mCallInfo = new CallInfo(); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 149 | public SipCall(CallInfo info) |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 150 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 151 | mCallInfo = info; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 152 | } |
| 153 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 154 | public static void setCallElementList(CallElementListFragment list) |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 155 | { |
| 156 | mCallElementList = list; |
| 157 | } |
| 158 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 159 | public static void setSFLPhoneHomeContext(SFLPhoneHomeActivity home) |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 160 | { |
| 161 | mHome = home; |
| 162 | } |
| 163 | |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 164 | public void setAssociatedRowView(View view) |
| 165 | { |
| 166 | mRowView = view; |
| 167 | } |
| 168 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 169 | public void setCallID(String callID) { |
| 170 | mCallInfo.mCallID = callID; |
| 171 | } |
| 172 | |
| 173 | public String getCallId() { |
| 174 | return mCallInfo.mCallID; |
| 175 | } |
| 176 | |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 177 | public void setAccountID(String accountID) { |
| 178 | mCallInfo.mAccountID = accountID; |
| 179 | } |
| 180 | |
| 181 | public String getAccountID() { |
| 182 | return mCallInfo.mAccountID; |
| 183 | } |
| 184 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 185 | public void setDisplayName(String displayName) { |
| 186 | mCallInfo.mDisplayName = displayName; |
| 187 | } |
| 188 | |
| 189 | public String getDisplayName() { |
| 190 | return mCallInfo.mDisplayName; |
| 191 | } |
| 192 | |
| 193 | public void setPhone(String phone) { |
| 194 | mCallInfo.mPhone = phone; |
| 195 | } |
| 196 | |
| 197 | public String getPhone() { |
| 198 | return mCallInfo.mPhone; |
| 199 | } |
| 200 | |
| 201 | public void setEmail(String email) { |
| 202 | mCallInfo.mEmail = email; |
| 203 | } |
| 204 | |
| 205 | public String getEmail() { |
| 206 | return mCallInfo.mEmail; |
| 207 | } |
| 208 | |
| 209 | public void setRemoteContact(String remoteContact) { |
| 210 | mCallInfo.mRemoteContact = remoteContact; |
| 211 | } |
| 212 | |
| 213 | public String getRemoteContact() { |
| 214 | return mCallInfo.mRemoteContact; |
| 215 | } |
| 216 | |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 217 | public void setCallType(int callType) { |
| 218 | mCallInfo.mCallType = callType; |
| 219 | } |
| 220 | |
| 221 | public int getCallType() { |
| 222 | return mCallInfo.mCallType; |
| 223 | } |
| 224 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 225 | public void setCallState(int callState) { |
| 226 | mCallInfo.mCallState = callState; |
Alexandre Savard | de82007 | 2012-10-26 15:39:21 -0400 | [diff] [blame] | 227 | |
| 228 | // Check if this call is associated to a view in CallElementList |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 229 | if(mRowView == null) |
| 230 | return; |
| 231 | |
Alexandre Savard | de82007 | 2012-10-26 15:39:21 -0400 | [diff] [blame] | 232 | // Update the state to the view |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 233 | CallElementView entryView = (CallElementView) mRowView.getTag(); |
| 234 | final String CURRENT_STATE_LABEL = " CURRENT STATE: "; |
| 235 | entryView.state.setText(CURRENT_STATE_LABEL + getCallStateString()); |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 238 | public int getCallStateInt() { |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 239 | return mCallInfo.mCallState; |
| 240 | } |
| 241 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 242 | public String getCallStateString() { |
| 243 | String state; |
| 244 | |
| 245 | switch(mCallInfo.mCallState) { |
| 246 | case CALL_STATE_INCOMING: |
| 247 | state = "INCOMING"; |
| 248 | break; |
| 249 | case CALL_STATE_RINGING: |
| 250 | state = "RINGING"; |
| 251 | break; |
| 252 | case CALL_STATE_CURRENT: |
| 253 | state = "CURRENT"; |
| 254 | break; |
| 255 | case CALL_STATE_HUNGUP: |
| 256 | state = "HUNGUP"; |
| 257 | break; |
| 258 | case CALL_STATE_BUSY: |
| 259 | state = "BUSY"; |
| 260 | break; |
| 261 | case CALL_STATE_FAILURE: |
| 262 | state = "FAILURE"; |
| 263 | break; |
| 264 | case CALL_STATE_HOLD: |
| 265 | state = "HOLD"; |
| 266 | break; |
| 267 | case CALL_STATE_UNHOLD: |
| 268 | state = "UNHOLD"; |
| 269 | break; |
| 270 | default: |
| 271 | state = "NULL"; |
| 272 | } |
| 273 | |
| 274 | return state; |
| 275 | } |
| 276 | |
| 277 | |
Alexandre Savard | c58c0fd | 2012-10-25 10:44:08 -0400 | [diff] [blame] | 278 | public void setMediaState(int mediaState) { |
| 279 | mCallInfo.mMediaState = mediaState; |
| 280 | } |
| 281 | |
| 282 | public int getMediaState() { |
| 283 | return mCallInfo.mMediaState; |
| 284 | } |
| 285 | |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 286 | public void placeCallUpdateUi() |
| 287 | { |
| 288 | if(mCallElementList != null) |
| 289 | mCallElementList.addCall(this); |
| 290 | |
| 291 | if(mHome != null) |
| 292 | mHome.onSelectedCallAction(this); |
| 293 | } |
| 294 | |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 295 | |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 296 | public void receiveCallUpdateUi() |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 297 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 298 | if(mCallElementList != null) |
| 299 | mCallElementList.addCall(this); |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 300 | |
| 301 | if(mHome != null) |
| 302 | mHome.onSelectedCallAction(this); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 305 | public void answerUpdateUi() |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 306 | { |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 307 | if(mHome != null) |
| 308 | mHome.onSelectedCallAction(this); |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 309 | |
| 310 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 311 | |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 312 | public boolean notifyServiceAnswer(ISipService service) |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 313 | { |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 314 | int callState = getCallStateInt(); |
| 315 | if((callState != CALL_STATE_RINGING) && |
| 316 | (callState != CALL_STATE_NONE)) { |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 317 | return false; |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 318 | } |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 319 | |
| 320 | try { |
| 321 | service.accept(mCallInfo.mCallID); |
| 322 | } catch (RemoteException e) { |
| 323 | Log.e(TAG, "Cannot call service method", e); |
| 324 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 325 | |
| 326 | return true; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 329 | /** |
| 330 | * Perform hangup action without sending request to the service |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 331 | * Used when SipService haved been notified that this call hung up |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 332 | */ |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 333 | public void hangupUpdateUi() { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 334 | Log.i(TAG, "Hangup call " + mCallInfo.mCallID); |
| 335 | |
| 336 | if(mCallElementList != null) |
| 337 | mCallElementList.removeCall(this); |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 338 | |
| 339 | if(mHome != null) |
| 340 | mHome.onUnselectedCallAction(); |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Perform hangup action and send request to the service |
| 345 | */ |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 346 | public boolean notifyServiceHangup(ISipService service) |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 347 | { |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 348 | try { |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 349 | if((getCallStateInt() == CALL_STATE_NONE) || |
| 350 | (getCallStateInt() == CALL_STATE_CURRENT) || |
| 351 | (getCallStateInt() == CALL_STATE_HOLD)) { |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 352 | service.hangUp(mCallInfo.mCallID); |
| 353 | return true; |
| 354 | |
| 355 | } |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 356 | else if(getCallStateInt() == CALL_STATE_RINGING) { |
| 357 | if(getCallType() == CALL_TYPE_INCOMING) { |
| 358 | service.refuse(mCallInfo.mCallID); |
| 359 | return true; |
| 360 | } |
| 361 | else if(getCallType() == CALL_TYPE_OUTGOING) { |
| 362 | service.hangUp(mCallInfo.mCallID); |
| 363 | return true; |
| 364 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 365 | } |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 366 | } catch (RemoteException e) { |
| 367 | Log.e(TAG, "Cannot call service method", e); |
| 368 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 369 | |
| 370 | return false; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 371 | } |
Alexandre Savard | aef9d80 | 2012-09-20 17:31:32 -0400 | [diff] [blame] | 372 | |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 373 | public boolean notifyServiceRefuse(ISipService service) |
Alexandre Savard | 8386985 | 2012-10-26 09:14:12 -0400 | [diff] [blame] | 374 | { |
| 375 | try { |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 376 | if(getCallStateInt() == CALL_STATE_RINGING) { |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 377 | service.refuse(mCallInfo.mCallID); |
| 378 | return true; |
| 379 | } |
Alexandre Savard | 8386985 | 2012-10-26 09:14:12 -0400 | [diff] [blame] | 380 | } catch (RemoteException e) { |
| 381 | Log.e(TAG, "Cannot call service method", e); |
| 382 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 383 | |
| 384 | return false; |
Alexandre Savard | 8386985 | 2012-10-26 09:14:12 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 387 | public boolean notifyServiceHold(ISipService service) |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 388 | { |
| 389 | try { |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 390 | if(getCallStateInt() == CALL_STATE_CURRENT) { |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 391 | service.hold(mCallInfo.mCallID); |
| 392 | return true; |
| 393 | } |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 394 | } catch (RemoteException e) { |
| 395 | Log.e(TAG, "Cannot call service method", e); |
| 396 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 397 | |
| 398 | return false; |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 401 | public boolean notifyServiceUnhold(ISipService service) |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 402 | { |
| 403 | try { |
Alexandre Savard | 2f1ae54 | 2012-10-26 17:05:00 -0400 | [diff] [blame] | 404 | if(getCallStateInt() == CALL_STATE_HOLD) { |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 405 | service.unhold(mCallInfo.mCallID); |
| 406 | return true; |
| 407 | } |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 408 | } catch (RemoteException e) { |
| 409 | Log.e(TAG, "Cannot call service method", e); |
| 410 | } |
Alexandre Savard | 08545ae | 2012-10-26 16:11:42 -0400 | [diff] [blame] | 411 | |
| 412 | return false; |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 413 | } |
Alexandre Savard | 8386985 | 2012-10-26 09:14:12 -0400 | [diff] [blame] | 414 | |
Alexandre Savard | aef9d80 | 2012-09-20 17:31:32 -0400 | [diff] [blame] | 415 | public void addToConference() |
| 416 | { |
| 417 | Log.i(TAG, "Add call to conference"); |
| 418 | } |
| 419 | |
| 420 | public void sendTextMessage() |
| 421 | { |
| 422 | Log.i(TAG, "Send text message"); |
| 423 | } |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 424 | |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 425 | public void printCallInfo() |
| 426 | { |
| 427 | Log.i(TAG, "CallInfo: CallID: " + mCallInfo.mCallID); |
| 428 | Log.i(TAG, " AccountID: " + mCallInfo.mAccountID); |
| 429 | Log.i(TAG, " Display Name: " + mCallInfo.mDisplayName); |
| 430 | Log.i(TAG, " Phone: " + mCallInfo.mPhone); |
| 431 | Log.i(TAG, " Email: " + mCallInfo.mEmail); |
| 432 | Log.i(TAG, " Contact: " + mCallInfo.mRemoteContact); |
| 433 | } |
| 434 | |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 435 | public void launchCallActivity(Context context) |
| 436 | { |
| 437 | Log.i(TAG, "Launch Call Activity"); |
| 438 | Bundle bundle = new Bundle(); |
| 439 | bundle.putParcelable("CallInfo", mCallInfo); |
| 440 | Intent intent = new Intent().setClass(context, CallActivity.class); |
| 441 | intent.putExtras(bundle); |
| 442 | context.startActivity(intent); |
| 443 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame^] | 444 | |
| 445 | /** |
| 446 | * Compare sip calls based on call ID |
| 447 | */ |
| 448 | @Override |
| 449 | public boolean equals(Object c){ |
| 450 | if(c instanceof SipCall && ((SipCall) c).mCallInfo.mCallID == mCallInfo.mCallID){ |
| 451 | return true; |
| 452 | } |
| 453 | return false; |
| 454 | |
| 455 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 456 | } |