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> |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 7 | * Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 8 | * |
| 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 Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 25 | package com.savoirfairelinux.sflphone.service; |
| 26 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 27 | import java.lang.ref.WeakReference; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 28 | import java.util.ArrayList; |
| 29 | import java.util.HashMap; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 30 | import java.util.List; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 31 | import java.util.Map; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 32 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 33 | import android.app.Service; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
| 35 | import android.content.Context; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 36 | import android.content.Intent; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 37 | import android.content.IntentFilter; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 38 | import android.os.Bundle; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 39 | import android.os.Handler; |
| 40 | import android.os.HandlerThread; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 41 | import android.os.IBinder; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 42 | import android.os.Looper; |
| 43 | import android.os.Message; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 44 | import android.os.Parcelable; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 46 | import android.os.Vibrator; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 47 | import android.support.v4.content.LocalBroadcastManager; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 48 | import android.util.Log; |
| 49 | import android.widget.Toast; |
| 50 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | import com.savoirfairelinux.sflphone.account.AccountDetailsHandler; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 52 | import com.savoirfairelinux.sflphone.account.AudioHandler; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.account.HistoryHandler; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 54 | import com.savoirfairelinux.sflphone.client.SFLphoneApplication; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.model.CallContact; |
| 56 | import com.savoirfairelinux.sflphone.model.SipCall; |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 57 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 58 | public class SipService extends Service { |
| 59 | |
| 60 | static final String TAG = "SipService"; |
| 61 | static final int DELAY = 5000; /* 5 sec */ |
| 62 | private boolean runFlag = false; |
| 63 | private SipServiceThread sipServiceThread; |
Emeric Vigier | 84e05da | 2012-09-20 14:53:05 -0400 | [diff] [blame] | 64 | private SFLphoneApplication sflphoneApp; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 65 | private SipServiceExecutor mExecutor; |
| 66 | private static HandlerThread executorThread; |
| 67 | private CallManagerJNI callManagerJNI; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 68 | private CallManagerCallBack callManagerCallBack; |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 69 | private ConfigurationManagerJNI configurationManagerJNI; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 70 | private ConfigurationManagerCallback configurationManagerCallback; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 71 | private ManagerImpl managerImpl; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 72 | private boolean isPjSipStackStarted = false; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 73 | |
| 74 | HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 75 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 76 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 77 | private BroadcastReceiver IncomingReceiver = new BroadcastReceiver() { |
| 78 | |
| 79 | @Override |
| 80 | public void onReceive(Context context, Intent intent) { |
| 81 | // Get instance of Vibrator from current Context |
| 82 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 83 | if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) { |
| 84 | Log.i(TAG, "Received" + intent.getAction()); |
| 85 | } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_LOADED)) { |
| 86 | Log.i(TAG, "Received" + intent.getAction()); |
| 87 | } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) { |
| 88 | Log.i(TAG, "Received" + intent.getAction()); |
| 89 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_TEXT)) { |
| 90 | Log.i(TAG, "Received" + intent.getAction()); |
| 91 | sendBroadcast(intent); |
| 92 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 93 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newcall"); |
| 94 | |
| 95 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 96 | callBuilder.startCallCreation(b.getString("CallID")).setAccountID(b.getString("AccountID")).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 97 | callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(b.getString("From"))); |
| 98 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 99 | Intent toSend = new Intent(CallManagerCallBack.INCOMING_CALL); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 100 | try { |
| 101 | SipCall newCall = callBuilder.build(); |
| 102 | toSend.putExtra("newcall",newCall); |
| 103 | current_calls.put(newCall.getCallId(), newCall); |
| 104 | sendBroadcast(toSend); |
| 105 | } catch (Exception e) { |
| 106 | Log.e(TAG, e.toString()); |
| 107 | } |
| 108 | |
| 109 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 110 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 111 | |
| 112 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 113 | String newState = b.getString("State"); |
| 114 | if (newState.equals("INCOMING")) { |
| 115 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_INCOMING); |
| 116 | } else if (newState.equals("RINGING")) { |
| 117 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_RINGING); |
| 118 | } else if (newState.equals("CURRENT")) { |
| 119 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_CURRENT); |
| 120 | } else if (newState.equals("HUNGUP")) { |
| 121 | current_calls.remove(b.getString("CallID")); |
| 122 | } else if (newState.equals("BUSY")) { |
| 123 | current_calls.remove(b.getString("CallID")); |
| 124 | } else if (newState.equals("FAILURE")) { |
| 125 | current_calls.remove(b.getString("CallID")); |
| 126 | } else if (newState.equals("HOLD")) { |
| 127 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_HOLD); |
| 128 | } else if (newState.equals("UNHOLD")) { |
| 129 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_CURRENT); |
| 130 | } else { |
| 131 | current_calls.get(b.getString("CallID")).setmCallState(SipCall.state.CALL_STATE_NONE); |
| 132 | } |
| 133 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 134 | sendBroadcast(intent); |
| 135 | } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { |
| 136 | Log.i(TAG, "Received" + intent.getAction()); |
| 137 | Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| 138 | mVibrator.vibrate(300); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | @Override |
| 145 | public boolean onUnbind(Intent i) { |
| 146 | super.onUnbind(i); |
| 147 | Log.i(TAG, "onUnbind(intent)"); |
| 148 | return false; |
| 149 | |
| 150 | } |
| 151 | |
| 152 | /* called once by startService() */ |
| 153 | @Override |
| 154 | public void onCreate() { |
| 155 | Log.i(TAG, "onCreated"); |
| 156 | super.onCreate(); |
| 157 | |
| 158 | sflphoneApp = (SFLphoneApplication) getApplication(); |
| 159 | sipServiceThread = new SipServiceThread(); |
| 160 | |
| 161 | IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED); |
| 162 | callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 163 | callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED); |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 164 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
| 165 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
| 166 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_LOADED); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 167 | callFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 168 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 169 | LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver, callFilter); |
| 170 | getExecutor().execute(new StartRunnable()); |
| 171 | } |
| 172 | |
| 173 | /* called for each startService() */ |
| 174 | @Override |
| 175 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 176 | Log.i(TAG, "onStarted"); |
| 177 | super.onStartCommand(intent, flags, startId); |
| 178 | |
| 179 | if (!runFlag) { |
| 180 | sipServiceThread.start(); |
| 181 | runFlag = true; |
| 182 | sflphoneApp.setServiceRunning(true); |
| 183 | Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show(); |
| 184 | } |
| 185 | |
| 186 | return START_STICKY; /* started and stopped explicitly */ |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void onDestroy() { |
| 191 | /* called once by stopService() */ |
| 192 | sipServiceThread.interrupt(); |
| 193 | sipServiceThread = null; |
| 194 | runFlag = false; |
| 195 | sflphoneApp.setServiceRunning(false); |
| 196 | Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show(); |
| 197 | super.onDestroy(); |
| 198 | |
| 199 | Log.i(TAG, "onDestroyed"); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public IBinder onBind(Intent arg0) { |
| 204 | Log.i(TAG, "onBound"); |
| 205 | return mBinder; |
| 206 | } |
| 207 | |
| 208 | private static Looper createLooper() { |
| 209 | if (executorThread == null) { |
| 210 | Log.d(TAG, "Creating new handler thread"); |
| 211 | // ADT gives a fake warning due to bad parse rule. |
| 212 | executorThread = new HandlerThread("SipService.Executor"); |
| 213 | executorThread.start(); |
| 214 | } |
| 215 | return executorThread.getLooper(); |
| 216 | } |
| 217 | |
| 218 | public SipServiceExecutor getExecutor() { |
| 219 | // create mExecutor lazily |
| 220 | if (mExecutor == null) { |
| 221 | mExecutor = new SipServiceExecutor(this); |
| 222 | } |
| 223 | return mExecutor; |
| 224 | } |
| 225 | |
| 226 | // Executes immediate tasks in a single executorThread. |
| 227 | public static class SipServiceExecutor extends Handler { |
| 228 | WeakReference<SipService> handlerService; |
| 229 | |
| 230 | SipServiceExecutor(SipService s) { |
| 231 | super(createLooper()); |
| 232 | handlerService = new WeakReference<SipService>(s); |
| 233 | } |
| 234 | |
| 235 | public void execute(Runnable task) { |
| 236 | // TODO: add wakelock |
| 237 | Message.obtain(this, 0/* don't care */, task).sendToTarget(); |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public void handleMessage(Message msg) { |
| 242 | if (msg.obj instanceof Runnable) { |
| 243 | executeInternal((Runnable) msg.obj); |
| 244 | } else { |
| 245 | Log.w(TAG, "can't handle msg: " + msg); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | private void executeInternal(Runnable task) { |
| 250 | try { |
| 251 | task.run(); |
| 252 | } catch (Throwable t) { |
| 253 | Log.e(TAG, "run task: " + task, t); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | private void startPjSipStack() throws SameThreadException { |
| 259 | if (isPjSipStackStarted) |
| 260 | return; |
| 261 | |
| 262 | try { |
| 263 | System.loadLibrary("gnustl_shared"); |
| 264 | System.loadLibrary("expat"); |
| 265 | System.loadLibrary("yaml"); |
| 266 | System.loadLibrary("ccgnu2"); |
| 267 | System.loadLibrary("crypto"); |
| 268 | System.loadLibrary("ssl"); |
| 269 | System.loadLibrary("ccrtp1"); |
| 270 | System.loadLibrary("dbus"); |
| 271 | System.loadLibrary("dbus-c++-1"); |
| 272 | System.loadLibrary("samplerate"); |
| 273 | System.loadLibrary("codec_ulaw"); |
| 274 | System.loadLibrary("codec_alaw"); |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 275 | System.loadLibrary("codec_g722"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 276 | System.loadLibrary("speexresampler"); |
| 277 | System.loadLibrary("sflphone"); |
| 278 | isPjSipStackStarted = true; |
| 279 | } catch (UnsatisfiedLinkError e) { |
| 280 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 281 | isPjSipStackStarted = false; |
| 282 | return; |
| 283 | } catch (Exception e) { |
| 284 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 285 | } |
| 286 | |
| 287 | /* get unique instance of managerImpl */ |
| 288 | managerImpl = SFLPhoneservice.instance(); |
| 289 | |
| 290 | /* set static AppPath before calling manager.init */ |
| 291 | managerImpl.setPath(sflphoneApp.getAppPath()); |
| 292 | |
| 293 | callManagerJNI = new CallManagerJNI(); |
| 294 | callManagerCallBack = new CallManagerCallBack(this); |
| 295 | SFLPhoneservice.setCallbackObject(callManagerCallBack); |
| 296 | |
| 297 | configurationManagerJNI = new ConfigurationManagerJNI(); |
| 298 | configurationManagerCallback = new ConfigurationManagerCallback(this); |
| 299 | SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback); |
| 300 | |
| 301 | managerImpl.init(""); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | // Enforce same thread contract to ensure we do not call from somewhere else |
| 306 | public class SameThreadException extends Exception { |
| 307 | private static final long serialVersionUID = -905639124232613768L; |
| 308 | |
| 309 | public SameThreadException() { |
| 310 | super("Should be launched from a single worker thread"); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | public abstract static class SipRunnable implements Runnable { |
| 315 | protected abstract void doRun() throws SameThreadException, RemoteException; |
| 316 | |
| 317 | public void run() { |
| 318 | try { |
| 319 | doRun(); |
| 320 | } catch (SameThreadException e) { |
| 321 | Log.e(TAG, "Not done from same thread"); |
| 322 | } catch (RemoteException e) { |
| 323 | Log.e(TAG, e.toString()); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | public abstract static class SipRunnableWithReturn implements Runnable { |
| 329 | Object obj = null; |
| 330 | boolean done = false; |
| 331 | |
| 332 | protected abstract Object doRun() throws SameThreadException; |
| 333 | |
| 334 | public Object getVal() { |
| 335 | return obj; |
| 336 | } |
| 337 | |
| 338 | public boolean isDone() { |
| 339 | return done; |
| 340 | } |
| 341 | |
| 342 | public void run() { |
| 343 | try { |
| 344 | obj = doRun(); |
| 345 | done = true; |
| 346 | } catch (SameThreadException e) { |
| 347 | Log.e(TAG, "Not done from same thread"); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | class StartRunnable extends SipRunnable { |
| 353 | @Override |
| 354 | protected void doRun() throws SameThreadException { |
| 355 | startPjSipStack(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | private class SipServiceThread extends Thread { |
| 360 | |
| 361 | public SipServiceThread() { |
| 362 | super("sipServiceThread"); |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void run() { |
| 367 | Log.i(TAG, "SipService thread running..."); |
| 368 | SipService sipService = SipService.this; |
| 369 | while (sipService.runFlag) { |
| 370 | try { |
| 371 | Thread.sleep(DELAY); |
| 372 | } catch (InterruptedException e) { |
| 373 | sipService.runFlag = false; |
| 374 | Log.w(TAG, "service thread interrupted!"); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /* ************************************ |
| 381 | * |
| 382 | * Implement public interface for the service |
| 383 | * |
| 384 | * |
| 385 | * ********************************** |
| 386 | */ |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 387 | private final ISipService.Stub mBinder = new ISipService.Stub() { |
| 388 | |
| 389 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 390 | public void placeCall(final SipCall call) { |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 391 | getExecutor().execute(new SipRunnable() { |
| 392 | @Override |
| 393 | protected void doRun() throws SameThreadException { |
| 394 | Log.i(TAG, "SipService.placeCall() thread running..."); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 395 | callManagerJNI.placeCall(call.getAccountID(), call.getCallId(), call.getContacts().get(0).getPhones().get(0).getNumber()); |
| 396 | current_calls.put(call.getCallId(), call); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 397 | } |
| 398 | }); |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public void refuse(final String callID) { |
| 403 | getExecutor().execute(new SipRunnable() { |
| 404 | @Override |
| 405 | protected void doRun() throws SameThreadException { |
| 406 | Log.i(TAG, "SipService.refuse() thread running..."); |
| 407 | callManagerJNI.refuse(callID); |
| 408 | } |
| 409 | }); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public void accept(final String callID) { |
| 414 | getExecutor().execute(new SipRunnable() { |
| 415 | @Override |
| 416 | protected void doRun() throws SameThreadException { |
| 417 | Log.i(TAG, "SipService.placeCall() thread running..."); |
| 418 | callManagerJNI.accept(callID); |
| 419 | } |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void hangUp(final String callID) { |
| 425 | getExecutor().execute(new SipRunnable() { |
| 426 | @Override |
| 427 | protected void doRun() throws SameThreadException { |
| 428 | Log.i(TAG, "SipService.hangUp() thread running..."); |
| 429 | callManagerJNI.hangUp(callID); |
| 430 | } |
| 431 | }); |
| 432 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 433 | |
| 434 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 435 | public void hold(final String callID) { |
| 436 | getExecutor().execute(new SipRunnable() { |
| 437 | @Override |
| 438 | protected void doRun() throws SameThreadException { |
| 439 | Log.i(TAG, "SipService.hold() thread running..."); |
| 440 | callManagerJNI.hold(callID); |
| 441 | } |
| 442 | }); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public void unhold(final String callID) { |
| 447 | getExecutor().execute(new SipRunnable() { |
| 448 | @Override |
| 449 | protected void doRun() throws SameThreadException { |
| 450 | Log.i(TAG, "SipService.unhold() thread running..."); |
| 451 | callManagerJNI.unhold(callID); |
| 452 | } |
| 453 | }); |
| 454 | } |
| 455 | |
| 456 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 457 | public void setAudioPlugin(final String audioPlugin) { |
| 458 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 459 | @Override |
| 460 | protected void doRun() throws SameThreadException { |
| 461 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
| 462 | configurationManagerJNI.setAudioPlugin(audioPlugin); |
| 463 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 464 | }); |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public String getCurrentAudioOutputPlugin() { |
| 469 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 470 | @Override |
| 471 | protected String doRun() throws SameThreadException { |
| 472 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
| 473 | return configurationManagerJNI.getCurrentAudioOutputPlugin(); |
| 474 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 475 | } |
| 476 | ; |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 477 | |
| 478 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 479 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 480 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 481 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 482 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 483 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 484 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 485 | |
| 486 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 487 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 488 | class AccountList extends SipRunnableWithReturn { |
| 489 | @Override |
| 490 | protected StringVect doRun() throws SameThreadException { |
| 491 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 492 | return configurationManagerJNI.getAccountList(); |
| 493 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 494 | } |
| 495 | ; |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 496 | AccountList runInstance = new AccountList(); |
| 497 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 498 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 499 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 500 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 501 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 502 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 503 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 504 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 505 | for (int i = 0; i < swigvect.size(); i++) |
| 506 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 507 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 508 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 509 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 510 | |
| 511 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 512 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 513 | class AccountDetails extends SipRunnableWithReturn { |
| 514 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 515 | |
| 516 | AccountDetails(String accountId) { |
| 517 | id = accountId; |
| 518 | } |
| 519 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 520 | @Override |
| 521 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 522 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 523 | return configurationManagerJNI.getAccountDetails(id); |
| 524 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 525 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 526 | |
| 527 | AccountDetails runInstance = new AccountDetails(accountID); |
| 528 | getExecutor().execute(runInstance); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 529 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 530 | while (!runInstance.isDone()) { |
| 531 | } |
| 532 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 533 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 534 | HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 535 | |
| 536 | return nativemap; |
| 537 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 538 | |
| 539 | @Override |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 540 | public void setAccountDetails(final String accountId, Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 541 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 542 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 543 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 544 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 545 | getExecutor().execute(new SipRunnable() { |
| 546 | @Override |
| 547 | protected void doRun() throws SameThreadException { |
| 548 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 549 | configurationManagerJNI.setAccountDetails(accountId, swigmap); |
| 550 | } |
| 551 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 554 | @Override |
| 555 | public String addAccount(Map map) { |
| 556 | class AddAccount extends SipRunnableWithReturn { |
| 557 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 558 | |
| 559 | AddAccount(StringMap m) { |
| 560 | map = m; |
| 561 | } |
| 562 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 563 | @Override |
| 564 | protected String doRun() throws SameThreadException { |
| 565 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
| 566 | return configurationManagerJNI.addAccount(map); |
| 567 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 568 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 569 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 570 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 571 | |
| 572 | AddAccount runInstance = new AddAccount(swigmap); |
| 573 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 574 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 575 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 576 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 577 | String accountId = (String) runInstance.getVal(); |
| 578 | |
| 579 | return accountId; |
| 580 | } |
| 581 | |
| 582 | @Override |
| 583 | public void removeAccount(final String accountId) { |
| 584 | getExecutor().execute(new SipRunnable() { |
| 585 | @Override |
| 586 | protected void doRun() throws SameThreadException { |
| 587 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 588 | configurationManagerJNI.removeAccount(accountId); |
| 589 | } |
| 590 | }); |
| 591 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 592 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 593 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 594 | @Override |
| 595 | public ArrayList<HashMap<String, String>> getHistory() throws RemoteException { |
| 596 | class History extends SipRunnableWithReturn { |
| 597 | |
| 598 | @Override |
| 599 | protected VectMap doRun() throws SameThreadException { |
| 600 | Log.i(TAG, "SipService.getHistory() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 601 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 602 | return configurationManagerJNI.getHistory(); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | History runInstance = new History(); |
| 607 | getExecutor().execute(runInstance); |
| 608 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 609 | // Log.w(TAG, "Waiting for getHistory"); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 610 | } |
| 611 | VectMap swigmap = (VectMap) runInstance.getVal(); |
| 612 | |
| 613 | ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap); |
| 614 | |
| 615 | return nativemap; |
| 616 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 617 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 618 | /************************* |
| 619 | * Transfer related API |
| 620 | *************************/ |
| 621 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 622 | @Override |
| 623 | public void transfer(final String callID, final String to) throws RemoteException { |
| 624 | getExecutor().execute(new SipRunnable() { |
| 625 | @Override |
| 626 | protected void doRun() throws SameThreadException, RemoteException { |
| 627 | Log.i(TAG, "SipService.transfer() thread running..."); |
| 628 | if (callManagerJNI.transfer(callID, to)) { |
| 629 | Bundle bundle = new Bundle(); |
| 630 | bundle.putString("CallID", callID); |
| 631 | bundle.putString("State", "HUNGUP"); |
| 632 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 633 | intent.putExtra(CallManagerCallBack.SIGNAL_NAME, CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 634 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 635 | sendBroadcast(intent); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 636 | } else |
| 637 | Log.i(TAG, "NOT OK"); |
| 638 | } |
| 639 | }); |
| 640 | |
| 641 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 642 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 643 | @Override |
| 644 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 645 | getExecutor().execute(new SipRunnable() { |
| 646 | @Override |
| 647 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 648 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 649 | if (callManagerJNI.attendedTransfer(transferID, targetID)) { |
| 650 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 651 | } else |
| 652 | Log.i(TAG, "NOT OK"); |
| 653 | } |
| 654 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 655 | |
| 656 | } |
| 657 | |
| 658 | /************************* |
| 659 | * Conference related API |
| 660 | *************************/ |
| 661 | |
| 662 | @Override |
| 663 | public void removeConference(final String confID) throws RemoteException { |
| 664 | getExecutor().execute(new SipRunnable() { |
| 665 | @Override |
| 666 | protected void doRun() throws SameThreadException, RemoteException { |
| 667 | Log.i(TAG, "SipService.createConference() thread running..."); |
| 668 | callManagerJNI.removeConference(confID); |
| 669 | } |
| 670 | }); |
| 671 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 675 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 676 | getExecutor().execute(new SipRunnable() { |
| 677 | @Override |
| 678 | protected void doRun() throws SameThreadException, RemoteException { |
| 679 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
| 680 | callManagerJNI.joinParticipant(sel_callID, drag_callID); |
| 681 | } |
| 682 | }); |
| 683 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 687 | public void createConfFromParticipantList(final List participants) throws RemoteException { |
| 688 | getExecutor().execute(new SipRunnable() { |
| 689 | @Override |
| 690 | protected void doRun() throws SameThreadException, RemoteException { |
| 691 | Log.i(TAG, "SipService.createConfFromParticipantList() thread running..."); |
| 692 | // callManagerJNI.createConfFromParticipantList(participants); |
| 693 | } |
| 694 | }); |
| 695 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 699 | public void addParticipant(final String callID, final String confID) throws RemoteException { |
| 700 | getExecutor().execute(new SipRunnable() { |
| 701 | @Override |
| 702 | protected void doRun() throws SameThreadException, RemoteException { |
| 703 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
| 704 | callManagerJNI.addParticipant(callID, confID); |
| 705 | } |
| 706 | }); |
| 707 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 711 | public void addMainParticipant(final String confID) throws RemoteException { |
| 712 | getExecutor().execute(new SipRunnable() { |
| 713 | @Override |
| 714 | protected void doRun() throws SameThreadException, RemoteException { |
| 715 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
| 716 | callManagerJNI.addMainParticipant(confID); |
| 717 | } |
| 718 | }); |
| 719 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 723 | public void detachParticipant(final String callID) throws RemoteException { |
| 724 | getExecutor().execute(new SipRunnable() { |
| 725 | @Override |
| 726 | protected void doRun() throws SameThreadException, RemoteException { |
| 727 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
| 728 | callManagerJNI.detachParticipant(callID); |
| 729 | } |
| 730 | }); |
| 731 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 735 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 736 | getExecutor().execute(new SipRunnable() { |
| 737 | @Override |
| 738 | protected void doRun() throws SameThreadException, RemoteException { |
| 739 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 740 | callManagerJNI.joinConference(sel_confID, drag_confID); |
| 741 | } |
| 742 | }); |
| 743 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 747 | public void hangUpConference(final String confID) throws RemoteException { |
| 748 | getExecutor().execute(new SipRunnable() { |
| 749 | @Override |
| 750 | protected void doRun() throws SameThreadException, RemoteException { |
| 751 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 752 | callManagerJNI.hangUpConference(confID); |
| 753 | } |
| 754 | }); |
| 755 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 759 | public void holdConference(final String confID) throws RemoteException { |
| 760 | getExecutor().execute(new SipRunnable() { |
| 761 | @Override |
| 762 | protected void doRun() throws SameThreadException, RemoteException { |
| 763 | Log.i(TAG, "SipService.holdConference() thread running..."); |
| 764 | callManagerJNI.holdConference(confID); |
| 765 | } |
| 766 | }); |
| 767 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 771 | public void unholdConference(final String confID) throws RemoteException { |
| 772 | getExecutor().execute(new SipRunnable() { |
| 773 | @Override |
| 774 | protected void doRun() throws SameThreadException, RemoteException { |
| 775 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
| 776 | callManagerJNI.unholdConference(confID); |
| 777 | } |
| 778 | }); |
| 779 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | @Override |
| 783 | public List getConferenceList() throws RemoteException { |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 784 | class ConfList extends SipRunnableWithReturn { |
| 785 | @Override |
| 786 | protected StringVect doRun() throws SameThreadException { |
| 787 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 788 | return callManagerJNI.getConferenceList(); |
| 789 | } |
| 790 | } |
| 791 | ; |
| 792 | ConfList runInstance = new ConfList(); |
| 793 | getExecutor().execute(runInstance); |
| 794 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 795 | // Log.w(TAG, "Waiting for getConferenceList"); |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 796 | } |
| 797 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 798 | |
| 799 | ArrayList<String> nativelist = new ArrayList<String>(); |
| 800 | |
| 801 | for (int i = 0; i < swigvect.size(); i++) |
| 802 | nativelist.add(swigvect.get(i)); |
| 803 | |
| 804 | return nativelist; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | @Override |
| 808 | public List getParticipantList(String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 809 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 810 | return null; |
| 811 | } |
| 812 | |
| 813 | @Override |
| 814 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 815 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 816 | return null; |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public Map getConferenceDetails(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 821 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 822 | return null; |
| 823 | } |
| 824 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 825 | @Override |
| 826 | public String getRecordPath() throws RemoteException { |
| 827 | class RecordPath extends SipRunnableWithReturn { |
| 828 | |
| 829 | @Override |
| 830 | protected String doRun() throws SameThreadException { |
| 831 | Log.i(TAG, "SipService.getRecordPath() thread running..."); |
| 832 | return configurationManagerJNI.getRecordPath(); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | RecordPath runInstance = new RecordPath(); |
| 837 | getExecutor().execute(runInstance); |
| 838 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 839 | // Log.w(TAG, "Waiting for getRecordPath"); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 840 | } |
| 841 | String path = (String) runInstance.getVal(); |
| 842 | |
| 843 | return path; |
| 844 | } |
| 845 | |
| 846 | @Override |
| 847 | public void setRecordingCall(final String id) throws RemoteException { |
| 848 | getExecutor().execute(new SipRunnable() { |
| 849 | @Override |
| 850 | protected void doRun() throws SameThreadException, RemoteException { |
| 851 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 852 | callManagerJNI.setRecordingCall(id); |
| 853 | } |
| 854 | }); |
| 855 | |
| 856 | } |
| 857 | |
| 858 | @Override |
| 859 | public void setRecordPath(final String path) throws RemoteException { |
| 860 | getExecutor().execute(new SipRunnable() { |
| 861 | @Override |
| 862 | protected void doRun() throws SameThreadException, RemoteException { |
| 863 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 864 | configurationManagerJNI.setRecordPath(path); |
| 865 | } |
| 866 | }); |
| 867 | } |
| 868 | |
| 869 | @Override |
| 870 | public void sendTextMessage(final String callID, final String message, final String from) throws RemoteException { |
| 871 | getExecutor().execute(new SipRunnable() { |
| 872 | @Override |
| 873 | protected void doRun() throws SameThreadException, RemoteException { |
| 874 | Log.i(TAG, "SipService.sendTextMessage() thread running..."); |
| 875 | callManagerJNI.sendTextMessage(callID, message, from); |
| 876 | } |
| 877 | }); |
| 878 | |
| 879 | } |
| 880 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 881 | @Override |
| 882 | public List getAudioCodecList(String accountID) throws RemoteException { |
| 883 | class AudioCodecList extends SipRunnableWithReturn { |
| 884 | |
| 885 | @Override |
| 886 | protected IntVect doRun() throws SameThreadException { |
| 887 | Log.i(TAG, "SipService.getAudioCodecList() thread running..."); |
| 888 | return configurationManagerJNI.getAudioCodecList(); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | AudioCodecList runInstance = new AudioCodecList(); |
| 893 | getExecutor().execute(runInstance); |
| 894 | while (!runInstance.isDone()) { |
| 895 | Log.w(TAG, "Waiting for getAudioCodecList"); |
| 896 | } |
| 897 | IntVect swigmap = (IntVect) runInstance.getVal(); |
| 898 | |
| 899 | ArrayList<Integer> codecs = AudioHandler.convertSwigToNative(swigmap); |
| 900 | |
| 901 | return codecs; |
| 902 | } |
| 903 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 904 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 905 | public HashMap<String, SipCall> getCallList() throws RemoteException { |
| 906 | // class CallList extends SipRunnableWithReturn { |
| 907 | // |
| 908 | // @Override |
| 909 | // protected StringVect doRun() throws SameThreadException { |
| 910 | // Log.i(TAG, "SipService.getCallList() thread running..."); |
| 911 | // return callManagerJNI.getCallList(); |
| 912 | // } |
| 913 | // } |
| 914 | // |
| 915 | // CallList runInstance = new CallList(); |
| 916 | // getExecutor().execute(runInstance); |
| 917 | // while (!runInstance.isDone()) { |
| 918 | // Log.w(TAG, "Waiting for getAudioCodecList"); |
| 919 | // } |
| 920 | // StringVect swigmap = (StringVect) runInstance.getVal(); |
| 921 | // |
| 922 | // ArrayList<String> nativemap = new ArrayList<String>(); |
| 923 | // for (int i = 0; i < swigmap.size(); ++i) { |
| 924 | // |
| 925 | // String t = swigmap.get(i); |
| 926 | // nativemap.add(t); |
| 927 | // } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 928 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 929 | return current_calls; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 932 | }; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 933 | } |