blob: cd403e1d8608353ad932fa6e1578e20072ffc6b9 [file] [log] [blame]
Emeric Vigier6119d782012-09-21 18:04:14 -04001/**
2 * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr)
alisionb1763882013-06-18 17:30:51 -04003 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Emeric Vigier6119d782012-09-21 18:04:14 -04004 *
5 * Author: Regis Montoya <r3gis.3R@gmail.com>
6 * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
alision11e8e162013-05-28 10:33:14 -04007 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Emeric Vigier6119d782012-09-21 18:04:14 -04008 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 * If you own a pjsip commercial license you can also redistribute it
14 * and/or modify it under the terms of the GNU Lesser General Public License
15 * as an android library.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040025package org.sflphone.service;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040026
Emeric Vigier6119d782012-09-21 18:04:14 -040027import java.lang.ref.WeakReference;
alision17052d42013-04-22 10:39:38 -040028import java.util.ArrayList;
29import java.util.HashMap;
alisioncc7bb422013-06-06 15:31:39 -040030import java.util.Iterator;
alision7f18fc82013-05-01 09:37:33 -040031import java.util.List;
alision17052d42013-04-22 10:39:38 -040032import java.util.Map;
alision806e18e2013-06-21 15:30:17 -040033import java.util.Map.Entry;
alision2cb99562013-05-30 17:02:20 -040034import java.util.Random;
Emeric Vigier6119d782012-09-21 18:04:14 -040035
Alexandre Lision3ccccf02013-10-07 14:10:46 -040036import org.sflphone.R;
Alexandre Lision064e1e02013-10-01 16:18:42 -040037import org.sflphone.account.AccountDetailBasic;
38import org.sflphone.account.AccountDetailsHandler;
Alexandre Lisionafd40e42013-10-15 13:48:37 -040039import org.sflphone.account.AudioHandler;
Alexandre Lision064e1e02013-10-01 16:18:42 -040040import org.sflphone.account.CallDetailsHandler;
41import org.sflphone.account.HistoryHandler;
42import org.sflphone.client.SFLPhoneHomeActivity;
Alexandre Lision064e1e02013-10-01 16:18:42 -040043import org.sflphone.model.Conference;
44import org.sflphone.model.SipCall;
45import org.sflphone.receivers.IncomingReceiver;
46
alision2cb99562013-05-30 17:02:20 -040047import android.app.Notification;
48import android.app.NotificationManager;
49import android.app.PendingIntent;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040050import android.app.Service;
alision17052d42013-04-22 10:39:38 -040051import android.content.Context;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040052import android.content.Intent;
alision17052d42013-04-22 10:39:38 -040053import android.content.IntentFilter;
alision7f18fc82013-05-01 09:37:33 -040054import android.os.Bundle;
Emeric Vigier6119d782012-09-21 18:04:14 -040055import android.os.Handler;
56import android.os.HandlerThread;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040057import android.os.IBinder;
Emeric Vigier6119d782012-09-21 18:04:14 -040058import android.os.Looper;
59import android.os.Message;
alision5f899632013-04-22 17:26:56 -040060import android.os.RemoteException;
alision2cb99562013-05-30 17:02:20 -040061import android.support.v4.app.NotificationCompat;
alision17052d42013-04-22 10:39:38 -040062import android.support.v4.content.LocalBroadcastManager;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040063import android.util.Log;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040064
Emeric Vigiereaf2c492012-09-19 14:38:20 -040065public class SipService extends Service {
66
67 static final String TAG = "SipService";
68 static final int DELAY = 5000; /* 5 sec */
69 private boolean runFlag = false;
70 private SipServiceThread sipServiceThread;
Emeric Vigier6119d782012-09-21 18:04:14 -040071 private SipServiceExecutor mExecutor;
72 private static HandlerThread executorThread;
alision3ea8f3c2013-07-16 17:35:35 -040073 private CallManager callManagerJNI;
Alexandre Lision67817192013-07-18 12:04:30 -040074 private ManagerImpl managerImpl;
Emeric Vigier0007dee2012-09-24 11:35:58 -040075 private CallManagerCallBack callManagerCallBack;
alision3ea8f3c2013-07-16 17:35:35 -040076 private ConfigurationManager configurationManagerJNI;
Alexandre Savardfccd1dc2012-10-17 17:31:38 -040077 private ConfigurationManagerCallback configurationManagerCallback;
Emeric Vigier6119d782012-09-21 18:04:14 -040078 private boolean isPjSipStackStarted = false;
alisioncc7bb422013-06-06 15:31:39 -040079
alision2cb99562013-05-30 17:02:20 -040080 public static final String NOTIF_CREATION = "notif_creation";
81 public static final String NOTIF_DELETION = "notif_deletion";
alision04a00182013-05-10 17:05:29 -040082
alision2cb99562013-05-30 17:02:20 -040083 private HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>();
alision806e18e2013-06-21 15:30:17 -040084 private HashMap<String, Conference> current_confs = new HashMap<String, Conference>();
85 private IncomingReceiver receiver;
Emeric Vigier6119d782012-09-21 18:04:14 -040086
alision806e18e2013-06-21 15:30:17 -040087 public HashMap<String, Conference> getCurrent_confs() {
88 return current_confs;
89 }
alision43a9b362013-05-01 16:30:15 -040090
91 @Override
92 public boolean onUnbind(Intent i) {
93 super.onUnbind(i);
94 Log.i(TAG, "onUnbind(intent)");
95 return false;
96
97 }
98
99 /* called once by startService() */
100 @Override
101 public void onCreate() {
102 Log.i(TAG, "onCreated");
103 super.onCreate();
104
alision43a9b362013-05-01 16:30:15 -0400105 sipServiceThread = new SipServiceThread();
106
107 IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED);
108 callFilter.addAction(CallManagerCallBack.INCOMING_CALL);
109 callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED);
alision4a0eb092013-05-07 13:52:03 -0400110 callFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
111 callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
alision04a00182013-05-10 17:05:29 -0400112 callFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
alision806e18e2013-06-21 15:30:17 -0400113 callFilter.addAction(CallManagerCallBack.CONF_CREATED);
114 callFilter.addAction(CallManagerCallBack.CONF_REMOVED);
115 callFilter.addAction(CallManagerCallBack.CONF_CHANGED);
alisiondf1dac92013-06-27 17:35:53 -0400116 callFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED);
alision806e18e2013-06-21 15:30:17 -0400117 receiver = new IncomingReceiver(this, mBinder);
alision2cb99562013-05-30 17:02:20 -0400118 LocalBroadcastManager.getInstance(this).registerReceiver(receiver, callFilter);
alision2cb99562013-05-30 17:02:20 -0400119
alisioncc7bb422013-06-06 15:31:39 -0400120 getExecutor().execute(new StartRunnable());
alisioncc7bb422013-06-06 15:31:39 -0400121 }
alision43a9b362013-05-01 16:30:15 -0400122
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
alision806e18e2013-06-21 15:30:17 -0400129 receiver = new IncomingReceiver(this, mBinder);
alision43a9b362013-05-01 16:30:15 -0400130 if (!runFlag) {
131 sipServiceThread.start();
132 runFlag = true;
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400133 // sflphoneApp.setServiceRunning(true);
Alexandre Lision0a300ff2013-09-23 14:22:34 -0400134 Log.i(TAG, "Sflphone Service started");
alision43a9b362013-05-01 16:30:15 -0400135 }
136
alision907bde72013-06-20 14:40:37 -0400137 return START_NOT_STICKY; /* started and stopped explicitly */
alision43a9b362013-05-01 16:30:15 -0400138 }
139
140 @Override
141 public void onDestroy() {
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400142 Log.i(TAG, "onDestroyed");
alision43a9b362013-05-01 16:30:15 -0400143 /* called once by stopService() */
144 sipServiceThread.interrupt();
145 sipServiceThread = null;
146 runFlag = false;
Alexandre Lision0a300ff2013-09-23 14:22:34 -0400147
148 LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
alision2cb99562013-05-30 17:02:20 -0400149
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400150 // sflphoneApp.setServiceRunning(false);
151 // Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show();
alision43a9b362013-05-01 16:30:15 -0400152 super.onDestroy();
153
alision43a9b362013-05-01 16:30:15 -0400154 }
155
156 @Override
157 public IBinder onBind(Intent arg0) {
158 Log.i(TAG, "onBound");
159 return mBinder;
160 }
161
162 private static Looper createLooper() {
163 if (executorThread == null) {
164 Log.d(TAG, "Creating new handler thread");
165 // ADT gives a fake warning due to bad parse rule.
166 executorThread = new HandlerThread("SipService.Executor");
167 executorThread.start();
168 }
169 return executorThread.getLooper();
170 }
171
172 public SipServiceExecutor getExecutor() {
173 // create mExecutor lazily
174 if (mExecutor == null) {
175 mExecutor = new SipServiceExecutor(this);
176 }
177 return mExecutor;
178 }
179
180 // Executes immediate tasks in a single executorThread.
181 public static class SipServiceExecutor extends Handler {
182 WeakReference<SipService> handlerService;
183
184 SipServiceExecutor(SipService s) {
185 super(createLooper());
186 handlerService = new WeakReference<SipService>(s);
187 }
188
189 public void execute(Runnable task) {
190 // TODO: add wakelock
191 Message.obtain(this, 0/* don't care */, task).sendToTarget();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400192 Log.w(TAG, "SenT!");
alision43a9b362013-05-01 16:30:15 -0400193 }
194
195 @Override
196 public void handleMessage(Message msg) {
197 if (msg.obj instanceof Runnable) {
198 executeInternal((Runnable) msg.obj);
199 } else {
200 Log.w(TAG, "can't handle msg: " + msg);
201 }
202 }
203
204 private void executeInternal(Runnable task) {
205 try {
206 task.run();
207 } catch (Throwable t) {
208 Log.e(TAG, "run task: " + task, t);
209 }
210 }
211 }
212
213 private void startPjSipStack() throws SameThreadException {
214 if (isPjSipStackStarted)
215 return;
216
217 try {
218 System.loadLibrary("gnustl_shared");
219 System.loadLibrary("expat");
220 System.loadLibrary("yaml");
221 System.loadLibrary("ccgnu2");
222 System.loadLibrary("crypto");
223 System.loadLibrary("ssl");
Alexandre Lision7c6f4a62013-09-05 13:27:01 -0400224 System.loadLibrary("sndfile");
alision43a9b362013-05-01 16:30:15 -0400225 System.loadLibrary("ccrtp1");
alision43a9b362013-05-01 16:30:15 -0400226 System.loadLibrary("samplerate");
227 System.loadLibrary("codec_ulaw");
228 System.loadLibrary("codec_alaw");
Alexandre Lision0a300ff2013-09-23 14:22:34 -0400229 System.loadLibrary("codec_g722");
Alexandre Lision6deda412013-09-25 13:21:22 -0400230 System.loadLibrary("codec_opus");
Alexandre Lisiona1ad1c32013-10-15 16:35:20 -0400231 System.loadLibrary("codec_gsm");
alision43a9b362013-05-01 16:30:15 -0400232 System.loadLibrary("speexresampler");
233 System.loadLibrary("sflphone");
234 isPjSipStackStarted = true;
Adrien Béraud9360f242013-09-19 11:07:42 +1000235
alision43a9b362013-05-01 16:30:15 -0400236 } catch (UnsatisfiedLinkError e) {
237 Log.e(TAG, "Problem with the current Pj stack...", e);
238 isPjSipStackStarted = false;
239 return;
240 } catch (Exception e) {
241 Log.e(TAG, "Problem with the current Pj stack...", e);
242 }
243
Alexandre Lision67817192013-07-18 12:04:30 -0400244 Log.i(TAG, "PjSIPStack started");
245 managerImpl = SFLPhoneservice.instance();
246
247 /* set static AppPath before calling manager.init */
248
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400249 // managerImpl.setPath(sflphoneApp.getAppPath());
alision43a9b362013-05-01 16:30:15 -0400250
alision3ea8f3c2013-07-16 17:35:35 -0400251 callManagerJNI = new CallManager();
alision43a9b362013-05-01 16:30:15 -0400252 callManagerCallBack = new CallManagerCallBack(this);
253 SFLPhoneservice.setCallbackObject(callManagerCallBack);
254
alision3ea8f3c2013-07-16 17:35:35 -0400255 configurationManagerJNI = new ConfigurationManager();
alision43a9b362013-05-01 16:30:15 -0400256 configurationManagerCallback = new ConfigurationManagerCallback(this);
257 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
Adrien Béraud9360f242013-09-19 11:07:42 +1000258
Alexandre Lision67817192013-07-18 12:04:30 -0400259 Log.i(TAG, "before init");
260 managerImpl.init("");
Adrien Béraud9360f242013-09-19 11:07:42 +1000261
Alexandre Lision67817192013-07-18 12:04:30 -0400262 Log.i(TAG, "->startPjSipStack");
alision43a9b362013-05-01 16:30:15 -0400263
alision43a9b362013-05-01 16:30:15 -0400264 }
265
Adrien Béraud9360f242013-09-19 11:07:42 +1000266 public HashMap<String, SipCall> getCurrent_calls() {
alision2cb99562013-05-30 17:02:20 -0400267 return current_calls;
268 }
269
alision43a9b362013-05-01 16:30:15 -0400270 // Enforce same thread contract to ensure we do not call from somewhere else
271 public class SameThreadException extends Exception {
272 private static final long serialVersionUID = -905639124232613768L;
273
274 public SameThreadException() {
275 super("Should be launched from a single worker thread");
276 }
277 }
278
279 public abstract static class SipRunnable implements Runnable {
280 protected abstract void doRun() throws SameThreadException, RemoteException;
281
Adrien Béraud9360f242013-09-19 11:07:42 +1000282 @Override
alision43a9b362013-05-01 16:30:15 -0400283 public void run() {
284 try {
285 doRun();
286 } catch (SameThreadException e) {
287 Log.e(TAG, "Not done from same thread");
288 } catch (RemoteException e) {
289 Log.e(TAG, e.toString());
290 }
291 }
292 }
293
294 public abstract static class SipRunnableWithReturn implements Runnable {
295 Object obj = null;
296 boolean done = false;
297
298 protected abstract Object doRun() throws SameThreadException;
299
300 public Object getVal() {
301 return obj;
302 }
303
304 public boolean isDone() {
305 return done;
306 }
307
Adrien Béraud9360f242013-09-19 11:07:42 +1000308 @Override
alision43a9b362013-05-01 16:30:15 -0400309 public void run() {
310 try {
311 obj = doRun();
312 done = true;
313 } catch (SameThreadException e) {
314 Log.e(TAG, "Not done from same thread");
315 }
316 }
317 }
318
319 class StartRunnable extends SipRunnable {
320 @Override
321 protected void doRun() throws SameThreadException {
322 startPjSipStack();
323 }
324 }
325
326 private class SipServiceThread extends Thread {
327
328 public SipServiceThread() {
329 super("sipServiceThread");
330 }
331
332 @Override
333 public void run() {
334 Log.i(TAG, "SipService thread running...");
335 SipService sipService = SipService.this;
336 while (sipService.runFlag) {
337 try {
338 Thread.sleep(DELAY);
339 } catch (InterruptedException e) {
340 sipService.runFlag = false;
341 Log.w(TAG, "service thread interrupted!");
342 }
343 }
344 }
345 }
346
347 /* ************************************
348 *
349 * Implement public interface for the service
350 *
Alexandre Lision67817192013-07-18 12:04:30 -0400351 * *********************************
352 */
353
Emeric Vigier6119d782012-09-21 18:04:14 -0400354 private final ISipService.Stub mBinder = new ISipService.Stub() {
355
356 @Override
alisionfde875f2013-05-28 17:01:54 -0400357 public void placeCall(final SipCall call) {
Emeric Vigier6119d782012-09-21 18:04:14 -0400358 getExecutor().execute(new SipRunnable() {
359 @Override
360 protected void doRun() throws SameThreadException {
361 Log.i(TAG, "SipService.placeCall() thread running...");
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400362 callManagerJNI.placeCall(call.getAccount().getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber());
Adrien Béraud9360f242013-09-19 11:07:42 +1000363
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400364 HashMap<String, String> details = CallDetailsHandler.convertSwigToNative(callManagerJNI.getCallDetails(call.getCallId()));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400365 // watchout timestamp stored by sflphone is in seconds
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400366 call.setTimestamp_start(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START)));
alision2cb99562013-05-30 17:02:20 -0400367 getCurrent_calls().put(call.getCallId(), call);
Adrien Béraud9360f242013-09-19 11:07:42 +1000368
Emeric Vigier6119d782012-09-21 18:04:14 -0400369 }
370 });
371 }
372
373 @Override
374 public void refuse(final String callID) {
375 getExecutor().execute(new SipRunnable() {
376 @Override
377 protected void doRun() throws SameThreadException {
378 Log.i(TAG, "SipService.refuse() thread running...");
379 callManagerJNI.refuse(callID);
380 }
381 });
382 }
383
384 @Override
385 public void accept(final String callID) {
386 getExecutor().execute(new SipRunnable() {
387 @Override
388 protected void doRun() throws SameThreadException {
Tristan Matthews40cf25e2013-07-24 13:45:15 -0400389 Log.i(TAG, "SipService.accept() thread running...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400390 callManagerJNI.accept(callID);
391 }
392 });
393 }
394
395 @Override
396 public void hangUp(final String callID) {
397 getExecutor().execute(new SipRunnable() {
398 @Override
399 protected void doRun() throws SameThreadException {
400 Log.i(TAG, "SipService.hangUp() thread running...");
401 callManagerJNI.hangUp(callID);
402 }
403 });
404 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400405
406 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400407 public void hold(final String callID) {
408 getExecutor().execute(new SipRunnable() {
409 @Override
410 protected void doRun() throws SameThreadException {
411 Log.i(TAG, "SipService.hold() thread running...");
412 callManagerJNI.hold(callID);
413 }
414 });
415 }
416
417 @Override
418 public void unhold(final String callID) {
419 getExecutor().execute(new SipRunnable() {
420 @Override
421 protected void doRun() throws SameThreadException {
422 Log.i(TAG, "SipService.unhold() thread running...");
423 callManagerJNI.unhold(callID);
424 }
425 });
426 }
Adrien Béraud9360f242013-09-19 11:07:42 +1000427
Alexandre Lision6711ab22013-09-16 15:15:38 -0400428 @Override
429 public HashMap<String, String> getCallDetails(String callID) throws RemoteException {
430 class CallDetails extends SipRunnableWithReturn {
431 private String id;
432
433 CallDetails(String callID) {
434 id = callID;
435 }
436
437 @Override
438 protected StringMap doRun() throws SameThreadException {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400439 Log.i(TAG, "SipService.getCallDetails() thread running...");
Alexandre Lision6711ab22013-09-16 15:15:38 -0400440 return callManagerJNI.getCallDetails(id);
441 }
442 }
443
444 CallDetails runInstance = new CallDetails(callID);
445 getExecutor().execute(runInstance);
446
447 while (!runInstance.isDone()) {
448 }
449 StringMap swigmap = (StringMap) runInstance.getVal();
450
451 HashMap<String, String> nativemap = CallDetailsHandler.convertSwigToNative(swigmap);
452
453 return nativemap;
Adrien Béraud9360f242013-09-19 11:07:42 +1000454
Alexandre Lision6711ab22013-09-16 15:15:38 -0400455 }
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400456
457 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400458 public void setAudioPlugin(final String audioPlugin) {
459 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400460 @Override
461 protected void doRun() throws SameThreadException {
462 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
463 configurationManagerJNI.setAudioPlugin(audioPlugin);
464 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400465 });
466 }
467
468 @Override
469 public String getCurrentAudioOutputPlugin() {
470 class CurrentAudioPlugin extends SipRunnableWithReturn {
471 @Override
472 protected String doRun() throws SameThreadException {
473 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
474 return configurationManagerJNI.getCurrentAudioOutputPlugin();
475 }
alision371b77e2013-04-23 14:51:26 -0400476 }
477 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400478
479 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
480 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400481 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400482 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400483 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400484 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400485 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400486
487 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400488 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400489 class AccountList extends SipRunnableWithReturn {
490 @Override
491 protected StringVect doRun() throws SameThreadException {
492 Log.i(TAG, "SipService.getAccountList() thread running...");
493 return configurationManagerJNI.getAccountList();
494 }
alision371b77e2013-04-23 14:51:26 -0400495 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400496 AccountList runInstance = new AccountList();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400497 Log.i(TAG, "SipService.getAccountList() thread running...");
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400498 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400499 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400500 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400501 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400502 StringVect swigvect = (StringVect) runInstance.getVal();
503
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400504 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400505
alision371b77e2013-04-23 14:51:26 -0400506 for (int i = 0; i < swigvect.size(); i++)
507 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400508
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400509 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400510 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400511
512 @Override
alision371b77e2013-04-23 14:51:26 -0400513 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400514 class AccountDetails extends SipRunnableWithReturn {
515 private String id;
alision371b77e2013-04-23 14:51:26 -0400516
517 AccountDetails(String accountId) {
518 id = accountId;
519 }
520
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400521 @Override
522 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400523 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400524 return configurationManagerJNI.getAccountDetails(id);
525 }
alision371b77e2013-04-23 14:51:26 -0400526 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400527
528 AccountDetails runInstance = new AccountDetails(accountID);
529 getExecutor().execute(runInstance);
alisionfde875f2013-05-28 17:01:54 -0400530
alision371b77e2013-04-23 14:51:26 -0400531 while (!runInstance.isDone()) {
532 }
533 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400534
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400535 HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400536
537 return nativemap;
538 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400539
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400540 @SuppressWarnings("unchecked")
541 // Hashmap runtime cast
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400542 @Override
alisioncc7bb422013-06-06 15:31:39 -0400543 public void setAccountDetails(final String accountId, final Map map) {
alision371b77e2013-04-23 14:51:26 -0400544 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400545
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400546 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400547
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400548 getExecutor().execute(new SipRunnable() {
549 @Override
550 protected void doRun() throws SameThreadException {
alisioncc7bb422013-06-06 15:31:39 -0400551
552 configurationManagerJNI.setCredentials(accountId, extractCredentials(map));
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400553 configurationManagerJNI.setAccountDetails(accountId, swigmap);
alisioncc7bb422013-06-06 15:31:39 -0400554
Alexandre Lisionafd40e42013-10-15 13:48:37 -0400555 // convertSwigToNative(configurationManagerJNI.getCredentials(accountId));
alisioncc7bb422013-06-06 15:31:39 -0400556 Log.i(TAG, "SipService.setAccountDetails() thread running...");
557 }
558
559 private VectMap extractCredentials(Map map) {
560 VectMap swigmap = new VectMap();
561 StringMap entry = new StringMap();
alision5cfc35d2013-07-11 15:11:39 -0400562 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
563 if ((String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM) != null)
564 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM));
alisioncc7bb422013-06-06 15:31:39 -0400565 else
alision5cfc35d2013-07-11 15:11:39 -0400566 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, "*");
567 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
alisioncc7bb422013-06-06 15:31:39 -0400568 swigmap.add(entry);
569 return swigmap;
570
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400571 }
572 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400573 }
574
Alexandre Lisionafd40e42013-10-15 13:48:37 -0400575 // public ArrayList<HashMap<String, String>> convertSwigToNative(VectMap swigmap) {
576 //
577 // ArrayList<HashMap<String, String>> nativemap = new ArrayList<HashMap<String, String>>();
578 // Log.i(TAG, "swigmap size " + swigmap.size());
579 // for (int i = 0; i < swigmap.size(); ++i) {
580 // Log.i(TAG, "Entry " + i);
581 // StringMap tmp = swigmap.get(i);
582 // Log.i(TAG, tmp.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
583 // // Log.i(TAG, tmp.get(ServiceConstants.CONFIG_ACCOUNT_REALM));
584 // Log.i(TAG, tmp.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
585 // }
586 //
587 // return nativemap;
588 // }
alisioncc7bb422013-06-06 15:31:39 -0400589
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400590 @SuppressWarnings("unchecked")
591 // Hashmap runtime cast
Alexandre Savard46036572012-10-05 13:56:49 -0400592 @Override
593 public String addAccount(Map map) {
594 class AddAccount extends SipRunnableWithReturn {
595 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400596
597 AddAccount(StringMap m) {
598 map = m;
599 }
600
Alexandre Savard46036572012-10-05 13:56:49 -0400601 @Override
602 protected String doRun() throws SameThreadException {
603 Log.i(TAG, "SipService.getAccountDetails() thread running...");
604 return configurationManagerJNI.addAccount(map);
605 }
alision371b77e2013-04-23 14:51:26 -0400606 }
Alexandre Savard46036572012-10-05 13:56:49 -0400607
alision371b77e2013-04-23 14:51:26 -0400608 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400609
610 AddAccount runInstance = new AddAccount(swigmap);
611 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400612 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400613 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400614 }
Alexandre Savard46036572012-10-05 13:56:49 -0400615 String accountId = (String) runInstance.getVal();
616
617 return accountId;
618 }
619
620 @Override
621 public void removeAccount(final String accountId) {
622 getExecutor().execute(new SipRunnable() {
623 @Override
624 protected void doRun() throws SameThreadException {
625 Log.i(TAG, "SipService.setAccountDetails() thread running...");
626 configurationManagerJNI.removeAccount(accountId);
627 }
628 });
629 }
alision5f899632013-04-22 17:26:56 -0400630
alisione2a38e12013-04-25 14:20:20 -0400631 @Override
632 public ArrayList<HashMap<String, String>> getHistory() throws RemoteException {
633 class History extends SipRunnableWithReturn {
634
635 @Override
636 protected VectMap doRun() throws SameThreadException {
637 Log.i(TAG, "SipService.getHistory() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400638
alisione2a38e12013-04-25 14:20:20 -0400639 return configurationManagerJNI.getHistory();
640 }
641 }
642
643 History runInstance = new History();
644 getExecutor().execute(runInstance);
645 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400646 // Log.w(TAG, "Waiting for getHistory");
alisione2a38e12013-04-25 14:20:20 -0400647 }
alision1005ba12013-06-19 13:52:44 -0400648 Log.i(TAG, "SipService.getHistory() DONE");
alisione2a38e12013-04-25 14:20:20 -0400649 VectMap swigmap = (VectMap) runInstance.getVal();
650
651 ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap);
652
653 return nativemap;
654 }
alision7f18fc82013-05-01 09:37:33 -0400655
alision43a9b362013-05-01 16:30:15 -0400656 /*************************
657 * Transfer related API
658 *************************/
659
alision7f18fc82013-05-01 09:37:33 -0400660 @Override
661 public void transfer(final String callID, final String to) throws RemoteException {
662 getExecutor().execute(new SipRunnable() {
663 @Override
664 protected void doRun() throws SameThreadException, RemoteException {
665 Log.i(TAG, "SipService.transfer() thread running...");
666 if (callManagerJNI.transfer(callID, to)) {
667 Bundle bundle = new Bundle();
668 bundle.putString("CallID", callID);
669 bundle.putString("State", "HUNGUP");
670 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400671 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
alision84813a12013-05-27 17:40:39 -0400672 sendBroadcast(intent);
alision7f18fc82013-05-01 09:37:33 -0400673 } else
674 Log.i(TAG, "NOT OK");
675 }
676 });
677
678 }
alision43a9b362013-05-01 16:30:15 -0400679
alision7f18fc82013-05-01 09:37:33 -0400680 @Override
681 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
682 getExecutor().execute(new SipRunnable() {
683 @Override
684 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400685 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400686 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
687 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400688 } else
689 Log.i(TAG, "NOT OK");
690 }
691 });
alision43a9b362013-05-01 16:30:15 -0400692
693 }
694
695 /*************************
696 * Conference related API
697 *************************/
698
699 @Override
700 public void removeConference(final String confID) throws RemoteException {
701 getExecutor().execute(new SipRunnable() {
702 @Override
703 protected void doRun() throws SameThreadException, RemoteException {
704 Log.i(TAG, "SipService.createConference() thread running...");
705 callManagerJNI.removeConference(confID);
706 }
707 });
708
alision7f18fc82013-05-01 09:37:33 -0400709 }
710
711 @Override
alision43a9b362013-05-01 16:30:15 -0400712 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
713 getExecutor().execute(new SipRunnable() {
714 @Override
715 protected void doRun() throws SameThreadException, RemoteException {
716 Log.i(TAG, "SipService.joinParticipant() thread running...");
717 callManagerJNI.joinParticipant(sel_callID, drag_callID);
alision806e18e2013-06-21 15:30:17 -0400718 // Generate a CONF_CREATED callback
alision43a9b362013-05-01 16:30:15 -0400719 }
720 });
721
alision7f18fc82013-05-01 09:37:33 -0400722 }
723
alision7f18fc82013-05-01 09:37:33 -0400724 @Override
alision806e18e2013-06-21 15:30:17 -0400725 public void addParticipant(final SipCall call, final String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400726 getExecutor().execute(new SipRunnable() {
727 @Override
728 protected void doRun() throws SameThreadException, RemoteException {
729 Log.i(TAG, "SipService.addParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400730 callManagerJNI.addParticipant(call.getCallId(), confID);
731 current_confs.get(confID).getParticipants().add(call);
alision43a9b362013-05-01 16:30:15 -0400732 }
733 });
734
alision7f18fc82013-05-01 09:37:33 -0400735 }
736
737 @Override
alision43a9b362013-05-01 16:30:15 -0400738 public void addMainParticipant(final String confID) throws RemoteException {
739 getExecutor().execute(new SipRunnable() {
740 @Override
741 protected void doRun() throws SameThreadException, RemoteException {
742 Log.i(TAG, "SipService.addMainParticipant() thread running...");
743 callManagerJNI.addMainParticipant(confID);
744 }
745 });
746
alision7f18fc82013-05-01 09:37:33 -0400747 }
748
749 @Override
alision43a9b362013-05-01 16:30:15 -0400750 public void detachParticipant(final String callID) throws RemoteException {
751 getExecutor().execute(new SipRunnable() {
752 @Override
753 protected void doRun() throws SameThreadException, RemoteException {
754 Log.i(TAG, "SipService.detachParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400755 Log.i(TAG, "Detaching " + callID);
756 Iterator<Entry<String, Conference>> it = current_confs.entrySet().iterator();
757 Log.i(TAG, "current_confs size " + current_confs.size());
758 while (it.hasNext()) {
759 Conference tmp = it.next().getValue();
760 Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants");
761 if (tmp.contains(callID)) {
762 current_calls.put(callID, tmp.getCall(callID));
763 Log.i(TAG, "Call found and put in current_calls");
764 }
765 }
alision43a9b362013-05-01 16:30:15 -0400766 callManagerJNI.detachParticipant(callID);
767 }
768 });
769
alision7f18fc82013-05-01 09:37:33 -0400770 }
771
772 @Override
alision43a9b362013-05-01 16:30:15 -0400773 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
774 getExecutor().execute(new SipRunnable() {
775 @Override
776 protected void doRun() throws SameThreadException, RemoteException {
777 Log.i(TAG, "SipService.joinConference() thread running...");
778 callManagerJNI.joinConference(sel_confID, drag_confID);
779 }
780 });
781
alision7f18fc82013-05-01 09:37:33 -0400782 }
783
784 @Override
alision43a9b362013-05-01 16:30:15 -0400785 public void hangUpConference(final String confID) throws RemoteException {
786 getExecutor().execute(new SipRunnable() {
787 @Override
788 protected void doRun() throws SameThreadException, RemoteException {
789 Log.i(TAG, "SipService.joinConference() thread running...");
790 callManagerJNI.hangUpConference(confID);
791 }
792 });
793
alision7f18fc82013-05-01 09:37:33 -0400794 }
795
796 @Override
alision43a9b362013-05-01 16:30:15 -0400797 public void holdConference(final String confID) throws RemoteException {
798 getExecutor().execute(new SipRunnable() {
799 @Override
800 protected void doRun() throws SameThreadException, RemoteException {
801 Log.i(TAG, "SipService.holdConference() thread running...");
802 callManagerJNI.holdConference(confID);
803 }
804 });
805
alision7f18fc82013-05-01 09:37:33 -0400806 }
807
808 @Override
alision43a9b362013-05-01 16:30:15 -0400809 public void unholdConference(final String confID) throws RemoteException {
810 getExecutor().execute(new SipRunnable() {
811 @Override
812 protected void doRun() throws SameThreadException, RemoteException {
813 Log.i(TAG, "SipService.unholdConference() thread running...");
814 callManagerJNI.unholdConference(confID);
815 }
816 });
817
alision7f18fc82013-05-01 09:37:33 -0400818 }
Alexandre Lision67817192013-07-18 12:04:30 -0400819
alisioncd8fb912013-06-28 14:43:51 -0400820 @Override
821 public boolean isConferenceParticipant(final String callID) throws RemoteException {
822 class IsParticipant extends SipRunnableWithReturn {
823
824 @Override
825 protected Boolean doRun() throws SameThreadException {
826 Log.i(TAG, "SipService.isRecording() thread running...");
827 return callManagerJNI.isConferenceParticipant(callID);
828 }
829 }
830
831 IsParticipant runInstance = new IsParticipant();
832 getExecutor().execute(runInstance);
833 while (!runInstance.isDone()) {
834 }
835
836 return (Boolean) runInstance.getVal();
837 }
alision7f18fc82013-05-01 09:37:33 -0400838
839 @Override
alisiondf1dac92013-06-27 17:35:53 -0400840 public HashMap<String, Conference> getConferenceList() throws RemoteException {
Alexandre Lision67817192013-07-18 12:04:30 -0400841 // class ConfList extends SipRunnableWithReturn {
842 // @Override
843 // protected StringVect doRun() throws SameThreadException {
844 // Log.i(TAG, "SipService.getConferenceList() thread running...");
845 // return callManagerJNI.getConferenceList();
846 // }
847 // }
848 // ;
849 // ConfList runInstance = new ConfList();
850 // getExecutor().execute(runInstance);
851 // while (!runInstance.isDone()) {
852 // // Log.w(TAG, "Waiting for getConferenceList");
853 // }
854 // StringVect swigvect = (StringVect) runInstance.getVal();
855 //
856 // ArrayList<String> nativelist = new ArrayList<String>();
857 //
858 // for (int i = 0; i < swigvect.size(); i++)
859 // nativelist.add(swigvect.get(i));
860 //
861 // return nativelist;
alisiondf1dac92013-06-27 17:35:53 -0400862 return current_confs;
alision7f18fc82013-05-01 09:37:33 -0400863 }
864
865 @Override
alision907bde72013-06-20 14:40:37 -0400866 public List getParticipantList(final String confID) throws RemoteException {
867 class PartList extends SipRunnableWithReturn {
868 @Override
869 protected StringVect doRun() throws SameThreadException {
870 Log.i(TAG, "SipService.getAccountList() thread running...");
871 return callManagerJNI.getParticipantList(confID);
872 }
873 }
874 ;
875 PartList runInstance = new PartList();
876 getExecutor().execute(runInstance);
877 while (!runInstance.isDone()) {
878 // Log.w(TAG, "Waiting for getConferenceList");
879 }
880 StringVect swigvect = (StringVect) runInstance.getVal();
881
882 ArrayList<String> nativelist = new ArrayList<String>();
883
884 for (int i = 0; i < swigvect.size(); i++)
885 nativelist.add(swigvect.get(i));
886
887 return nativelist;
alision7f18fc82013-05-01 09:37:33 -0400888 }
alision806e18e2013-06-21 15:30:17 -0400889
alision1005ba12013-06-19 13:52:44 -0400890 @Override
alision7f18fc82013-05-01 09:37:33 -0400891 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400892 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400893 return null;
894 }
895
896 @Override
alision806e18e2013-06-21 15:30:17 -0400897 public String getConferenceDetails(final String callID) throws RemoteException {
898 class ConfDetails extends SipRunnableWithReturn {
899 @Override
900 protected StringMap doRun() throws SameThreadException {
901 Log.i(TAG, "SipService.getAccountList() thread running...");
902 return callManagerJNI.getConferenceDetails(callID);
903 }
904 }
905 ;
906 ConfDetails runInstance = new ConfDetails();
907 getExecutor().execute(runInstance);
908 while (!runInstance.isDone()) {
909 // Log.w(TAG, "Waiting for getConferenceList");
910 }
911 StringMap swigvect = (StringMap) runInstance.getVal();
912
913 return swigvect.get("CONF_STATE");
alision7f18fc82013-05-01 09:37:33 -0400914 }
915
alision04a00182013-05-10 17:05:29 -0400916 @Override
917 public String getRecordPath() throws RemoteException {
918 class RecordPath extends SipRunnableWithReturn {
919
920 @Override
921 protected String doRun() throws SameThreadException {
922 Log.i(TAG, "SipService.getRecordPath() thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000923 return configurationManagerJNI.getRecordPath();
alision04a00182013-05-10 17:05:29 -0400924 }
925 }
926
927 RecordPath runInstance = new RecordPath();
928 getExecutor().execute(runInstance);
929 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400930 // Log.w(TAG, "Waiting for getRecordPath");
alision04a00182013-05-10 17:05:29 -0400931 }
932 String path = (String) runInstance.getVal();
933
934 return path;
935 }
936
937 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400938 public boolean toggleRecordingCall(final String id) throws RemoteException {
Adrien Béraud9360f242013-09-19 11:07:42 +1000939
Alexandre Lisiona764c682013-09-09 10:02:07 -0400940 class ToggleRecording extends SipRunnableWithReturn {
941
alision04a00182013-05-10 17:05:29 -0400942 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400943 protected Boolean doRun() throws SameThreadException {
944 Log.i(TAG, "SipService.toggleRecordingCall() thread running...");
945 return callManagerJNI.toggleRecording(id);
alision04a00182013-05-10 17:05:29 -0400946 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400947 }
948
949 ToggleRecording runInstance = new ToggleRecording();
950 getExecutor().execute(runInstance);
951 while (!runInstance.isDone()) {
952 }
953
954 return (Boolean) runInstance.getVal();
alision04a00182013-05-10 17:05:29 -0400955
956 }
Alexandre Lision67817192013-07-18 12:04:30 -0400957
alision50fa0722013-06-25 17:29:44 -0400958 @Override
alisiondf1dac92013-06-27 17:35:53 -0400959 public boolean isRecording(final String id) throws RemoteException {
960 class IsRecording extends SipRunnableWithReturn {
961
962 @Override
963 protected Boolean doRun() throws SameThreadException {
964 Log.i(TAG, "SipService.isRecording() thread running...");
965 return callManagerJNI.getIsRecording(id);
966 }
967 }
968
969 IsRecording runInstance = new IsRecording();
970 getExecutor().execute(runInstance);
971 while (!runInstance.isDone()) {
972 }
973
974 return (Boolean) runInstance.getVal();
Alexandre Lision67817192013-07-18 12:04:30 -0400975
alisiondf1dac92013-06-27 17:35:53 -0400976 }
Alexandre Lision67817192013-07-18 12:04:30 -0400977
alisiondf1dac92013-06-27 17:35:53 -0400978 @Override
alision50fa0722013-06-25 17:29:44 -0400979 public boolean startRecordedFilePlayback(final String filepath) throws RemoteException {
980 getExecutor().execute(new SipRunnable() {
981 @Override
982 protected void doRun() throws SameThreadException, RemoteException {
983 Log.i(TAG, "SipService.setRecordingCall() thread running...");
984 callManagerJNI.startRecordedFilePlayback(filepath);
985 }
986 });
987 return false;
988 }
989
990 @Override
991 public void stopRecordedFilePlayback(final String filepath) throws RemoteException {
992 getExecutor().execute(new SipRunnable() {
993 @Override
994 protected void doRun() throws SameThreadException, RemoteException {
995 Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running...");
996 callManagerJNI.stopRecordedFilePlayback(filepath);
997 }
998 });
999 }
alision04a00182013-05-10 17:05:29 -04001000
1001 @Override
1002 public void setRecordPath(final String path) throws RemoteException {
1003 getExecutor().execute(new SipRunnable() {
1004 @Override
1005 protected void doRun() throws SameThreadException, RemoteException {
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001006 Log.i(TAG, "SipService.setRecordPath() " + path + " thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +10001007 configurationManagerJNI.setRecordPath(path);
alision04a00182013-05-10 17:05:29 -04001008 }
1009 });
1010 }
1011
1012 @Override
1013 public void sendTextMessage(final String callID, final String message, final String from) throws RemoteException {
1014 getExecutor().execute(new SipRunnable() {
1015 @Override
1016 protected void doRun() throws SameThreadException, RemoteException {
1017 Log.i(TAG, "SipService.sendTextMessage() thread running...");
Alexandre Lision10314352013-07-17 15:06:56 -04001018 callManagerJNI.sendTextMessage(callID, message);
alision04a00182013-05-10 17:05:29 -04001019 }
1020 });
1021
1022 }
1023
alisiond295ec22013-05-17 10:12:13 -04001024 @Override
1025 public List getAudioCodecList(String accountID) throws RemoteException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001026 class AudioCodecList extends SipRunnableWithReturn {
1027
1028 @Override
1029 protected IntVect doRun() throws SameThreadException {
1030 Log.i(TAG, "SipService.getAudioCodecList() thread running...");
1031 return configurationManagerJNI.getAudioCodecList();
1032 }
1033 }
1034
1035 AudioCodecList runInstance = new AudioCodecList();
1036 getExecutor().execute(runInstance);
1037 while (!runInstance.isDone()) {
1038 Log.w(TAG, "Waiting for getAudioCodecList");
1039 }
1040 IntVect swigmap = (IntVect) runInstance.getVal();
1041
1042 ArrayList<Integer> codecs = AudioHandler.convertSwigToNative(swigmap);
1043
1044 return codecs;
alisiond295ec22013-05-17 10:12:13 -04001045 }
1046
alision9f7a6ec2013-05-24 16:26:26 -04001047 @Override
alisionfde875f2013-05-28 17:01:54 -04001048 public HashMap<String, SipCall> getCallList() throws RemoteException {
alision85704182013-05-29 15:23:03 -04001049 // class CallList extends SipRunnableWithReturn {
1050 //
1051 // @Override
1052 // protected StringVect doRun() throws SameThreadException {
1053 // Log.i(TAG, "SipService.getCallList() thread running...");
1054 // return callManagerJNI.getCallList();
1055 // }
1056 // }
1057 //
1058 // CallList runInstance = new CallList();
1059 // getExecutor().execute(runInstance);
1060 // while (!runInstance.isDone()) {
1061 // Log.w(TAG, "Waiting for getAudioCodecList");
1062 // }
1063 // StringVect swigmap = (StringVect) runInstance.getVal();
1064 //
1065 // ArrayList<String> nativemap = new ArrayList<String>();
1066 // for (int i = 0; i < swigmap.size(); ++i) {
1067 //
1068 // String t = swigmap.get(i);
1069 // nativemap.add(t);
1070 // }
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001071 // if(callManagerJNI == null)
1072 // return new HashMap<String, SipCall>();
1073 //
1074 //
1075 // HashMap<String, SipCall> results = new HashMap<String, SipCall>();
1076 // StringVect calls = callManagerJNI.getCallList();
1077 // for(int i = 0 ; i < calls.size(); ++i){
1078 // results.put(calls.get(i), new SipCall(calls.get(i), callManagerJNI.getCallDetails(calls.get(i))));
1079 // }
alision9f7a6ec2013-05-24 16:26:26 -04001080
alision2cb99562013-05-30 17:02:20 -04001081 return getCurrent_calls();
alision9f7a6ec2013-05-24 16:26:26 -04001082 }
1083
alision85704182013-05-29 15:23:03 -04001084 @Override
1085 public SipCall getCall(String callID) throws RemoteException {
alision2cb99562013-05-30 17:02:20 -04001086 return getCurrent_calls().get(callID);
1087 }
1088
1089 /***********************
1090 * Notification API
1091 ***********************/
1092 @Override
1093 public void createNotification() throws RemoteException {
1094 makeNotification();
alisioncc7bb422013-06-06 15:31:39 -04001095
alision2cb99562013-05-30 17:02:20 -04001096 }
1097
1098 @Override
1099 public void destroyNotification() throws RemoteException {
1100 removeNotification();
alisioncc7bb422013-06-06 15:31:39 -04001101
alision2cb99562013-05-30 17:02:20 -04001102 }
alisioncc7bb422013-06-06 15:31:39 -04001103
Adrien Béraud9360f242013-09-19 11:07:42 +10001104 private final int NOTIFICATION_ID = new Random().nextInt(1000);
alisioncc7bb422013-06-06 15:31:39 -04001105
alision2cb99562013-05-30 17:02:20 -04001106 private void makeNotification() {
alisioncc7bb422013-06-06 15:31:39 -04001107 if (current_calls.size() == 0) {
alision2cb99562013-05-30 17:02:20 -04001108 return;
1109 }
1110 Intent notificationIntent = new Intent(getApplicationContext(), SFLPhoneHomeActivity.class);
alisioncc7bb422013-06-06 15:31:39 -04001111 PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 007, notificationIntent,
1112 PendingIntent.FLAG_UPDATE_CURRENT);
alision2cb99562013-05-30 17:02:20 -04001113
1114 NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
Adrien Béraud9360f242013-09-19 11:07:42 +10001115 nm.cancel(NOTIFICATION_ID); // clear previous notifications.
alision2cb99562013-05-30 17:02:20 -04001116
1117 NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext());
alisioncc7bb422013-06-06 15:31:39 -04001118 //
1119 // builder.setContent(view);
1120 builder.setContentIntent(contentIntent).setOngoing(true).setSmallIcon(R.drawable.ic_launcher)
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001121 .setContentTitle(getCurrent_calls().size() + " ongoing calls").setTicker("Pending calls").setWhen(System.currentTimeMillis())
1122 .setAutoCancel(false);
alision2cb99562013-05-30 17:02:20 -04001123 builder.setPriority(NotificationCompat.PRIORITY_MAX);
1124 Notification n = builder.build();
1125
1126 nm.notify(NOTIFICATION_ID, n);
alision2cb99562013-05-30 17:02:20 -04001127 }
1128
1129 public void removeNotification() {
1130 NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
1131 nm.cancel(NOTIFICATION_ID);
alision85704182013-05-29 15:23:03 -04001132 }
1133
alisiondf1dac92013-06-27 17:35:53 -04001134 @Override
1135 public Conference getCurrentCall() throws RemoteException {
Alexandre Lision67817192013-07-18 12:04:30 -04001136 for (SipCall i : current_calls.values()) {
Adrien Béraud9360f242013-09-19 11:07:42 +10001137
Alexandre Lisionc51ccb12013-09-11 16:00:30 -04001138 // Incoming >> Ongoing
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001139 if (i.isIncoming()) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -04001140 Conference tmp = new Conference("-1");
1141 tmp.getParticipants().add(i);
1142 return tmp;
1143 }
Adrien Béraud9360f242013-09-19 11:07:42 +10001144
Alexandre Lision67817192013-07-18 12:04:30 -04001145 if (i.isOngoing()) {
alisiondf1dac92013-06-27 17:35:53 -04001146 Conference tmp = new Conference("-1");
1147 tmp.getParticipants().add(i);
1148 return tmp;
1149 }
1150 }
Alexandre Lision67817192013-07-18 12:04:30 -04001151
1152 if (!current_confs.isEmpty()) {
alisiondf1dac92013-06-27 17:35:53 -04001153 return (Conference) current_confs.values().toArray()[0];
1154 }
1155 return null;
1156 }
1157
Alexandre Lision64dc8c02013-09-25 15:32:25 -04001158 @Override
1159 public void playDtmf(final String key) throws RemoteException {
1160 getExecutor().execute(new SipRunnable() {
1161 @Override
1162 protected void doRun() throws SameThreadException, RemoteException {
1163 Log.i(TAG, "SipService.playDtmf() thread running...");
1164 callManagerJNI.playDTMF(key);
1165 }
1166 });
1167 }
1168
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001169 @Override
1170 public List getConcurrentCalls() throws RemoteException {
1171 ArrayList<Conference> toReturn = new ArrayList<Conference>();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001172
1173 for (SipCall sip : current_calls.values()) {
1174 if (!sip.isCurrent()) {
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001175 Conference tmp = new Conference("-1");
1176 tmp.getParticipants().add(sip);
1177 toReturn.add(tmp);
1178 }
1179 }
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001180
1181 Log.i(TAG, "toReturn SIZE " + toReturn.size());
1182
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001183 return toReturn;
1184 }
1185
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001186 @Override
1187 public Map getRingtoneList() throws RemoteException {
1188 // TODO Stub de la méthode généré automatiquement
1189 return null;
1190 }
1191
Emeric Vigier6119d782012-09-21 18:04:14 -04001192 };
Emeric Vigiereaf2c492012-09-19 14:38:20 -04001193}