blob: d381b10735c96c8fa588c1eea3585203ce8c15c0 [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
Alexandre Lision5f144b82014-02-11 09:59:36 -0500188 public SipCall getCallById(String callID) {
189 if (getConferences().get(callID) != null) {
190 return getConferences().get(callID).getCallById(callID);
191 } else {
192 // Check if call is in a conference
193 Iterator<Map.Entry<String, Conference>> it = getConferences().entrySet().iterator();
194 while (it.hasNext()) {
195 Conference tmp = it.next().getValue();
196 SipCall c = tmp.getCallById(callID);
197 if(c != null)
198 return c;
199 }
200 }
201 return null;
202 }
203
alision43a9b362013-05-01 16:30:15 -0400204 // Executes immediate tasks in a single executorThread.
205 public static class SipServiceExecutor extends Handler {
alision43a9b362013-05-01 16:30:15 -0400206
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500207 SipServiceExecutor() {
alision43a9b362013-05-01 16:30:15 -0400208 super(createLooper());
alision43a9b362013-05-01 16:30:15 -0400209 }
210
211 public void execute(Runnable task) {
212 // TODO: add wakelock
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500213 Message.obtain(SipServiceExecutor.this, 0/* don't care */, task).sendToTarget();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400214 Log.w(TAG, "SenT!");
alision43a9b362013-05-01 16:30:15 -0400215 }
216
217 @Override
218 public void handleMessage(Message msg) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500219 Log.w(TAG, "handleMessage");
alision43a9b362013-05-01 16:30:15 -0400220 if (msg.obj instanceof Runnable) {
221 executeInternal((Runnable) msg.obj);
222 } else {
223 Log.w(TAG, "can't handle msg: " + msg);
224 }
225 }
226
227 private void executeInternal(Runnable task) {
228 try {
229 task.run();
230 } catch (Throwable t) {
231 Log.e(TAG, "run task: " + task, t);
232 }
233 }
234 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400235
236 private void stopDaemon() {
237 if (managerImpl != null) {
238 managerImpl.finish();
239 isPjSipStackStarted = false;
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400240 }
241 }
alision43a9b362013-05-01 16:30:15 -0400242
243 private void startPjSipStack() throws SameThreadException {
244 if (isPjSipStackStarted)
245 return;
246
247 try {
248 System.loadLibrary("gnustl_shared");
alision43a9b362013-05-01 16:30:15 -0400249 System.loadLibrary("crypto");
250 System.loadLibrary("ssl");
alision43a9b362013-05-01 16:30:15 -0400251 System.loadLibrary("sflphone");
252 isPjSipStackStarted = true;
Adrien Béraud9360f242013-09-19 11:07:42 +1000253
alision43a9b362013-05-01 16:30:15 -0400254 } catch (UnsatisfiedLinkError e) {
255 Log.e(TAG, "Problem with the current Pj stack...", e);
256 isPjSipStackStarted = false;
257 return;
258 } catch (Exception e) {
259 Log.e(TAG, "Problem with the current Pj stack...", e);
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400260 isPjSipStackStarted = false;
alision43a9b362013-05-01 16:30:15 -0400261 }
262
Alexandre Lision67817192013-07-18 12:04:30 -0400263 Log.i(TAG, "PjSIPStack started");
264 managerImpl = SFLPhoneservice.instance();
265
266 /* set static AppPath before calling manager.init */
Alexandre Lision63870a72013-10-28 16:33:47 -0400267 // managerImpl.setPath(getApplication().getFilesDir().getAbsolutePath());
alision43a9b362013-05-01 16:30:15 -0400268
alision3ea8f3c2013-07-16 17:35:35 -0400269 callManagerJNI = new CallManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500270 callManagerCallBack = new CallManagerCallBack(this);
alision43a9b362013-05-01 16:30:15 -0400271 SFLPhoneservice.setCallbackObject(callManagerCallBack);
272
alision3ea8f3c2013-07-16 17:35:35 -0400273 configurationManagerJNI = new ConfigurationManager();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500274 configurationManagerCallback = new ConfigurationManagerCallback(this);
alision43a9b362013-05-01 16:30:15 -0400275 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
Alexandre Lision67817192013-07-18 12:04:30 -0400276 managerImpl.init("");
Adrien Béraud9360f242013-09-19 11:07:42 +1000277
Alexandre Lision67817192013-07-18 12:04:30 -0400278 Log.i(TAG, "->startPjSipStack");
alision43a9b362013-05-01 16:30:15 -0400279 }
280
281 // Enforce same thread contract to ensure we do not call from somewhere else
282 public class SameThreadException extends Exception {
283 private static final long serialVersionUID = -905639124232613768L;
284
285 public SameThreadException() {
286 super("Should be launched from a single worker thread");
287 }
288 }
289
290 public abstract static class SipRunnable implements Runnable {
291 protected abstract void doRun() throws SameThreadException, RemoteException;
292
Adrien Béraud9360f242013-09-19 11:07:42 +1000293 @Override
alision43a9b362013-05-01 16:30:15 -0400294 public void run() {
295 try {
296 doRun();
297 } catch (SameThreadException e) {
298 Log.e(TAG, "Not done from same thread");
299 } catch (RemoteException e) {
300 Log.e(TAG, e.toString());
301 }
302 }
303 }
304
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400305 public abstract class SipRunnableWithReturn implements Runnable {
alision43a9b362013-05-01 16:30:15 -0400306 Object obj = null;
307 boolean done = false;
308
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500309 protected abstract Object doRun() throws SameThreadException, RemoteException;
alision43a9b362013-05-01 16:30:15 -0400310
311 public Object getVal() {
312 return obj;
313 }
314
315 public boolean isDone() {
316 return done;
317 }
318
Adrien Béraud9360f242013-09-19 11:07:42 +1000319 @Override
alision43a9b362013-05-01 16:30:15 -0400320 public void run() {
321 try {
Alexandre Lision35577132013-12-06 15:21:15 -0500322 if (isPjSipStackStarted)
Alexandre Lisionfab23f82013-11-01 11:22:30 -0400323 obj = doRun();
alision43a9b362013-05-01 16:30:15 -0400324 done = true;
325 } catch (SameThreadException e) {
326 Log.e(TAG, "Not done from same thread");
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500327 } catch (RemoteException e) {
328 Log.e(TAG, e.toString());
alision43a9b362013-05-01 16:30:15 -0400329 }
330 }
331 }
332
333 class StartRunnable extends SipRunnable {
334 @Override
335 protected void doRun() throws SameThreadException {
336 startPjSipStack();
337 }
338 }
Alexandre Lision63870a72013-10-28 16:33:47 -0400339
Alexandre Lisiondd68f652013-10-28 11:00:12 -0400340 class FinalizeRunnable extends SipRunnable {
341 @Override
342 protected void doRun() throws SameThreadException {
343 stopDaemon();
344 }
345 }
alision43a9b362013-05-01 16:30:15 -0400346
alision43a9b362013-05-01 16:30:15 -0400347 /* ************************************
348 *
349 * Implement public interface for the service
350 *
Alexandre Lision67817192013-07-18 12:04:30 -0400351 * *********************************
352 */
353
Emeric Vigier6119d782012-09-21 18:04:14 -0400354 private final ISipService.Stub mBinder = new ISipService.Stub() {
355
356 @Override
alisionfde875f2013-05-28 17:01:54 -0400357 public void placeCall(final SipCall call) {
Emeric Vigier6119d782012-09-21 18:04:14 -0400358 getExecutor().execute(new SipRunnable() {
359 @Override
360 protected void doRun() throws SameThreadException {
361 Log.i(TAG, "SipService.placeCall() thread running...");
Alexandre Lision3ee516e2013-10-07 17:32:15 -0400362 callManagerJNI.placeCall(call.getAccount().getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber());
Adrien Béraud9360f242013-09-19 11:07:42 +1000363
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500364 HashMap<String, String> details = SwigNativeConverter.convertCallDetailsToNative(callManagerJNI.getCallDetails(call.getCallId()));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400365 // watchout timestamp stored by sflphone is in seconds
Alexandre Lision945e4612014-01-15 17:40:31 -0500366 call.setTimestampStart_(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START)));
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500367 Conference toAdd = new Conference(call);
Alexandre Lision945e4612014-01-15 17:40:31 -0500368 mConferences.put(toAdd.getId(), toAdd);
369 mMediaManager.obtainAudioFocus(false);
Emeric Vigier6119d782012-09-21 18:04:14 -0400370 }
371 });
372 }
373
374 @Override
375 public void refuse(final String callID) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500376
Emeric Vigier6119d782012-09-21 18:04:14 -0400377 getExecutor().execute(new SipRunnable() {
378 @Override
379 protected void doRun() throws SameThreadException {
380 Log.i(TAG, "SipService.refuse() thread running...");
381 callManagerJNI.refuse(callID);
382 }
383 });
384 }
385
386 @Override
387 public void accept(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500388 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400389 getExecutor().execute(new SipRunnable() {
390 @Override
391 protected void doRun() throws SameThreadException {
Tristan Matthews40cf25e2013-07-24 13:45:15 -0400392 Log.i(TAG, "SipService.accept() thread running...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400393 callManagerJNI.accept(callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500394 mMediaManager.RouteToInternalSpeaker();
Emeric Vigier6119d782012-09-21 18:04:14 -0400395 }
396 });
397 }
398
399 @Override
400 public void hangUp(final String callID) {
Alexandre Lision945e4612014-01-15 17:40:31 -0500401 mMediaManager.stopRing();
Emeric Vigier6119d782012-09-21 18:04:14 -0400402 getExecutor().execute(new SipRunnable() {
403 @Override
404 protected void doRun() throws SameThreadException {
405 Log.i(TAG, "SipService.hangUp() thread running...");
406 callManagerJNI.hangUp(callID);
Alexandre Lision183bf452014-01-17 11:21:59 -0500407 if(mConferences.size() == 0)
408 mMediaManager.abandonAudioFocus();
Emeric Vigier6119d782012-09-21 18:04:14 -0400409 }
410 });
411 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400412
413 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400414 public void hold(final String callID) {
415 getExecutor().execute(new SipRunnable() {
416 @Override
417 protected void doRun() throws SameThreadException {
418 Log.i(TAG, "SipService.hold() thread running...");
419 callManagerJNI.hold(callID);
420 }
421 });
422 }
423
424 @Override
425 public void unhold(final String callID) {
426 getExecutor().execute(new SipRunnable() {
427 @Override
428 protected void doRun() throws SameThreadException {
429 Log.i(TAG, "SipService.unhold() thread running...");
430 callManagerJNI.unhold(callID);
431 }
432 });
433 }
Adrien Béraud9360f242013-09-19 11:07:42 +1000434
Alexandre Lision6711ab22013-09-16 15:15:38 -0400435 @Override
436 public HashMap<String, String> getCallDetails(String callID) throws RemoteException {
437 class CallDetails extends SipRunnableWithReturn {
438 private String id;
439
440 CallDetails(String callID) {
441 id = callID;
442 }
443
444 @Override
445 protected StringMap doRun() throws SameThreadException {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400446 Log.i(TAG, "SipService.getCallDetails() thread running...");
Alexandre Lision6711ab22013-09-16 15:15:38 -0400447 return callManagerJNI.getCallDetails(id);
448 }
449 }
450
451 CallDetails runInstance = new CallDetails(callID);
452 getExecutor().execute(runInstance);
453
454 while (!runInstance.isDone()) {
455 }
456 StringMap swigmap = (StringMap) runInstance.getVal();
457
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500458 HashMap<String, String> nativemap = SwigNativeConverter.convertCallDetailsToNative(swigmap);
Alexandre Lision6711ab22013-09-16 15:15:38 -0400459
460 return nativemap;
Adrien Béraud9360f242013-09-19 11:07:42 +1000461
Alexandre Lision6711ab22013-09-16 15:15:38 -0400462 }
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400463
464 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400465 public void setAudioPlugin(final String audioPlugin) {
466 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400467 @Override
468 protected void doRun() throws SameThreadException {
469 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
470 configurationManagerJNI.setAudioPlugin(audioPlugin);
471 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400472 });
473 }
474
475 @Override
476 public String getCurrentAudioOutputPlugin() {
477 class CurrentAudioPlugin extends SipRunnableWithReturn {
478 @Override
479 protected String doRun() throws SameThreadException {
480 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
481 return configurationManagerJNI.getCurrentAudioOutputPlugin();
482 }
alision371b77e2013-04-23 14:51:26 -0400483 }
484 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400485
486 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
487 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400488 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400489 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400490 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400491 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400492 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400493
494 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400495 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400496 class AccountList extends SipRunnableWithReturn {
497 @Override
498 protected StringVect doRun() throws SameThreadException {
499 Log.i(TAG, "SipService.getAccountList() thread running...");
500 return configurationManagerJNI.getAccountList();
501 }
alision371b77e2013-04-23 14:51:26 -0400502 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400503 AccountList runInstance = new AccountList();
Alexandre Lisioncdec5952013-07-17 14:18:22 -0400504 Log.i(TAG, "SipService.getAccountList() thread running...");
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400505 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 Savard7a2b2202012-10-04 17:07:33 -0400509 StringVect swigvect = (StringVect) runInstance.getVal();
510
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400511 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400512
alision371b77e2013-04-23 14:51:26 -0400513 for (int i = 0; i < swigvect.size(); i++)
514 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400515
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400516 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400517 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400518
Alexandre Lision4cf78702013-10-16 13:43:23 -0400519 @Override
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400520 public void setAccountOrder(final String order) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400521 getExecutor().execute(new SipRunnable() {
522 @Override
523 protected void doRun() throws SameThreadException {
524 Log.i(TAG, "SipService.setAccountsOrder() thread running...");
525 configurationManagerJNI.setAccountsOrder(order);
526 }
527 });
528 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400529
530 @Override
alision371b77e2013-04-23 14:51:26 -0400531 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400532 class AccountDetails extends SipRunnableWithReturn {
533 private String id;
alision371b77e2013-04-23 14:51:26 -0400534
535 AccountDetails(String accountId) {
536 id = accountId;
537 }
538
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400539 @Override
540 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400541 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400542 return configurationManagerJNI.getAccountDetails(id);
543 }
alision371b77e2013-04-23 14:51:26 -0400544 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400545
546 AccountDetails runInstance = new AccountDetails(accountID);
547 getExecutor().execute(runInstance);
alisionfde875f2013-05-28 17:01:54 -0400548
alision371b77e2013-04-23 14:51:26 -0400549 while (!runInstance.isDone()) {
550 }
551 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400552
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500553 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400554
555 return nativemap;
556 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400557
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400558 @SuppressWarnings("unchecked")
559 // Hashmap runtime cast
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400560 @Override
alisioncc7bb422013-06-06 15:31:39 -0400561 public void setAccountDetails(final String accountId, final Map map) {
alision371b77e2013-04-23 14:51:26 -0400562 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400563
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500564 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400565
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400566 getExecutor().execute(new SipRunnable() {
567 @Override
568 protected void doRun() throws SameThreadException {
alisioncc7bb422013-06-06 15:31:39 -0400569
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400570 configurationManagerJNI.setAccountDetails(accountId, swigmap);
alisioncc7bb422013-06-06 15:31:39 -0400571 Log.i(TAG, "SipService.setAccountDetails() thread running...");
572 }
573
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400574 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400575 }
576
Alexandre Lision451f2a82013-11-12 12:55:55 -0500577 @Override
578 public Map getAccountTemplate() throws RemoteException {
579 class AccountTemplate extends SipRunnableWithReturn {
580
581 @Override
582 protected StringMap doRun() throws SameThreadException {
583 Log.i(TAG, "SipService.getAccountTemplate() thread running...");
584 return configurationManagerJNI.getAccountTemplate();
585 }
586 }
587
588 AccountTemplate runInstance = new AccountTemplate();
589 getExecutor().execute(runInstance);
590
591 while (!runInstance.isDone()) {
592 }
593 StringMap swigmap = (StringMap) runInstance.getVal();
594
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500595 HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap);
Alexandre Lision451f2a82013-11-12 12:55:55 -0500596
597 return nativemap;
598 }
alisioncc7bb422013-06-06 15:31:39 -0400599
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400600 @SuppressWarnings("unchecked")
601 // Hashmap runtime cast
Alexandre Savard46036572012-10-05 13:56:49 -0400602 @Override
603 public String addAccount(Map map) {
604 class AddAccount extends SipRunnableWithReturn {
605 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400606
607 AddAccount(StringMap m) {
608 map = m;
609 }
610
Alexandre Savard46036572012-10-05 13:56:49 -0400611 @Override
612 protected String doRun() throws SameThreadException {
613 Log.i(TAG, "SipService.getAccountDetails() thread running...");
614 return configurationManagerJNI.addAccount(map);
615 }
alision371b77e2013-04-23 14:51:26 -0400616 }
Alexandre Savard46036572012-10-05 13:56:49 -0400617
Alexandre Lision2aae48d2013-12-04 13:50:38 -0500618 final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400619
620 AddAccount runInstance = new AddAccount(swigmap);
621 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400622 while (!runInstance.isDone()) {
623 }
Alexandre Savard46036572012-10-05 13:56:49 -0400624 String accountId = (String) runInstance.getVal();
625
626 return accountId;
627 }
628
629 @Override
630 public void removeAccount(final String accountId) {
631 getExecutor().execute(new SipRunnable() {
632 @Override
633 protected void doRun() throws SameThreadException {
634 Log.i(TAG, "SipService.setAccountDetails() thread running...");
635 configurationManagerJNI.removeAccount(accountId);
636 }
637 });
638 }
alision5f899632013-04-22 17:26:56 -0400639
alision43a9b362013-05-01 16:30:15 -0400640 /*************************
641 * Transfer related API
642 *************************/
643
alision7f18fc82013-05-01 09:37:33 -0400644 @Override
645 public void transfer(final String callID, final String to) throws RemoteException {
646 getExecutor().execute(new SipRunnable() {
647 @Override
648 protected void doRun() throws SameThreadException, RemoteException {
649 Log.i(TAG, "SipService.transfer() thread running...");
650 if (callManagerJNI.transfer(callID, to)) {
651 Bundle bundle = new Bundle();
652 bundle.putString("CallID", callID);
653 bundle.putString("State", "HUNGUP");
654 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400655 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
alision84813a12013-05-27 17:40:39 -0400656 sendBroadcast(intent);
alision7f18fc82013-05-01 09:37:33 -0400657 } else
658 Log.i(TAG, "NOT OK");
659 }
660 });
661
662 }
alision43a9b362013-05-01 16:30:15 -0400663
alision7f18fc82013-05-01 09:37:33 -0400664 @Override
665 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
666 getExecutor().execute(new SipRunnable() {
667 @Override
668 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400669 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400670 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
671 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400672 } else
673 Log.i(TAG, "NOT OK");
674 }
675 });
alision43a9b362013-05-01 16:30:15 -0400676
677 }
678
679 /*************************
680 * Conference related API
681 *************************/
682
683 @Override
684 public void removeConference(final String confID) throws RemoteException {
685 getExecutor().execute(new SipRunnable() {
686 @Override
687 protected void doRun() throws SameThreadException, RemoteException {
688 Log.i(TAG, "SipService.createConference() thread running...");
689 callManagerJNI.removeConference(confID);
690 }
691 });
692
alision7f18fc82013-05-01 09:37:33 -0400693 }
694
695 @Override
alision43a9b362013-05-01 16:30:15 -0400696 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
697 getExecutor().execute(new SipRunnable() {
698 @Override
699 protected void doRun() throws SameThreadException, RemoteException {
700 Log.i(TAG, "SipService.joinParticipant() thread running...");
701 callManagerJNI.joinParticipant(sel_callID, drag_callID);
alision806e18e2013-06-21 15:30:17 -0400702 // Generate a CONF_CREATED callback
alision43a9b362013-05-01 16:30:15 -0400703 }
704 });
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500705 Log.i(TAG, "After joining participants");
alision7f18fc82013-05-01 09:37:33 -0400706 }
707
alision7f18fc82013-05-01 09:37:33 -0400708 @Override
alision806e18e2013-06-21 15:30:17 -0400709 public void addParticipant(final SipCall call, final String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400710 getExecutor().execute(new SipRunnable() {
711 @Override
712 protected void doRun() throws SameThreadException, RemoteException {
713 Log.i(TAG, "SipService.addParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400714 callManagerJNI.addParticipant(call.getCallId(), confID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500715 mConferences.get(confID).getParticipants().add(call);
alision43a9b362013-05-01 16:30:15 -0400716 }
717 });
718
alision7f18fc82013-05-01 09:37:33 -0400719 }
720
721 @Override
alision43a9b362013-05-01 16:30:15 -0400722 public void addMainParticipant(final String confID) throws RemoteException {
723 getExecutor().execute(new SipRunnable() {
724 @Override
725 protected void doRun() throws SameThreadException, RemoteException {
726 Log.i(TAG, "SipService.addMainParticipant() thread running...");
727 callManagerJNI.addMainParticipant(confID);
728 }
729 });
730
alision7f18fc82013-05-01 09:37:33 -0400731 }
732
733 @Override
alision43a9b362013-05-01 16:30:15 -0400734 public void detachParticipant(final String callID) throws RemoteException {
735 getExecutor().execute(new SipRunnable() {
736 @Override
737 protected void doRun() throws SameThreadException, RemoteException {
738 Log.i(TAG, "SipService.detachParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400739 Log.i(TAG, "Detaching " + callID);
Alexandre Lision945e4612014-01-15 17:40:31 -0500740 Iterator<Entry<String, Conference>> it = mConferences.entrySet().iterator();
741 Log.i(TAG, "mConferences size " + mConferences.size());
alision806e18e2013-06-21 15:30:17 -0400742 while (it.hasNext()) {
743 Conference tmp = it.next().getValue();
744 Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants");
745 if (tmp.contains(callID)) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500746 Conference toDetach = new Conference(tmp.getCallById(callID));
Alexandre Lision945e4612014-01-15 17:40:31 -0500747 mConferences.put(toDetach.getId(), toDetach);
alision806e18e2013-06-21 15:30:17 -0400748 Log.i(TAG, "Call found and put in current_calls");
749 }
750 }
alision43a9b362013-05-01 16:30:15 -0400751 callManagerJNI.detachParticipant(callID);
752 }
753 });
754
alision7f18fc82013-05-01 09:37:33 -0400755 }
756
757 @Override
alision43a9b362013-05-01 16:30:15 -0400758 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
759 getExecutor().execute(new SipRunnable() {
760 @Override
761 protected void doRun() throws SameThreadException, RemoteException {
762 Log.i(TAG, "SipService.joinConference() thread running...");
763 callManagerJNI.joinConference(sel_confID, drag_confID);
764 }
765 });
766
alision7f18fc82013-05-01 09:37:33 -0400767 }
768
769 @Override
alision43a9b362013-05-01 16:30:15 -0400770 public void hangUpConference(final String confID) throws RemoteException {
771 getExecutor().execute(new SipRunnable() {
772 @Override
773 protected void doRun() throws SameThreadException, RemoteException {
774 Log.i(TAG, "SipService.joinConference() thread running...");
775 callManagerJNI.hangUpConference(confID);
776 }
777 });
778
alision7f18fc82013-05-01 09:37:33 -0400779 }
780
781 @Override
alision43a9b362013-05-01 16:30:15 -0400782 public void holdConference(final String confID) throws RemoteException {
783 getExecutor().execute(new SipRunnable() {
784 @Override
785 protected void doRun() throws SameThreadException, RemoteException {
786 Log.i(TAG, "SipService.holdConference() thread running...");
787 callManagerJNI.holdConference(confID);
788 }
789 });
790
alision7f18fc82013-05-01 09:37:33 -0400791 }
792
793 @Override
alision43a9b362013-05-01 16:30:15 -0400794 public void unholdConference(final String confID) throws RemoteException {
795 getExecutor().execute(new SipRunnable() {
796 @Override
797 protected void doRun() throws SameThreadException, RemoteException {
798 Log.i(TAG, "SipService.unholdConference() thread running...");
799 callManagerJNI.unholdConference(confID);
800 }
801 });
802
alision7f18fc82013-05-01 09:37:33 -0400803 }
Alexandre Lision67817192013-07-18 12:04:30 -0400804
alisioncd8fb912013-06-28 14:43:51 -0400805 @Override
806 public boolean isConferenceParticipant(final String callID) throws RemoteException {
807 class IsParticipant extends SipRunnableWithReturn {
808
809 @Override
810 protected Boolean doRun() throws SameThreadException {
811 Log.i(TAG, "SipService.isRecording() thread running...");
812 return callManagerJNI.isConferenceParticipant(callID);
813 }
814 }
815
816 IsParticipant runInstance = new IsParticipant();
817 getExecutor().execute(runInstance);
818 while (!runInstance.isDone()) {
819 }
820
821 return (Boolean) runInstance.getVal();
822 }
alision7f18fc82013-05-01 09:37:33 -0400823
824 @Override
alisiondf1dac92013-06-27 17:35:53 -0400825 public HashMap<String, Conference> getConferenceList() throws RemoteException {
Alexandre Lision67817192013-07-18 12:04:30 -0400826 // class ConfList extends SipRunnableWithReturn {
827 // @Override
828 // protected StringVect doRun() throws SameThreadException {
829 // Log.i(TAG, "SipService.getConferenceList() thread running...");
830 // return callManagerJNI.getConferenceList();
831 // }
832 // }
833 // ;
834 // ConfList runInstance = new ConfList();
835 // getExecutor().execute(runInstance);
836 // while (!runInstance.isDone()) {
837 // // Log.w(TAG, "Waiting for getConferenceList");
838 // }
839 // StringVect swigvect = (StringVect) runInstance.getVal();
840 //
841 // ArrayList<String> nativelist = new ArrayList<String>();
842 //
843 // for (int i = 0; i < swigvect.size(); i++)
844 // nativelist.add(swigvect.get(i));
845 //
846 // return nativelist;
Alexandre Lision945e4612014-01-15 17:40:31 -0500847 return mConferences;
alision7f18fc82013-05-01 09:37:33 -0400848 }
849
850 @Override
alision907bde72013-06-20 14:40:37 -0400851 public List getParticipantList(final String confID) throws RemoteException {
852 class PartList extends SipRunnableWithReturn {
853 @Override
854 protected StringVect doRun() throws SameThreadException {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500855 Log.i(TAG, "SipService.getParticipantList() thread running...");
alision907bde72013-06-20 14:40:37 -0400856 return callManagerJNI.getParticipantList(confID);
857 }
858 }
859 ;
860 PartList runInstance = new PartList();
861 getExecutor().execute(runInstance);
862 while (!runInstance.isDone()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500863 Log.w(TAG, "getParticipantList");
alision907bde72013-06-20 14:40:37 -0400864 }
865 StringVect swigvect = (StringVect) runInstance.getVal();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500866 Log.w(TAG, "After that");
alision907bde72013-06-20 14:40:37 -0400867 ArrayList<String> nativelist = new ArrayList<String>();
868
869 for (int i = 0; i < swigvect.size(); i++)
870 nativelist.add(swigvect.get(i));
871
872 return nativelist;
alision7f18fc82013-05-01 09:37:33 -0400873 }
alision806e18e2013-06-21 15:30:17 -0400874
alision1005ba12013-06-19 13:52:44 -0400875 @Override
alision7f18fc82013-05-01 09:37:33 -0400876 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400877 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400878 return null;
879 }
880
881 @Override
alision806e18e2013-06-21 15:30:17 -0400882 public String getConferenceDetails(final String callID) throws RemoteException {
883 class ConfDetails extends SipRunnableWithReturn {
884 @Override
885 protected StringMap doRun() throws SameThreadException {
886 Log.i(TAG, "SipService.getAccountList() thread running...");
887 return callManagerJNI.getConferenceDetails(callID);
888 }
889 }
890 ;
891 ConfDetails runInstance = new ConfDetails();
892 getExecutor().execute(runInstance);
893 while (!runInstance.isDone()) {
894 // Log.w(TAG, "Waiting for getConferenceList");
895 }
896 StringMap swigvect = (StringMap) runInstance.getVal();
897
898 return swigvect.get("CONF_STATE");
alision7f18fc82013-05-01 09:37:33 -0400899 }
900
alision04a00182013-05-10 17:05:29 -0400901 @Override
902 public String getRecordPath() throws RemoteException {
903 class RecordPath extends SipRunnableWithReturn {
904
905 @Override
906 protected String doRun() throws SameThreadException {
907 Log.i(TAG, "SipService.getRecordPath() thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000908 return configurationManagerJNI.getRecordPath();
alision04a00182013-05-10 17:05:29 -0400909 }
910 }
911
912 RecordPath runInstance = new RecordPath();
913 getExecutor().execute(runInstance);
914 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400915 // Log.w(TAG, "Waiting for getRecordPath");
alision04a00182013-05-10 17:05:29 -0400916 }
917 String path = (String) runInstance.getVal();
918
919 return path;
920 }
921
922 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400923 public boolean toggleRecordingCall(final String id) throws RemoteException {
Adrien Béraud9360f242013-09-19 11:07:42 +1000924
Alexandre Lisiona764c682013-09-09 10:02:07 -0400925 class ToggleRecording extends SipRunnableWithReturn {
926
alision04a00182013-05-10 17:05:29 -0400927 @Override
Alexandre Lisiona764c682013-09-09 10:02:07 -0400928 protected Boolean doRun() throws SameThreadException {
929 Log.i(TAG, "SipService.toggleRecordingCall() thread running...");
Alexandre Lision3874e552013-11-04 17:20:12 -0500930 boolean result = callManagerJNI.toggleRecording(id);
Alexandre Lision35577132013-12-06 15:21:15 -0500931
Alexandre Lision945e4612014-01-15 17:40:31 -0500932 if (getConferences().containsKey(id)) {
933 getConferences().get(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500934 } else {
Alexandre Lision945e4612014-01-15 17:40:31 -0500935 Iterator<Conference> it = getConferences().values().iterator();
Alexandre Lision3874e552013-11-04 17:20:12 -0500936 while (it.hasNext()) {
937 Conference c = it.next();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500938 if (c.getCallById(id) != null)
939 c.getCallById(id).setRecording(result);
Alexandre Lision3874e552013-11-04 17:20:12 -0500940 }
941 }
942 return result;
alision04a00182013-05-10 17:05:29 -0400943 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400944 }
945
946 ToggleRecording runInstance = new ToggleRecording();
947 getExecutor().execute(runInstance);
948 while (!runInstance.isDone()) {
949 }
950
951 return (Boolean) runInstance.getVal();
alision04a00182013-05-10 17:05:29 -0400952
953 }
Alexandre Lision67817192013-07-18 12:04:30 -0400954
alision50fa0722013-06-25 17:29:44 -0400955 @Override
956 public boolean startRecordedFilePlayback(final String filepath) throws RemoteException {
957 getExecutor().execute(new SipRunnable() {
958 @Override
959 protected void doRun() throws SameThreadException, RemoteException {
960 Log.i(TAG, "SipService.setRecordingCall() thread running...");
961 callManagerJNI.startRecordedFilePlayback(filepath);
962 }
963 });
964 return false;
965 }
966
967 @Override
968 public void stopRecordedFilePlayback(final String filepath) throws RemoteException {
969 getExecutor().execute(new SipRunnable() {
970 @Override
971 protected void doRun() throws SameThreadException, RemoteException {
972 Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running...");
973 callManagerJNI.stopRecordedFilePlayback(filepath);
974 }
975 });
976 }
alision04a00182013-05-10 17:05:29 -0400977
978 @Override
979 public void setRecordPath(final String path) throws RemoteException {
980 getExecutor().execute(new SipRunnable() {
981 @Override
982 protected void doRun() throws SameThreadException, RemoteException {
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400983 Log.i(TAG, "SipService.setRecordPath() " + path + " thread running...");
Adrien Béraud9360f242013-09-19 11:07:42 +1000984 configurationManagerJNI.setRecordPath(path);
alision04a00182013-05-10 17:05:29 -0400985 }
986 });
987 }
988
989 @Override
Alexandre Lisiond5686032013-10-29 11:09:21 -0400990 public void sendTextMessage(final String callID, final SipMessage message) throws RemoteException {
alision04a00182013-05-10 17:05:29 -0400991 getExecutor().execute(new SipRunnable() {
992 @Override
993 protected void doRun() throws SameThreadException, RemoteException {
994 Log.i(TAG, "SipService.sendTextMessage() thread running...");
Alexandre Lisiond5686032013-10-29 11:09:21 -0400995 callManagerJNI.sendTextMessage(callID, message.comment);
Alexandre Lision945e4612014-01-15 17:40:31 -0500996 if (getConferences().get(callID) != null)
997 getConferences().get(callID).addSipMessage(message);
alision04a00182013-05-10 17:05:29 -0400998 }
999 });
1000
1001 }
1002
alisiond295ec22013-05-17 10:12:13 -04001003 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -04001004 public List getAudioCodecList(final String accountID) throws RemoteException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001005 class AudioCodecList extends SipRunnableWithReturn {
1006
1007 @Override
Alexandre Lision933ef0a2013-10-15 17:28:40 -04001008 protected ArrayList<Codec> doRun() throws SameThreadException {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001009 Log.i(TAG, "SipService.getAudioCodecList() thread running...");
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001010 ArrayList<Codec> results = new ArrayList<Codec>();
Alexandre Lision4cf78702013-10-16 13:43:23 -04001011
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001012 IntVect active_payloads = configurationManagerJNI.getActiveAudioCodecList(accountID);
1013 for (int i = 0; i < active_payloads.size(); ++i) {
1014
Alexandre Lision039a3cf2013-10-16 17:44:57 -04001015 results.add(new Codec(active_payloads.get(i), configurationManagerJNI.getAudioCodecDetails(active_payloads.get(i)), true));
Alexandre Lisione0045442013-10-25 09:16:19 -04001016
Alexandre Lision4cf78702013-10-16 13:43:23 -04001017 }
Alexandre Lision039a3cf2013-10-16 17:44:57 -04001018 IntVect payloads = configurationManagerJNI.getAudioCodecList();
1019
1020 for (int i = 0; i < payloads.size(); ++i) {
1021 boolean isActive = false;
1022 for (Codec co : results) {
1023 if (co.getPayload().toString().contentEquals(String.valueOf(payloads.get(i))))
1024 isActive = true;
1025
1026 }
1027 if (isActive)
1028 continue;
1029 else
1030 results.add(new Codec(payloads.get(i), configurationManagerJNI.getAudioCodecDetails(payloads.get(i)), false));
1031
1032 }
1033
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001034 return results;
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001035 }
1036 }
1037
1038 AudioCodecList runInstance = new AudioCodecList();
1039 getExecutor().execute(runInstance);
1040 while (!runInstance.isDone()) {
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001041 }
Alexandre Lision933ef0a2013-10-15 17:28:40 -04001042 ArrayList<Codec> codecs = (ArrayList<Codec>) runInstance.getVal();
Alexandre Lisionafd40e42013-10-15 13:48:37 -04001043 return codecs;
alisiond295ec22013-05-17 10:12:13 -04001044 }
1045
alision9f7a6ec2013-05-24 16:26:26 -04001046 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -04001047 public Map getRingtoneList() throws RemoteException {
1048 class RingtoneList extends SipRunnableWithReturn {
1049
1050 @Override
1051 protected StringMap doRun() throws SameThreadException {
1052 Log.i(TAG, "SipService.getRingtoneList() thread running...");
1053 return configurationManagerJNI.getRingtoneList();
1054 }
1055 }
1056
1057 RingtoneList runInstance = new RingtoneList();
1058 getExecutor().execute(runInstance);
1059 while (!runInstance.isDone()) {
1060 }
Alexandre Lision4b4233a2013-10-16 17:24:17 -04001061 StringMap ringtones = (StringMap) runInstance.getVal();
1062
1063 for (int i = 0; i < ringtones.size(); ++i) {
1064 // Log.i(TAG,"ringtones "+i+" "+ ringtones.);
1065 }
1066
Alexandre Lision4cf78702013-10-16 13:43:23 -04001067 return null;
1068 }
1069
1070 @Override
1071 public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException {
1072 getExecutor().execute(new SipRunnable() {
1073 @Override
1074 protected void doRun() throws SameThreadException, RemoteException {
1075 Log.i(TAG, "SipService.setActiveAudioCodecList() thread running...");
1076 StringVect list = new StringVect();
1077 for (int i = 0; i < codecs.size(); ++i) {
1078 list.add((String) codecs.get(i));
1079 }
1080 configurationManagerJNI.setActiveAudioCodecList(list, accountID);
1081 }
1082 });
1083 }
1084
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001085/* @Override
1086 public Conference getCallById(String callID) throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001087 if(mConferences.containsKey(callID))
1088 return mConferences.get(callID);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001089 else{
Alexandre Lision945e4612014-01-15 17:40:31 -05001090 Iterator<Conference> it = getConferences().values().iterator();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001091 while (it.hasNext()) {
1092 Conference c = it.next();
1093 if (c.getCallById(callID) != null)
1094 return c;
1095 }
1096 }
1097 return null;
1098 }*/
alision2cb99562013-05-30 17:02:20 -04001099
1100 /***********************
1101 * Notification API
1102 ***********************/
1103 @Override
1104 public void createNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001105
alision2cb99562013-05-30 17:02:20 -04001106 }
1107
1108 @Override
1109 public void destroyNotification() throws RemoteException {
alisioncc7bb422013-06-06 15:31:39 -04001110
alision2cb99562013-05-30 17:02:20 -04001111 }
alisioncc7bb422013-06-06 15:31:39 -04001112
alisiondf1dac92013-06-27 17:35:53 -04001113 @Override
1114 public Conference getCurrentCall() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001115 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001116 if (conf.isIncoming())
1117 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001118 }
Alexandre Lision67817192013-07-18 12:04:30 -04001119
Alexandre Lision945e4612014-01-15 17:40:31 -05001120 for (Conference conf : mConferences.values()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001121 if (conf.isOnGoing())
1122 return conf;
alisiondf1dac92013-06-27 17:35:53 -04001123 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001124
alisiondf1dac92013-06-27 17:35:53 -04001125 return null;
1126 }
1127
Alexandre Lision64dc8c02013-09-25 15:32:25 -04001128 @Override
1129 public void playDtmf(final String key) throws RemoteException {
1130 getExecutor().execute(new SipRunnable() {
1131 @Override
1132 protected void doRun() throws SameThreadException, RemoteException {
1133 Log.i(TAG, "SipService.playDtmf() thread running...");
1134 callManagerJNI.playDTMF(key);
1135 }
1136 });
1137 }
1138
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001139 @Override
1140 public List getConcurrentCalls() throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001141 return new ArrayList(mConferences.values());
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001142 }
Alexandre Lisionb4a9e392013-10-01 14:39:43 -04001143
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -05001144 @Override
1145 public Conference getConference(String id) throws RemoteException {
Alexandre Lision945e4612014-01-15 17:40:31 -05001146 return mConferences.get(id);
Alexandre Lision6ae652d2013-09-26 16:39:20 -04001147 }
1148
Alexandre Lision4fb22622013-10-21 16:26:33 -04001149 @Override
1150 public String getCurrentAudioCodecName(String callID) throws RemoteException {
1151 return callManagerJNI.getCurrentAudioCodecName(callID);
1152 }
1153
Alexandre Lision31e30902013-11-08 15:16:59 -05001154 @Override
1155 public void setMuted(final boolean mute) throws RemoteException {
1156 getExecutor().execute(new SipRunnable() {
1157 @Override
1158 protected void doRun() throws SameThreadException, RemoteException {
1159 Log.i(TAG, "SipService.setMuted() thread running...");
1160 configurationManagerJNI.muteCapture(mute);
1161 }
1162 });
1163 }
1164
1165 @Override
1166 public boolean isCaptureMuted() throws RemoteException {
1167 class IsMuted extends SipRunnableWithReturn {
1168
1169 @Override
1170 protected Boolean doRun() throws SameThreadException {
1171 Log.i(TAG, "SipService.isCaptureMuted() thread running...");
1172 return configurationManagerJNI.isCaptureMuted();
1173 }
1174 }
1175
1176 IsMuted runInstance = new IsMuted();
1177 getExecutor().execute(runInstance);
1178 while (!runInstance.isDone()) {
1179 }
1180
1181 return (Boolean) runInstance.getVal();
1182 }
1183
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001184 @Override
1185 public List getCredentials(final String accountID) throws RemoteException {
1186 class Credentials extends SipRunnableWithReturn {
1187
1188 @Override
1189 protected List doRun() throws SameThreadException {
1190 Log.i(TAG, "SipService.getCredentials() thread running...");
1191 VectMap map = configurationManagerJNI.getCredentials(accountID);
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001192 ArrayList<HashMap<String, String>> result = SwigNativeConverter.convertCredentialsToNative(map);
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001193 return result;
1194 }
1195 }
1196
1197 Credentials runInstance = new Credentials();
1198 getExecutor().execute(runInstance);
1199 while (!runInstance.isDone()) {
1200 }
1201 return (List) runInstance.getVal();
1202 }
1203
1204 @Override
1205 public void setCredentials(final String accountID, final List creds) throws RemoteException {
1206 getExecutor().execute(new SipRunnable() {
1207 @Override
1208 protected void doRun() throws SameThreadException, RemoteException {
1209 Log.i(TAG, "SipService.setCredentials() thread running...");
Alexandre Lision3cefec22013-11-14 17:26:35 -05001210 ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds;
Alexandre Lision2aae48d2013-12-04 13:50:38 -05001211 configurationManagerJNI.setCredentials(accountID, SwigNativeConverter.convertFromNativeToSwig(creds));
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001212 }
1213 });
1214 }
1215
Alexandre Lision3e2a1d02013-11-19 17:23:00 -05001216 @Override
1217 public void registerAllAccounts() throws RemoteException {
1218 getExecutor().execute(new SipRunnable() {
1219 @Override
1220 protected void doRun() throws SameThreadException, RemoteException {
1221 Log.i(TAG, "SipService.registerAllAccounts() thread running...");
1222 configurationManagerJNI.registerAllAccounts();
1223 }
1224 });
1225 }
1226
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001227 @Override
Alexandre Lision35577132013-12-06 15:21:15 -05001228 public void toggleSpeakerPhone(boolean toggle) throws RemoteException {
1229 if (toggle)
Alexandre Lision945e4612014-01-15 17:40:31 -05001230 mMediaManager.RouteToSpeaker();
Alexandre Lision35577132013-12-06 15:21:15 -05001231 else
Alexandre Lision945e4612014-01-15 17:40:31 -05001232 mMediaManager.RouteToInternalSpeaker();
Alexandre Lision5f733bc2013-12-04 13:10:30 -05001233 }
1234
Emeric Vigier6119d782012-09-21 18:04:14 -04001235 };
Alexandre Lision35577132013-12-06 15:21:15 -05001236}