blob: 258564bc073c0617d57afb5bd5be29c514d4b43a [file] [log] [blame]
Emeric Vigier6119d782012-09-21 18:04:14 -04001/**
2 * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr)
Alexandre Lisionc1024c02014-01-06 11:12:53 -05003 * Copyright (C) 2004-2014 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
alision17052d42013-04-22 10:39:38 -040027import java.util.ArrayList;
28import java.util.HashMap;
alisioncc7bb422013-06-06 15:31:39 -040029import java.util.Iterator;
alision7f18fc82013-05-01 09:37:33 -040030import java.util.List;
alision17052d42013-04-22 10:39:38 -040031import java.util.Map;
alision806e18e2013-06-21 15:30:17 -040032import java.util.Map.Entry;
Emeric Vigier6119d782012-09-21 18:04:14 -040033
Alexandre Lision945e4612014-01-15 17:40:31 -050034import org.sflphone.history.HistoryManager;
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050035import org.sflphone.model.*;
Alexandre Lision6d867b92013-10-25 15:36:28 -040036import org.sflphone.utils.MediaManager;
Alexandre Lisione0045442013-10-25 09:16:19 -040037import org.sflphone.utils.SipNotifications;
Alexandre Lision2aae48d2013-12-04 13:50:38 -050038import org.sflphone.utils.SwigNativeConverter;
Alexandre Lision064e1e02013-10-01 16:18:42 -040039
Emeric Vigiereaf2c492012-09-19 14:38:20 -040040import android.app.Service;
41import android.content.Intent;
alision7f18fc82013-05-01 09:37:33 -040042import android.os.Bundle;
Emeric Vigier6119d782012-09-21 18:04:14 -040043import android.os.Handler;
44import android.os.HandlerThread;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040045import android.os.IBinder;
Emeric Vigier6119d782012-09-21 18:04:14 -040046import android.os.Looper;
47import android.os.Message;
alision5f899632013-04-22 17:26:56 -040048import android.os.RemoteException;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040049import android.util.Log;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040050
Emeric Vigiereaf2c492012-09-19 14:38:20 -040051public class SipService extends Service {
52
53 static final String TAG = "SipService";
Emeric Vigier6119d782012-09-21 18:04:14 -040054 private SipServiceExecutor mExecutor;
55 private static HandlerThread executorThread;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050056
alision3ea8f3c2013-07-16 17:35:35 -040057 private CallManager callManagerJNI;
Alexandre Lision67817192013-07-18 12:04:30 -040058 private ManagerImpl managerImpl;
Emeric Vigier0007dee2012-09-24 11:35:58 -040059 private CallManagerCallBack callManagerCallBack;
Alexandre Lisionb2669692014-01-28 14:06:08 -050060
alision3ea8f3c2013-07-16 17:35:35 -040061 private ConfigurationManager configurationManagerJNI;
Alexandre Savardfccd1dc2012-10-17 17:31:38 -040062 private ConfigurationManagerCallback configurationManagerCallback;
Emeric Vigier6119d782012-09-21 18:04:14 -040063 private boolean isPjSipStackStarted = false;
alisioncc7bb422013-06-06 15:31:39 -040064
Alexandre Lision945e4612014-01-15 17:40:31 -050065 protected SipNotifications mNotificationManager;
66 protected HistoryManager mHistoryManager;
67 protected MediaManager mMediaManager;
Alexandre Lisione0045442013-10-25 09:16:19 -040068
Alexandre Lision945e4612014-01-15 17:40:31 -050069 private HashMap<String, Conference> mConferences = new HashMap<String, Conference>();
Emeric Vigier6119d782012-09-21 18:04:14 -040070
Alexandre Lision945e4612014-01-15 17:40:31 -050071 public HashMap<String, Conference> getConferences() {
72 return mConferences;
alision806e18e2013-06-21 15:30:17 -040073 }
alision43a9b362013-05-01 16:30:15 -040074
Alexandre Lisionb2669692014-01-28 14:06:08 -050075 public CallManager getCallManagerJNI() {
76 return callManagerJNI;
77 }
78
79 public ConfigurationManager getConfigurationManagerJNI() {
80 return configurationManagerJNI;
81 }
82
Alexandre Lision183bf452014-01-17 11:21:59 -050083 public void addCallToConference(String confId, String callId) {
84 if(mConferences.get(callId) != null){
85 // We add a simple call to a conference
Alexandre Lision96db8032014-01-17 16:43:51 -050086 Log.i(TAG, "// We add a simple call to a conference");
Alexandre Lision183bf452014-01-17 11:21:59 -050087 mConferences.get(confId).addParticipant(mConferences.get(callId).getParticipants().get(0));
88 mConferences.remove(callId);
89 } else {
Alexandre Lision96db8032014-01-17 16:43:51 -050090 Log.i(TAG, "addCallToConference");
Alexandre Lision183bf452014-01-17 11:21:59 -050091 Iterator<Map.Entry<String, Conference>> it = mConferences.entrySet().iterator();
92 while (it.hasNext()) {
93 Conference tmp = it.next().getValue();
94 for (SipCall c : tmp.getParticipants()) {
95 if (c.getCallId().contentEquals(callId)) {
96 mConferences.get(confId).addParticipant(c);
Alexandre Lision96db8032014-01-17 16:43:51 -050097 mConferences.get(tmp.getId()).removeParticipant(c);
Alexandre Lision183bf452014-01-17 11:21:59 -050098 }
99 }
100 }
101 }
102
103 }
104
Alexandre Lision96db8032014-01-17 16:43:51 -0500105 public void detachCallFromConference(String confId, SipCall call) {
106 Log.i(TAG, "detachCallFromConference");
Alexandre Lision183bf452014-01-17 11:21:59 -0500107 Conference separate = new Conference(call);
108 mConferences.put(separate.getId(), separate);
Alexandre Lision96db8032014-01-17 16:43:51 -0500109 mConferences.get(confId).removeParticipant(call);
Alexandre Lision183bf452014-01-17 11:21:59 -0500110 }
111
112
alision43a9b362013-05-01 16:30:15 -0400113 @Override
114 public boolean onUnbind(Intent i) {
115 super.onUnbind(i);
116 Log.i(TAG, "onUnbind(intent)");
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400117 return true;
118 }
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400119
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400120 @Override
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400121 public void onRebind(Intent i) {
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400122 super.onRebind(i);
alision43a9b362013-05-01 16:30:15 -0400123 }
124
125 /* called once by startService() */
126 @Override
127 public void onCreate() {
128 Log.i(TAG, "onCreated");
129 super.onCreate();
130
alisioncc7bb422013-06-06 15:31:39 -0400131 getExecutor().execute(new StartRunnable());
Alexandre Lisione0045442013-10-25 09:16:19 -0400132
Alexandre Lision945e4612014-01-15 17:40:31 -0500133 mNotificationManager = new SipNotifications(this);
134 mMediaManager = new MediaManager(this);
135 mHistoryManager = new HistoryManager(this);
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400136
Alexandre Lision945e4612014-01-15 17:40:31 -0500137 mNotificationManager.onServiceCreate();
138 mMediaManager.startService();
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400139
alisioncc7bb422013-06-06 15:31:39 -0400140 }
alision43a9b362013-05-01 16:30:15 -0400141
142 /* called for each startService() */
143 @Override
144 public int onStartCommand(Intent intent, int flags, int startId) {
145 Log.i(TAG, "onStarted");
146 super.onStartCommand(intent, flags, startId);
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400147 return START_STICKY; /* started and stopped explicitly */
alision43a9b362013-05-01 16:30:15 -0400148 }
149
150 @Override
151 public void onDestroy() {
Alexandre Lision52214992013-10-28 17:41:23 -0400152 Log.i(TAG, "onDestroy");
alision43a9b362013-05-01 16:30:15 -0400153 /* called once by stopService() */
Alexandre Lision945e4612014-01-15 17:40:31 -0500154 mNotificationManager.onServiceDestroy();
Alexandre Lision183bf452014-01-17 11:21:59 -0500155 mMediaManager.stopService();
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400156 getExecutor().execute(new FinalizeRunnable());
alision43a9b362013-05-01 16:30:15 -0400157 super.onDestroy();
158
alision43a9b362013-05-01 16:30:15 -0400159 }
160
161 @Override
162 public IBinder onBind(Intent arg0) {
163 Log.i(TAG, "onBound");
164 return mBinder;
165 }
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400166
alision43a9b362013-05-01 16:30:15 -0400167 private static Looper createLooper() {
168 if (executorThread == null) {
169 Log.d(TAG, "Creating new handler thread");
170 // ADT gives a fake warning due to bad parse rule.
171 executorThread = new HandlerThread("SipService.Executor");
172 executorThread.start();
173 }
174 return executorThread.getLooper();
175 }
176
177 public SipServiceExecutor getExecutor() {
178 // create mExecutor lazily
179 if (mExecutor == null) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500180 mExecutor = new SipServiceExecutor();
alision43a9b362013-05-01 16:30:15 -0400181 }
182 return mExecutor;
183 }
184
Alexandre Lision5f144b82014-02-11 09:59:36 -0500185 public SipCall getCallById(String callID) {
186 if (getConferences().get(callID) != null) {
187 return getConferences().get(callID).getCallById(callID);
188 } else {
189 // Check if call is in a conference
190 Iterator<Map.Entry<String, Conference>> it = getConferences().entrySet().iterator();
191 while (it.hasNext()) {
192 Conference tmp = it.next().getValue();
193 SipCall c = tmp.getCallById(callID);
194 if(c != null)
195 return c;
196 }
197 }
198 return null;
199 }
200
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500201 /*
202 *
203 * Used when we need to transform a SipCall in a SecureSipCall or vice versa
204 *
205 * */
206 public void replaceCall(SipCall replace) {
207 if (getConferences().get(replace.getCallId()) != null) {
208 getConferences().get(replace.getCallId()).removeParticipant(replace);
209 getConferences().get(replace.getCallId()).addParticipant(replace);
210 } else {
211 // Check if call is in a conference
212 Iterator<Map.Entry<String, Conference>> it = getConferences().entrySet().iterator();
213 while (it.hasNext()) {
214 Conference tmp = it.next().getValue();
215 SipCall c = tmp.getCallById(replace.getCallId());
216 if(c != null){
217 tmp.removeParticipant(c);
218 tmp.addParticipant(replace);
219 return;
220 }
221 }
222 }
223 }
224
alision43a9b362013-05-01 16:30:15 -0400225 // Executes immediate tasks in a single executorThread.
226 public static class SipServiceExecutor extends Handler {
alision43a9b362013-05-01 16:30:15 -0400227
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500228 SipServiceExecutor() {
alision43a9b362013-05-01 16:30:15 -0400229 super(createLooper());
alision43a9b362013-05-01 16:30:15 -0400230 }
231
232 public void execute(Runnable task) {
233 // TODO: add wakelock
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500234 Message.obtain(SipServiceExecutor.this, 0/* don't care */, task).sendToTarget();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400235 Log.w(TAG, "SenT!");
alision43a9b362013-05-01 16:30:15 -0400236 }
237
238 @Override
239 public void handleMessage(Message msg) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500240 Log.w(TAG, "handleMessage");
alision43a9b362013-05-01 16:30:15 -0400241 if (msg.obj instanceof Runnable) {
242 executeInternal((Runnable) msg.obj);
243 } else {
244 Log.w(TAG, "can't handle msg: " + msg);
245 }
246 }
247
248 private void executeInternal(Runnable task) {
249 try {
250 task.run();
251 } catch (Throwable t) {
252 Log.e(TAG, "run task: " + task, t);
253 }
254 }
255 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400256
257 private void stopDaemon() {
258 if (managerImpl != null) {
259 managerImpl.finish();
260 isPjSipStackStarted = false;
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400261 }
262 }
alision43a9b362013-05-01 16:30:15 -0400263
264 private void startPjSipStack() throws SameThreadException {
265 if (isPjSipStackStarted)
266 return;
267
268 try {
269 System.loadLibrary("gnustl_shared");
alision43a9b362013-05-01 16:30:15 -0400270 System.loadLibrary("crypto");
271 System.loadLibrary("ssl");
alision43a9b362013-05-01 16:30:15 -0400272 System.loadLibrary("sflphone");
273 isPjSipStackStarted = true;
Adrien Béraud9360f242013-09-19 11:07:42 +1000274
alision43a9b362013-05-01 16:30:15 -0400275 } catch (UnsatisfiedLinkError e) {
276 Log.e(TAG, "Problem with the current Pj stack...", e);
277 isPjSipStackStarted = false;
278 return;
279 } catch (Exception e) {
280 Log.e(TAG, "Problem with the current Pj stack...", e);
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400281 isPjSipStackStarted = false;
alision43a9b362013-05-01 16:30:15 -0400282 }
283
Alexandre Lision67817192013-07-18 12:04:30 -0400284 Log.i(TAG, "PjSIPStack started");
285 managerImpl = SFLPhoneservice.instance();
286
287 /* set static AppPath before calling manager.init */
Alexandre Lision63870a72013-10-28 16:33:47 -0400288 // managerImpl.setPath(getApplication().getFilesDir().getAbsolutePath());
alision43a9b362013-05-01 16:30:15 -0400289
alision3ea8f3c2013-07-16 17:35:35 -0400290 callManagerJNI = new CallManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500291 callManagerCallBack = new CallManagerCallBack(this);
alision43a9b362013-05-01 16:30:15 -0400292 SFLPhoneservice.setCallbackObject(callManagerCallBack);
293
alision3ea8f3c2013-07-16 17:35:35 -0400294 configurationManagerJNI = new ConfigurationManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500295 configurationManagerCallback = new ConfigurationManagerCallback(this);
alision43a9b362013-05-01 16:30:15 -0400296 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
Alexandre Lision67817192013-07-18 12:04:30 -0400297 managerImpl.init("");
Adrien Béraud9360f242013-09-19 11:07:42 +1000298
Alexandre Lision67817192013-07-18 12:04:30 -0400299 Log.i(TAG, "->startPjSipStack");
alision43a9b362013-05-01 16:30:15 -0400300 }
301
302 // Enforce same thread contract to ensure we do not call from somewhere else
303 public class SameThreadException extends Exception {
304 private static final long serialVersionUID = -905639124232613768L;
305
306 public SameThreadException() {
307 super("Should be launched from a single worker thread");
308 }
309 }
310
311 public abstract static class SipRunnable implements Runnable {
312 protected abstract void doRun() throws SameThreadException, RemoteException;
313
Adrien Béraud9360f242013-09-19 11:07:42 +1000314 @Override
alision43a9b362013-05-01 16:30:15 -0400315 public void run() {
316 try {
317 doRun();
318 } catch (SameThreadException e) {
319 Log.e(TAG, "Not done from same thread");
320 } catch (RemoteException e) {
321 Log.e(TAG, e.toString());
322 }
323 }
324 }
325
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400326 public abstract class SipRunnableWithReturn implements Runnable {
alision43a9b362013-05-01 16:30:15 -0400327 Object obj = null;
328 boolean done = false;
329
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500330 protected abstract Object doRun() throws SameThreadException, RemoteException;
alision43a9b362013-05-01 16:30:15 -0400331
332 public Object getVal() {
333 return obj;
334 }
335
336 public boolean isDone() {
337 return done;
338 }
339
Adrien Béraud9360f242013-09-19 11:07:42 +1000340 @Override
alision43a9b362013-05-01 16:30:15 -0400341 public void run() {
342 try {
Alexandre Lision35577132013-12-06 15:21:15 -0500343 if (isPjSipStackStarted)
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400344 obj = doRun();
alision43a9b362013-05-01 16:30:15 -0400345 done = true;
346 } catch (SameThreadException e) {
347 Log.e(TAG, "Not done from same thread");
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500348 } catch (RemoteException e) {
349 Log.e(TAG, e.toString());
alision43a9b362013-05-01 16:30:15 -0400350 }
351 }
352 }
353
354 class StartRunnable extends SipRunnable {
355 @Override
356 protected void doRun() throws SameThreadException {
357 startPjSipStack();
358 }
359 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400360
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400361 class FinalizeRunnable extends SipRunnable {
362 @Override
363 protected void doRun() throws SameThreadException {
364 stopDaemon();
365 }
366 }
alision43a9b362013-05-01 16:30:15 -0400367
alision43a9b362013-05-01 16:30:15 -0400368 /* ************************************
369 *
370 * Implement public interface for the service
371 *
Alexandre Lision67817192013-07-18 12:04:30 -0400372 * *********************************
373 */
374
Emeric Vigier6119d782012-09-21 18:04:14 -0400375 private final ISipService.Stub mBinder = new ISipService.Stub() {
376
377 @Override
alisionfde875f2013-05-28 17:01:54 -0400378 public void placeCall(final SipCall call) {
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500379
Emeric Vigier6119d782012-09-21 18:04:14 -0400380 getExecutor().execute(new SipRunnable() {
381 @Override
382 protected void doRun() throws SameThreadException {
383 Log.i(TAG, "SipService.placeCall() thread running...");
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500384 Conference toAdd = new Conference(call);
Alexandre Lision945e4612014-01-15 17:40:31 -0500385 mConferences.put(toAdd.getId(), toAdd);
386 mMediaManager.obtainAudioFocus(false);
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -0500387 callManagerJNI.placeCall(call.getAccount().getAccountID(), call.getCallId(), call.getmContact().getPhones().get(0).getNumber());
Emeric Vigier6119d782012-09-21 18:04:14 -0400388 }
389 });
390 }
391
392 @Override
393 public void refuse(final String callID) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500394
Emeric Vigier6119d782012-09-21 18:04:14 -0400395 getExecutor().execute(new SipRunnable() {
396 @Override
397 protected void doRun() throws SameThreadException {
398 Log.i(TAG, "SipService.refuse() thread running...");
399 callManagerJNI.refuse(callID);
400 }
401 });
402 }
403
404 @Override
405 public void accept(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500406 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400407 getExecutor().execute(new SipRunnable() {
408 @Override
409 protected void doRun() throws SameThreadException {
Tristan Matthews40cf25e2013-07-24 13:45:15 -0400410 Log.i(TAG, "SipService.accept() thread running...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400411 callManagerJNI.accept(callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500412 mMediaManager.RouteToInternalSpeaker();
Emeric Vigier6119d782012-09-21 18:04:14 -0400413 }
414 });
415 }
416
417 @Override
418 public void hangUp(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500419 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400420 getExecutor().execute(new SipRunnable() {
421 @Override
422 protected void doRun() throws SameThreadException {
423 Log.i(TAG, "SipService.hangUp() thread running...");
424 callManagerJNI.hangUp(callID);
Alexandre Lision183bf452014-01-17 11:21:59 -0500425 if(mConferences.size() == 0)
426 mMediaManager.abandonAudioFocus();
Emeric Vigier6119d782012-09-21 18:04:14 -0400427 }
428 });
429 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400430
431 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400432 public void hold(final String callID) {
433 getExecutor().execute(new SipRunnable() {
434 @Override
435 protected void doRun() throws SameThreadException {
436 Log.i(TAG, "SipService.hold() thread running...");
437 callManagerJNI.hold(callID);
438 }
439 });
440 }
441
442 @Override
443 public void unhold(final String callID) {
444 getExecutor().execute(new SipRunnable() {
445 @Override
446 protected void doRun() throws SameThreadException {
447 Log.i(TAG, "SipService.unhold() thread running...");
448 callManagerJNI.unhold(callID);
449 }
450 });
451 }
Adrien Béraud9360f242013-09-19 11:07:42 +1000452
Alexandre Lision6711ab22013-09-16 15:15:38 -0400453 @Override
454 public HashMap<String, String> getCallDetails(String callID) throws RemoteException {
455 class CallDetails extends SipRunnableWithReturn {
456 private String id;
457
458 CallDetails(String callID) {
459 id = callID;
460 }
461
462 @Override
463 protected StringMap doRun() throws SameThreadException {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400464 Log.i(TAG, "SipService.getCallDetails() thread running...");
Alexandre Lision6711ab22013-09-16 15:15:38 -0400465 return callManagerJNI.getCallDetails(id);
466 }
467 }
468
469 CallDetails runInstance = new CallDetails(callID);
470 getExecutor().execute(runInstance);
471
472 while (!runInstance.isDone()) {
473 }
474 StringMap swigmap = (StringMap) runInstance.getVal();
475
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500476 HashMap<String, String> nativemap = SwigNativeConverter.convertCallDetailsToNative(swigmap);
Alexandre Lision6711ab22013-09-16 15:15:38 -0400477
478 return nativemap;
Adrien Béraud9360f242013-09-19 11:07:42 +1000479
Alexandre Lision6711ab22013-09-16 15:15:38 -0400480 }
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400481
482 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400483 public void setAudioPlugin(final String audioPlugin) {
484 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400485 @Override
486 protected void doRun() throws SameThreadException {
487 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
488 configurationManagerJNI.setAudioPlugin(audioPlugin);
489 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400490 });
491 }
492
493 @Override
494 public String getCurrentAudioOutputPlugin() {
495 class CurrentAudioPlugin extends SipRunnableWithReturn {
496 @Override
497 protected String doRun() throws SameThreadException {
498 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
499 return configurationManagerJNI.getCurrentAudioOutputPlugin();
500 }
alision371b77e2013-04-23 14:51:26 -0400501 }
502 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400503
504 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
505 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400506 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400507 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400508 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400509 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400510 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400511
512 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400513 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400514 class AccountList extends SipRunnableWithReturn {
515 @Override
516 protected StringVect doRun() throws SameThreadException {
517 Log.i(TAG, "SipService.getAccountList() thread running...");
518 return configurationManagerJNI.getAccountList();
519 }
alision371b77e2013-04-23 14:51:26 -0400520 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400521 AccountList runInstance = new AccountList();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400522 Log.i(TAG, "SipService.getAccountList() thread running...");
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400523 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400524 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400525 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400526 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400527 StringVect swigvect = (StringVect) runInstance.getVal();
528
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400529 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400530
alision371b77e2013-04-23 14:51:26 -0400531 for (int i = 0; i < swigvect.size(); i++)
532 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400533
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400534 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400535 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400536
Alexandre Lision4cf78702013-10-16 13:43:23 -0400537 @Override
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400538 public void setAccountOrder(final String order) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400539 getExecutor().execute(new SipRunnable() {
540 @Override
541 protected void doRun() throws SameThreadException {
542 Log.i(TAG, "SipService.setAccountsOrder() thread running...");
543 configurationManagerJNI.setAccountsOrder(order);
544 }
545 });
546 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400547
548 @Override
alision371b77e2013-04-23 14:51:26 -0400549 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400550 class AccountDetails extends SipRunnableWithReturn {
551 private String id;
alision371b77e2013-04-23 14:51:26 -0400552
553 AccountDetails(String accountId) {
554 id = accountId;
555 }
556
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400557 @Override
558 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400559 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400560 return configurationManagerJNI.getAccountDetails(id);
561 }
alision371b77e2013-04-23 14:51:26 -0400562 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400563
564 AccountDetails runInstance = new AccountDetails(accountID);
565 getExecutor().execute(runInstance);
alisionfde875f2013-05-28 17:01:54 -0400566
alision371b77e2013-04-23 14:51:26 -0400567 while (!runInstance.isDone()) {
568 }
569 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400570
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500571 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400572
573 return nativemap;
574 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400575
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400576 @SuppressWarnings("unchecked")
577 // Hashmap runtime cast
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400578 @Override
alisioncc7bb422013-06-06 15:31:39 -0400579 public void setAccountDetails(final String accountId, final Map map) {
alision371b77e2013-04-23 14:51:26 -0400580 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400581
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500582 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400583
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400584 getExecutor().execute(new SipRunnable() {
585 @Override
586 protected void doRun() throws SameThreadException {
alisioncc7bb422013-06-06 15:31:39 -0400587
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400588 configurationManagerJNI.setAccountDetails(accountId, swigmap);
alisioncc7bb422013-06-06 15:31:39 -0400589 Log.i(TAG, "SipService.setAccountDetails() thread running...");
590 }
591
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400592 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400593 }
594
Alexandre Lision451f2a82013-11-12 12:55:55 -0500595 @Override
596 public Map getAccountTemplate() throws RemoteException {
597 class AccountTemplate extends SipRunnableWithReturn {
598
599 @Override
600 protected StringMap doRun() throws SameThreadException {
601 Log.i(TAG, "SipService.getAccountTemplate() thread running...");
602 return configurationManagerJNI.getAccountTemplate();
603 }
604 }
605
606 AccountTemplate runInstance = new AccountTemplate();
607 getExecutor().execute(runInstance);
608
609 while (!runInstance.isDone()) {
610 }
611 StringMap swigmap = (StringMap) runInstance.getVal();
612
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500613 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Lision451f2a82013-11-12 12:55:55 -0500614
615 return nativemap;
616 }
alisioncc7bb422013-06-06 15:31:39 -0400617
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400618 @SuppressWarnings("unchecked")
619 // Hashmap runtime cast
Alexandre Savard46036572012-10-05 13:56:49 -0400620 @Override
621 public String addAccount(Map map) {
622 class AddAccount extends SipRunnableWithReturn {
623 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400624
625 AddAccount(StringMap m) {
626 map = m;
627 }
628
Alexandre Savard46036572012-10-05 13:56:49 -0400629 @Override
630 protected String doRun() throws SameThreadException {
631 Log.i(TAG, "SipService.getAccountDetails() thread running...");
632 return configurationManagerJNI.addAccount(map);
633 }
alision371b77e2013-04-23 14:51:26 -0400634 }
Alexandre Savard46036572012-10-05 13:56:49 -0400635
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500636 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400637
638 AddAccount runInstance = new AddAccount(swigmap);
639 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400640 while (!runInstance.isDone()) {
641 }
Alexandre Savard46036572012-10-05 13:56:49 -0400642 String accountId = (String) runInstance.getVal();
643
644 return accountId;
645 }
646
647 @Override
648 public void removeAccount(final String accountId) {
649 getExecutor().execute(new SipRunnable() {
650 @Override
651 protected void doRun() throws SameThreadException {
652 Log.i(TAG, "SipService.setAccountDetails() thread running...");
653 configurationManagerJNI.removeAccount(accountId);
654 }
655 });
656 }
alision5f899632013-04-22 17:26:56 -0400657
alision43a9b362013-05-01 16:30:15 -0400658 /*************************
659 * Transfer related API
660 *************************/
661
alision7f18fc82013-05-01 09:37:33 -0400662 @Override
663 public void transfer(final String callID, final String to) throws RemoteException {
664 getExecutor().execute(new SipRunnable() {
665 @Override
666 protected void doRun() throws SameThreadException, RemoteException {
667 Log.i(TAG, "SipService.transfer() thread running...");
668 if (callManagerJNI.transfer(callID, to)) {
669 Bundle bundle = new Bundle();
670 bundle.putString("CallID", callID);
671 bundle.putString("State", "HUNGUP");
672 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400673 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
alision84813a12013-05-27 17:40:39 -0400674 sendBroadcast(intent);
alision7f18fc82013-05-01 09:37:33 -0400675 } else
676 Log.i(TAG, "NOT OK");
677 }
678 });
679
680 }
alision43a9b362013-05-01 16:30:15 -0400681
alision7f18fc82013-05-01 09:37:33 -0400682 @Override
683 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
684 getExecutor().execute(new SipRunnable() {
685 @Override
686 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400687 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400688 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
689 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400690 } else
691 Log.i(TAG, "NOT OK");
692 }
693 });
alision43a9b362013-05-01 16:30:15 -0400694
695 }
696
697 /*************************
698 * Conference related API
699 *************************/
700
701 @Override
702 public void removeConference(final String confID) throws RemoteException {
703 getExecutor().execute(new SipRunnable() {
704 @Override
705 protected void doRun() throws SameThreadException, RemoteException {
706 Log.i(TAG, "SipService.createConference() thread running...");
707 callManagerJNI.removeConference(confID);
708 }
709 });
710
alision7f18fc82013-05-01 09:37:33 -0400711 }
712
713 @Override
alision43a9b362013-05-01 16:30:15 -0400714 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
715 getExecutor().execute(new SipRunnable() {
716 @Override
717 protected void doRun() throws SameThreadException, RemoteException {
718 Log.i(TAG, "SipService.joinParticipant() thread running...");
719 callManagerJNI.joinParticipant(sel_callID, drag_callID);
alision806e18e2013-06-21 15:30:17 -0400720 // Generate a CONF_CREATED callback
alision43a9b362013-05-01 16:30:15 -0400721 }
722 });
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500723 Log.i(TAG, "After joining participants");
alision7f18fc82013-05-01 09:37:33 -0400724 }
725
alision7f18fc82013-05-01 09:37:33 -0400726 @Override
alision806e18e2013-06-21 15:30:17 -0400727 public void addParticipant(final SipCall call, final String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400728 getExecutor().execute(new SipRunnable() {
729 @Override
730 protected void doRun() throws SameThreadException, RemoteException {
731 Log.i(TAG, "SipService.addParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400732 callManagerJNI.addParticipant(call.getCallId(), confID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500733 mConferences.get(confID).getParticipants().add(call);
alision43a9b362013-05-01 16:30:15 -0400734 }
735 });
736
alision7f18fc82013-05-01 09:37:33 -0400737 }
738
739 @Override
alision43a9b362013-05-01 16:30:15 -0400740 public void addMainParticipant(final String confID) throws RemoteException {
741 getExecutor().execute(new SipRunnable() {
742 @Override
743 protected void doRun() throws SameThreadException, RemoteException {
744 Log.i(TAG, "SipService.addMainParticipant() thread running...");
745 callManagerJNI.addMainParticipant(confID);
746 }
747 });
748
alision7f18fc82013-05-01 09:37:33 -0400749 }
750
751 @Override
alision43a9b362013-05-01 16:30:15 -0400752 public void detachParticipant(final String callID) throws RemoteException {
753 getExecutor().execute(new SipRunnable() {
754 @Override
755 protected void doRun() throws SameThreadException, RemoteException {
756 Log.i(TAG, "SipService.detachParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400757 Log.i(TAG, "Detaching " + callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500758 Iterator<Entry<String, Conference>> it = mConferences.entrySet().iterator();
759 Log.i(TAG, "mConferences size " + mConferences.size());
alision806e18e2013-06-21 15:30:17 -0400760 while (it.hasNext()) {
761 Conference tmp = it.next().getValue();
762 Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants");
763 if (tmp.contains(callID)) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500764 Conference toDetach = new Conference(tmp.getCallById(callID));
Alexandre Lision945e4612014-01-15 17:40:31 -0500765 mConferences.put(toDetach.getId(), toDetach);
alision806e18e2013-06-21 15:30:17 -0400766 Log.i(TAG, "Call found and put in current_calls");
767 }
768 }
alision43a9b362013-05-01 16:30:15 -0400769 callManagerJNI.detachParticipant(callID);
770 }
771 });
772
alision7f18fc82013-05-01 09:37:33 -0400773 }
774
775 @Override
alision43a9b362013-05-01 16:30:15 -0400776 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
777 getExecutor().execute(new SipRunnable() {
778 @Override
779 protected void doRun() throws SameThreadException, RemoteException {
780 Log.i(TAG, "SipService.joinConference() thread running...");
781 callManagerJNI.joinConference(sel_confID, drag_confID);
782 }
783 });
784
alision7f18fc82013-05-01 09:37:33 -0400785 }
786
787 @Override
alision43a9b362013-05-01 16:30:15 -0400788 public void hangUpConference(final String confID) throws RemoteException {
789 getExecutor().execute(new SipRunnable() {
790 @Override
791 protected void doRun() throws SameThreadException, RemoteException {
792 Log.i(TAG, "SipService.joinConference() thread running...");
793 callManagerJNI.hangUpConference(confID);
794 }
795 });
796
alision7f18fc82013-05-01 09:37:33 -0400797 }
798
799 @Override
alision43a9b362013-05-01 16:30:15 -0400800 public void holdConference(final String confID) throws RemoteException {
801 getExecutor().execute(new SipRunnable() {
802 @Override
803 protected void doRun() throws SameThreadException, RemoteException {
804 Log.i(TAG, "SipService.holdConference() thread running...");
805 callManagerJNI.holdConference(confID);
806 }
807 });
808
alision7f18fc82013-05-01 09:37:33 -0400809 }
810
811 @Override
alision43a9b362013-05-01 16:30:15 -0400812 public void unholdConference(final String confID) throws RemoteException {
813 getExecutor().execute(new SipRunnable() {
814 @Override
815 protected void doRun() throws SameThreadException, RemoteException {
816 Log.i(TAG, "SipService.unholdConference() thread running...");
817 callManagerJNI.unholdConference(confID);
818 }
819 });
820
alision7f18fc82013-05-01 09:37:33 -0400821 }
Alexandre Lision67817192013-07-18 12:04:30 -0400822
alisioncd8fb912013-06-28 14:43:51 -0400823 @Override
824 public boolean isConferenceParticipant(final String callID) throws RemoteException {
825 class IsParticipant extends SipRunnableWithReturn {
826
827 @Override
828 protected Boolean doRun() throws SameThreadException {
829 Log.i(TAG, "SipService.isRecording() thread running...");
830 return callManagerJNI.isConferenceParticipant(callID);
831 }
832 }
833
834 IsParticipant runInstance = new IsParticipant();
835 getExecutor().execute(runInstance);
836 while (!runInstance.isDone()) {
837 }
838
839 return (Boolean) runInstance.getVal();
840 }
alision7f18fc82013-05-01 09:37:33 -0400841
842 @Override
alisiondf1dac92013-06-27 17:35:53 -0400843 public HashMap<String, Conference> getConferenceList() throws RemoteException {
Alexandre Lision67817192013-07-18 12:04:30 -0400844 // class ConfList extends SipRunnableWithReturn {
845 // @Override
846 // protected StringVect doRun() throws SameThreadException {
847 // Log.i(TAG, "SipService.getConferenceList() thread running...");
848 // return callManagerJNI.getConferenceList();
849 // }
850 // }
851 // ;
852 // ConfList runInstance = new ConfList();
853 // getExecutor().execute(runInstance);
854 // while (!runInstance.isDone()) {
855 // // Log.w(TAG, "Waiting for getConferenceList");
856 // }
857 // StringVect swigvect = (StringVect) runInstance.getVal();
858 //
859 // ArrayList<String> nativelist = new ArrayList<String>();
860 //
861 // for (int i = 0; i < swigvect.size(); i++)
862 // nativelist.add(swigvect.get(i));
863 //
864 // return nativelist;
Alexandre Lision945e4612014-01-15 17:40:31 -0500865 return mConferences;
alision7f18fc82013-05-01 09:37:33 -0400866 }
867
868 @Override
alision907bde72013-06-20 14:40:37 -0400869 public List getParticipantList(final String confID) throws RemoteException {
870 class PartList extends SipRunnableWithReturn {
871 @Override
872 protected StringVect doRun() throws SameThreadException {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500873 Log.i(TAG, "SipService.getParticipantList() thread running...");
alision907bde72013-06-20 14:40:37 -0400874 return callManagerJNI.getParticipantList(confID);
875 }
876 }
877 ;
878 PartList runInstance = new PartList();
879 getExecutor().execute(runInstance);
880 while (!runInstance.isDone()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500881 Log.w(TAG, "getParticipantList");
alision907bde72013-06-20 14:40:37 -0400882 }
883 StringVect swigvect = (StringVect) runInstance.getVal();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500884 Log.w(TAG, "After that");
alision907bde72013-06-20 14:40:37 -0400885 ArrayList<String> nativelist = new ArrayList<String>();
886
887 for (int i = 0; i < swigvect.size(); i++)
888 nativelist.add(swigvect.get(i));
889
890 return nativelist;
alision7f18fc82013-05-01 09:37:33 -0400891 }
alision806e18e2013-06-21 15:30:17 -0400892
alision1005ba12013-06-19 13:52:44 -0400893 @Override
alision7f18fc82013-05-01 09:37:33 -0400894 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400895 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400896 return null;
897 }
898
899 @Override
alision806e18e2013-06-21 15:30:17 -0400900 public String getConferenceDetails(final String callID) throws RemoteException {
901 class ConfDetails extends SipRunnableWithReturn {
902 @Override
903 protected StringMap doRun() throws SameThreadException {
904 Log.i(TAG, "SipService.getAccountList() thread running...");
905 return callManagerJNI.getConferenceDetails(callID);
906 }
907 }
908 ;
909 ConfDetails runInstance = new ConfDetails();
910 getExecutor().execute(runInstance);
911 while (!runInstance.isDone()) {
912 // Log.w(TAG, "Waiting for getConferenceList");
913 }
914 StringMap swigvect = (StringMap) runInstance.getVal();
915
916 return swigvect.get("CONF_STATE");
alision7f18fc82013-05-01 09:37:33 -0400917 }
918
alision04a00182013-05-10 17:05:29 -0400919 @Override
920 public String getRecordPath() throws RemoteException {
921 class RecordPath extends SipRunnableWithReturn {
922
923 @Override
924 protected String doRun() throws SameThreadException {
925 Log.i(TAG, "SipService.getRecordPath() thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000926 return configurationManagerJNI.getRecordPath();
alision04a00182013-05-10 17:05:29 -0400927 }
928 }
929
930 RecordPath runInstance = new RecordPath();
931 getExecutor().execute(runInstance);
932 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400933 // Log.w(TAG, "Waiting for getRecordPath");
alision04a00182013-05-10 17:05:29 -0400934 }
935 String path = (String) runInstance.getVal();
936
937 return path;
938 }
939
940 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400941 public boolean toggleRecordingCall(final String id) throws RemoteException {
Adrien Béraud9360f242013-09-19 11:07:42 +1000942
Alexandre Lisiona764c682013-09-09 10:02:07 -0400943 class ToggleRecording extends SipRunnableWithReturn {
944
alision04a00182013-05-10 17:05:29 -0400945 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400946 protected Boolean doRun() throws SameThreadException {
947 Log.i(TAG, "SipService.toggleRecordingCall() thread running...");
Alexandre Lision3874e552013-11-04 17:20:12 -0500948 boolean result = callManagerJNI.toggleRecording(id);
Alexandre Lision35577132013-12-06 15:21:15 -0500949
Alexandre Lision945e4612014-01-15 17:40:31 -0500950 if (getConferences().containsKey(id)) {
951 getConferences().get(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500952 } else {
Alexandre Lision945e4612014-01-15 17:40:31 -0500953 Iterator<Conference> it = getConferences().values().iterator();
Alexandre Lision3874e552013-11-04 17:20:12 -0500954 while (it.hasNext()) {
955 Conference c = it.next();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500956 if (c.getCallById(id) != null)
957 c.getCallById(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500958 }
959 }
960 return result;
alision04a00182013-05-10 17:05:29 -0400961 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400962 }
963
964 ToggleRecording runInstance = new ToggleRecording();
965 getExecutor().execute(runInstance);
966 while (!runInstance.isDone()) {
967 }
968
969 return (Boolean) runInstance.getVal();
alision04a00182013-05-10 17:05:29 -0400970
971 }
Alexandre Lision67817192013-07-18 12:04:30 -0400972
alision50fa0722013-06-25 17:29:44 -0400973 @Override
974 public boolean startRecordedFilePlayback(final String filepath) throws RemoteException {
975 getExecutor().execute(new SipRunnable() {
976 @Override
977 protected void doRun() throws SameThreadException, RemoteException {
978 Log.i(TAG, "SipService.setRecordingCall() thread running...");
979 callManagerJNI.startRecordedFilePlayback(filepath);
980 }
981 });
982 return false;
983 }
984
985 @Override
986 public void stopRecordedFilePlayback(final String filepath) throws RemoteException {
987 getExecutor().execute(new SipRunnable() {
988 @Override
989 protected void doRun() throws SameThreadException, RemoteException {
990 Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running...");
991 callManagerJNI.stopRecordedFilePlayback(filepath);
992 }
993 });
994 }
alision04a00182013-05-10 17:05:29 -0400995
996 @Override
997 public void setRecordPath(final String path) throws RemoteException {
998 getExecutor().execute(new SipRunnable() {
999 @Override
1000 protected void doRun() throws SameThreadException, RemoteException {
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001001 Log.i(TAG, "SipService.setRecordPath() " + path + " thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +10001002 configurationManagerJNI.setRecordPath(path);
alision04a00182013-05-10 17:05:29 -04001003 }
1004 });
1005 }
1006
1007 @Override
Alexandre Lisiond5686032013-10-29 11:09:21 -04001008 public void sendTextMessage(final String callID, final SipMessage message) throws RemoteException {
alision04a00182013-05-10 17:05:29 -04001009 getExecutor().execute(new SipRunnable() {
1010 @Override
1011 protected void doRun() throws SameThreadException, RemoteException {
1012 Log.i(TAG, "SipService.sendTextMessage() thread running...");
Alexandre Lisiond5686032013-10-29 11:09:21 -04001013 callManagerJNI.sendTextMessage(callID, message.comment);
Alexandre Lision945e4612014-01-15 17:40:31 -05001014 if (getConferences().get(callID) != null)
1015 getConferences().get(callID).addSipMessage(message);
alision04a00182013-05-10 17:05:29 -04001016 }
1017 });
1018
1019 }
1020
alisiond295ec22013-05-17 10:12:13 -04001021 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -04001022 public List getAudioCodecList(final String accountID) throws RemoteException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001023 class AudioCodecList extends SipRunnableWithReturn {
1024
1025 @Override
Alexandre Lision933ef0a2013-10-15 17:28:40 -04001026 protected ArrayList<Codec> doRun() throws SameThreadException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001027 Log.i(TAG, "SipService.getAudioCodecList() thread running...");
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001028 ArrayList<Codec> results = new ArrayList<Codec>();
Alexandre Lision4cf78702013-10-16 13:43:23 -04001029
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001030 IntVect active_payloads = configurationManagerJNI.getActiveAudioCodecList(accountID);
1031 for (int i = 0; i < active_payloads.size(); ++i) {
1032
Alexandre Lision039a3cf2013-10-16 17:44:57 -04001033 results.add(new Codec(active_payloads.get(i), configurationManagerJNI.getAudioCodecDetails(active_payloads.get(i)), true));
Alexandre Lisione0045442013-10-25 09:16:19 -04001034
Alexandre Lision4cf78702013-10-16 13:43:23 -04001035 }
Alexandre Lision039a3cf2013-10-16 17:44:57 -04001036 IntVect payloads = configurationManagerJNI.getAudioCodecList();
1037
1038 for (int i = 0; i < payloads.size(); ++i) {
1039 boolean isActive = false;
1040 for (Codec co : results) {
1041 if (co.getPayload().toString().contentEquals(String.valueOf(payloads.get(i))))
1042 isActive = true;
1043
1044 }
1045 if (isActive)
1046 continue;
1047 else
1048 results.add(new Codec(payloads.get(i), configurationManagerJNI.getAudioCodecDetails(payloads.get(i)), false));
1049
1050 }
1051
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001052 return results;
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001053 }
1054 }
1055
1056 AudioCodecList runInstance = new AudioCodecList();
1057 getExecutor().execute(runInstance);
1058 while (!runInstance.isDone()) {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001059 }
Alexandre Lision933ef0a2013-10-15 17:28:40 -04001060 ArrayList<Codec> codecs = (ArrayList<Codec>) runInstance.getVal();
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001061 return codecs;
alisiond295ec22013-05-17 10:12:13 -04001062 }
1063
alision9f7a6ec2013-05-24 16:26:26 -04001064 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -04001065 public Map getRingtoneList() throws RemoteException {
1066 class RingtoneList extends SipRunnableWithReturn {
1067
1068 @Override
1069 protected StringMap doRun() throws SameThreadException {
1070 Log.i(TAG, "SipService.getRingtoneList() thread running...");
1071 return configurationManagerJNI.getRingtoneList();
1072 }
1073 }
1074
1075 RingtoneList runInstance = new RingtoneList();
1076 getExecutor().execute(runInstance);
1077 while (!runInstance.isDone()) {
1078 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001079 StringMap ringtones = (StringMap) runInstance.getVal();
1080
1081 for (int i = 0; i < ringtones.size(); ++i) {
1082 // Log.i(TAG,"ringtones "+i+" "+ ringtones.);
1083 }
1084
Alexandre Lision4cf78702013-10-16 13:43:23 -04001085 return null;
1086 }
1087
1088 @Override
1089 public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException {
1090 getExecutor().execute(new SipRunnable() {
1091 @Override
1092 protected void doRun() throws SameThreadException, RemoteException {
1093 Log.i(TAG, "SipService.setActiveAudioCodecList() thread running...");
1094 StringVect list = new StringVect();
1095 for (int i = 0; i < codecs.size(); ++i) {
1096 list.add((String) codecs.get(i));
1097 }
1098 configurationManagerJNI.setActiveAudioCodecList(list, accountID);
1099 }
1100 });
1101 }
1102
alision2cb99562013-05-30 17:02:20 -04001103 /***********************
1104 * Notification API
1105 ***********************/
1106 @Override
1107 public void createNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001108
alision2cb99562013-05-30 17:02:20 -04001109 }
1110
1111 @Override
1112 public void destroyNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001113
alision2cb99562013-05-30 17:02:20 -04001114 }
alisioncc7bb422013-06-06 15:31:39 -04001115
alisiondf1dac92013-06-27 17:35:53 -04001116 @Override
1117 public Conference getCurrentCall() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001118 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001119 if (conf.isIncoming())
1120 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001121 }
Alexandre Lision67817192013-07-18 12:04:30 -04001122
Alexandre Lision945e4612014-01-15 17:40:31 -05001123 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001124 if (conf.isOnGoing())
1125 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001126 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001127
alisiondf1dac92013-06-27 17:35:53 -04001128 return null;
1129 }
1130
Alexandre Lision64dc8c02013-09-25 15:32:25 -04001131 @Override
1132 public void playDtmf(final String key) throws RemoteException {
1133 getExecutor().execute(new SipRunnable() {
1134 @Override
1135 protected void doRun() throws SameThreadException, RemoteException {
1136 Log.i(TAG, "SipService.playDtmf() thread running...");
1137 callManagerJNI.playDTMF(key);
1138 }
1139 });
1140 }
1141
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001142 @Override
1143 public List getConcurrentCalls() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001144 return new ArrayList(mConferences.values());
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001145 }
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001146
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001147 @Override
1148 public Conference getConference(String id) throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001149 return mConferences.get(id);
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001150 }
1151
Alexandre Lision4fb22622013-10-21 16:26:33 -04001152 @Override
1153 public String getCurrentAudioCodecName(String callID) throws RemoteException {
1154 return callManagerJNI.getCurrentAudioCodecName(callID);
1155 }
1156
Alexandre Lision31e30902013-11-08 15:16:59 -05001157 @Override
1158 public void setMuted(final boolean mute) throws RemoteException {
1159 getExecutor().execute(new SipRunnable() {
1160 @Override
1161 protected void doRun() throws SameThreadException, RemoteException {
1162 Log.i(TAG, "SipService.setMuted() thread running...");
1163 configurationManagerJNI.muteCapture(mute);
1164 }
1165 });
1166 }
1167
1168 @Override
1169 public boolean isCaptureMuted() throws RemoteException {
1170 class IsMuted extends SipRunnableWithReturn {
1171
1172 @Override
1173 protected Boolean doRun() throws SameThreadException {
1174 Log.i(TAG, "SipService.isCaptureMuted() thread running...");
1175 return configurationManagerJNI.isCaptureMuted();
1176 }
1177 }
1178
1179 IsMuted runInstance = new IsMuted();
1180 getExecutor().execute(runInstance);
1181 while (!runInstance.isDone()) {
1182 }
1183
1184 return (Boolean) runInstance.getVal();
1185 }
1186
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001187 @Override
Alexandre Lision48b49eb2014-02-11 13:37:33 -05001188 public void confirmSAS(final String callID) throws RemoteException {
1189 getExecutor().execute(new SipRunnable() {
1190 @Override
1191 protected void doRun() throws SameThreadException, RemoteException {
1192 Log.i(TAG, "SipService.confirmSAS() thread running...");
1193 callManagerJNI.setSASVerified(callID);
1194 }
1195 });
1196 }
1197
1198 @Override
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001199 public List getCredentials(final String accountID) throws RemoteException {
1200 class Credentials extends SipRunnableWithReturn {
1201
1202 @Override
1203 protected List doRun() throws SameThreadException {
1204 Log.i(TAG, "SipService.getCredentials() thread running...");
1205 VectMap map = configurationManagerJNI.getCredentials(accountID);
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001206 ArrayList<HashMap<String, String>> result = SwigNativeConverter.convertCredentialsToNative(map);
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001207 return result;
1208 }
1209 }
1210
1211 Credentials runInstance = new Credentials();
1212 getExecutor().execute(runInstance);
1213 while (!runInstance.isDone()) {
1214 }
1215 return (List) runInstance.getVal();
1216 }
1217
1218 @Override
1219 public void setCredentials(final String accountID, final List creds) throws RemoteException {
1220 getExecutor().execute(new SipRunnable() {
1221 @Override
1222 protected void doRun() throws SameThreadException, RemoteException {
1223 Log.i(TAG, "SipService.setCredentials() thread running...");
Alexandre Lision3cefec22013-11-14 17:26:35 -05001224 ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds;
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001225 configurationManagerJNI.setCredentials(accountID, SwigNativeConverter.convertFromNativeToSwig(creds));
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001226 }
1227 });
1228 }
1229
Alexandre Lision3e2a1d02013-11-19 17:23:00 -05001230 @Override
1231 public void registerAllAccounts() throws RemoteException {
1232 getExecutor().execute(new SipRunnable() {
1233 @Override
1234 protected void doRun() throws SameThreadException, RemoteException {
1235 Log.i(TAG, "SipService.registerAllAccounts() thread running...");
1236 configurationManagerJNI.registerAllAccounts();
1237 }
1238 });
1239 }
1240
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001241 @Override
Alexandre Lision35577132013-12-06 15:21:15 -05001242 public void toggleSpeakerPhone(boolean toggle) throws RemoteException {
1243 if (toggle)
Alexandre Lision945e4612014-01-15 17:40:31 -05001244 mMediaManager.RouteToSpeaker();
Alexandre Lision35577132013-12-06 15:21:15 -05001245 else
Alexandre Lision945e4612014-01-15 17:40:31 -05001246 mMediaManager.RouteToInternalSpeaker();
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001247 }
1248
Emeric Vigier6119d782012-09-21 18:04:14 -04001249 };
Alexandre Lision35577132013-12-06 15:21:15 -05001250}