blob: 37834bcaaeaf722eea1cf431980d1aa4d77d1a0b [file] [log] [blame]
Emeric Vigier6119d782012-09-21 18:04:14 -04001/**
2 * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr)
alisionb1763882013-06-18 17:30:51 -04003 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Emeric Vigier6119d782012-09-21 18:04:14 -04004 *
5 * Author: Regis Montoya <r3gis.3R@gmail.com>
6 * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
alision11e8e162013-05-28 10:33:14 -04007 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Emeric Vigier6119d782012-09-21 18:04:14 -04008 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 * If you own a pjsip commercial license you can also redistribute it
14 * and/or modify it under the terms of the GNU Lesser General Public License
15 * as an android library.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
Emeric Vigiereaf2c492012-09-19 14:38:20 -040025package com.savoirfairelinux.sflphone.service;
26
Emeric Vigier6119d782012-09-21 18:04:14 -040027import java.lang.ref.WeakReference;
alision17052d42013-04-22 10:39:38 -040028import java.util.ArrayList;
29import java.util.HashMap;
alisioncc7bb422013-06-06 15:31:39 -040030import java.util.Iterator;
alision7f18fc82013-05-01 09:37:33 -040031import java.util.List;
alision17052d42013-04-22 10:39:38 -040032import java.util.Map;
alision806e18e2013-06-21 15:30:17 -040033import java.util.Map.Entry;
alision2cb99562013-05-30 17:02:20 -040034import java.util.Random;
Emeric Vigier6119d782012-09-21 18:04:14 -040035
alision2cb99562013-05-30 17:02:20 -040036import android.app.Notification;
37import android.app.NotificationManager;
38import android.app.PendingIntent;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040039import android.app.Service;
alision17052d42013-04-22 10:39:38 -040040import android.content.Context;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040041import android.content.Intent;
alision17052d42013-04-22 10:39:38 -040042import android.content.IntentFilter;
alision7f18fc82013-05-01 09:37:33 -040043import android.os.Bundle;
Emeric Vigier6119d782012-09-21 18:04:14 -040044import android.os.Handler;
45import android.os.HandlerThread;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040046import android.os.IBinder;
Emeric Vigier6119d782012-09-21 18:04:14 -040047import android.os.Looper;
48import android.os.Message;
alision5f899632013-04-22 17:26:56 -040049import android.os.RemoteException;
alision2cb99562013-05-30 17:02:20 -040050import android.support.v4.app.NotificationCompat;
alision17052d42013-04-22 10:39:38 -040051import android.support.v4.content.LocalBroadcastManager;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040052import android.util.Log;
53import android.widget.Toast;
54
alision2cb99562013-05-30 17:02:20 -040055import com.savoirfairelinux.sflphone.R;
alision5cfc35d2013-07-11 15:11:39 -040056import com.savoirfairelinux.sflphone.account.AccountDetailBasic;
alisionf76de3b2013-04-16 15:35:22 -040057import com.savoirfairelinux.sflphone.account.AccountDetailsHandler;
alisione2a38e12013-04-25 14:20:20 -040058import com.savoirfairelinux.sflphone.account.HistoryHandler;
alision2cb99562013-05-30 17:02:20 -040059import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040060import com.savoirfairelinux.sflphone.client.SFLphoneApplication;
alision806e18e2013-06-21 15:30:17 -040061import com.savoirfairelinux.sflphone.model.Conference;
alisionfde875f2013-05-28 17:01:54 -040062import com.savoirfairelinux.sflphone.model.SipCall;
alisioncc7bb422013-06-06 15:31:39 -040063import com.savoirfairelinux.sflphone.receivers.IncomingReceiver;
Alexandre Savard713a34d2012-09-26 15:50:41 -040064
Emeric Vigiereaf2c492012-09-19 14:38:20 -040065public class SipService extends Service {
66
67 static final String TAG = "SipService";
68 static final int DELAY = 5000; /* 5 sec */
69 private boolean runFlag = false;
70 private SipServiceThread sipServiceThread;
Emeric Vigier84e05da2012-09-20 14:53:05 -040071 private SFLphoneApplication sflphoneApp;
Emeric Vigier6119d782012-09-21 18:04:14 -040072 private SipServiceExecutor mExecutor;
73 private static HandlerThread executorThread;
alision3ea8f3c2013-07-16 17:35:35 -040074 private CallManager callManagerJNI;
Emeric Vigier0007dee2012-09-24 11:35:58 -040075 private CallManagerCallBack callManagerCallBack;
alision3ea8f3c2013-07-16 17:35:35 -040076 private ConfigurationManager configurationManagerJNI;
Alexandre Savardfccd1dc2012-10-17 17:31:38 -040077 private ConfigurationManagerCallback configurationManagerCallback;
Emeric Vigier0007dee2012-09-24 11:35:58 -040078 private ManagerImpl managerImpl;
Emeric Vigier6119d782012-09-21 18:04:14 -040079 private boolean isPjSipStackStarted = false;
alisioncc7bb422013-06-06 15:31:39 -040080
alision2cb99562013-05-30 17:02:20 -040081 public static final String NOTIF_CREATION = "notif_creation";
82 public static final String NOTIF_DELETION = "notif_deletion";
alision04a00182013-05-10 17:05:29 -040083
alision2cb99562013-05-30 17:02:20 -040084 private HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>();
alision806e18e2013-06-21 15:30:17 -040085 private HashMap<String, Conference> current_confs = new HashMap<String, Conference>();
86 private IncomingReceiver receiver;
Emeric Vigier6119d782012-09-21 18:04:14 -040087
alision806e18e2013-06-21 15:30:17 -040088 public HashMap<String, Conference> getCurrent_confs() {
89 return current_confs;
90 }
alision43a9b362013-05-01 16:30:15 -040091
92 @Override
93 public boolean onUnbind(Intent i) {
94 super.onUnbind(i);
95 Log.i(TAG, "onUnbind(intent)");
96 return false;
97
98 }
99
100 /* called once by startService() */
101 @Override
102 public void onCreate() {
103 Log.i(TAG, "onCreated");
104 super.onCreate();
105
106 sflphoneApp = (SFLphoneApplication) getApplication();
107 sipServiceThread = new SipServiceThread();
108
109 IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED);
110 callFilter.addAction(CallManagerCallBack.INCOMING_CALL);
111 callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED);
alision4a0eb092013-05-07 13:52:03 -0400112 callFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
113 callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
alision04a00182013-05-10 17:05:29 -0400114 callFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
alision806e18e2013-06-21 15:30:17 -0400115 callFilter.addAction(CallManagerCallBack.CONF_CREATED);
116 callFilter.addAction(CallManagerCallBack.CONF_REMOVED);
117 callFilter.addAction(CallManagerCallBack.CONF_CHANGED);
alisiondf1dac92013-06-27 17:35:53 -0400118 callFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED);
alision806e18e2013-06-21 15:30:17 -0400119 receiver = new IncomingReceiver(this, mBinder);
alision2cb99562013-05-30 17:02:20 -0400120 LocalBroadcastManager.getInstance(this).registerReceiver(receiver, callFilter);
alision2cb99562013-05-30 17:02:20 -0400121
alisioncc7bb422013-06-06 15:31:39 -0400122 getExecutor().execute(new StartRunnable());
123
124 }
alision43a9b362013-05-01 16:30:15 -0400125
126 /* called for each startService() */
127 @Override
128 public int onStartCommand(Intent intent, int flags, int startId) {
129 Log.i(TAG, "onStarted");
130 super.onStartCommand(intent, flags, startId);
131
alision806e18e2013-06-21 15:30:17 -0400132 receiver = new IncomingReceiver(this, mBinder);
alision43a9b362013-05-01 16:30:15 -0400133 if (!runFlag) {
134 sipServiceThread.start();
135 runFlag = true;
136 sflphoneApp.setServiceRunning(true);
137 Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show();
138 }
139
alision907bde72013-06-20 14:40:37 -0400140 return START_NOT_STICKY; /* started and stopped explicitly */
alision43a9b362013-05-01 16:30:15 -0400141 }
142
143 @Override
144 public void onDestroy() {
145 /* called once by stopService() */
146 sipServiceThread.interrupt();
147 sipServiceThread = null;
148 runFlag = false;
alision2cb99562013-05-30 17:02:20 -0400149 unregisterReceiver(receiver);
150
alision43a9b362013-05-01 16:30:15 -0400151 sflphoneApp.setServiceRunning(false);
152 Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show();
153 super.onDestroy();
154
155 Log.i(TAG, "onDestroyed");
156 }
157
158 @Override
159 public IBinder onBind(Intent arg0) {
160 Log.i(TAG, "onBound");
161 return mBinder;
162 }
163
164 private static Looper createLooper() {
165 if (executorThread == null) {
166 Log.d(TAG, "Creating new handler thread");
167 // ADT gives a fake warning due to bad parse rule.
168 executorThread = new HandlerThread("SipService.Executor");
169 executorThread.start();
170 }
171 return executorThread.getLooper();
172 }
173
174 public SipServiceExecutor getExecutor() {
175 // create mExecutor lazily
176 if (mExecutor == null) {
177 mExecutor = new SipServiceExecutor(this);
178 }
179 return mExecutor;
180 }
181
182 // Executes immediate tasks in a single executorThread.
183 public static class SipServiceExecutor extends Handler {
184 WeakReference<SipService> handlerService;
185
186 SipServiceExecutor(SipService s) {
187 super(createLooper());
188 handlerService = new WeakReference<SipService>(s);
189 }
190
191 public void execute(Runnable task) {
192 // TODO: add wakelock
193 Message.obtain(this, 0/* don't care */, task).sendToTarget();
194 }
195
196 @Override
197 public void handleMessage(Message msg) {
198 if (msg.obj instanceof Runnable) {
199 executeInternal((Runnable) msg.obj);
200 } else {
201 Log.w(TAG, "can't handle msg: " + msg);
202 }
203 }
204
205 private void executeInternal(Runnable task) {
206 try {
207 task.run();
208 } catch (Throwable t) {
209 Log.e(TAG, "run task: " + task, t);
210 }
211 }
212 }
213
214 private void startPjSipStack() throws SameThreadException {
215 if (isPjSipStackStarted)
216 return;
217
218 try {
219 System.loadLibrary("gnustl_shared");
220 System.loadLibrary("expat");
221 System.loadLibrary("yaml");
222 System.loadLibrary("ccgnu2");
223 System.loadLibrary("crypto");
224 System.loadLibrary("ssl");
225 System.loadLibrary("ccrtp1");
226 System.loadLibrary("dbus");
227 System.loadLibrary("dbus-c++-1");
228 System.loadLibrary("samplerate");
229 System.loadLibrary("codec_ulaw");
230 System.loadLibrary("codec_alaw");
alisiond8c83882013-05-17 17:00:42 -0400231 System.loadLibrary("codec_g722");
alision43a9b362013-05-01 16:30:15 -0400232 System.loadLibrary("speexresampler");
233 System.loadLibrary("sflphone");
234 isPjSipStackStarted = true;
235 } catch (UnsatisfiedLinkError e) {
236 Log.e(TAG, "Problem with the current Pj stack...", e);
237 isPjSipStackStarted = false;
238 return;
239 } catch (Exception e) {
240 Log.e(TAG, "Problem with the current Pj stack...", e);
241 }
242
243 /* get unique instance of managerImpl */
244 managerImpl = SFLPhoneservice.instance();
245
246 /* set static AppPath before calling manager.init */
247 managerImpl.setPath(sflphoneApp.getAppPath());
248
alision3ea8f3c2013-07-16 17:35:35 -0400249 callManagerJNI = new CallManager();
alision43a9b362013-05-01 16:30:15 -0400250 callManagerCallBack = new CallManagerCallBack(this);
251 SFLPhoneservice.setCallbackObject(callManagerCallBack);
252
alision3ea8f3c2013-07-16 17:35:35 -0400253 configurationManagerJNI = new ConfigurationManager();
alision43a9b362013-05-01 16:30:15 -0400254 configurationManagerCallback = new ConfigurationManagerCallback(this);
255 SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback);
256
257 managerImpl.init("");
258 return;
259 }
260
alision2cb99562013-05-30 17:02:20 -0400261 public HashMap<String, SipCall> getCurrent_calls() {
262 return current_calls;
263 }
264
alision43a9b362013-05-01 16:30:15 -0400265 // 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
277 public void run() {
278 try {
279 doRun();
280 } catch (SameThreadException e) {
281 Log.e(TAG, "Not done from same thread");
282 } catch (RemoteException e) {
283 Log.e(TAG, e.toString());
284 }
285 }
286 }
287
288 public abstract static class SipRunnableWithReturn implements Runnable {
289 Object obj = null;
290 boolean done = false;
291
292 protected abstract Object doRun() throws SameThreadException;
293
294 public Object getVal() {
295 return obj;
296 }
297
298 public boolean isDone() {
299 return done;
300 }
301
302 public void run() {
303 try {
304 obj = doRun();
305 done = true;
306 } catch (SameThreadException e) {
307 Log.e(TAG, "Not done from same thread");
308 }
309 }
310 }
311
312 class StartRunnable extends SipRunnable {
313 @Override
314 protected void doRun() throws SameThreadException {
315 startPjSipStack();
316 }
317 }
318
319 private class SipServiceThread extends Thread {
320
321 public SipServiceThread() {
322 super("sipServiceThread");
323 }
324
325 @Override
326 public void run() {
327 Log.i(TAG, "SipService thread running...");
328 SipService sipService = SipService.this;
329 while (sipService.runFlag) {
330 try {
331 Thread.sleep(DELAY);
332 } catch (InterruptedException e) {
333 sipService.runFlag = false;
334 Log.w(TAG, "service thread interrupted!");
335 }
336 }
337 }
338 }
339
340 /* ************************************
341 *
342 * Implement public interface for the service
343 *
344 *
345 * **********************************
346 */
Emeric Vigier6119d782012-09-21 18:04:14 -0400347 private final ISipService.Stub mBinder = new ISipService.Stub() {
348
349 @Override
alisionfde875f2013-05-28 17:01:54 -0400350 public void placeCall(final SipCall call) {
Emeric Vigier6119d782012-09-21 18:04:14 -0400351 getExecutor().execute(new SipRunnable() {
352 @Override
353 protected void doRun() throws SameThreadException {
354 Log.i(TAG, "SipService.placeCall() thread running...");
alision907bde72013-06-20 14:40:37 -0400355 callManagerJNI.placeCall(call.getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber());
alision2cb99562013-05-30 17:02:20 -0400356 getCurrent_calls().put(call.getCallId(), call);
Emeric Vigier6119d782012-09-21 18:04:14 -0400357 }
358 });
359 }
360
361 @Override
362 public void refuse(final String callID) {
363 getExecutor().execute(new SipRunnable() {
364 @Override
365 protected void doRun() throws SameThreadException {
366 Log.i(TAG, "SipService.refuse() thread running...");
367 callManagerJNI.refuse(callID);
368 }
369 });
370 }
371
372 @Override
373 public void accept(final String callID) {
374 getExecutor().execute(new SipRunnable() {
375 @Override
376 protected void doRun() throws SameThreadException {
377 Log.i(TAG, "SipService.placeCall() thread running...");
378 callManagerJNI.accept(callID);
379 }
380 });
381 }
382
383 @Override
384 public void hangUp(final String callID) {
385 getExecutor().execute(new SipRunnable() {
386 @Override
387 protected void doRun() throws SameThreadException {
388 Log.i(TAG, "SipService.hangUp() thread running...");
389 callManagerJNI.hangUp(callID);
390 }
391 });
392 }
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400393
394 @Override
Alexandre Savarde9dc8992012-10-26 12:12:27 -0400395 public void hold(final String callID) {
396 getExecutor().execute(new SipRunnable() {
397 @Override
398 protected void doRun() throws SameThreadException {
399 Log.i(TAG, "SipService.hold() thread running...");
400 callManagerJNI.hold(callID);
401 }
402 });
403 }
404
405 @Override
406 public void unhold(final String callID) {
407 getExecutor().execute(new SipRunnable() {
408 @Override
409 protected void doRun() throws SameThreadException {
410 Log.i(TAG, "SipService.unhold() thread running...");
411 callManagerJNI.unhold(callID);
412 }
413 });
414 }
415
416 @Override
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400417 public void setAudioPlugin(final String audioPlugin) {
418 getExecutor().execute(new SipRunnable() {
alision371b77e2013-04-23 14:51:26 -0400419 @Override
420 protected void doRun() throws SameThreadException {
421 Log.i(TAG, "SipService.setAudioPlugin() thread running...");
422 configurationManagerJNI.setAudioPlugin(audioPlugin);
423 }
Alexandre Savard31d27c62012-10-04 16:05:08 -0400424 });
425 }
426
427 @Override
428 public String getCurrentAudioOutputPlugin() {
429 class CurrentAudioPlugin extends SipRunnableWithReturn {
430 @Override
431 protected String doRun() throws SameThreadException {
432 Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
433 return configurationManagerJNI.getCurrentAudioOutputPlugin();
434 }
alision371b77e2013-04-23 14:51:26 -0400435 }
436 ;
Alexandre Savard31d27c62012-10-04 16:05:08 -0400437
438 CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
439 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400440 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400441 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400442 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400443 return (String) runInstance.getVal();
Alexandre Savardc1b08fe2012-09-25 16:24:47 -0400444 }
Alexandre Savard713a34d2012-09-26 15:50:41 -0400445
446 @Override
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400447 public ArrayList<String> getAccountList() {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400448 class AccountList extends SipRunnableWithReturn {
449 @Override
450 protected StringVect doRun() throws SameThreadException {
451 Log.i(TAG, "SipService.getAccountList() thread running...");
452 return configurationManagerJNI.getAccountList();
453 }
alision371b77e2013-04-23 14:51:26 -0400454 }
455 ;
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400456 AccountList runInstance = new AccountList();
457 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400458 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400459 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400460 }
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400461 StringVect swigvect = (StringVect) runInstance.getVal();
462
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400463 ArrayList<String> nativelist = new ArrayList<String>();
Alexandre Savard52a72522012-09-27 16:40:13 -0400464
alision371b77e2013-04-23 14:51:26 -0400465 for (int i = 0; i < swigvect.size(); i++)
466 nativelist.add(swigvect.get(i));
Alexandre Savard52a72522012-09-27 16:40:13 -0400467
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400468 return nativelist;
alision371b77e2013-04-23 14:51:26 -0400469 }
Alexandre Savard6b85e7e2012-09-27 15:43:14 -0400470
471 @Override
alision371b77e2013-04-23 14:51:26 -0400472 public HashMap<String, String> getAccountDetails(final String accountID) {
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400473 class AccountDetails extends SipRunnableWithReturn {
474 private String id;
alision371b77e2013-04-23 14:51:26 -0400475
476 AccountDetails(String accountId) {
477 id = accountId;
478 }
479
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400480 @Override
481 protected StringMap doRun() throws SameThreadException {
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400482 Log.i(TAG, "SipService.getAccountDetails() thread running...");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400483 return configurationManagerJNI.getAccountDetails(id);
484 }
alision371b77e2013-04-23 14:51:26 -0400485 }
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400486
487 AccountDetails runInstance = new AccountDetails(accountID);
488 getExecutor().execute(runInstance);
alisionfde875f2013-05-28 17:01:54 -0400489
alision371b77e2013-04-23 14:51:26 -0400490 while (!runInstance.isDone()) {
491 }
492 StringMap swigmap = (StringMap) runInstance.getVal();
Alexandre Savard713a34d2012-09-26 15:50:41 -0400493
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400494 HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap);
Alexandre Savard713a34d2012-09-26 15:50:41 -0400495
496 return nativemap;
497 }
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400498
499 @Override
alisioncc7bb422013-06-06 15:31:39 -0400500 public void setAccountDetails(final String accountId, final Map map) {
alision371b77e2013-04-23 14:51:26 -0400501 HashMap<String, String> nativemap = (HashMap<String, String>) map;
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400502
Alexandre Savard3bbb4792012-10-05 11:30:01 -0400503 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap);
Alexandre Savard718d49f2012-10-02 15:17:13 -0400504
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400505 getExecutor().execute(new SipRunnable() {
506 @Override
507 protected void doRun() throws SameThreadException {
alisioncc7bb422013-06-06 15:31:39 -0400508
509 configurationManagerJNI.setCredentials(accountId, extractCredentials(map));
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400510 configurationManagerJNI.setAccountDetails(accountId, swigmap);
alisioncc7bb422013-06-06 15:31:39 -0400511
512 convertSwigToNative(configurationManagerJNI.getCredentials(accountId));
513 Log.i(TAG, "SipService.setAccountDetails() thread running...");
514 }
515
516 private VectMap extractCredentials(Map map) {
517 VectMap swigmap = new VectMap();
518 StringMap entry = new StringMap();
alision5cfc35d2013-07-11 15:11:39 -0400519 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
520 if ((String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM) != null)
521 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM));
alisioncc7bb422013-06-06 15:31:39 -0400522 else
alision5cfc35d2013-07-11 15:11:39 -0400523 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, "*");
524 entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
alisioncc7bb422013-06-06 15:31:39 -0400525 swigmap.add(entry);
526 return swigmap;
527
Alexandre Savard7a2b2202012-10-04 17:07:33 -0400528 }
529 });
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400530 }
531
alisioncc7bb422013-06-06 15:31:39 -0400532 public ArrayList<HashMap<String, String>> convertSwigToNative(VectMap swigmap) {
533
534 ArrayList<HashMap<String, String>> nativemap = new ArrayList<HashMap<String, String>>();
535 Log.i(TAG, "swigmap size " + swigmap.size());
536 for (int i = 0; i < swigmap.size(); ++i) {
537 Log.i(TAG, "Entry " + i);
538 StringMap tmp = swigmap.get(i);
alision5cfc35d2013-07-11 15:11:39 -0400539 Log.i(TAG, tmp.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
alision806e18e2013-06-21 15:30:17 -0400540 // Log.i(TAG, tmp.get(ServiceConstants.CONFIG_ACCOUNT_REALM));
alision5cfc35d2013-07-11 15:11:39 -0400541 Log.i(TAG, tmp.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
alisioncc7bb422013-06-06 15:31:39 -0400542 }
543
544 return nativemap;
545 }
546
Alexandre Savard46036572012-10-05 13:56:49 -0400547 @Override
548 public String addAccount(Map map) {
549 class AddAccount extends SipRunnableWithReturn {
550 StringMap map;
alision371b77e2013-04-23 14:51:26 -0400551
552 AddAccount(StringMap m) {
553 map = m;
554 }
555
Alexandre Savard46036572012-10-05 13:56:49 -0400556 @Override
557 protected String doRun() throws SameThreadException {
558 Log.i(TAG, "SipService.getAccountDetails() thread running...");
559 return configurationManagerJNI.addAccount(map);
560 }
alision371b77e2013-04-23 14:51:26 -0400561 }
Alexandre Savard46036572012-10-05 13:56:49 -0400562
alision371b77e2013-04-23 14:51:26 -0400563 final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map);
Alexandre Savard46036572012-10-05 13:56:49 -0400564
565 AddAccount runInstance = new AddAccount(swigmap);
566 getExecutor().execute(runInstance);
alision371b77e2013-04-23 14:51:26 -0400567 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400568 // Log.e(TAG, "Waiting for Nofing");
alision371b77e2013-04-23 14:51:26 -0400569 }
Alexandre Savard46036572012-10-05 13:56:49 -0400570 String accountId = (String) runInstance.getVal();
571
572 return accountId;
573 }
574
575 @Override
576 public void removeAccount(final String accountId) {
577 getExecutor().execute(new SipRunnable() {
578 @Override
579 protected void doRun() throws SameThreadException {
580 Log.i(TAG, "SipService.setAccountDetails() thread running...");
581 configurationManagerJNI.removeAccount(accountId);
582 }
583 });
584 }
alision5f899632013-04-22 17:26:56 -0400585
alisione2a38e12013-04-25 14:20:20 -0400586 @Override
587 public ArrayList<HashMap<String, String>> getHistory() throws RemoteException {
588 class History extends SipRunnableWithReturn {
589
590 @Override
591 protected VectMap doRun() throws SameThreadException {
592 Log.i(TAG, "SipService.getHistory() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400593
alisione2a38e12013-04-25 14:20:20 -0400594 return configurationManagerJNI.getHistory();
595 }
596 }
597
598 History runInstance = new History();
599 getExecutor().execute(runInstance);
600 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400601 // Log.w(TAG, "Waiting for getHistory");
alisione2a38e12013-04-25 14:20:20 -0400602 }
alision1005ba12013-06-19 13:52:44 -0400603 Log.i(TAG, "SipService.getHistory() DONE");
alisione2a38e12013-04-25 14:20:20 -0400604 VectMap swigmap = (VectMap) runInstance.getVal();
605
606 ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap);
607
608 return nativemap;
609 }
alision7f18fc82013-05-01 09:37:33 -0400610
alision43a9b362013-05-01 16:30:15 -0400611 /*************************
612 * Transfer related API
613 *************************/
614
alision7f18fc82013-05-01 09:37:33 -0400615 @Override
616 public void transfer(final String callID, final String to) throws RemoteException {
617 getExecutor().execute(new SipRunnable() {
618 @Override
619 protected void doRun() throws SameThreadException, RemoteException {
620 Log.i(TAG, "SipService.transfer() thread running...");
621 if (callManagerJNI.transfer(callID, to)) {
622 Bundle bundle = new Bundle();
623 bundle.putString("CallID", callID);
624 bundle.putString("State", "HUNGUP");
625 Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED);
alision7f18fc82013-05-01 09:37:33 -0400626 intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
alision84813a12013-05-27 17:40:39 -0400627 sendBroadcast(intent);
alision7f18fc82013-05-01 09:37:33 -0400628 } else
629 Log.i(TAG, "NOT OK");
630 }
631 });
632
633 }
alision43a9b362013-05-01 16:30:15 -0400634
alision7f18fc82013-05-01 09:37:33 -0400635 @Override
636 public void attendedTransfer(final String transferID, final String targetID) throws RemoteException {
637 getExecutor().execute(new SipRunnable() {
638 @Override
639 protected void doRun() throws SameThreadException, RemoteException {
alision43a9b362013-05-01 16:30:15 -0400640 Log.i(TAG, "SipService.attendedTransfer() thread running...");
alision7f18fc82013-05-01 09:37:33 -0400641 if (callManagerJNI.attendedTransfer(transferID, targetID)) {
642 Log.i(TAG, "OK");
alision7f18fc82013-05-01 09:37:33 -0400643 } else
644 Log.i(TAG, "NOT OK");
645 }
646 });
alision43a9b362013-05-01 16:30:15 -0400647
648 }
649
650 /*************************
651 * Conference related API
652 *************************/
653
654 @Override
655 public void removeConference(final String confID) throws RemoteException {
656 getExecutor().execute(new SipRunnable() {
657 @Override
658 protected void doRun() throws SameThreadException, RemoteException {
659 Log.i(TAG, "SipService.createConference() thread running...");
660 callManagerJNI.removeConference(confID);
661 }
662 });
663
alision7f18fc82013-05-01 09:37:33 -0400664 }
665
666 @Override
alision43a9b362013-05-01 16:30:15 -0400667 public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException {
668 getExecutor().execute(new SipRunnable() {
669 @Override
670 protected void doRun() throws SameThreadException, RemoteException {
671 Log.i(TAG, "SipService.joinParticipant() thread running...");
672 callManagerJNI.joinParticipant(sel_callID, drag_callID);
alision806e18e2013-06-21 15:30:17 -0400673 // Generate a CONF_CREATED callback
alision43a9b362013-05-01 16:30:15 -0400674 }
675 });
676
alision7f18fc82013-05-01 09:37:33 -0400677 }
678
alision7f18fc82013-05-01 09:37:33 -0400679 @Override
alision806e18e2013-06-21 15:30:17 -0400680 public void addParticipant(final SipCall call, final String confID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400681 getExecutor().execute(new SipRunnable() {
682 @Override
683 protected void doRun() throws SameThreadException, RemoteException {
684 Log.i(TAG, "SipService.addParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400685 callManagerJNI.addParticipant(call.getCallId(), confID);
686 current_confs.get(confID).getParticipants().add(call);
alision43a9b362013-05-01 16:30:15 -0400687 }
688 });
689
alision7f18fc82013-05-01 09:37:33 -0400690 }
691
692 @Override
alision43a9b362013-05-01 16:30:15 -0400693 public void addMainParticipant(final String confID) throws RemoteException {
694 getExecutor().execute(new SipRunnable() {
695 @Override
696 protected void doRun() throws SameThreadException, RemoteException {
697 Log.i(TAG, "SipService.addMainParticipant() thread running...");
698 callManagerJNI.addMainParticipant(confID);
699 }
700 });
701
alision7f18fc82013-05-01 09:37:33 -0400702 }
703
704 @Override
alision43a9b362013-05-01 16:30:15 -0400705 public void detachParticipant(final String callID) throws RemoteException {
706 getExecutor().execute(new SipRunnable() {
707 @Override
708 protected void doRun() throws SameThreadException, RemoteException {
709 Log.i(TAG, "SipService.detachParticipant() thread running...");
alision806e18e2013-06-21 15:30:17 -0400710 Log.i(TAG, "Detaching " + callID);
711 Iterator<Entry<String, Conference>> it = current_confs.entrySet().iterator();
712 Log.i(TAG, "current_confs size " + current_confs.size());
713 while (it.hasNext()) {
714 Conference tmp = it.next().getValue();
715 Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants");
716 if (tmp.contains(callID)) {
717 current_calls.put(callID, tmp.getCall(callID));
718 Log.i(TAG, "Call found and put in current_calls");
719 }
720 }
alision43a9b362013-05-01 16:30:15 -0400721 callManagerJNI.detachParticipant(callID);
722 }
723 });
724
alision7f18fc82013-05-01 09:37:33 -0400725 }
726
727 @Override
alision43a9b362013-05-01 16:30:15 -0400728 public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException {
729 getExecutor().execute(new SipRunnable() {
730 @Override
731 protected void doRun() throws SameThreadException, RemoteException {
732 Log.i(TAG, "SipService.joinConference() thread running...");
733 callManagerJNI.joinConference(sel_confID, drag_confID);
734 }
735 });
736
alision7f18fc82013-05-01 09:37:33 -0400737 }
738
739 @Override
alision43a9b362013-05-01 16:30:15 -0400740 public void hangUpConference(final String confID) throws RemoteException {
741 getExecutor().execute(new SipRunnable() {
742 @Override
743 protected void doRun() throws SameThreadException, RemoteException {
744 Log.i(TAG, "SipService.joinConference() thread running...");
745 callManagerJNI.hangUpConference(confID);
746 }
747 });
748
alision7f18fc82013-05-01 09:37:33 -0400749 }
750
751 @Override
alision43a9b362013-05-01 16:30:15 -0400752 public void holdConference(final String confID) throws RemoteException {
753 getExecutor().execute(new SipRunnable() {
754 @Override
755 protected void doRun() throws SameThreadException, RemoteException {
756 Log.i(TAG, "SipService.holdConference() thread running...");
757 callManagerJNI.holdConference(confID);
758 }
759 });
760
alision7f18fc82013-05-01 09:37:33 -0400761 }
762
763 @Override
alision43a9b362013-05-01 16:30:15 -0400764 public void unholdConference(final String confID) throws RemoteException {
765 getExecutor().execute(new SipRunnable() {
766 @Override
767 protected void doRun() throws SameThreadException, RemoteException {
768 Log.i(TAG, "SipService.unholdConference() thread running...");
769 callManagerJNI.unholdConference(confID);
770 }
771 });
772
alision7f18fc82013-05-01 09:37:33 -0400773 }
alisioncd8fb912013-06-28 14:43:51 -0400774
775 @Override
776 public boolean isConferenceParticipant(final String callID) throws RemoteException {
777 class IsParticipant extends SipRunnableWithReturn {
778
779 @Override
780 protected Boolean doRun() throws SameThreadException {
781 Log.i(TAG, "SipService.isRecording() thread running...");
782 return callManagerJNI.isConferenceParticipant(callID);
783 }
784 }
785
786 IsParticipant runInstance = new IsParticipant();
787 getExecutor().execute(runInstance);
788 while (!runInstance.isDone()) {
789 }
790
791 return (Boolean) runInstance.getVal();
792 }
alision7f18fc82013-05-01 09:37:33 -0400793
794 @Override
alisiondf1dac92013-06-27 17:35:53 -0400795 public HashMap<String, Conference> getConferenceList() throws RemoteException {
796// class ConfList extends SipRunnableWithReturn {
797// @Override
798// protected StringVect doRun() throws SameThreadException {
799// Log.i(TAG, "SipService.getConferenceList() thread running...");
800// return callManagerJNI.getConferenceList();
801// }
802// }
803// ;
804// ConfList runInstance = new ConfList();
805// getExecutor().execute(runInstance);
806// while (!runInstance.isDone()) {
807// // Log.w(TAG, "Waiting for getConferenceList");
808// }
809// StringVect swigvect = (StringVect) runInstance.getVal();
810//
811// ArrayList<String> nativelist = new ArrayList<String>();
812//
813// for (int i = 0; i < swigvect.size(); i++)
814// nativelist.add(swigvect.get(i));
815//
816// return nativelist;
817 return current_confs;
alision7f18fc82013-05-01 09:37:33 -0400818 }
819
820 @Override
alision907bde72013-06-20 14:40:37 -0400821 public List getParticipantList(final String confID) throws RemoteException {
822 class PartList extends SipRunnableWithReturn {
823 @Override
824 protected StringVect doRun() throws SameThreadException {
825 Log.i(TAG, "SipService.getAccountList() thread running...");
826 return callManagerJNI.getParticipantList(confID);
827 }
828 }
829 ;
830 PartList runInstance = new PartList();
831 getExecutor().execute(runInstance);
832 while (!runInstance.isDone()) {
833 // Log.w(TAG, "Waiting for getConferenceList");
834 }
835 StringVect swigvect = (StringVect) runInstance.getVal();
836
837 ArrayList<String> nativelist = new ArrayList<String>();
838
839 for (int i = 0; i < swigvect.size(); i++)
840 nativelist.add(swigvect.get(i));
841
842 return nativelist;
alision7f18fc82013-05-01 09:37:33 -0400843 }
alision806e18e2013-06-21 15:30:17 -0400844
alision1005ba12013-06-19 13:52:44 -0400845 @Override
alision7f18fc82013-05-01 09:37:33 -0400846 public String getConferenceId(String callID) throws RemoteException {
alision43a9b362013-05-01 16:30:15 -0400847 Log.e(TAG, "getConferenceList not implemented");
alision7f18fc82013-05-01 09:37:33 -0400848 return null;
849 }
850
851 @Override
alision806e18e2013-06-21 15:30:17 -0400852 public String getConferenceDetails(final String callID) throws RemoteException {
853 class ConfDetails extends SipRunnableWithReturn {
854 @Override
855 protected StringMap doRun() throws SameThreadException {
856 Log.i(TAG, "SipService.getAccountList() thread running...");
857 return callManagerJNI.getConferenceDetails(callID);
858 }
859 }
860 ;
861 ConfDetails runInstance = new ConfDetails();
862 getExecutor().execute(runInstance);
863 while (!runInstance.isDone()) {
864 // Log.w(TAG, "Waiting for getConferenceList");
865 }
866 StringMap swigvect = (StringMap) runInstance.getVal();
867
868 return swigvect.get("CONF_STATE");
alision7f18fc82013-05-01 09:37:33 -0400869 }
870
alision04a00182013-05-10 17:05:29 -0400871 @Override
872 public String getRecordPath() throws RemoteException {
873 class RecordPath extends SipRunnableWithReturn {
874
875 @Override
876 protected String doRun() throws SameThreadException {
877 Log.i(TAG, "SipService.getRecordPath() thread running...");
alision3ea8f3c2013-07-16 17:35:35 -0400878// return configurationManager.getRecordPath();
879 return "";
alision04a00182013-05-10 17:05:29 -0400880 }
881 }
882
883 RecordPath runInstance = new RecordPath();
884 getExecutor().execute(runInstance);
885 while (!runInstance.isDone()) {
alision84813a12013-05-27 17:40:39 -0400886 // Log.w(TAG, "Waiting for getRecordPath");
alision04a00182013-05-10 17:05:29 -0400887 }
888 String path = (String) runInstance.getVal();
889
890 return path;
891 }
892
893 @Override
894 public void setRecordingCall(final String id) throws RemoteException {
895 getExecutor().execute(new SipRunnable() {
896 @Override
897 protected void doRun() throws SameThreadException, RemoteException {
898 Log.i(TAG, "SipService.setRecordingCall() thread running...");
alision3ea8f3c2013-07-16 17:35:35 -0400899 callManagerJNI.toggleRecordingCall(id);
alision04a00182013-05-10 17:05:29 -0400900 }
901 });
902
903 }
alision50fa0722013-06-25 17:29:44 -0400904
905 @Override
alisiondf1dac92013-06-27 17:35:53 -0400906 public boolean isRecording(final String id) throws RemoteException {
907 class IsRecording extends SipRunnableWithReturn {
908
909 @Override
910 protected Boolean doRun() throws SameThreadException {
911 Log.i(TAG, "SipService.isRecording() thread running...");
912 return callManagerJNI.getIsRecording(id);
913 }
914 }
915
916 IsRecording runInstance = new IsRecording();
917 getExecutor().execute(runInstance);
918 while (!runInstance.isDone()) {
919 }
920
921 return (Boolean) runInstance.getVal();
922
923 }
924
925 @Override
alision50fa0722013-06-25 17:29:44 -0400926 public boolean startRecordedFilePlayback(final String filepath) throws RemoteException {
927 getExecutor().execute(new SipRunnable() {
928 @Override
929 protected void doRun() throws SameThreadException, RemoteException {
930 Log.i(TAG, "SipService.setRecordingCall() thread running...");
931 callManagerJNI.startRecordedFilePlayback(filepath);
932 }
933 });
934 return false;
935 }
936
937 @Override
938 public void stopRecordedFilePlayback(final String filepath) throws RemoteException {
939 getExecutor().execute(new SipRunnable() {
940 @Override
941 protected void doRun() throws SameThreadException, RemoteException {
942 Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running...");
943 callManagerJNI.stopRecordedFilePlayback(filepath);
944 }
945 });
946 }
alision04a00182013-05-10 17:05:29 -0400947
948 @Override
949 public void setRecordPath(final String path) throws RemoteException {
950 getExecutor().execute(new SipRunnable() {
951 @Override
952 protected void doRun() throws SameThreadException, RemoteException {
953 Log.i(TAG, "SipService.setRecordingCall() thread running...");
alision3ea8f3c2013-07-16 17:35:35 -0400954// configurationManagerJNI.setRecordPath(path);
alision04a00182013-05-10 17:05:29 -0400955 }
956 });
957 }
958
959 @Override
960 public void sendTextMessage(final String callID, final String message, final String from) throws RemoteException {
961 getExecutor().execute(new SipRunnable() {
962 @Override
963 protected void doRun() throws SameThreadException, RemoteException {
964 Log.i(TAG, "SipService.sendTextMessage() thread running...");
965 callManagerJNI.sendTextMessage(callID, message, from);
966 }
967 });
968
969 }
970
alisiond295ec22013-05-17 10:12:13 -0400971 @Override
972 public List getAudioCodecList(String accountID) throws RemoteException {
alision806e18e2013-06-21 15:30:17 -0400973 // class AudioCodecList extends SipRunnableWithReturn {
974 //
975 // @Override
976 // protected IntVect doRun() throws SameThreadException {
977 // Log.i(TAG, "SipService.getAudioCodecList() thread running...");
978 // return configurationManagerJNI.getAudioCodecList();
979 // }
980 // }
981 //
982 // AudioCodecList runInstance = new AudioCodecList();
983 // getExecutor().execute(runInstance);
984 // while (!runInstance.isDone()) {
985 // Log.w(TAG, "Waiting for getAudioCodecList");
986 // }
987 // IntVect swigmap = (IntVect) runInstance.getVal();
988 //
989 // ArrayList<Integer> codecs = AudioHandler.convertSwigToNative(swigmap);
990 //
991 // return codecs;
alision907bde72013-06-20 14:40:37 -0400992 return null;
alisiond295ec22013-05-17 10:12:13 -0400993 }
994
alision9f7a6ec2013-05-24 16:26:26 -0400995 @Override
alisionfde875f2013-05-28 17:01:54 -0400996 public HashMap<String, SipCall> getCallList() throws RemoteException {
alision85704182013-05-29 15:23:03 -0400997 // class CallList extends SipRunnableWithReturn {
998 //
999 // @Override
1000 // protected StringVect doRun() throws SameThreadException {
1001 // Log.i(TAG, "SipService.getCallList() thread running...");
1002 // return callManagerJNI.getCallList();
1003 // }
1004 // }
1005 //
1006 // CallList runInstance = new CallList();
1007 // getExecutor().execute(runInstance);
1008 // while (!runInstance.isDone()) {
1009 // Log.w(TAG, "Waiting for getAudioCodecList");
1010 // }
1011 // StringVect swigmap = (StringVect) runInstance.getVal();
1012 //
1013 // ArrayList<String> nativemap = new ArrayList<String>();
1014 // for (int i = 0; i < swigmap.size(); ++i) {
1015 //
1016 // String t = swigmap.get(i);
1017 // nativemap.add(t);
1018 // }
alision9f7a6ec2013-05-24 16:26:26 -04001019
alision2cb99562013-05-30 17:02:20 -04001020 return getCurrent_calls();
alision9f7a6ec2013-05-24 16:26:26 -04001021 }
1022
alision85704182013-05-29 15:23:03 -04001023 @Override
1024 public SipCall getCall(String callID) throws RemoteException {
alision2cb99562013-05-30 17:02:20 -04001025 return getCurrent_calls().get(callID);
1026 }
1027
1028 /***********************
1029 * Notification API
1030 ***********************/
1031 @Override
1032 public void createNotification() throws RemoteException {
1033 makeNotification();
alisioncc7bb422013-06-06 15:31:39 -04001034
alision2cb99562013-05-30 17:02:20 -04001035 }
1036
1037 @Override
1038 public void destroyNotification() throws RemoteException {
1039 removeNotification();
alisioncc7bb422013-06-06 15:31:39 -04001040
alision2cb99562013-05-30 17:02:20 -04001041 }
alisioncc7bb422013-06-06 15:31:39 -04001042
alision2cb99562013-05-30 17:02:20 -04001043 private int NOTIFICATION_ID = new Random().nextInt(1000);
alisioncc7bb422013-06-06 15:31:39 -04001044
alision2cb99562013-05-30 17:02:20 -04001045 private void makeNotification() {
alisioncc7bb422013-06-06 15:31:39 -04001046 if (current_calls.size() == 0) {
alision2cb99562013-05-30 17:02:20 -04001047 return;
1048 }
1049 Intent notificationIntent = new Intent(getApplicationContext(), SFLPhoneHomeActivity.class);
alisioncc7bb422013-06-06 15:31:39 -04001050 PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 007, notificationIntent,
1051 PendingIntent.FLAG_UPDATE_CURRENT);
alision2cb99562013-05-30 17:02:20 -04001052
1053 NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
1054
1055 NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext());
alisioncc7bb422013-06-06 15:31:39 -04001056 //
1057 // builder.setContent(view);
1058 builder.setContentIntent(contentIntent).setOngoing(true).setSmallIcon(R.drawable.ic_launcher)
1059 .setContentTitle(getCurrent_calls().size() + " ongoing calls").setTicker("Pending calls").setWhen(System.currentTimeMillis())
1060 .setAutoCancel(false);
alision2cb99562013-05-30 17:02:20 -04001061 builder.setPriority(NotificationCompat.PRIORITY_MAX);
1062 Notification n = builder.build();
1063
1064 nm.notify(NOTIFICATION_ID, n);
alisioncc7bb422013-06-06 15:31:39 -04001065
alision2cb99562013-05-30 17:02:20 -04001066 }
1067
1068 public void removeNotification() {
1069 NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
1070 nm.cancel(NOTIFICATION_ID);
alision85704182013-05-29 15:23:03 -04001071 }
1072
alisiondf1dac92013-06-27 17:35:53 -04001073 @Override
1074 public Conference getCurrentCall() throws RemoteException {
1075 for(SipCall i : current_calls.values()){
1076 if(i.isOngoing()){
1077 Conference tmp = new Conference("-1");
1078 tmp.getParticipants().add(i);
1079 return tmp;
1080 }
1081 }
1082
1083 if(!current_confs.isEmpty()){
1084 return (Conference) current_confs.values().toArray()[0];
1085 }
1086 return null;
1087 }
1088
1089
1090
alisioncd8fb912013-06-28 14:43:51 -04001091
1092
alision50fa0722013-06-25 17:29:44 -04001093
1094
Emeric Vigier6119d782012-09-21 18:04:14 -04001095 };
Emeric Vigiereaf2c492012-09-19 14:38:20 -04001096}