blob: 50c934a8ae800eeb957db6c3f3bdcc6c8be05fc1 [file] [log] [blame]
Emeric Vigier6119d782012-09-21 18:04:14 -04001/**
2 * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr)
3 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
4 *
5 * Author: Regis Montoya <r3gis.3R@gmail.com>
6 * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 * If you own a pjsip commercial license you can also redistribute it
13 * and/or modify it under the terms of the GNU Lesser General Public License
14 * as an android library.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
Emeric Vigiereaf2c492012-09-19 14:38:20 -040024package com.savoirfairelinux.sflphone.service;
25
Emeric Vigier6119d782012-09-21 18:04:14 -040026import java.lang.ref.WeakReference;
alision17052d42013-04-22 10:39:38 -040027import java.util.ArrayList;
28import java.util.HashMap;
alision7f18fc82013-05-01 09:37:33 -040029import java.util.List;
alision17052d42013-04-22 10:39:38 -040030import java.util.Map;
Emeric Vigier6119d782012-09-21 18:04:14 -040031
Emeric Vigiereaf2c492012-09-19 14:38:20 -040032import android.app.Service;
alision17052d42013-04-22 10:39:38 -040033import android.content.BroadcastReceiver;
34import android.content.Context;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040035import android.content.Intent;
alision17052d42013-04-22 10:39:38 -040036import android.content.IntentFilter;
alision7f18fc82013-05-01 09:37:33 -040037import android.os.Bundle;
Emeric Vigier6119d782012-09-21 18:04:14 -040038import android.os.Handler;
39import android.os.HandlerThread;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040040import android.os.IBinder;
Emeric Vigier6119d782012-09-21 18:04:14 -040041import android.os.Looper;
42import android.os.Message;
alision5f899632013-04-22 17:26:56 -040043import android.os.RemoteException;
alision43a9b362013-05-01 16:30:15 -040044import android.os.Vibrator;
alision17052d42013-04-22 10:39:38 -040045import android.support.v4.content.LocalBroadcastManager;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040046import android.util.Log;
47import android.widget.Toast;
48
alisionf76de3b2013-04-16 15:35:22 -040049import com.savoirfairelinux.sflphone.account.AccountDetailsHandler;
alisione2a38e12013-04-25 14:20:20 -040050import com.savoirfairelinux.sflphone.account.HistoryHandler;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040051import com.savoirfairelinux.sflphone.client.SFLphoneApplication;
Alexandre Savard713a34d2012-09-26 15:50:41 -040052
Emeric Vigiereaf2c492012-09-19 14:38:20 -040053public class SipService extends Service {
54
55 static final String TAG = "SipService";
56 static final int DELAY = 5000; /* 5 sec */
57 private boolean runFlag = false;
58 private SipServiceThread sipServiceThread;
Emeric Vigier84e05da2012-09-20 14:53:05 -040059 private SFLphoneApplication sflphoneApp;
Emeric Vigier6119d782012-09-21 18:04:14 -040060 private SipServiceExecutor mExecutor;
61 private static HandlerThread executorThread;
62 private CallManagerJNI callManagerJNI;
Emeric Vigier0007dee2012-09-24 11:35:58 -040063 private CallManagerCallBack callManagerCallBack;
Alexandre Savardc1b08fe2012-09-25 16:24:47 -040064 private ConfigurationManagerJNI configurationManagerJNI;
Alexandre Savardfccd1dc2012-10-17 17:31:38 -040065 private ConfigurationManagerCallback configurationManagerCallback;
Emeric Vigier0007dee2012-09-24 11:35:58 -040066 private ManagerImpl managerImpl;
Emeric Vigier6119d782012-09-21 18:04:14 -040067 private boolean isPjSipStackStarted = false;
alision5f899632013-04-22 17:26:56 -040068 ISipClient client;
Emeric Vigier6119d782012-09-21 18:04:14 -040069
alision43a9b362013-05-01 16:30:15 -040070 private BroadcastReceiver IncomingReceiver = new BroadcastReceiver() {
71
72 @Override
73 public void onReceive(Context context, Intent intent) {
74 // Get instance of Vibrator from current Context
75
76 if (client != null) {
77 try {
78 if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) {
79 Log.i(TAG, "Received" + intent.getAction());
80
81 client.incomingCall(intent);
82
83 } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) {
84 Log.i(TAG, "Received" + intent.getAction());
85 client.callStateChanged(intent);
86 } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) {
87 Log.i(TAG, "Received" + intent.getAction());
88 Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
89 mVibrator.vibrate(300);
90 }
91 } catch (RemoteException e) {
92 Log.e(TAG, e.toString());
93 }
94 }
95
96 }
97 };
98
99 @Override
100 public boolean onUnbind(Intent i) {
101 super.onUnbind(i);
102 Log.i(TAG, "onUnbind(intent)");
103 return false;
104
105 }
106
107 /* called once by startService() */
108 @Override
109 public void onCreate() {
110 Log.i(TAG, "onCreated");
111 super.onCreate();
112
113 sflphoneApp = (SFLphoneApplication) getApplication();
114 sipServiceThread = new SipServiceThread();
115
116 IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED);
117 callFilter.addAction(CallManagerCallBack.INCOMING_CALL);
118 callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED);
119 LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver, callFilter);
120 getExecutor().execute(new StartRunnable());
121 }
122
123 /* called for each startService() */
124 @Override
125 public int onStartCommand(Intent intent, int flags, int startId) {
126 Log.i(TAG, "onStarted");
127 super.onStartCommand(intent, flags, startId);
128
129 if (!runFlag) {
130 sipServiceThread.start();
131 runFlag = true;
132 sflphoneApp.setServiceRunning(true);
133 Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show();
134 }
135
136 return START_STICKY; /* started and stopped explicitly */
137 }
138
139 @Override
140 public void onDestroy() {
141 /* called once by stopService() */
142 sipServiceThread.interrupt();
143 sipServiceThread = null;
144 runFlag = false;
145 sflphoneApp.setServiceRunning(false);
146 Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show();
147 super.onDestroy();
148
149 Log.i(TAG, "onDestroyed");
150 }
151
152 @Override
153 public IBinder onBind(Intent arg0) {
154 Log.i(TAG, "onBound");
155 return mBinder;
156 }
157
158 private static Looper createLooper() {
159 if (executorThread == null) {
160 Log.d(TAG, "Creating new handler thread");
161 // ADT gives a fake warning due to bad parse rule.
162 executorThread = new HandlerThread("SipService.Executor");
163 executorThread.start();
164 }
165 return executorThread.getLooper();
166 }
167
168 public SipServiceExecutor getExecutor() {
169 // create mExecutor lazily
170 if (mExecutor == null) {
171 mExecutor = new SipServiceExecutor(this);
172 }
173 return mExecutor;
174 }
175
176 // Executes immediate tasks in a single executorThread.
177 public static class SipServiceExecutor extends Handler {
178 WeakReference<SipService> handlerService;
179
180 SipServiceExecutor(SipService s) {
181 super(createLooper());
182 handlerService = new WeakReference<SipService>(s);
183 }
184
185 public void execute(Runnable task) {
186 // TODO: add wakelock
187 Message.obtain(this, 0/* don't care */, task).sendToTarget();
188 }
189
190 @Override
191 public void handleMessage(Message msg) {
192 if (msg.obj instanceof Runnable) {
193 executeInternal((Runnable) msg.obj);
194 } else {
195 Log.w(TAG, "can't handle msg: " + msg);
196 }
197 }
198
199 private void executeInternal(Runnable task) {
200 try {
201 task.run();
202 } catch (Throwable t) {
203 Log.e(TAG, "run task: " + task, t);
204 }
205 }
206 }
207
208 private void startPjSipStack() throws SameThreadException {
209 if (isPjSipStackStarted)
210 return;
211
212 try {
213 System.loadLibrary("gnustl_shared");
214 System.loadLibrary("expat");
215 System.loadLibrary("yaml");
216 System.loadLibrary("ccgnu2");
217 System.loadLibrary("crypto");
218 System.loadLibrary("ssl");
219 System.loadLibrary("ccrtp1");
220 System.loadLibrary("dbus");
221 System.loadLibrary("dbus-c++-1");
222 System.loadLibrary("samplerate");
223 System.loadLibrary("codec_ulaw");
224 System.loadLibrary("codec_alaw");
225 System.loadLibrary("speexresampler");
226 System.loadLibrary("sflphone");
227 isPjSipStackStarted = true;
228 } catch (UnsatisfiedLinkError e) {
229 Log.e(TAG, "Problem with the current Pj stack...", e);
230 isPjSipStackStarted = false;
231 return;
232 } catch (Exception e) {
233 Log.e(TAG, "Problem with the current Pj stack...", e);
234 }
235
236 /* get unique instance of managerImpl */
237 managerImpl = SFLPhoneservice.instance();
238
239 /* set static AppPath before calling manager.init */
240 managerImpl.setPath(sflphoneApp.getAppPath());
241
242 callManagerJNI = new CallManagerJNI();
243 callManagerCallBack = new CallManagerCallBack(this);
244 SFLPhoneservice.setCallbackObject(callManagerCallBack);
245
246 configurationManagerJNI = new ConfigurationManagerJNI();
247 configurationManagerCallback = new ConfigurationManagerCallback(this);
248 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
249
250 managerImpl.init("");
251 return;
252 }
253
254 // Enforce same thread contract to ensure we do not call from somewhere else
255 public class SameThreadException extends Exception {
256 private static final long serialVersionUID = -905639124232613768L;
257
258 public SameThreadException() {
259 super("Should be launched from a single worker thread");
260 }
261 }
262
263 public abstract static class SipRunnable implements Runnable {
264 protected abstract void doRun() throws SameThreadException, RemoteException;
265
266 public void run() {
267 try {
268 doRun();
269 } catch (SameThreadException e) {
270 Log.e(TAG, "Not done from same thread");
271 } catch (RemoteException e) {
272 Log.e(TAG, e.toString());
273 }
274 }
275 }
276
277 public abstract static class SipRunnableWithReturn implements Runnable {
278 Object obj = null;
279 boolean done = false;
280
281 protected abstract Object doRun() throws SameThreadException;
282
283 public Object getVal() {
284 return obj;
285 }
286
287 public boolean isDone() {
288 return done;
289 }
290
291 public void run() {
292 try {
293 obj = doRun();
294 done = true;
295 } catch (SameThreadException e) {
296 Log.e(TAG, "Not done from same thread");
297 }
298 }
299 }
300
301 class StartRunnable extends SipRunnable {
302 @Override
303 protected void doRun() throws SameThreadException {
304 startPjSipStack();
305 }
306 }
307
308 private class SipServiceThread extends Thread {
309
310 public SipServiceThread() {
311 super("sipServiceThread");
312 }
313
314 @Override
315 public void run() {
316 Log.i(TAG, "SipService thread running...");
317 SipService sipService = SipService.this;
318 while (sipService.runFlag) {
319 try {
320 Thread.sleep(DELAY);
321 } catch (InterruptedException e) {
322 sipService.runFlag = false;
323 Log.w(TAG, "service thread interrupted!");
324 }
325 }
326 }
327 }
328
329 /* ************************************
330 *
331 * Implement public interface for the service
332 *
333 *
334 * **********************************
335 */
Emeric Vigier6119d782012-09-21 18:04:14 -0400336 private final ISipService.Stub mBinder = new ISipService.Stub() {
337
338 @Override
339 public void placeCall(final String accountID, final String callID, final String to) {
340 getExecutor().execute(new SipRunnable() {
341 @Override
342 protected void doRun() throws SameThreadException {
343 Log.i(TAG, "SipService.placeCall() thread running...");
344 callManagerJNI.placeCall(accountID, callID, to);
345 }
346 });
347 }
348
349 @Override
350 public void refuse(final String callID) {
351 getExecutor().execute(new SipRunnable() {
352 @Override
353 protected void doRun() throws SameThreadException {
354 Log.i(TAG, "SipService.refuse() thread running...");
355 callManagerJNI.refuse(callID);
356 }
357 });
358 }
359
360 @Override
361 public void accept(final String callID) {
362 getExecutor().execute(new SipRunnable() {
363 @Override
364 protected void doRun() throws SameThreadException {
365 Log.i(TAG, "SipService.placeCall() thread running...");
366 callManagerJNI.accept(callID);
367 }
368 });
369 }
370
371 @Override
372 public void hangUp(final String callID) {
373 getExecutor().execute(new SipRunnable() {
374 @Override
375 protected void doRun() throws SameThreadException {
376 Log.i(TAG, "SipService.hangUp() thread running...");
377 callManagerJNI.hangUp(callID);
378 }
379 });
380 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400381
382 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400383 public void hold(final String callID) {
384 getExecutor().execute(new SipRunnable() {
385 @Override
386 protected void doRun() throws SameThreadException {
387 Log.i(TAG, "SipService.hold() thread running...");
388 callManagerJNI.hold(callID);
389 }
390 });
391 }
392
393 @Override
394 public void unhold(final String callID) {
395 getExecutor().execute(new SipRunnable() {
396 @Override
397 protected void doRun() throws SameThreadException {
398 Log.i(TAG, "SipService.unhold() thread running...");
399 callManagerJNI.unhold(callID);
400 }
401 });
402 }
403
404 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400405 public void setAudioPlugin(final String audioPlugin) {
406 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400407 @Override
408 protected void doRun() throws SameThreadException {
409 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
410 configurationManagerJNI.setAudioPlugin(audioPlugin);
411 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400412 });
413 }
414
415 @Override
416 public String getCurrentAudioOutputPlugin() {
417 class CurrentAudioPlugin extends SipRunnableWithReturn {
418 @Override
419 protected String doRun() throws SameThreadException {
420 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
421 return configurationManagerJNI.getCurrentAudioOutputPlugin();
422 }
alision371b77e2013-04-23 14:51:26 -0400423 }
424 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400425
426 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
427 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400428 while (!runInstance.isDone()) {
429 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400430 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400431 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400432
433 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400434 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400435 class AccountList extends SipRunnableWithReturn {
436 @Override
437 protected StringVect doRun() throws SameThreadException {
438 Log.i(TAG, "SipService.getAccountList() thread running...");
439 return configurationManagerJNI.getAccountList();
440 }
alision371b77e2013-04-23 14:51:26 -0400441 }
442 ;
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400443 AccountList runInstance = new AccountList();
444 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400445 while (!runInstance.isDone()) {
446 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400447 StringVect swigvect = (StringVect) runInstance.getVal();
448
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400449 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400450
alision371b77e2013-04-23 14:51:26 -0400451 for (int i = 0; i < swigvect.size(); i++)
452 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400453
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400454 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400455 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400456
457 @Override
alision371b77e2013-04-23 14:51:26 -0400458 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400459 class AccountDetails extends SipRunnableWithReturn {
460 private String id;
alision371b77e2013-04-23 14:51:26 -0400461
462 AccountDetails(String accountId) {
463 id = accountId;
464 }
465
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400466 @Override
467 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400468 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400469 return configurationManagerJNI.getAccountDetails(id);
470 }
alision371b77e2013-04-23 14:51:26 -0400471 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400472
473 AccountDetails runInstance = new AccountDetails(accountID);
474 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400475 while (!runInstance.isDone()) {
476 }
477 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400478
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400479 HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400480
481 return nativemap;
482 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400483
484 @Override
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400485 public void setAccountDetails(final String accountId, Map map) {
alision371b77e2013-04-23 14:51:26 -0400486 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400487
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400488 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400489
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400490 getExecutor().execute(new SipRunnable() {
491 @Override
492 protected void doRun() throws SameThreadException {
493 Log.i(TAG, "SipService.setAccountDetails() thread running...");
494 configurationManagerJNI.setAccountDetails(accountId, swigmap);
495 }
496 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400497 }
498
Alexandre Savard46036572012-10-05 13:56:49 -0400499 @Override
500 public String addAccount(Map map) {
501 class AddAccount extends SipRunnableWithReturn {
502 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400503
504 AddAccount(StringMap m) {
505 map = m;
506 }
507
Alexandre Savard46036572012-10-05 13:56:49 -0400508 @Override
509 protected String doRun() throws SameThreadException {
510 Log.i(TAG, "SipService.getAccountDetails() thread running...");
511 return configurationManagerJNI.addAccount(map);
512 }
alision371b77e2013-04-23 14:51:26 -0400513 }
514 ;
Alexandre Savard46036572012-10-05 13:56:49 -0400515
alision371b77e2013-04-23 14:51:26 -0400516 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400517
518 AddAccount runInstance = new AddAccount(swigmap);
519 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400520 while (!runInstance.isDone()) {
521 }
Alexandre Savard46036572012-10-05 13:56:49 -0400522 String accountId = (String) runInstance.getVal();
523
524 return accountId;
525 }
526
527 @Override
528 public void removeAccount(final String accountId) {
529 getExecutor().execute(new SipRunnable() {
530 @Override
531 protected void doRun() throws SameThreadException {
532 Log.i(TAG, "SipService.setAccountDetails() thread running...");
533 configurationManagerJNI.removeAccount(accountId);
534 }
535 });
536 }
alision5f899632013-04-22 17:26:56 -0400537
538 @Override
539 public void registerClient(ISipClient callback) throws RemoteException {
alision371b77e2013-04-23 14:51:26 -0400540 client = callback;
alision5f899632013-04-22 17:26:56 -0400541 }
alisione2a38e12013-04-25 14:20:20 -0400542
543 @Override
544 public ArrayList<HashMap<String, String>> getHistory() throws RemoteException {
545 class History extends SipRunnableWithReturn {
546
547 @Override
548 protected VectMap doRun() throws SameThreadException {
549 Log.i(TAG, "SipService.getHistory() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400550
alisione2a38e12013-04-25 14:20:20 -0400551 return configurationManagerJNI.getHistory();
552 }
553 }
554
555 History runInstance = new History();
556 getExecutor().execute(runInstance);
557 while (!runInstance.isDone()) {
558 }
559 VectMap swigmap = (VectMap) runInstance.getVal();
560
561 ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap);
562
563 return nativemap;
564 }
alision7f18fc82013-05-01 09:37:33 -0400565
alision43a9b362013-05-01 16:30:15 -0400566 /*************************
567 * Transfer related API
568 *************************/
569
alision7f18fc82013-05-01 09:37:33 -0400570 @Override
571 public void transfer(final String callID, final String to) throws RemoteException {
572 getExecutor().execute(new SipRunnable() {
573 @Override
574 protected void doRun() throws SameThreadException, RemoteException {
575 Log.i(TAG, "SipService.transfer() thread running...");
576 if (callManagerJNI.transfer(callID, to)) {
577 Bundle bundle = new Bundle();
578 bundle.putString("CallID", callID);
579 bundle.putString("State", "HUNGUP");
580 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision43a9b362013-05-01 16:30:15 -0400581 intent.putExtra(CallManagerCallBack.SIGNAL_NAME, CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400582 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
583 client.callStateChanged(intent);
584 } else
585 Log.i(TAG, "NOT OK");
586 }
587 });
588
589 }
alision43a9b362013-05-01 16:30:15 -0400590
alision7f18fc82013-05-01 09:37:33 -0400591 @Override
592 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
593 getExecutor().execute(new SipRunnable() {
594 @Override
595 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400596 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400597 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
598 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400599 } else
600 Log.i(TAG, "NOT OK");
601 }
602 });
alision43a9b362013-05-01 16:30:15 -0400603
604 }
605
606 /*************************
607 * Conference related API
608 *************************/
609
610 @Override
611 public void removeConference(final String confID) throws RemoteException {
612 getExecutor().execute(new SipRunnable() {
613 @Override
614 protected void doRun() throws SameThreadException, RemoteException {
615 Log.i(TAG, "SipService.createConference() thread running...");
616 callManagerJNI.removeConference(confID);
617 }
618 });
619
alision7f18fc82013-05-01 09:37:33 -0400620 }
621
622 @Override
alision43a9b362013-05-01 16:30:15 -0400623 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
624 getExecutor().execute(new SipRunnable() {
625 @Override
626 protected void doRun() throws SameThreadException, RemoteException {
627 Log.i(TAG, "SipService.joinParticipant() thread running...");
628 callManagerJNI.joinParticipant(sel_callID, drag_callID);
629 }
630 });
631
alision7f18fc82013-05-01 09:37:33 -0400632 }
633
634 @Override
alision43a9b362013-05-01 16:30:15 -0400635 public void createConfFromParticipantList(final List participants) throws RemoteException {
636 getExecutor().execute(new SipRunnable() {
637 @Override
638 protected void doRun() throws SameThreadException, RemoteException {
639 Log.i(TAG, "SipService.createConfFromParticipantList() thread running...");
640 // callManagerJNI.createConfFromParticipantList(participants);
641 }
642 });
643
alision7f18fc82013-05-01 09:37:33 -0400644 }
645
646 @Override
alision43a9b362013-05-01 16:30:15 -0400647 public void addParticipant(final String callID, final String confID) throws RemoteException {
648 getExecutor().execute(new SipRunnable() {
649 @Override
650 protected void doRun() throws SameThreadException, RemoteException {
651 Log.i(TAG, "SipService.addParticipant() thread running...");
652 callManagerJNI.addParticipant(callID, confID);
653 }
654 });
655
alision7f18fc82013-05-01 09:37:33 -0400656 }
657
658 @Override
alision43a9b362013-05-01 16:30:15 -0400659 public void addMainParticipant(final String confID) throws RemoteException {
660 getExecutor().execute(new SipRunnable() {
661 @Override
662 protected void doRun() throws SameThreadException, RemoteException {
663 Log.i(TAG, "SipService.addMainParticipant() thread running...");
664 callManagerJNI.addMainParticipant(confID);
665 }
666 });
667
alision7f18fc82013-05-01 09:37:33 -0400668 }
669
670 @Override
alision43a9b362013-05-01 16:30:15 -0400671 public void detachParticipant(final String callID) throws RemoteException {
672 getExecutor().execute(new SipRunnable() {
673 @Override
674 protected void doRun() throws SameThreadException, RemoteException {
675 Log.i(TAG, "SipService.detachParticipant() thread running...");
676 callManagerJNI.detachParticipant(callID);
677 }
678 });
679
alision7f18fc82013-05-01 09:37:33 -0400680 }
681
682 @Override
alision43a9b362013-05-01 16:30:15 -0400683 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
684 getExecutor().execute(new SipRunnable() {
685 @Override
686 protected void doRun() throws SameThreadException, RemoteException {
687 Log.i(TAG, "SipService.joinConference() thread running...");
688 callManagerJNI.joinConference(sel_confID, drag_confID);
689 }
690 });
691
alision7f18fc82013-05-01 09:37:33 -0400692 }
693
694 @Override
alision43a9b362013-05-01 16:30:15 -0400695 public void hangUpConference(final String confID) throws RemoteException {
696 getExecutor().execute(new SipRunnable() {
697 @Override
698 protected void doRun() throws SameThreadException, RemoteException {
699 Log.i(TAG, "SipService.joinConference() thread running...");
700 callManagerJNI.hangUpConference(confID);
701 }
702 });
703
alision7f18fc82013-05-01 09:37:33 -0400704 }
705
706 @Override
alision43a9b362013-05-01 16:30:15 -0400707 public void holdConference(final String confID) throws RemoteException {
708 getExecutor().execute(new SipRunnable() {
709 @Override
710 protected void doRun() throws SameThreadException, RemoteException {
711 Log.i(TAG, "SipService.holdConference() thread running...");
712 callManagerJNI.holdConference(confID);
713 }
714 });
715
alision7f18fc82013-05-01 09:37:33 -0400716 }
717
718 @Override
alision43a9b362013-05-01 16:30:15 -0400719 public void unholdConference(final String confID) throws RemoteException {
720 getExecutor().execute(new SipRunnable() {
721 @Override
722 protected void doRun() throws SameThreadException, RemoteException {
723 Log.i(TAG, "SipService.unholdConference() thread running...");
724 callManagerJNI.unholdConference(confID);
725 }
726 });
727
alision7f18fc82013-05-01 09:37:33 -0400728 }
729
730 @Override
731 public List getConferenceList() throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400732 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400733 return null;
734 }
735
736 @Override
737 public List getParticipantList(String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400738 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400739 return null;
740 }
741
742 @Override
743 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400744 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400745 return null;
746 }
747
748 @Override
749 public Map getConferenceDetails(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400750 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400751 return null;
752 }
753
Emeric Vigier6119d782012-09-21 18:04:14 -0400754 };
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400755}