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