Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) |
| 3 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 4 | * |
| 5 | * Author: Regis Montoya <r3gis.3R@gmail.com> |
| 6 | * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation, either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * If you own a pjsip commercial license you can also redistribute it |
| 13 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 14 | * as an android library. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | */ |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 24 | package com.savoirfairelinux.sflphone.service; |
| 25 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 26 | import java.lang.ref.WeakReference; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | import java.util.HashMap; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 29 | import java.util.List; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 30 | import java.util.Map; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 31 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 32 | import android.app.Service; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 33 | import android.content.BroadcastReceiver; |
| 34 | import android.content.Context; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 35 | import android.content.Intent; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 36 | import android.content.IntentFilter; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 37 | import android.os.Bundle; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 38 | import android.os.Handler; |
| 39 | import android.os.HandlerThread; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 40 | import android.os.IBinder; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 43 | import android.os.RemoteException; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 44 | import android.os.Vibrator; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 45 | import android.support.v4.content.LocalBroadcastManager; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 46 | import android.util.Log; |
| 47 | import android.widget.Toast; |
| 48 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 49 | import com.savoirfairelinux.sflphone.account.AccountDetailsHandler; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 50 | import com.savoirfairelinux.sflphone.account.HistoryHandler; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 51 | import com.savoirfairelinux.sflphone.client.SFLphoneApplication; |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 52 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 53 | public class SipService extends Service { |
| 54 | |
| 55 | static final String TAG = "SipService"; |
| 56 | static final int DELAY = 5000; /* 5 sec */ |
| 57 | private boolean runFlag = false; |
| 58 | private SipServiceThread sipServiceThread; |
Emeric Vigier | 84e05da | 2012-09-20 14:53:05 -0400 | [diff] [blame] | 59 | private SFLphoneApplication sflphoneApp; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 60 | private SipServiceExecutor mExecutor; |
| 61 | private static HandlerThread executorThread; |
| 62 | private CallManagerJNI callManagerJNI; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 63 | private CallManagerCallBack callManagerCallBack; |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 64 | private ConfigurationManagerJNI configurationManagerJNI; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 65 | private ConfigurationManagerCallback configurationManagerCallback; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 66 | private ManagerImpl managerImpl; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 67 | private boolean isPjSipStackStarted = false; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 68 | ISipClient client; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 69 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 70 | private BroadcastReceiver IncomingReceiver = new BroadcastReceiver() { |
| 71 | |
| 72 | @Override |
| 73 | public void onReceive(Context context, Intent intent) { |
| 74 | // Get instance of Vibrator from current Context |
| 75 | |
| 76 | if (client != null) { |
| 77 | try { |
| 78 | if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { |
| 79 | Log.i(TAG, "Received" + intent.getAction()); |
| 80 | |
| 81 | client.incomingCall(intent); |
| 82 | |
| 83 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
| 84 | Log.i(TAG, "Received" + intent.getAction()); |
| 85 | client.callStateChanged(intent); |
| 86 | } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { |
| 87 | Log.i(TAG, "Received" + intent.getAction()); |
| 88 | Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| 89 | mVibrator.vibrate(300); |
| 90 | } |
| 91 | } catch (RemoteException e) { |
| 92 | Log.e(TAG, e.toString()); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | @Override |
| 100 | public boolean onUnbind(Intent i) { |
| 101 | super.onUnbind(i); |
| 102 | Log.i(TAG, "onUnbind(intent)"); |
| 103 | return false; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | /* called once by startService() */ |
| 108 | @Override |
| 109 | public void onCreate() { |
| 110 | Log.i(TAG, "onCreated"); |
| 111 | super.onCreate(); |
| 112 | |
| 113 | sflphoneApp = (SFLphoneApplication) getApplication(); |
| 114 | sipServiceThread = new SipServiceThread(); |
| 115 | |
| 116 | IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED); |
| 117 | callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 118 | callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED); |
| 119 | LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver, callFilter); |
| 120 | getExecutor().execute(new StartRunnable()); |
| 121 | } |
| 122 | |
| 123 | /* called for each startService() */ |
| 124 | @Override |
| 125 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 126 | Log.i(TAG, "onStarted"); |
| 127 | super.onStartCommand(intent, flags, startId); |
| 128 | |
| 129 | if (!runFlag) { |
| 130 | sipServiceThread.start(); |
| 131 | runFlag = true; |
| 132 | sflphoneApp.setServiceRunning(true); |
| 133 | Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show(); |
| 134 | } |
| 135 | |
| 136 | return START_STICKY; /* started and stopped explicitly */ |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void onDestroy() { |
| 141 | /* called once by stopService() */ |
| 142 | sipServiceThread.interrupt(); |
| 143 | sipServiceThread = null; |
| 144 | runFlag = false; |
| 145 | sflphoneApp.setServiceRunning(false); |
| 146 | Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show(); |
| 147 | super.onDestroy(); |
| 148 | |
| 149 | Log.i(TAG, "onDestroyed"); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public IBinder onBind(Intent arg0) { |
| 154 | Log.i(TAG, "onBound"); |
| 155 | return mBinder; |
| 156 | } |
| 157 | |
| 158 | private static Looper createLooper() { |
| 159 | if (executorThread == null) { |
| 160 | Log.d(TAG, "Creating new handler thread"); |
| 161 | // ADT gives a fake warning due to bad parse rule. |
| 162 | executorThread = new HandlerThread("SipService.Executor"); |
| 163 | executorThread.start(); |
| 164 | } |
| 165 | return executorThread.getLooper(); |
| 166 | } |
| 167 | |
| 168 | public SipServiceExecutor getExecutor() { |
| 169 | // create mExecutor lazily |
| 170 | if (mExecutor == null) { |
| 171 | mExecutor = new SipServiceExecutor(this); |
| 172 | } |
| 173 | return mExecutor; |
| 174 | } |
| 175 | |
| 176 | // Executes immediate tasks in a single executorThread. |
| 177 | public static class SipServiceExecutor extends Handler { |
| 178 | WeakReference<SipService> handlerService; |
| 179 | |
| 180 | SipServiceExecutor(SipService s) { |
| 181 | super(createLooper()); |
| 182 | handlerService = new WeakReference<SipService>(s); |
| 183 | } |
| 184 | |
| 185 | public void execute(Runnable task) { |
| 186 | // TODO: add wakelock |
| 187 | Message.obtain(this, 0/* don't care */, task).sendToTarget(); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void handleMessage(Message msg) { |
| 192 | if (msg.obj instanceof Runnable) { |
| 193 | executeInternal((Runnable) msg.obj); |
| 194 | } else { |
| 195 | Log.w(TAG, "can't handle msg: " + msg); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | private void executeInternal(Runnable task) { |
| 200 | try { |
| 201 | task.run(); |
| 202 | } catch (Throwable t) { |
| 203 | Log.e(TAG, "run task: " + task, t); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | private void startPjSipStack() throws SameThreadException { |
| 209 | if (isPjSipStackStarted) |
| 210 | return; |
| 211 | |
| 212 | try { |
| 213 | System.loadLibrary("gnustl_shared"); |
| 214 | System.loadLibrary("expat"); |
| 215 | System.loadLibrary("yaml"); |
| 216 | System.loadLibrary("ccgnu2"); |
| 217 | System.loadLibrary("crypto"); |
| 218 | System.loadLibrary("ssl"); |
| 219 | System.loadLibrary("ccrtp1"); |
| 220 | System.loadLibrary("dbus"); |
| 221 | System.loadLibrary("dbus-c++-1"); |
| 222 | System.loadLibrary("samplerate"); |
| 223 | System.loadLibrary("codec_ulaw"); |
| 224 | System.loadLibrary("codec_alaw"); |
| 225 | System.loadLibrary("speexresampler"); |
| 226 | System.loadLibrary("sflphone"); |
| 227 | isPjSipStackStarted = true; |
| 228 | } catch (UnsatisfiedLinkError e) { |
| 229 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 230 | isPjSipStackStarted = false; |
| 231 | return; |
| 232 | } catch (Exception e) { |
| 233 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 234 | } |
| 235 | |
| 236 | /* get unique instance of managerImpl */ |
| 237 | managerImpl = SFLPhoneservice.instance(); |
| 238 | |
| 239 | /* set static AppPath before calling manager.init */ |
| 240 | managerImpl.setPath(sflphoneApp.getAppPath()); |
| 241 | |
| 242 | callManagerJNI = new CallManagerJNI(); |
| 243 | callManagerCallBack = new CallManagerCallBack(this); |
| 244 | SFLPhoneservice.setCallbackObject(callManagerCallBack); |
| 245 | |
| 246 | configurationManagerJNI = new ConfigurationManagerJNI(); |
| 247 | configurationManagerCallback = new ConfigurationManagerCallback(this); |
| 248 | SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback); |
| 249 | |
| 250 | managerImpl.init(""); |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | // Enforce same thread contract to ensure we do not call from somewhere else |
| 255 | public class SameThreadException extends Exception { |
| 256 | private static final long serialVersionUID = -905639124232613768L; |
| 257 | |
| 258 | public SameThreadException() { |
| 259 | super("Should be launched from a single worker thread"); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | public abstract static class SipRunnable implements Runnable { |
| 264 | protected abstract void doRun() throws SameThreadException, RemoteException; |
| 265 | |
| 266 | public void run() { |
| 267 | try { |
| 268 | doRun(); |
| 269 | } catch (SameThreadException e) { |
| 270 | Log.e(TAG, "Not done from same thread"); |
| 271 | } catch (RemoteException e) { |
| 272 | Log.e(TAG, e.toString()); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | public abstract static class SipRunnableWithReturn implements Runnable { |
| 278 | Object obj = null; |
| 279 | boolean done = false; |
| 280 | |
| 281 | protected abstract Object doRun() throws SameThreadException; |
| 282 | |
| 283 | public Object getVal() { |
| 284 | return obj; |
| 285 | } |
| 286 | |
| 287 | public boolean isDone() { |
| 288 | return done; |
| 289 | } |
| 290 | |
| 291 | public void run() { |
| 292 | try { |
| 293 | obj = doRun(); |
| 294 | done = true; |
| 295 | } catch (SameThreadException e) { |
| 296 | Log.e(TAG, "Not done from same thread"); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | class StartRunnable extends SipRunnable { |
| 302 | @Override |
| 303 | protected void doRun() throws SameThreadException { |
| 304 | startPjSipStack(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | private class SipServiceThread extends Thread { |
| 309 | |
| 310 | public SipServiceThread() { |
| 311 | super("sipServiceThread"); |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public void run() { |
| 316 | Log.i(TAG, "SipService thread running..."); |
| 317 | SipService sipService = SipService.this; |
| 318 | while (sipService.runFlag) { |
| 319 | try { |
| 320 | Thread.sleep(DELAY); |
| 321 | } catch (InterruptedException e) { |
| 322 | sipService.runFlag = false; |
| 323 | Log.w(TAG, "service thread interrupted!"); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /* ************************************ |
| 330 | * |
| 331 | * Implement public interface for the service |
| 332 | * |
| 333 | * |
| 334 | * ********************************** |
| 335 | */ |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 336 | private final ISipService.Stub mBinder = new ISipService.Stub() { |
| 337 | |
| 338 | @Override |
| 339 | public void placeCall(final String accountID, final String callID, final String to) { |
| 340 | getExecutor().execute(new SipRunnable() { |
| 341 | @Override |
| 342 | protected void doRun() throws SameThreadException { |
| 343 | Log.i(TAG, "SipService.placeCall() thread running..."); |
| 344 | callManagerJNI.placeCall(accountID, callID, to); |
| 345 | } |
| 346 | }); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public void refuse(final String callID) { |
| 351 | getExecutor().execute(new SipRunnable() { |
| 352 | @Override |
| 353 | protected void doRun() throws SameThreadException { |
| 354 | Log.i(TAG, "SipService.refuse() thread running..."); |
| 355 | callManagerJNI.refuse(callID); |
| 356 | } |
| 357 | }); |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void accept(final String callID) { |
| 362 | getExecutor().execute(new SipRunnable() { |
| 363 | @Override |
| 364 | protected void doRun() throws SameThreadException { |
| 365 | Log.i(TAG, "SipService.placeCall() thread running..."); |
| 366 | callManagerJNI.accept(callID); |
| 367 | } |
| 368 | }); |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void hangUp(final String callID) { |
| 373 | getExecutor().execute(new SipRunnable() { |
| 374 | @Override |
| 375 | protected void doRun() throws SameThreadException { |
| 376 | Log.i(TAG, "SipService.hangUp() thread running..."); |
| 377 | callManagerJNI.hangUp(callID); |
| 378 | } |
| 379 | }); |
| 380 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 381 | |
| 382 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 383 | public void hold(final String callID) { |
| 384 | getExecutor().execute(new SipRunnable() { |
| 385 | @Override |
| 386 | protected void doRun() throws SameThreadException { |
| 387 | Log.i(TAG, "SipService.hold() thread running..."); |
| 388 | callManagerJNI.hold(callID); |
| 389 | } |
| 390 | }); |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void unhold(final String callID) { |
| 395 | getExecutor().execute(new SipRunnable() { |
| 396 | @Override |
| 397 | protected void doRun() throws SameThreadException { |
| 398 | Log.i(TAG, "SipService.unhold() thread running..."); |
| 399 | callManagerJNI.unhold(callID); |
| 400 | } |
| 401 | }); |
| 402 | } |
| 403 | |
| 404 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 405 | public void setAudioPlugin(final String audioPlugin) { |
| 406 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 407 | @Override |
| 408 | protected void doRun() throws SameThreadException { |
| 409 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
| 410 | configurationManagerJNI.setAudioPlugin(audioPlugin); |
| 411 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 412 | }); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public String getCurrentAudioOutputPlugin() { |
| 417 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 418 | @Override |
| 419 | protected String doRun() throws SameThreadException { |
| 420 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
| 421 | return configurationManagerJNI.getCurrentAudioOutputPlugin(); |
| 422 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 423 | } |
| 424 | ; |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 425 | |
| 426 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 427 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 428 | while (!runInstance.isDone()) { |
| 429 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 430 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 431 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 432 | |
| 433 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 434 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 435 | class AccountList extends SipRunnableWithReturn { |
| 436 | @Override |
| 437 | protected StringVect doRun() throws SameThreadException { |
| 438 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 439 | return configurationManagerJNI.getAccountList(); |
| 440 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 441 | } |
| 442 | ; |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 443 | AccountList runInstance = new AccountList(); |
| 444 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 445 | while (!runInstance.isDone()) { |
| 446 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 447 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 448 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 449 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 450 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 451 | for (int i = 0; i < swigvect.size(); i++) |
| 452 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 453 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 454 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 455 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 456 | |
| 457 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 458 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 459 | class AccountDetails extends SipRunnableWithReturn { |
| 460 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 461 | |
| 462 | AccountDetails(String accountId) { |
| 463 | id = accountId; |
| 464 | } |
| 465 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 466 | @Override |
| 467 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 468 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 469 | return configurationManagerJNI.getAccountDetails(id); |
| 470 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 471 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 472 | |
| 473 | AccountDetails runInstance = new AccountDetails(accountID); |
| 474 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 475 | while (!runInstance.isDone()) { |
| 476 | } |
| 477 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 478 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 479 | HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 480 | |
| 481 | return nativemap; |
| 482 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 483 | |
| 484 | @Override |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 485 | public void setAccountDetails(final String accountId, Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 486 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 487 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 488 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 489 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 490 | getExecutor().execute(new SipRunnable() { |
| 491 | @Override |
| 492 | protected void doRun() throws SameThreadException { |
| 493 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 494 | configurationManagerJNI.setAccountDetails(accountId, swigmap); |
| 495 | } |
| 496 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 499 | @Override |
| 500 | public String addAccount(Map map) { |
| 501 | class AddAccount extends SipRunnableWithReturn { |
| 502 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 503 | |
| 504 | AddAccount(StringMap m) { |
| 505 | map = m; |
| 506 | } |
| 507 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 508 | @Override |
| 509 | protected String doRun() throws SameThreadException { |
| 510 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
| 511 | return configurationManagerJNI.addAccount(map); |
| 512 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 513 | } |
| 514 | ; |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 515 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 516 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 517 | |
| 518 | AddAccount runInstance = new AddAccount(swigmap); |
| 519 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 520 | while (!runInstance.isDone()) { |
| 521 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 522 | String accountId = (String) runInstance.getVal(); |
| 523 | |
| 524 | return accountId; |
| 525 | } |
| 526 | |
| 527 | @Override |
| 528 | public void removeAccount(final String accountId) { |
| 529 | getExecutor().execute(new SipRunnable() { |
| 530 | @Override |
| 531 | protected void doRun() throws SameThreadException { |
| 532 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 533 | configurationManagerJNI.removeAccount(accountId); |
| 534 | } |
| 535 | }); |
| 536 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 537 | |
| 538 | @Override |
| 539 | public void registerClient(ISipClient callback) throws RemoteException { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 540 | client = callback; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 541 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 542 | |
| 543 | @Override |
| 544 | public ArrayList<HashMap<String, String>> getHistory() throws RemoteException { |
| 545 | class History extends SipRunnableWithReturn { |
| 546 | |
| 547 | @Override |
| 548 | protected VectMap doRun() throws SameThreadException { |
| 549 | Log.i(TAG, "SipService.getHistory() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 550 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 551 | return configurationManagerJNI.getHistory(); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | History runInstance = new History(); |
| 556 | getExecutor().execute(runInstance); |
| 557 | while (!runInstance.isDone()) { |
| 558 | } |
| 559 | VectMap swigmap = (VectMap) runInstance.getVal(); |
| 560 | |
| 561 | ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap); |
| 562 | |
| 563 | return nativemap; |
| 564 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 565 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 566 | /************************* |
| 567 | * Transfer related API |
| 568 | *************************/ |
| 569 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 570 | @Override |
| 571 | public void transfer(final String callID, final String to) throws RemoteException { |
| 572 | getExecutor().execute(new SipRunnable() { |
| 573 | @Override |
| 574 | protected void doRun() throws SameThreadException, RemoteException { |
| 575 | Log.i(TAG, "SipService.transfer() thread running..."); |
| 576 | if (callManagerJNI.transfer(callID, to)) { |
| 577 | Bundle bundle = new Bundle(); |
| 578 | bundle.putString("CallID", callID); |
| 579 | bundle.putString("State", "HUNGUP"); |
| 580 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 581 | intent.putExtra(CallManagerCallBack.SIGNAL_NAME, CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 582 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
| 583 | client.callStateChanged(intent); |
| 584 | } else |
| 585 | Log.i(TAG, "NOT OK"); |
| 586 | } |
| 587 | }); |
| 588 | |
| 589 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 590 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 591 | @Override |
| 592 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 593 | getExecutor().execute(new SipRunnable() { |
| 594 | @Override |
| 595 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 596 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 597 | if (callManagerJNI.attendedTransfer(transferID, targetID)) { |
| 598 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 599 | } else |
| 600 | Log.i(TAG, "NOT OK"); |
| 601 | } |
| 602 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 603 | |
| 604 | } |
| 605 | |
| 606 | /************************* |
| 607 | * Conference related API |
| 608 | *************************/ |
| 609 | |
| 610 | @Override |
| 611 | public void removeConference(final String confID) throws RemoteException { |
| 612 | getExecutor().execute(new SipRunnable() { |
| 613 | @Override |
| 614 | protected void doRun() throws SameThreadException, RemoteException { |
| 615 | Log.i(TAG, "SipService.createConference() thread running..."); |
| 616 | callManagerJNI.removeConference(confID); |
| 617 | } |
| 618 | }); |
| 619 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 623 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 624 | getExecutor().execute(new SipRunnable() { |
| 625 | @Override |
| 626 | protected void doRun() throws SameThreadException, RemoteException { |
| 627 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
| 628 | callManagerJNI.joinParticipant(sel_callID, drag_callID); |
| 629 | } |
| 630 | }); |
| 631 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 635 | public void createConfFromParticipantList(final List participants) throws RemoteException { |
| 636 | getExecutor().execute(new SipRunnable() { |
| 637 | @Override |
| 638 | protected void doRun() throws SameThreadException, RemoteException { |
| 639 | Log.i(TAG, "SipService.createConfFromParticipantList() thread running..."); |
| 640 | // callManagerJNI.createConfFromParticipantList(participants); |
| 641 | } |
| 642 | }); |
| 643 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 647 | public void addParticipant(final String callID, final String confID) throws RemoteException { |
| 648 | getExecutor().execute(new SipRunnable() { |
| 649 | @Override |
| 650 | protected void doRun() throws SameThreadException, RemoteException { |
| 651 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
| 652 | callManagerJNI.addParticipant(callID, confID); |
| 653 | } |
| 654 | }); |
| 655 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 659 | public void addMainParticipant(final String confID) throws RemoteException { |
| 660 | getExecutor().execute(new SipRunnable() { |
| 661 | @Override |
| 662 | protected void doRun() throws SameThreadException, RemoteException { |
| 663 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
| 664 | callManagerJNI.addMainParticipant(confID); |
| 665 | } |
| 666 | }); |
| 667 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 671 | public void detachParticipant(final String callID) throws RemoteException { |
| 672 | getExecutor().execute(new SipRunnable() { |
| 673 | @Override |
| 674 | protected void doRun() throws SameThreadException, RemoteException { |
| 675 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
| 676 | callManagerJNI.detachParticipant(callID); |
| 677 | } |
| 678 | }); |
| 679 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 683 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 684 | getExecutor().execute(new SipRunnable() { |
| 685 | @Override |
| 686 | protected void doRun() throws SameThreadException, RemoteException { |
| 687 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 688 | callManagerJNI.joinConference(sel_confID, drag_confID); |
| 689 | } |
| 690 | }); |
| 691 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 695 | public void hangUpConference(final String confID) throws RemoteException { |
| 696 | getExecutor().execute(new SipRunnable() { |
| 697 | @Override |
| 698 | protected void doRun() throws SameThreadException, RemoteException { |
| 699 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 700 | callManagerJNI.hangUpConference(confID); |
| 701 | } |
| 702 | }); |
| 703 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 707 | public void holdConference(final String confID) throws RemoteException { |
| 708 | getExecutor().execute(new SipRunnable() { |
| 709 | @Override |
| 710 | protected void doRun() throws SameThreadException, RemoteException { |
| 711 | Log.i(TAG, "SipService.holdConference() thread running..."); |
| 712 | callManagerJNI.holdConference(confID); |
| 713 | } |
| 714 | }); |
| 715 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 719 | public void unholdConference(final String confID) throws RemoteException { |
| 720 | getExecutor().execute(new SipRunnable() { |
| 721 | @Override |
| 722 | protected void doRun() throws SameThreadException, RemoteException { |
| 723 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
| 724 | callManagerJNI.unholdConference(confID); |
| 725 | } |
| 726 | }); |
| 727 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public List getConferenceList() throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 732 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 733 | return null; |
| 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public List getParticipantList(String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 738 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 739 | return null; |
| 740 | } |
| 741 | |
| 742 | @Override |
| 743 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 744 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 745 | return null; |
| 746 | } |
| 747 | |
| 748 | @Override |
| 749 | public Map getConferenceDetails(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame^] | 750 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 751 | return null; |
| 752 | } |
| 753 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 754 | }; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 755 | } |