blob: 1d9a5d13fe456995d7fd16a073842d76771ce8c2 [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 Lision933ef0a2013-10-15 17:28:40 -040035import org.sflphone.model.Codec;
Alexandre Lision064e1e02013-10-01 16:18:42 -040036import org.sflphone.model.Conference;
37import org.sflphone.model.SipCall;
Alexandre Lisiond5686032013-10-29 11:09:21 -040038import org.sflphone.model.SipMessage;
Alexandre Lision6d867b92013-10-25 15:36:28 -040039import org.sflphone.utils.MediaManager;
Alexandre Lisione0045442013-10-25 09:16:19 -040040import org.sflphone.utils.SipNotifications;
Alexandre Lision2aae48d2013-12-04 13:50:38 -050041import org.sflphone.utils.SwigNativeConverter;
Alexandre Lision064e1e02013-10-01 16:18:42 -040042
Emeric Vigiereaf2c492012-09-19 14:38:20 -040043import android.app.Service;
44import android.content.Intent;
alision7f18fc82013-05-01 09:37:33 -040045import android.os.Bundle;
Emeric Vigier6119d782012-09-21 18:04:14 -040046import android.os.Handler;
47import android.os.HandlerThread;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040048import android.os.IBinder;
Emeric Vigier6119d782012-09-21 18:04:14 -040049import android.os.Looper;
50import android.os.Message;
alision5f899632013-04-22 17:26:56 -040051import android.os.RemoteException;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040052import android.util.Log;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040053
Emeric Vigiereaf2c492012-09-19 14:38:20 -040054public class SipService extends Service {
55
56 static final String TAG = "SipService";
Emeric Vigier6119d782012-09-21 18:04:14 -040057 private SipServiceExecutor mExecutor;
58 private static HandlerThread executorThread;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050059
alision3ea8f3c2013-07-16 17:35:35 -040060 private CallManager callManagerJNI;
Alexandre Lision67817192013-07-18 12:04:30 -040061 private ManagerImpl managerImpl;
Emeric Vigier0007dee2012-09-24 11:35:58 -040062 private CallManagerCallBack callManagerCallBack;
Alexandre Lisionb2669692014-01-28 14:06:08 -050063
alision3ea8f3c2013-07-16 17:35:35 -040064 private ConfigurationManager configurationManagerJNI;
Alexandre Savardfccd1dc2012-10-17 17:31:38 -040065 private ConfigurationManagerCallback configurationManagerCallback;
Emeric Vigier6119d782012-09-21 18:04:14 -040066 private boolean isPjSipStackStarted = false;
alisioncc7bb422013-06-06 15:31:39 -040067
Alexandre Lision945e4612014-01-15 17:40:31 -050068 protected SipNotifications mNotificationManager;
69 protected HistoryManager mHistoryManager;
70 protected MediaManager mMediaManager;
Alexandre Lisione0045442013-10-25 09:16:19 -040071
Alexandre Lision945e4612014-01-15 17:40:31 -050072 private HashMap<String, Conference> mConferences = new HashMap<String, Conference>();
Emeric Vigier6119d782012-09-21 18:04:14 -040073
Alexandre Lision945e4612014-01-15 17:40:31 -050074 public HashMap<String, Conference> getConferences() {
75 return mConferences;
alision806e18e2013-06-21 15:30:17 -040076 }
alision43a9b362013-05-01 16:30:15 -040077
Alexandre Lisionb2669692014-01-28 14:06:08 -050078 public CallManager getCallManagerJNI() {
79 return callManagerJNI;
80 }
81
82 public ConfigurationManager getConfigurationManagerJNI() {
83 return configurationManagerJNI;
84 }
85
Alexandre Lision183bf452014-01-17 11:21:59 -050086 public void addCallToConference(String confId, String callId) {
87 if(mConferences.get(callId) != null){
88 // We add a simple call to a conference
Alexandre Lision96db8032014-01-17 16:43:51 -050089 Log.i(TAG, "// We add a simple call to a conference");
Alexandre Lision183bf452014-01-17 11:21:59 -050090 mConferences.get(confId).addParticipant(mConferences.get(callId).getParticipants().get(0));
91 mConferences.remove(callId);
92 } else {
Alexandre Lision96db8032014-01-17 16:43:51 -050093 Log.i(TAG, "addCallToConference");
Alexandre Lision183bf452014-01-17 11:21:59 -050094 Iterator<Map.Entry<String, Conference>> it = mConferences.entrySet().iterator();
95 while (it.hasNext()) {
96 Conference tmp = it.next().getValue();
97 for (SipCall c : tmp.getParticipants()) {
98 if (c.getCallId().contentEquals(callId)) {
99 mConferences.get(confId).addParticipant(c);
Alexandre Lision96db8032014-01-17 16:43:51 -0500100 mConferences.get(tmp.getId()).removeParticipant(c);
Alexandre Lision183bf452014-01-17 11:21:59 -0500101 }
102 }
103 }
104 }
105
106 }
107
Alexandre Lision96db8032014-01-17 16:43:51 -0500108 public void detachCallFromConference(String confId, SipCall call) {
109 Log.i(TAG, "detachCallFromConference");
Alexandre Lision183bf452014-01-17 11:21:59 -0500110 Conference separate = new Conference(call);
111 mConferences.put(separate.getId(), separate);
Alexandre Lision96db8032014-01-17 16:43:51 -0500112 mConferences.get(confId).removeParticipant(call);
Alexandre Lision183bf452014-01-17 11:21:59 -0500113 }
114
115
alision43a9b362013-05-01 16:30:15 -0400116 @Override
117 public boolean onUnbind(Intent i) {
118 super.onUnbind(i);
119 Log.i(TAG, "onUnbind(intent)");
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400120 return true;
121 }
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400122
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400123 @Override
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400124 public void onRebind(Intent i) {
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400125 super.onRebind(i);
alision43a9b362013-05-01 16:30:15 -0400126 }
127
128 /* called once by startService() */
129 @Override
130 public void onCreate() {
131 Log.i(TAG, "onCreated");
132 super.onCreate();
133
alisioncc7bb422013-06-06 15:31:39 -0400134 getExecutor().execute(new StartRunnable());
Alexandre Lisione0045442013-10-25 09:16:19 -0400135
Alexandre Lision945e4612014-01-15 17:40:31 -0500136 mNotificationManager = new SipNotifications(this);
137 mMediaManager = new MediaManager(this);
138 mHistoryManager = new HistoryManager(this);
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400139
Alexandre Lision945e4612014-01-15 17:40:31 -0500140 mNotificationManager.onServiceCreate();
141 mMediaManager.startService();
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400142
alisioncc7bb422013-06-06 15:31:39 -0400143 }
alision43a9b362013-05-01 16:30:15 -0400144
145 /* called for each startService() */
146 @Override
147 public int onStartCommand(Intent intent, int flags, int startId) {
148 Log.i(TAG, "onStarted");
149 super.onStartCommand(intent, flags, startId);
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400150 return START_STICKY; /* started and stopped explicitly */
alision43a9b362013-05-01 16:30:15 -0400151 }
152
153 @Override
154 public void onDestroy() {
Alexandre Lision52214992013-10-28 17:41:23 -0400155 Log.i(TAG, "onDestroy");
alision43a9b362013-05-01 16:30:15 -0400156 /* called once by stopService() */
Alexandre Lision945e4612014-01-15 17:40:31 -0500157 mNotificationManager.onServiceDestroy();
Alexandre Lision183bf452014-01-17 11:21:59 -0500158 mMediaManager.stopService();
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400159 getExecutor().execute(new FinalizeRunnable());
alision43a9b362013-05-01 16:30:15 -0400160 super.onDestroy();
161
alision43a9b362013-05-01 16:30:15 -0400162 }
163
164 @Override
165 public IBinder onBind(Intent arg0) {
166 Log.i(TAG, "onBound");
167 return mBinder;
168 }
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400169
alision43a9b362013-05-01 16:30:15 -0400170 private static Looper createLooper() {
171 if (executorThread == null) {
172 Log.d(TAG, "Creating new handler thread");
173 // ADT gives a fake warning due to bad parse rule.
174 executorThread = new HandlerThread("SipService.Executor");
175 executorThread.start();
176 }
177 return executorThread.getLooper();
178 }
179
180 public SipServiceExecutor getExecutor() {
181 // create mExecutor lazily
182 if (mExecutor == null) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500183 mExecutor = new SipServiceExecutor();
alision43a9b362013-05-01 16:30:15 -0400184 }
185 return mExecutor;
186 }
187
188 // Executes immediate tasks in a single executorThread.
189 public static class SipServiceExecutor extends Handler {
alision43a9b362013-05-01 16:30:15 -0400190
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500191 SipServiceExecutor() {
alision43a9b362013-05-01 16:30:15 -0400192 super(createLooper());
alision43a9b362013-05-01 16:30:15 -0400193 }
194
195 public void execute(Runnable task) {
196 // TODO: add wakelock
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500197 Message.obtain(SipServiceExecutor.this, 0/* don't care */, task).sendToTarget();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400198 Log.w(TAG, "SenT!");
alision43a9b362013-05-01 16:30:15 -0400199 }
200
201 @Override
202 public void handleMessage(Message msg) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500203 Log.w(TAG, "handleMessage");
alision43a9b362013-05-01 16:30:15 -0400204 if (msg.obj instanceof Runnable) {
205 executeInternal((Runnable) msg.obj);
206 } else {
207 Log.w(TAG, "can't handle msg: " + msg);
208 }
209 }
210
211 private void executeInternal(Runnable task) {
212 try {
213 task.run();
214 } catch (Throwable t) {
215 Log.e(TAG, "run task: " + task, t);
216 }
217 }
218 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400219
220 private void stopDaemon() {
221 if (managerImpl != null) {
222 managerImpl.finish();
223 isPjSipStackStarted = false;
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400224 }
225 }
alision43a9b362013-05-01 16:30:15 -0400226
227 private void startPjSipStack() throws SameThreadException {
228 if (isPjSipStackStarted)
229 return;
230
231 try {
232 System.loadLibrary("gnustl_shared");
alision43a9b362013-05-01 16:30:15 -0400233 System.loadLibrary("crypto");
234 System.loadLibrary("ssl");
alision43a9b362013-05-01 16:30:15 -0400235 System.loadLibrary("sflphone");
236 isPjSipStackStarted = true;
Adrien Béraud9360f242013-09-19 11:07:42 +1000237
alision43a9b362013-05-01 16:30:15 -0400238 } catch (UnsatisfiedLinkError e) {
239 Log.e(TAG, "Problem with the current Pj stack...", e);
240 isPjSipStackStarted = false;
241 return;
242 } catch (Exception e) {
243 Log.e(TAG, "Problem with the current Pj stack...", e);
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400244 isPjSipStackStarted = false;
alision43a9b362013-05-01 16:30:15 -0400245 }
246
Alexandre Lision67817192013-07-18 12:04:30 -0400247 Log.i(TAG, "PjSIPStack started");
248 managerImpl = SFLPhoneservice.instance();
249
250 /* set static AppPath before calling manager.init */
Alexandre Lision63870a72013-10-28 16:33:47 -0400251 // managerImpl.setPath(getApplication().getFilesDir().getAbsolutePath());
alision43a9b362013-05-01 16:30:15 -0400252
alision3ea8f3c2013-07-16 17:35:35 -0400253 callManagerJNI = new CallManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500254 callManagerCallBack = new CallManagerCallBack(this);
alision43a9b362013-05-01 16:30:15 -0400255 SFLPhoneservice.setCallbackObject(callManagerCallBack);
256
alision3ea8f3c2013-07-16 17:35:35 -0400257 configurationManagerJNI = new ConfigurationManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500258 configurationManagerCallback = new ConfigurationManagerCallback(this);
alision43a9b362013-05-01 16:30:15 -0400259 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
Alexandre Lision67817192013-07-18 12:04:30 -0400260 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 }
264
265 // Enforce same thread contract to ensure we do not call from somewhere else
266 public class SameThreadException extends Exception {
267 private static final long serialVersionUID = -905639124232613768L;
268
269 public SameThreadException() {
270 super("Should be launched from a single worker thread");
271 }
272 }
273
274 public abstract static class SipRunnable implements Runnable {
275 protected abstract void doRun() throws SameThreadException, RemoteException;
276
Adrien Béraud9360f242013-09-19 11:07:42 +1000277 @Override
alision43a9b362013-05-01 16:30:15 -0400278 public void run() {
279 try {
280 doRun();
281 } catch (SameThreadException e) {
282 Log.e(TAG, "Not done from same thread");
283 } catch (RemoteException e) {
284 Log.e(TAG, e.toString());
285 }
286 }
287 }
288
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400289 public abstract class SipRunnableWithReturn implements Runnable {
alision43a9b362013-05-01 16:30:15 -0400290 Object obj = null;
291 boolean done = false;
292
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500293 protected abstract Object doRun() throws SameThreadException, RemoteException;
alision43a9b362013-05-01 16:30:15 -0400294
295 public Object getVal() {
296 return obj;
297 }
298
299 public boolean isDone() {
300 return done;
301 }
302
Adrien Béraud9360f242013-09-19 11:07:42 +1000303 @Override
alision43a9b362013-05-01 16:30:15 -0400304 public void run() {
305 try {
Alexandre Lision35577132013-12-06 15:21:15 -0500306 if (isPjSipStackStarted)
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400307 obj = doRun();
alision43a9b362013-05-01 16:30:15 -0400308 done = true;
309 } catch (SameThreadException e) {
310 Log.e(TAG, "Not done from same thread");
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500311 } catch (RemoteException e) {
312 Log.e(TAG, e.toString());
alision43a9b362013-05-01 16:30:15 -0400313 }
314 }
315 }
316
317 class StartRunnable extends SipRunnable {
318 @Override
319 protected void doRun() throws SameThreadException {
320 startPjSipStack();
321 }
322 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400323
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400324 class FinalizeRunnable extends SipRunnable {
325 @Override
326 protected void doRun() throws SameThreadException {
327 stopDaemon();
328 }
329 }
alision43a9b362013-05-01 16:30:15 -0400330
alision43a9b362013-05-01 16:30:15 -0400331 /* ************************************
332 *
333 * Implement public interface for the service
334 *
Alexandre Lision67817192013-07-18 12:04:30 -0400335 * *********************************
336 */
337
Emeric Vigier6119d782012-09-21 18:04:14 -0400338 private final ISipService.Stub mBinder = new ISipService.Stub() {
339
340 @Override
alisionfde875f2013-05-28 17:01:54 -0400341 public void placeCall(final SipCall call) {
Emeric Vigier6119d782012-09-21 18:04:14 -0400342 getExecutor().execute(new SipRunnable() {
343 @Override
344 protected void doRun() throws SameThreadException {
345 Log.i(TAG, "SipService.placeCall() thread running...");
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400346 callManagerJNI.placeCall(call.getAccount().getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber());
Adrien Béraud9360f242013-09-19 11:07:42 +1000347
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500348 HashMap<String, String> details = SwigNativeConverter.convertCallDetailsToNative(callManagerJNI.getCallDetails(call.getCallId()));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400349 // watchout timestamp stored by sflphone is in seconds
Alexandre Lision945e4612014-01-15 17:40:31 -0500350 call.setTimestampStart_(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START)));
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500351 Conference toAdd = new Conference(call);
Alexandre Lision945e4612014-01-15 17:40:31 -0500352 mConferences.put(toAdd.getId(), toAdd);
353 mMediaManager.obtainAudioFocus(false);
Emeric Vigier6119d782012-09-21 18:04:14 -0400354 }
355 });
356 }
357
358 @Override
359 public void refuse(final String callID) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500360
Emeric Vigier6119d782012-09-21 18:04:14 -0400361 getExecutor().execute(new SipRunnable() {
362 @Override
363 protected void doRun() throws SameThreadException {
364 Log.i(TAG, "SipService.refuse() thread running...");
365 callManagerJNI.refuse(callID);
366 }
367 });
368 }
369
370 @Override
371 public void accept(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500372 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400373 getExecutor().execute(new SipRunnable() {
374 @Override
375 protected void doRun() throws SameThreadException {
Tristan Matthews40cf25e2013-07-24 13:45:15 -0400376 Log.i(TAG, "SipService.accept() thread running...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400377 callManagerJNI.accept(callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500378 mMediaManager.RouteToInternalSpeaker();
Emeric Vigier6119d782012-09-21 18:04:14 -0400379 }
380 });
381 }
382
383 @Override
384 public void hangUp(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500385 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400386 getExecutor().execute(new SipRunnable() {
387 @Override
388 protected void doRun() throws SameThreadException {
389 Log.i(TAG, "SipService.hangUp() thread running...");
390 callManagerJNI.hangUp(callID);
Alexandre Lision183bf452014-01-17 11:21:59 -0500391 if(mConferences.size() == 0)
392 mMediaManager.abandonAudioFocus();
Emeric Vigier6119d782012-09-21 18:04:14 -0400393 }
394 });
395 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400396
397 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400398 public void hold(final String callID) {
399 getExecutor().execute(new SipRunnable() {
400 @Override
401 protected void doRun() throws SameThreadException {
402 Log.i(TAG, "SipService.hold() thread running...");
403 callManagerJNI.hold(callID);
404 }
405 });
406 }
407
408 @Override
409 public void unhold(final String callID) {
410 getExecutor().execute(new SipRunnable() {
411 @Override
412 protected void doRun() throws SameThreadException {
413 Log.i(TAG, "SipService.unhold() thread running...");
414 callManagerJNI.unhold(callID);
415 }
416 });
417 }
Adrien Béraud9360f242013-09-19 11:07:42 +1000418
Alexandre Lision6711ab22013-09-16 15:15:38 -0400419 @Override
420 public HashMap<String, String> getCallDetails(String callID) throws RemoteException {
421 class CallDetails extends SipRunnableWithReturn {
422 private String id;
423
424 CallDetails(String callID) {
425 id = callID;
426 }
427
428 @Override
429 protected StringMap doRun() throws SameThreadException {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400430 Log.i(TAG, "SipService.getCallDetails() thread running...");
Alexandre Lision6711ab22013-09-16 15:15:38 -0400431 return callManagerJNI.getCallDetails(id);
432 }
433 }
434
435 CallDetails runInstance = new CallDetails(callID);
436 getExecutor().execute(runInstance);
437
438 while (!runInstance.isDone()) {
439 }
440 StringMap swigmap = (StringMap) runInstance.getVal();
441
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500442 HashMap<String, String> nativemap = SwigNativeConverter.convertCallDetailsToNative(swigmap);
Alexandre Lision6711ab22013-09-16 15:15:38 -0400443
444 return nativemap;
Adrien Béraud9360f242013-09-19 11:07:42 +1000445
Alexandre Lision6711ab22013-09-16 15:15:38 -0400446 }
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400447
448 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400449 public void setAudioPlugin(final String audioPlugin) {
450 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400451 @Override
452 protected void doRun() throws SameThreadException {
453 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
454 configurationManagerJNI.setAudioPlugin(audioPlugin);
455 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400456 });
457 }
458
459 @Override
460 public String getCurrentAudioOutputPlugin() {
461 class CurrentAudioPlugin extends SipRunnableWithReturn {
462 @Override
463 protected String doRun() throws SameThreadException {
464 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
465 return configurationManagerJNI.getCurrentAudioOutputPlugin();
466 }
alision371b77e2013-04-23 14:51:26 -0400467 }
468 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400469
470 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
471 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400472 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400473 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400474 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400475 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400476 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400477
478 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400479 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400480 class AccountList extends SipRunnableWithReturn {
481 @Override
482 protected StringVect doRun() throws SameThreadException {
483 Log.i(TAG, "SipService.getAccountList() thread running...");
484 return configurationManagerJNI.getAccountList();
485 }
alision371b77e2013-04-23 14:51:26 -0400486 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400487 AccountList runInstance = new AccountList();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400488 Log.i(TAG, "SipService.getAccountList() thread running...");
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400489 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400490 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400491 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400492 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400493 StringVect swigvect = (StringVect) runInstance.getVal();
494
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400495 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400496
alision371b77e2013-04-23 14:51:26 -0400497 for (int i = 0; i < swigvect.size(); i++)
498 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400499
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400500 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400501 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400502
Alexandre Lision4cf78702013-10-16 13:43:23 -0400503 @Override
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400504 public void setAccountOrder(final String order) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400505 getExecutor().execute(new SipRunnable() {
506 @Override
507 protected void doRun() throws SameThreadException {
508 Log.i(TAG, "SipService.setAccountsOrder() thread running...");
509 configurationManagerJNI.setAccountsOrder(order);
510 }
511 });
512 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400513
514 @Override
alision371b77e2013-04-23 14:51:26 -0400515 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400516 class AccountDetails extends SipRunnableWithReturn {
517 private String id;
alision371b77e2013-04-23 14:51:26 -0400518
519 AccountDetails(String accountId) {
520 id = accountId;
521 }
522
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400523 @Override
524 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400525 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400526 return configurationManagerJNI.getAccountDetails(id);
527 }
alision371b77e2013-04-23 14:51:26 -0400528 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400529
530 AccountDetails runInstance = new AccountDetails(accountID);
531 getExecutor().execute(runInstance);
alisionfde875f2013-05-28 17:01:54 -0400532
alision371b77e2013-04-23 14:51:26 -0400533 while (!runInstance.isDone()) {
534 }
535 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400536
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500537 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400538
539 return nativemap;
540 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400541
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400542 @SuppressWarnings("unchecked")
543 // Hashmap runtime cast
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400544 @Override
alisioncc7bb422013-06-06 15:31:39 -0400545 public void setAccountDetails(final String accountId, final Map map) {
alision371b77e2013-04-23 14:51:26 -0400546 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400547
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500548 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400549
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400550 getExecutor().execute(new SipRunnable() {
551 @Override
552 protected void doRun() throws SameThreadException {
alisioncc7bb422013-06-06 15:31:39 -0400553
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400554 configurationManagerJNI.setAccountDetails(accountId, swigmap);
alisioncc7bb422013-06-06 15:31:39 -0400555 Log.i(TAG, "SipService.setAccountDetails() thread running...");
556 }
557
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400558 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400559 }
560
Alexandre Lision451f2a82013-11-12 12:55:55 -0500561 @Override
562 public Map getAccountTemplate() throws RemoteException {
563 class AccountTemplate extends SipRunnableWithReturn {
564
565 @Override
566 protected StringMap doRun() throws SameThreadException {
567 Log.i(TAG, "SipService.getAccountTemplate() thread running...");
568 return configurationManagerJNI.getAccountTemplate();
569 }
570 }
571
572 AccountTemplate runInstance = new AccountTemplate();
573 getExecutor().execute(runInstance);
574
575 while (!runInstance.isDone()) {
576 }
577 StringMap swigmap = (StringMap) runInstance.getVal();
578
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500579 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Lision451f2a82013-11-12 12:55:55 -0500580
581 return nativemap;
582 }
alisioncc7bb422013-06-06 15:31:39 -0400583
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400584 @SuppressWarnings("unchecked")
585 // Hashmap runtime cast
Alexandre Savard46036572012-10-05 13:56:49 -0400586 @Override
587 public String addAccount(Map map) {
588 class AddAccount extends SipRunnableWithReturn {
589 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400590
591 AddAccount(StringMap m) {
592 map = m;
593 }
594
Alexandre Savard46036572012-10-05 13:56:49 -0400595 @Override
596 protected String doRun() throws SameThreadException {
597 Log.i(TAG, "SipService.getAccountDetails() thread running...");
598 return configurationManagerJNI.addAccount(map);
599 }
alision371b77e2013-04-23 14:51:26 -0400600 }
Alexandre Savard46036572012-10-05 13:56:49 -0400601
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500602 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400603
604 AddAccount runInstance = new AddAccount(swigmap);
605 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400606 while (!runInstance.isDone()) {
607 }
Alexandre Savard46036572012-10-05 13:56:49 -0400608 String accountId = (String) runInstance.getVal();
609
610 return accountId;
611 }
612
613 @Override
614 public void removeAccount(final String accountId) {
615 getExecutor().execute(new SipRunnable() {
616 @Override
617 protected void doRun() throws SameThreadException {
618 Log.i(TAG, "SipService.setAccountDetails() thread running...");
619 configurationManagerJNI.removeAccount(accountId);
620 }
621 });
622 }
alision5f899632013-04-22 17:26:56 -0400623
alision43a9b362013-05-01 16:30:15 -0400624 /*************************
625 * Transfer related API
626 *************************/
627
alision7f18fc82013-05-01 09:37:33 -0400628 @Override
629 public void transfer(final String callID, final String to) throws RemoteException {
630 getExecutor().execute(new SipRunnable() {
631 @Override
632 protected void doRun() throws SameThreadException, RemoteException {
633 Log.i(TAG, "SipService.transfer() thread running...");
634 if (callManagerJNI.transfer(callID, to)) {
635 Bundle bundle = new Bundle();
636 bundle.putString("CallID", callID);
637 bundle.putString("State", "HUNGUP");
638 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400639 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
alision84813a12013-05-27 17:40:39 -0400640 sendBroadcast(intent);
alision7f18fc82013-05-01 09:37:33 -0400641 } else
642 Log.i(TAG, "NOT OK");
643 }
644 });
645
646 }
alision43a9b362013-05-01 16:30:15 -0400647
alision7f18fc82013-05-01 09:37:33 -0400648 @Override
649 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
650 getExecutor().execute(new SipRunnable() {
651 @Override
652 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400653 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400654 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
655 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400656 } else
657 Log.i(TAG, "NOT OK");
658 }
659 });
alision43a9b362013-05-01 16:30:15 -0400660
661 }
662
663 /*************************
664 * Conference related API
665 *************************/
666
667 @Override
668 public void removeConference(final String confID) throws RemoteException {
669 getExecutor().execute(new SipRunnable() {
670 @Override
671 protected void doRun() throws SameThreadException, RemoteException {
672 Log.i(TAG, "SipService.createConference() thread running...");
673 callManagerJNI.removeConference(confID);
674 }
675 });
676
alision7f18fc82013-05-01 09:37:33 -0400677 }
678
679 @Override
alision43a9b362013-05-01 16:30:15 -0400680 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
681 getExecutor().execute(new SipRunnable() {
682 @Override
683 protected void doRun() throws SameThreadException, RemoteException {
684 Log.i(TAG, "SipService.joinParticipant() thread running...");
685 callManagerJNI.joinParticipant(sel_callID, drag_callID);
alision806e18e2013-06-21 15:30:17 -0400686 // Generate a CONF_CREATED callback
alision43a9b362013-05-01 16:30:15 -0400687 }
688 });
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500689 Log.i(TAG, "After joining participants");
alision7f18fc82013-05-01 09:37:33 -0400690 }
691
alision7f18fc82013-05-01 09:37:33 -0400692 @Override
alision806e18e2013-06-21 15:30:17 -0400693 public void addParticipant(final SipCall call, final String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400694 getExecutor().execute(new SipRunnable() {
695 @Override
696 protected void doRun() throws SameThreadException, RemoteException {
697 Log.i(TAG, "SipService.addParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400698 callManagerJNI.addParticipant(call.getCallId(), confID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500699 mConferences.get(confID).getParticipants().add(call);
alision43a9b362013-05-01 16:30:15 -0400700 }
701 });
702
alision7f18fc82013-05-01 09:37:33 -0400703 }
704
705 @Override
alision43a9b362013-05-01 16:30:15 -0400706 public void addMainParticipant(final String confID) throws RemoteException {
707 getExecutor().execute(new SipRunnable() {
708 @Override
709 protected void doRun() throws SameThreadException, RemoteException {
710 Log.i(TAG, "SipService.addMainParticipant() thread running...");
711 callManagerJNI.addMainParticipant(confID);
712 }
713 });
714
alision7f18fc82013-05-01 09:37:33 -0400715 }
716
717 @Override
alision43a9b362013-05-01 16:30:15 -0400718 public void detachParticipant(final String callID) throws RemoteException {
719 getExecutor().execute(new SipRunnable() {
720 @Override
721 protected void doRun() throws SameThreadException, RemoteException {
722 Log.i(TAG, "SipService.detachParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400723 Log.i(TAG, "Detaching " + callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500724 Iterator<Entry<String, Conference>> it = mConferences.entrySet().iterator();
725 Log.i(TAG, "mConferences size " + mConferences.size());
alision806e18e2013-06-21 15:30:17 -0400726 while (it.hasNext()) {
727 Conference tmp = it.next().getValue();
728 Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants");
729 if (tmp.contains(callID)) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500730 Conference toDetach = new Conference(tmp.getCallById(callID));
Alexandre Lision945e4612014-01-15 17:40:31 -0500731 mConferences.put(toDetach.getId(), toDetach);
alision806e18e2013-06-21 15:30:17 -0400732 Log.i(TAG, "Call found and put in current_calls");
733 }
734 }
alision43a9b362013-05-01 16:30:15 -0400735 callManagerJNI.detachParticipant(callID);
736 }
737 });
738
alision7f18fc82013-05-01 09:37:33 -0400739 }
740
741 @Override
alision43a9b362013-05-01 16:30:15 -0400742 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
743 getExecutor().execute(new SipRunnable() {
744 @Override
745 protected void doRun() throws SameThreadException, RemoteException {
746 Log.i(TAG, "SipService.joinConference() thread running...");
747 callManagerJNI.joinConference(sel_confID, drag_confID);
748 }
749 });
750
alision7f18fc82013-05-01 09:37:33 -0400751 }
752
753 @Override
alision43a9b362013-05-01 16:30:15 -0400754 public void hangUpConference(final String confID) throws RemoteException {
755 getExecutor().execute(new SipRunnable() {
756 @Override
757 protected void doRun() throws SameThreadException, RemoteException {
758 Log.i(TAG, "SipService.joinConference() thread running...");
759 callManagerJNI.hangUpConference(confID);
760 }
761 });
762
alision7f18fc82013-05-01 09:37:33 -0400763 }
764
765 @Override
alision43a9b362013-05-01 16:30:15 -0400766 public void holdConference(final String confID) throws RemoteException {
767 getExecutor().execute(new SipRunnable() {
768 @Override
769 protected void doRun() throws SameThreadException, RemoteException {
770 Log.i(TAG, "SipService.holdConference() thread running...");
771 callManagerJNI.holdConference(confID);
772 }
773 });
774
alision7f18fc82013-05-01 09:37:33 -0400775 }
776
777 @Override
alision43a9b362013-05-01 16:30:15 -0400778 public void unholdConference(final String confID) throws RemoteException {
779 getExecutor().execute(new SipRunnable() {
780 @Override
781 protected void doRun() throws SameThreadException, RemoteException {
782 Log.i(TAG, "SipService.unholdConference() thread running...");
783 callManagerJNI.unholdConference(confID);
784 }
785 });
786
alision7f18fc82013-05-01 09:37:33 -0400787 }
Alexandre Lision67817192013-07-18 12:04:30 -0400788
alisioncd8fb912013-06-28 14:43:51 -0400789 @Override
790 public boolean isConferenceParticipant(final String callID) throws RemoteException {
791 class IsParticipant extends SipRunnableWithReturn {
792
793 @Override
794 protected Boolean doRun() throws SameThreadException {
795 Log.i(TAG, "SipService.isRecording() thread running...");
796 return callManagerJNI.isConferenceParticipant(callID);
797 }
798 }
799
800 IsParticipant runInstance = new IsParticipant();
801 getExecutor().execute(runInstance);
802 while (!runInstance.isDone()) {
803 }
804
805 return (Boolean) runInstance.getVal();
806 }
alision7f18fc82013-05-01 09:37:33 -0400807
808 @Override
alisiondf1dac92013-06-27 17:35:53 -0400809 public HashMap<String, Conference> getConferenceList() throws RemoteException {
Alexandre Lision67817192013-07-18 12:04:30 -0400810 // class ConfList extends SipRunnableWithReturn {
811 // @Override
812 // protected StringVect doRun() throws SameThreadException {
813 // Log.i(TAG, "SipService.getConferenceList() thread running...");
814 // return callManagerJNI.getConferenceList();
815 // }
816 // }
817 // ;
818 // ConfList runInstance = new ConfList();
819 // getExecutor().execute(runInstance);
820 // while (!runInstance.isDone()) {
821 // // Log.w(TAG, "Waiting for getConferenceList");
822 // }
823 // StringVect swigvect = (StringVect) runInstance.getVal();
824 //
825 // ArrayList<String> nativelist = new ArrayList<String>();
826 //
827 // for (int i = 0; i < swigvect.size(); i++)
828 // nativelist.add(swigvect.get(i));
829 //
830 // return nativelist;
Alexandre Lision945e4612014-01-15 17:40:31 -0500831 return mConferences;
alision7f18fc82013-05-01 09:37:33 -0400832 }
833
834 @Override
alision907bde72013-06-20 14:40:37 -0400835 public List getParticipantList(final String confID) throws RemoteException {
836 class PartList extends SipRunnableWithReturn {
837 @Override
838 protected StringVect doRun() throws SameThreadException {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500839 Log.i(TAG, "SipService.getParticipantList() thread running...");
alision907bde72013-06-20 14:40:37 -0400840 return callManagerJNI.getParticipantList(confID);
841 }
842 }
843 ;
844 PartList runInstance = new PartList();
845 getExecutor().execute(runInstance);
846 while (!runInstance.isDone()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500847 Log.w(TAG, "getParticipantList");
alision907bde72013-06-20 14:40:37 -0400848 }
849 StringVect swigvect = (StringVect) runInstance.getVal();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500850 Log.w(TAG, "After that");
alision907bde72013-06-20 14:40:37 -0400851 ArrayList<String> nativelist = new ArrayList<String>();
852
853 for (int i = 0; i < swigvect.size(); i++)
854 nativelist.add(swigvect.get(i));
855
856 return nativelist;
alision7f18fc82013-05-01 09:37:33 -0400857 }
alision806e18e2013-06-21 15:30:17 -0400858
alision1005ba12013-06-19 13:52:44 -0400859 @Override
alision7f18fc82013-05-01 09:37:33 -0400860 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400861 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400862 return null;
863 }
864
865 @Override
alision806e18e2013-06-21 15:30:17 -0400866 public String getConferenceDetails(final String callID) throws RemoteException {
867 class ConfDetails extends SipRunnableWithReturn {
868 @Override
869 protected StringMap doRun() throws SameThreadException {
870 Log.i(TAG, "SipService.getAccountList() thread running...");
871 return callManagerJNI.getConferenceDetails(callID);
872 }
873 }
874 ;
875 ConfDetails runInstance = new ConfDetails();
876 getExecutor().execute(runInstance);
877 while (!runInstance.isDone()) {
878 // Log.w(TAG, "Waiting for getConferenceList");
879 }
880 StringMap swigvect = (StringMap) runInstance.getVal();
881
882 return swigvect.get("CONF_STATE");
alision7f18fc82013-05-01 09:37:33 -0400883 }
884
alision04a00182013-05-10 17:05:29 -0400885 @Override
886 public String getRecordPath() throws RemoteException {
887 class RecordPath extends SipRunnableWithReturn {
888
889 @Override
890 protected String doRun() throws SameThreadException {
891 Log.i(TAG, "SipService.getRecordPath() thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000892 return configurationManagerJNI.getRecordPath();
alision04a00182013-05-10 17:05:29 -0400893 }
894 }
895
896 RecordPath runInstance = new RecordPath();
897 getExecutor().execute(runInstance);
898 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400899 // Log.w(TAG, "Waiting for getRecordPath");
alision04a00182013-05-10 17:05:29 -0400900 }
901 String path = (String) runInstance.getVal();
902
903 return path;
904 }
905
906 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400907 public boolean toggleRecordingCall(final String id) throws RemoteException {
Adrien Béraud9360f242013-09-19 11:07:42 +1000908
Alexandre Lisiona764c682013-09-09 10:02:07 -0400909 class ToggleRecording extends SipRunnableWithReturn {
910
alision04a00182013-05-10 17:05:29 -0400911 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400912 protected Boolean doRun() throws SameThreadException {
913 Log.i(TAG, "SipService.toggleRecordingCall() thread running...");
Alexandre Lision3874e552013-11-04 17:20:12 -0500914 boolean result = callManagerJNI.toggleRecording(id);
Alexandre Lision35577132013-12-06 15:21:15 -0500915
Alexandre Lision945e4612014-01-15 17:40:31 -0500916 if (getConferences().containsKey(id)) {
917 getConferences().get(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500918 } else {
Alexandre Lision945e4612014-01-15 17:40:31 -0500919 Iterator<Conference> it = getConferences().values().iterator();
Alexandre Lision3874e552013-11-04 17:20:12 -0500920 while (it.hasNext()) {
921 Conference c = it.next();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500922 if (c.getCallById(id) != null)
923 c.getCallById(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500924 }
925 }
926 return result;
alision04a00182013-05-10 17:05:29 -0400927 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400928 }
929
930 ToggleRecording runInstance = new ToggleRecording();
931 getExecutor().execute(runInstance);
932 while (!runInstance.isDone()) {
933 }
934
935 return (Boolean) runInstance.getVal();
alision04a00182013-05-10 17:05:29 -0400936
937 }
Alexandre Lision67817192013-07-18 12:04:30 -0400938
alision50fa0722013-06-25 17:29:44 -0400939 @Override
940 public boolean startRecordedFilePlayback(final String filepath) throws RemoteException {
941 getExecutor().execute(new SipRunnable() {
942 @Override
943 protected void doRun() throws SameThreadException, RemoteException {
944 Log.i(TAG, "SipService.setRecordingCall() thread running...");
945 callManagerJNI.startRecordedFilePlayback(filepath);
946 }
947 });
948 return false;
949 }
950
951 @Override
952 public void stopRecordedFilePlayback(final String filepath) throws RemoteException {
953 getExecutor().execute(new SipRunnable() {
954 @Override
955 protected void doRun() throws SameThreadException, RemoteException {
956 Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running...");
957 callManagerJNI.stopRecordedFilePlayback(filepath);
958 }
959 });
960 }
alision04a00182013-05-10 17:05:29 -0400961
962 @Override
963 public void setRecordPath(final String path) throws RemoteException {
964 getExecutor().execute(new SipRunnable() {
965 @Override
966 protected void doRun() throws SameThreadException, RemoteException {
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400967 Log.i(TAG, "SipService.setRecordPath() " + path + " thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000968 configurationManagerJNI.setRecordPath(path);
alision04a00182013-05-10 17:05:29 -0400969 }
970 });
971 }
972
973 @Override
Alexandre Lisiond5686032013-10-29 11:09:21 -0400974 public void sendTextMessage(final String callID, final SipMessage message) throws RemoteException {
alision04a00182013-05-10 17:05:29 -0400975 getExecutor().execute(new SipRunnable() {
976 @Override
977 protected void doRun() throws SameThreadException, RemoteException {
978 Log.i(TAG, "SipService.sendTextMessage() thread running...");
Alexandre Lisiond5686032013-10-29 11:09:21 -0400979 callManagerJNI.sendTextMessage(callID, message.comment);
Alexandre Lision945e4612014-01-15 17:40:31 -0500980 if (getConferences().get(callID) != null)
981 getConferences().get(callID).addSipMessage(message);
alision04a00182013-05-10 17:05:29 -0400982 }
983 });
984
985 }
986
alisiond295ec22013-05-17 10:12:13 -0400987 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400988 public List getAudioCodecList(final String accountID) throws RemoteException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -0400989 class AudioCodecList extends SipRunnableWithReturn {
990
991 @Override
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400992 protected ArrayList<Codec> doRun() throws SameThreadException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -0400993 Log.i(TAG, "SipService.getAudioCodecList() thread running...");
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400994 ArrayList<Codec> results = new ArrayList<Codec>();
Alexandre Lision4cf78702013-10-16 13:43:23 -0400995
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400996 IntVect active_payloads = configurationManagerJNI.getActiveAudioCodecList(accountID);
997 for (int i = 0; i < active_payloads.size(); ++i) {
998
Alexandre Lision039a3cf2013-10-16 17:44:57 -0400999 results.add(new Codec(active_payloads.get(i), configurationManagerJNI.getAudioCodecDetails(active_payloads.get(i)), true));
Alexandre Lisione0045442013-10-25 09:16:19 -04001000
Alexandre Lision4cf78702013-10-16 13:43:23 -04001001 }
Alexandre Lision039a3cf2013-10-16 17:44:57 -04001002 IntVect payloads = configurationManagerJNI.getAudioCodecList();
1003
1004 for (int i = 0; i < payloads.size(); ++i) {
1005 boolean isActive = false;
1006 for (Codec co : results) {
1007 if (co.getPayload().toString().contentEquals(String.valueOf(payloads.get(i))))
1008 isActive = true;
1009
1010 }
1011 if (isActive)
1012 continue;
1013 else
1014 results.add(new Codec(payloads.get(i), configurationManagerJNI.getAudioCodecDetails(payloads.get(i)), false));
1015
1016 }
1017
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001018 return results;
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001019 }
1020 }
1021
1022 AudioCodecList runInstance = new AudioCodecList();
1023 getExecutor().execute(runInstance);
1024 while (!runInstance.isDone()) {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001025 }
Alexandre Lision933ef0a2013-10-15 17:28:40 -04001026 ArrayList<Codec> codecs = (ArrayList<Codec>) runInstance.getVal();
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001027 return codecs;
alisiond295ec22013-05-17 10:12:13 -04001028 }
1029
alision9f7a6ec2013-05-24 16:26:26 -04001030 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -04001031 public Map getRingtoneList() throws RemoteException {
1032 class RingtoneList extends SipRunnableWithReturn {
1033
1034 @Override
1035 protected StringMap doRun() throws SameThreadException {
1036 Log.i(TAG, "SipService.getRingtoneList() thread running...");
1037 return configurationManagerJNI.getRingtoneList();
1038 }
1039 }
1040
1041 RingtoneList runInstance = new RingtoneList();
1042 getExecutor().execute(runInstance);
1043 while (!runInstance.isDone()) {
1044 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001045 StringMap ringtones = (StringMap) runInstance.getVal();
1046
1047 for (int i = 0; i < ringtones.size(); ++i) {
1048 // Log.i(TAG,"ringtones "+i+" "+ ringtones.);
1049 }
1050
Alexandre Lision4cf78702013-10-16 13:43:23 -04001051 return null;
1052 }
1053
1054 @Override
1055 public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException {
1056 getExecutor().execute(new SipRunnable() {
1057 @Override
1058 protected void doRun() throws SameThreadException, RemoteException {
1059 Log.i(TAG, "SipService.setActiveAudioCodecList() thread running...");
1060 StringVect list = new StringVect();
1061 for (int i = 0; i < codecs.size(); ++i) {
1062 list.add((String) codecs.get(i));
1063 }
1064 configurationManagerJNI.setActiveAudioCodecList(list, accountID);
1065 }
1066 });
1067 }
1068
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001069/* @Override
1070 public Conference getCallById(String callID) throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001071 if(mConferences.containsKey(callID))
1072 return mConferences.get(callID);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001073 else{
Alexandre Lision945e4612014-01-15 17:40:31 -05001074 Iterator<Conference> it = getConferences().values().iterator();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001075 while (it.hasNext()) {
1076 Conference c = it.next();
1077 if (c.getCallById(callID) != null)
1078 return c;
1079 }
1080 }
1081 return null;
1082 }*/
alision2cb99562013-05-30 17:02:20 -04001083
1084 /***********************
1085 * Notification API
1086 ***********************/
1087 @Override
1088 public void createNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001089
alision2cb99562013-05-30 17:02:20 -04001090 }
1091
1092 @Override
1093 public void destroyNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001094
alision2cb99562013-05-30 17:02:20 -04001095 }
alisioncc7bb422013-06-06 15:31:39 -04001096
alisiondf1dac92013-06-27 17:35:53 -04001097 @Override
1098 public Conference getCurrentCall() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001099 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001100 if (conf.isIncoming())
1101 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001102 }
Alexandre Lision67817192013-07-18 12:04:30 -04001103
Alexandre Lision945e4612014-01-15 17:40:31 -05001104 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001105 if (conf.isOnGoing())
1106 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001107 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001108
alisiondf1dac92013-06-27 17:35:53 -04001109 return null;
1110 }
1111
Alexandre Lision64dc8c02013-09-25 15:32:25 -04001112 @Override
1113 public void playDtmf(final String key) throws RemoteException {
1114 getExecutor().execute(new SipRunnable() {
1115 @Override
1116 protected void doRun() throws SameThreadException, RemoteException {
1117 Log.i(TAG, "SipService.playDtmf() thread running...");
1118 callManagerJNI.playDTMF(key);
1119 }
1120 });
1121 }
1122
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001123 @Override
1124 public List getConcurrentCalls() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001125 return new ArrayList(mConferences.values());
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001126 }
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001127
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001128 @Override
1129 public Conference getConference(String id) throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001130 return mConferences.get(id);
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001131 }
1132
Alexandre Lision4fb22622013-10-21 16:26:33 -04001133 @Override
1134 public String getCurrentAudioCodecName(String callID) throws RemoteException {
1135 return callManagerJNI.getCurrentAudioCodecName(callID);
1136 }
1137
Alexandre Lision31e30902013-11-08 15:16:59 -05001138 @Override
1139 public void setMuted(final boolean mute) throws RemoteException {
1140 getExecutor().execute(new SipRunnable() {
1141 @Override
1142 protected void doRun() throws SameThreadException, RemoteException {
1143 Log.i(TAG, "SipService.setMuted() thread running...");
1144 configurationManagerJNI.muteCapture(mute);
1145 }
1146 });
1147 }
1148
1149 @Override
1150 public boolean isCaptureMuted() throws RemoteException {
1151 class IsMuted extends SipRunnableWithReturn {
1152
1153 @Override
1154 protected Boolean doRun() throws SameThreadException {
1155 Log.i(TAG, "SipService.isCaptureMuted() thread running...");
1156 return configurationManagerJNI.isCaptureMuted();
1157 }
1158 }
1159
1160 IsMuted runInstance = new IsMuted();
1161 getExecutor().execute(runInstance);
1162 while (!runInstance.isDone()) {
1163 }
1164
1165 return (Boolean) runInstance.getVal();
1166 }
1167
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001168 @Override
1169 public List getCredentials(final String accountID) throws RemoteException {
1170 class Credentials extends SipRunnableWithReturn {
1171
1172 @Override
1173 protected List doRun() throws SameThreadException {
1174 Log.i(TAG, "SipService.getCredentials() thread running...");
1175 VectMap map = configurationManagerJNI.getCredentials(accountID);
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001176 ArrayList<HashMap<String, String>> result = SwigNativeConverter.convertCredentialsToNative(map);
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001177 return result;
1178 }
1179 }
1180
1181 Credentials runInstance = new Credentials();
1182 getExecutor().execute(runInstance);
1183 while (!runInstance.isDone()) {
1184 }
1185 return (List) runInstance.getVal();
1186 }
1187
1188 @Override
1189 public void setCredentials(final String accountID, final List creds) throws RemoteException {
1190 getExecutor().execute(new SipRunnable() {
1191 @Override
1192 protected void doRun() throws SameThreadException, RemoteException {
1193 Log.i(TAG, "SipService.setCredentials() thread running...");
Alexandre Lision3cefec22013-11-14 17:26:35 -05001194 ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds;
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001195 configurationManagerJNI.setCredentials(accountID, SwigNativeConverter.convertFromNativeToSwig(creds));
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001196 }
1197 });
1198 }
1199
Alexandre Lision3e2a1d02013-11-19 17:23:00 -05001200 @Override
1201 public void registerAllAccounts() throws RemoteException {
1202 getExecutor().execute(new SipRunnable() {
1203 @Override
1204 protected void doRun() throws SameThreadException, RemoteException {
1205 Log.i(TAG, "SipService.registerAllAccounts() thread running...");
1206 configurationManagerJNI.registerAllAccounts();
1207 }
1208 });
1209 }
1210
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001211 @Override
Alexandre Lision35577132013-12-06 15:21:15 -05001212 public void toggleSpeakerPhone(boolean toggle) throws RemoteException {
1213 if (toggle)
Alexandre Lision945e4612014-01-15 17:40:31 -05001214 mMediaManager.RouteToSpeaker();
Alexandre Lision35577132013-12-06 15:21:15 -05001215 else
Alexandre Lision945e4612014-01-15 17:40:31 -05001216 mMediaManager.RouteToInternalSpeaker();
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001217 }
1218
Emeric Vigier6119d782012-09-21 18:04:14 -04001219 };
Alexandre Lision35577132013-12-06 15:21:15 -05001220}