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) |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 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 | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 30 | import java.util.Iterator; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 31 | import java.util.List; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 32 | import java.util.Map; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 33 | import java.util.Map.Entry; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 34 | import java.util.Random; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 35 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 36 | import android.app.Notification; |
| 37 | import android.app.NotificationManager; |
| 38 | import android.app.PendingIntent; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 39 | import android.app.Service; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 40 | import android.content.Context; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 41 | import android.content.Intent; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 42 | import android.content.IntentFilter; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 43 | import android.os.Bundle; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 44 | import android.os.Handler; |
| 45 | import android.os.HandlerThread; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 46 | import android.os.IBinder; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 47 | import android.os.Looper; |
| 48 | import android.os.Message; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 49 | import android.os.RemoteException; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 50 | import android.support.v4.app.NotificationCompat; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 51 | import android.support.v4.content.LocalBroadcastManager; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 52 | import android.util.Log; |
| 53 | import android.widget.Toast; |
| 54 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 56 | import com.savoirfairelinux.sflphone.account.AccountDetailsHandler; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 57 | import com.savoirfairelinux.sflphone.account.HistoryHandler; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.client.SFLphoneApplication; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.receivers.IncomingReceiver; |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 63 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 64 | public class SipService extends Service { |
| 65 | |
| 66 | static final String TAG = "SipService"; |
| 67 | static final int DELAY = 5000; /* 5 sec */ |
| 68 | private boolean runFlag = false; |
| 69 | private SipServiceThread sipServiceThread; |
Emeric Vigier | 84e05da | 2012-09-20 14:53:05 -0400 | [diff] [blame] | 70 | private SFLphoneApplication sflphoneApp; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 71 | private SipServiceExecutor mExecutor; |
| 72 | private static HandlerThread executorThread; |
| 73 | private CallManagerJNI callManagerJNI; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 74 | private CallManagerCallBack callManagerCallBack; |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 75 | private ConfigurationManagerJNI configurationManagerJNI; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 76 | private ConfigurationManagerCallback configurationManagerCallback; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 77 | private ManagerImpl managerImpl; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 78 | private boolean isPjSipStackStarted = false; |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 79 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 80 | public static final String NOTIF_CREATION = "notif_creation"; |
| 81 | public static final String NOTIF_DELETION = "notif_deletion"; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 82 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 83 | private HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 84 | private HashMap<String, Conference> current_confs = new HashMap<String, Conference>(); |
| 85 | private IncomingReceiver receiver; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 86 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 87 | public HashMap<String, Conference> getCurrent_confs() { |
| 88 | return current_confs; |
| 89 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 90 | |
| 91 | @Override |
| 92 | public boolean onUnbind(Intent i) { |
| 93 | super.onUnbind(i); |
| 94 | Log.i(TAG, "onUnbind(intent)"); |
| 95 | return false; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | /* called once by startService() */ |
| 100 | @Override |
| 101 | public void onCreate() { |
| 102 | Log.i(TAG, "onCreated"); |
| 103 | super.onCreate(); |
| 104 | |
| 105 | sflphoneApp = (SFLphoneApplication) getApplication(); |
| 106 | sipServiceThread = new SipServiceThread(); |
| 107 | |
| 108 | IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED); |
| 109 | callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 110 | callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED); |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 111 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
| 112 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 113 | callFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 114 | callFilter.addAction(CallManagerCallBack.CONF_CREATED); |
| 115 | callFilter.addAction(CallManagerCallBack.CONF_REMOVED); |
| 116 | callFilter.addAction(CallManagerCallBack.CONF_CHANGED); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 117 | callFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 118 | receiver = new IncomingReceiver(this, mBinder); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 119 | LocalBroadcastManager.getInstance(this).registerReceiver(receiver, callFilter); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 120 | |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 121 | getExecutor().execute(new StartRunnable()); |
| 122 | |
| 123 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 124 | |
| 125 | /* called for each startService() */ |
| 126 | @Override |
| 127 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 128 | Log.i(TAG, "onStarted"); |
| 129 | super.onStartCommand(intent, flags, startId); |
| 130 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 131 | receiver = new IncomingReceiver(this, mBinder); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 132 | if (!runFlag) { |
| 133 | sipServiceThread.start(); |
| 134 | runFlag = true; |
| 135 | sflphoneApp.setServiceRunning(true); |
| 136 | Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show(); |
| 137 | } |
| 138 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 139 | return START_NOT_STICKY; /* started and stopped explicitly */ |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void onDestroy() { |
| 144 | /* called once by stopService() */ |
| 145 | sipServiceThread.interrupt(); |
| 146 | sipServiceThread = null; |
| 147 | runFlag = false; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 148 | unregisterReceiver(receiver); |
| 149 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 150 | sflphoneApp.setServiceRunning(false); |
| 151 | Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show(); |
| 152 | super.onDestroy(); |
| 153 | |
| 154 | Log.i(TAG, "onDestroyed"); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public IBinder onBind(Intent arg0) { |
| 159 | Log.i(TAG, "onBound"); |
| 160 | return mBinder; |
| 161 | } |
| 162 | |
| 163 | private static Looper createLooper() { |
| 164 | if (executorThread == null) { |
| 165 | Log.d(TAG, "Creating new handler thread"); |
| 166 | // ADT gives a fake warning due to bad parse rule. |
| 167 | executorThread = new HandlerThread("SipService.Executor"); |
| 168 | executorThread.start(); |
| 169 | } |
| 170 | return executorThread.getLooper(); |
| 171 | } |
| 172 | |
| 173 | public SipServiceExecutor getExecutor() { |
| 174 | // create mExecutor lazily |
| 175 | if (mExecutor == null) { |
| 176 | mExecutor = new SipServiceExecutor(this); |
| 177 | } |
| 178 | return mExecutor; |
| 179 | } |
| 180 | |
| 181 | // Executes immediate tasks in a single executorThread. |
| 182 | public static class SipServiceExecutor extends Handler { |
| 183 | WeakReference<SipService> handlerService; |
| 184 | |
| 185 | SipServiceExecutor(SipService s) { |
| 186 | super(createLooper()); |
| 187 | handlerService = new WeakReference<SipService>(s); |
| 188 | } |
| 189 | |
| 190 | public void execute(Runnable task) { |
| 191 | // TODO: add wakelock |
| 192 | Message.obtain(this, 0/* don't care */, task).sendToTarget(); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void handleMessage(Message msg) { |
| 197 | if (msg.obj instanceof Runnable) { |
| 198 | executeInternal((Runnable) msg.obj); |
| 199 | } else { |
| 200 | Log.w(TAG, "can't handle msg: " + msg); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | private void executeInternal(Runnable task) { |
| 205 | try { |
| 206 | task.run(); |
| 207 | } catch (Throwable t) { |
| 208 | Log.e(TAG, "run task: " + task, t); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | private void startPjSipStack() throws SameThreadException { |
| 214 | if (isPjSipStackStarted) |
| 215 | return; |
| 216 | |
| 217 | try { |
| 218 | System.loadLibrary("gnustl_shared"); |
| 219 | System.loadLibrary("expat"); |
| 220 | System.loadLibrary("yaml"); |
| 221 | System.loadLibrary("ccgnu2"); |
| 222 | System.loadLibrary("crypto"); |
| 223 | System.loadLibrary("ssl"); |
| 224 | System.loadLibrary("ccrtp1"); |
| 225 | System.loadLibrary("dbus"); |
| 226 | System.loadLibrary("dbus-c++-1"); |
| 227 | System.loadLibrary("samplerate"); |
| 228 | System.loadLibrary("codec_ulaw"); |
| 229 | System.loadLibrary("codec_alaw"); |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 230 | System.loadLibrary("codec_g722"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 231 | System.loadLibrary("speexresampler"); |
| 232 | System.loadLibrary("sflphone"); |
| 233 | isPjSipStackStarted = true; |
| 234 | } catch (UnsatisfiedLinkError e) { |
| 235 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 236 | isPjSipStackStarted = false; |
| 237 | return; |
| 238 | } catch (Exception e) { |
| 239 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 240 | } |
| 241 | |
| 242 | /* get unique instance of managerImpl */ |
| 243 | managerImpl = SFLPhoneservice.instance(); |
| 244 | |
| 245 | /* set static AppPath before calling manager.init */ |
| 246 | managerImpl.setPath(sflphoneApp.getAppPath()); |
| 247 | |
| 248 | callManagerJNI = new CallManagerJNI(); |
| 249 | callManagerCallBack = new CallManagerCallBack(this); |
| 250 | SFLPhoneservice.setCallbackObject(callManagerCallBack); |
| 251 | |
| 252 | configurationManagerJNI = new ConfigurationManagerJNI(); |
| 253 | configurationManagerCallback = new ConfigurationManagerCallback(this); |
| 254 | SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback); |
| 255 | |
| 256 | managerImpl.init(""); |
| 257 | return; |
| 258 | } |
| 259 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 260 | public HashMap<String, SipCall> getCurrent_calls() { |
| 261 | return current_calls; |
| 262 | } |
| 263 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 264 | // Enforce same thread contract to ensure we do not call from somewhere else |
| 265 | public class SameThreadException extends Exception { |
| 266 | private static final long serialVersionUID = -905639124232613768L; |
| 267 | |
| 268 | public SameThreadException() { |
| 269 | super("Should be launched from a single worker thread"); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | public abstract static class SipRunnable implements Runnable { |
| 274 | protected abstract void doRun() throws SameThreadException, RemoteException; |
| 275 | |
| 276 | public void run() { |
| 277 | try { |
| 278 | doRun(); |
| 279 | } catch (SameThreadException e) { |
| 280 | Log.e(TAG, "Not done from same thread"); |
| 281 | } catch (RemoteException e) { |
| 282 | Log.e(TAG, e.toString()); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | public abstract static class SipRunnableWithReturn implements Runnable { |
| 288 | Object obj = null; |
| 289 | boolean done = false; |
| 290 | |
| 291 | protected abstract Object doRun() throws SameThreadException; |
| 292 | |
| 293 | public Object getVal() { |
| 294 | return obj; |
| 295 | } |
| 296 | |
| 297 | public boolean isDone() { |
| 298 | return done; |
| 299 | } |
| 300 | |
| 301 | public void run() { |
| 302 | try { |
| 303 | obj = doRun(); |
| 304 | done = true; |
| 305 | } catch (SameThreadException e) { |
| 306 | Log.e(TAG, "Not done from same thread"); |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | class StartRunnable extends SipRunnable { |
| 312 | @Override |
| 313 | protected void doRun() throws SameThreadException { |
| 314 | startPjSipStack(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | private class SipServiceThread extends Thread { |
| 319 | |
| 320 | public SipServiceThread() { |
| 321 | super("sipServiceThread"); |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void run() { |
| 326 | Log.i(TAG, "SipService thread running..."); |
| 327 | SipService sipService = SipService.this; |
| 328 | while (sipService.runFlag) { |
| 329 | try { |
| 330 | Thread.sleep(DELAY); |
| 331 | } catch (InterruptedException e) { |
| 332 | sipService.runFlag = false; |
| 333 | Log.w(TAG, "service thread interrupted!"); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /* ************************************ |
| 340 | * |
| 341 | * Implement public interface for the service |
| 342 | * |
| 343 | * |
| 344 | * ********************************** |
| 345 | */ |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 346 | private final ISipService.Stub mBinder = new ISipService.Stub() { |
| 347 | |
| 348 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 349 | public void placeCall(final SipCall call) { |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 350 | getExecutor().execute(new SipRunnable() { |
| 351 | @Override |
| 352 | protected void doRun() throws SameThreadException { |
| 353 | Log.i(TAG, "SipService.placeCall() thread running..."); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 354 | callManagerJNI.placeCall(call.getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber()); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 355 | getCurrent_calls().put(call.getCallId(), call); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 356 | } |
| 357 | }); |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void refuse(final String callID) { |
| 362 | getExecutor().execute(new SipRunnable() { |
| 363 | @Override |
| 364 | protected void doRun() throws SameThreadException { |
| 365 | Log.i(TAG, "SipService.refuse() thread running..."); |
| 366 | callManagerJNI.refuse(callID); |
| 367 | } |
| 368 | }); |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void accept(final String callID) { |
| 373 | getExecutor().execute(new SipRunnable() { |
| 374 | @Override |
| 375 | protected void doRun() throws SameThreadException { |
| 376 | Log.i(TAG, "SipService.placeCall() thread running..."); |
| 377 | callManagerJNI.accept(callID); |
| 378 | } |
| 379 | }); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void hangUp(final String callID) { |
| 384 | getExecutor().execute(new SipRunnable() { |
| 385 | @Override |
| 386 | protected void doRun() throws SameThreadException { |
| 387 | Log.i(TAG, "SipService.hangUp() thread running..."); |
| 388 | callManagerJNI.hangUp(callID); |
| 389 | } |
| 390 | }); |
| 391 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 392 | |
| 393 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 394 | public void hold(final String callID) { |
| 395 | getExecutor().execute(new SipRunnable() { |
| 396 | @Override |
| 397 | protected void doRun() throws SameThreadException { |
| 398 | Log.i(TAG, "SipService.hold() thread running..."); |
| 399 | callManagerJNI.hold(callID); |
| 400 | } |
| 401 | }); |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public void unhold(final String callID) { |
| 406 | getExecutor().execute(new SipRunnable() { |
| 407 | @Override |
| 408 | protected void doRun() throws SameThreadException { |
| 409 | Log.i(TAG, "SipService.unhold() thread running..."); |
| 410 | callManagerJNI.unhold(callID); |
| 411 | } |
| 412 | }); |
| 413 | } |
| 414 | |
| 415 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 416 | public void setAudioPlugin(final String audioPlugin) { |
| 417 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 418 | @Override |
| 419 | protected void doRun() throws SameThreadException { |
| 420 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
| 421 | configurationManagerJNI.setAudioPlugin(audioPlugin); |
| 422 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 423 | }); |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public String getCurrentAudioOutputPlugin() { |
| 428 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 429 | @Override |
| 430 | protected String doRun() throws SameThreadException { |
| 431 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
| 432 | return configurationManagerJNI.getCurrentAudioOutputPlugin(); |
| 433 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 434 | } |
| 435 | ; |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 436 | |
| 437 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 438 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 439 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 440 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 441 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 442 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 443 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 444 | |
| 445 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 446 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 447 | class AccountList extends SipRunnableWithReturn { |
| 448 | @Override |
| 449 | protected StringVect doRun() throws SameThreadException { |
| 450 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 451 | return configurationManagerJNI.getAccountList(); |
| 452 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 453 | } |
| 454 | ; |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 455 | AccountList runInstance = new AccountList(); |
| 456 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 457 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 458 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 459 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 460 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 461 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 462 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 463 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 464 | for (int i = 0; i < swigvect.size(); i++) |
| 465 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 466 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 467 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 468 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 469 | |
| 470 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 471 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 472 | class AccountDetails extends SipRunnableWithReturn { |
| 473 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 474 | |
| 475 | AccountDetails(String accountId) { |
| 476 | id = accountId; |
| 477 | } |
| 478 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 479 | @Override |
| 480 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 481 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 482 | return configurationManagerJNI.getAccountDetails(id); |
| 483 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 484 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 485 | |
| 486 | AccountDetails runInstance = new AccountDetails(accountID); |
| 487 | getExecutor().execute(runInstance); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 488 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 489 | while (!runInstance.isDone()) { |
| 490 | } |
| 491 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 492 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 493 | HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 494 | |
| 495 | return nativemap; |
| 496 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 497 | |
| 498 | @Override |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 499 | public void setAccountDetails(final String accountId, final Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 500 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 501 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 502 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 503 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 504 | getExecutor().execute(new SipRunnable() { |
| 505 | @Override |
| 506 | protected void doRun() throws SameThreadException { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 507 | |
| 508 | configurationManagerJNI.setCredentials(accountId, extractCredentials(map)); |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 509 | configurationManagerJNI.setAccountDetails(accountId, swigmap); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 510 | |
| 511 | convertSwigToNative(configurationManagerJNI.getCredentials(accountId)); |
| 512 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 513 | } |
| 514 | |
| 515 | private VectMap extractCredentials(Map map) { |
| 516 | VectMap swigmap = new VectMap(); |
| 517 | StringMap entry = new StringMap(); |
| 518 | entry.set(ServiceConstants.CONFIG_ACCOUNT_USERNAME, (String) map.get(ServiceConstants.CONFIG_ACCOUNT_USERNAME)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 519 | if ((String) map.get(ServiceConstants.CONFIG_ACCOUNT_REALM) != null) |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 520 | entry.set(ServiceConstants.CONFIG_ACCOUNT_REALM, (String) map.get(ServiceConstants.CONFIG_ACCOUNT_REALM)); |
| 521 | else |
| 522 | entry.set(ServiceConstants.CONFIG_ACCOUNT_REALM, "*"); |
| 523 | entry.set(ServiceConstants.CONFIG_ACCOUNT_PASSWORD, (String) map.get(ServiceConstants.CONFIG_ACCOUNT_PASSWORD)); |
| 524 | swigmap.add(entry); |
| 525 | return swigmap; |
| 526 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 527 | } |
| 528 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 529 | } |
| 530 | |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 531 | public ArrayList<HashMap<String, String>> convertSwigToNative(VectMap swigmap) { |
| 532 | |
| 533 | ArrayList<HashMap<String, String>> nativemap = new ArrayList<HashMap<String, String>>(); |
| 534 | Log.i(TAG, "swigmap size " + swigmap.size()); |
| 535 | for (int i = 0; i < swigmap.size(); ++i) { |
| 536 | Log.i(TAG, "Entry " + i); |
| 537 | StringMap tmp = swigmap.get(i); |
| 538 | Log.i(TAG, tmp.get(ServiceConstants.CONFIG_ACCOUNT_USERNAME)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 539 | // Log.i(TAG, tmp.get(ServiceConstants.CONFIG_ACCOUNT_REALM)); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 540 | Log.i(TAG, tmp.get(ServiceConstants.CONFIG_ACCOUNT_PASSWORD)); |
| 541 | } |
| 542 | |
| 543 | return nativemap; |
| 544 | } |
| 545 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 546 | @Override |
| 547 | public String addAccount(Map map) { |
| 548 | class AddAccount extends SipRunnableWithReturn { |
| 549 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 550 | |
| 551 | AddAccount(StringMap m) { |
| 552 | map = m; |
| 553 | } |
| 554 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 555 | @Override |
| 556 | protected String doRun() throws SameThreadException { |
| 557 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
| 558 | return configurationManagerJNI.addAccount(map); |
| 559 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 560 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 561 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 562 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 563 | |
| 564 | AddAccount runInstance = new AddAccount(swigmap); |
| 565 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 566 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 567 | // Log.e(TAG, "Waiting for Nofing"); |
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 | String accountId = (String) runInstance.getVal(); |
| 570 | |
| 571 | return accountId; |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public void removeAccount(final String accountId) { |
| 576 | getExecutor().execute(new SipRunnable() { |
| 577 | @Override |
| 578 | protected void doRun() throws SameThreadException { |
| 579 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 580 | configurationManagerJNI.removeAccount(accountId); |
| 581 | } |
| 582 | }); |
| 583 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 584 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 585 | @Override |
| 586 | public ArrayList<HashMap<String, String>> getHistory() throws RemoteException { |
| 587 | class History extends SipRunnableWithReturn { |
| 588 | |
| 589 | @Override |
| 590 | protected VectMap doRun() throws SameThreadException { |
| 591 | Log.i(TAG, "SipService.getHistory() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 592 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 593 | return configurationManagerJNI.getHistory(); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | History runInstance = new History(); |
| 598 | getExecutor().execute(runInstance); |
| 599 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 600 | // Log.w(TAG, "Waiting for getHistory"); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 601 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 602 | Log.i(TAG, "SipService.getHistory() DONE"); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 603 | VectMap swigmap = (VectMap) runInstance.getVal(); |
| 604 | |
| 605 | ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap); |
| 606 | |
| 607 | return nativemap; |
| 608 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 609 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 610 | /************************* |
| 611 | * Transfer related API |
| 612 | *************************/ |
| 613 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 614 | @Override |
| 615 | public void transfer(final String callID, final String to) throws RemoteException { |
| 616 | getExecutor().execute(new SipRunnable() { |
| 617 | @Override |
| 618 | protected void doRun() throws SameThreadException, RemoteException { |
| 619 | Log.i(TAG, "SipService.transfer() thread running..."); |
| 620 | if (callManagerJNI.transfer(callID, to)) { |
| 621 | Bundle bundle = new Bundle(); |
| 622 | bundle.putString("CallID", callID); |
| 623 | bundle.putString("State", "HUNGUP"); |
| 624 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 625 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 626 | sendBroadcast(intent); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 627 | } else |
| 628 | Log.i(TAG, "NOT OK"); |
| 629 | } |
| 630 | }); |
| 631 | |
| 632 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 633 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 634 | @Override |
| 635 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 636 | getExecutor().execute(new SipRunnable() { |
| 637 | @Override |
| 638 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 639 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 640 | if (callManagerJNI.attendedTransfer(transferID, targetID)) { |
| 641 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 642 | } else |
| 643 | Log.i(TAG, "NOT OK"); |
| 644 | } |
| 645 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 646 | |
| 647 | } |
| 648 | |
| 649 | /************************* |
| 650 | * Conference related API |
| 651 | *************************/ |
| 652 | |
| 653 | @Override |
| 654 | public void removeConference(final String confID) throws RemoteException { |
| 655 | getExecutor().execute(new SipRunnable() { |
| 656 | @Override |
| 657 | protected void doRun() throws SameThreadException, RemoteException { |
| 658 | Log.i(TAG, "SipService.createConference() thread running..."); |
| 659 | callManagerJNI.removeConference(confID); |
| 660 | } |
| 661 | }); |
| 662 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 666 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 667 | getExecutor().execute(new SipRunnable() { |
| 668 | @Override |
| 669 | protected void doRun() throws SameThreadException, RemoteException { |
| 670 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
| 671 | callManagerJNI.joinParticipant(sel_callID, drag_callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 672 | // Generate a CONF_CREATED callback |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 673 | } |
| 674 | }); |
| 675 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 676 | } |
| 677 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 678 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 679 | public void addParticipant(final SipCall call, final String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 680 | getExecutor().execute(new SipRunnable() { |
| 681 | @Override |
| 682 | protected void doRun() throws SameThreadException, RemoteException { |
| 683 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 684 | callManagerJNI.addParticipant(call.getCallId(), confID); |
| 685 | current_confs.get(confID).getParticipants().add(call); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 686 | } |
| 687 | }); |
| 688 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 692 | public void addMainParticipant(final String confID) throws RemoteException { |
| 693 | getExecutor().execute(new SipRunnable() { |
| 694 | @Override |
| 695 | protected void doRun() throws SameThreadException, RemoteException { |
| 696 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
| 697 | callManagerJNI.addMainParticipant(confID); |
| 698 | } |
| 699 | }); |
| 700 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 704 | public void detachParticipant(final String callID) throws RemoteException { |
| 705 | getExecutor().execute(new SipRunnable() { |
| 706 | @Override |
| 707 | protected void doRun() throws SameThreadException, RemoteException { |
| 708 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 709 | Log.i(TAG, "Detaching " + callID); |
| 710 | Iterator<Entry<String, Conference>> it = current_confs.entrySet().iterator(); |
| 711 | Log.i(TAG, "current_confs size " + current_confs.size()); |
| 712 | while (it.hasNext()) { |
| 713 | Conference tmp = it.next().getValue(); |
| 714 | Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants"); |
| 715 | if (tmp.contains(callID)) { |
| 716 | current_calls.put(callID, tmp.getCall(callID)); |
| 717 | Log.i(TAG, "Call found and put in current_calls"); |
| 718 | } |
| 719 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 720 | callManagerJNI.detachParticipant(callID); |
| 721 | } |
| 722 | }); |
| 723 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 727 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 728 | getExecutor().execute(new SipRunnable() { |
| 729 | @Override |
| 730 | protected void doRun() throws SameThreadException, RemoteException { |
| 731 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 732 | callManagerJNI.joinConference(sel_confID, drag_confID); |
| 733 | } |
| 734 | }); |
| 735 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 739 | public void hangUpConference(final String confID) throws RemoteException { |
| 740 | getExecutor().execute(new SipRunnable() { |
| 741 | @Override |
| 742 | protected void doRun() throws SameThreadException, RemoteException { |
| 743 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 744 | callManagerJNI.hangUpConference(confID); |
| 745 | } |
| 746 | }); |
| 747 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 751 | public void holdConference(final String confID) throws RemoteException { |
| 752 | getExecutor().execute(new SipRunnable() { |
| 753 | @Override |
| 754 | protected void doRun() throws SameThreadException, RemoteException { |
| 755 | Log.i(TAG, "SipService.holdConference() thread running..."); |
| 756 | callManagerJNI.holdConference(confID); |
| 757 | } |
| 758 | }); |
| 759 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 763 | public void unholdConference(final String confID) throws RemoteException { |
| 764 | getExecutor().execute(new SipRunnable() { |
| 765 | @Override |
| 766 | protected void doRun() throws SameThreadException, RemoteException { |
| 767 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
| 768 | callManagerJNI.unholdConference(confID); |
| 769 | } |
| 770 | }); |
| 771 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 772 | } |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 773 | |
| 774 | @Override |
| 775 | public boolean isConferenceParticipant(final String callID) throws RemoteException { |
| 776 | class IsParticipant extends SipRunnableWithReturn { |
| 777 | |
| 778 | @Override |
| 779 | protected Boolean doRun() throws SameThreadException { |
| 780 | Log.i(TAG, "SipService.isRecording() thread running..."); |
| 781 | return callManagerJNI.isConferenceParticipant(callID); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | IsParticipant runInstance = new IsParticipant(); |
| 786 | getExecutor().execute(runInstance); |
| 787 | while (!runInstance.isDone()) { |
| 788 | } |
| 789 | |
| 790 | return (Boolean) runInstance.getVal(); |
| 791 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 792 | |
| 793 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 794 | public HashMap<String, Conference> getConferenceList() throws RemoteException { |
| 795 | // class ConfList extends SipRunnableWithReturn { |
| 796 | // @Override |
| 797 | // protected StringVect doRun() throws SameThreadException { |
| 798 | // Log.i(TAG, "SipService.getConferenceList() thread running..."); |
| 799 | // return callManagerJNI.getConferenceList(); |
| 800 | // } |
| 801 | // } |
| 802 | // ; |
| 803 | // ConfList runInstance = new ConfList(); |
| 804 | // getExecutor().execute(runInstance); |
| 805 | // while (!runInstance.isDone()) { |
| 806 | // // Log.w(TAG, "Waiting for getConferenceList"); |
| 807 | // } |
| 808 | // StringVect swigvect = (StringVect) runInstance.getVal(); |
| 809 | // |
| 810 | // ArrayList<String> nativelist = new ArrayList<String>(); |
| 811 | // |
| 812 | // for (int i = 0; i < swigvect.size(); i++) |
| 813 | // nativelist.add(swigvect.get(i)); |
| 814 | // |
| 815 | // return nativelist; |
| 816 | return current_confs; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 820 | public List getParticipantList(final String confID) throws RemoteException { |
| 821 | class PartList extends SipRunnableWithReturn { |
| 822 | @Override |
| 823 | protected StringVect doRun() throws SameThreadException { |
| 824 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 825 | return callManagerJNI.getParticipantList(confID); |
| 826 | } |
| 827 | } |
| 828 | ; |
| 829 | PartList runInstance = new PartList(); |
| 830 | getExecutor().execute(runInstance); |
| 831 | while (!runInstance.isDone()) { |
| 832 | // Log.w(TAG, "Waiting for getConferenceList"); |
| 833 | } |
| 834 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 835 | |
| 836 | ArrayList<String> nativelist = new ArrayList<String>(); |
| 837 | |
| 838 | for (int i = 0; i < swigvect.size(); i++) |
| 839 | nativelist.add(swigvect.get(i)); |
| 840 | |
| 841 | return nativelist; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 842 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 843 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 844 | @Override |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 845 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 846 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 847 | return null; |
| 848 | } |
| 849 | |
| 850 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 851 | public String getConferenceDetails(final String callID) throws RemoteException { |
| 852 | class ConfDetails extends SipRunnableWithReturn { |
| 853 | @Override |
| 854 | protected StringMap doRun() throws SameThreadException { |
| 855 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 856 | return callManagerJNI.getConferenceDetails(callID); |
| 857 | } |
| 858 | } |
| 859 | ; |
| 860 | ConfDetails runInstance = new ConfDetails(); |
| 861 | getExecutor().execute(runInstance); |
| 862 | while (!runInstance.isDone()) { |
| 863 | // Log.w(TAG, "Waiting for getConferenceList"); |
| 864 | } |
| 865 | StringMap swigvect = (StringMap) runInstance.getVal(); |
| 866 | |
| 867 | return swigvect.get("CONF_STATE"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 868 | } |
| 869 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 870 | @Override |
| 871 | public String getRecordPath() throws RemoteException { |
| 872 | class RecordPath extends SipRunnableWithReturn { |
| 873 | |
| 874 | @Override |
| 875 | protected String doRun() throws SameThreadException { |
| 876 | Log.i(TAG, "SipService.getRecordPath() thread running..."); |
| 877 | return configurationManagerJNI.getRecordPath(); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | RecordPath runInstance = new RecordPath(); |
| 882 | getExecutor().execute(runInstance); |
| 883 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 884 | // Log.w(TAG, "Waiting for getRecordPath"); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 885 | } |
| 886 | String path = (String) runInstance.getVal(); |
| 887 | |
| 888 | return path; |
| 889 | } |
| 890 | |
| 891 | @Override |
| 892 | public void setRecordingCall(final String id) throws RemoteException { |
| 893 | getExecutor().execute(new SipRunnable() { |
| 894 | @Override |
| 895 | protected void doRun() throws SameThreadException, RemoteException { |
| 896 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 897 | callManagerJNI.setRecordingCall(id); |
| 898 | } |
| 899 | }); |
| 900 | |
| 901 | } |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 902 | |
| 903 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 904 | public boolean isRecording(final String id) throws RemoteException { |
| 905 | class IsRecording extends SipRunnableWithReturn { |
| 906 | |
| 907 | @Override |
| 908 | protected Boolean doRun() throws SameThreadException { |
| 909 | Log.i(TAG, "SipService.isRecording() thread running..."); |
| 910 | return callManagerJNI.getIsRecording(id); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | IsRecording runInstance = new IsRecording(); |
| 915 | getExecutor().execute(runInstance); |
| 916 | while (!runInstance.isDone()) { |
| 917 | } |
| 918 | |
| 919 | return (Boolean) runInstance.getVal(); |
| 920 | |
| 921 | } |
| 922 | |
| 923 | @Override |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 924 | public boolean startRecordedFilePlayback(final String filepath) throws RemoteException { |
| 925 | getExecutor().execute(new SipRunnable() { |
| 926 | @Override |
| 927 | protected void doRun() throws SameThreadException, RemoteException { |
| 928 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 929 | callManagerJNI.startRecordedFilePlayback(filepath); |
| 930 | } |
| 931 | }); |
| 932 | return false; |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | public void stopRecordedFilePlayback(final String filepath) throws RemoteException { |
| 937 | getExecutor().execute(new SipRunnable() { |
| 938 | @Override |
| 939 | protected void doRun() throws SameThreadException, RemoteException { |
| 940 | Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running..."); |
| 941 | callManagerJNI.stopRecordedFilePlayback(filepath); |
| 942 | } |
| 943 | }); |
| 944 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 945 | |
| 946 | @Override |
| 947 | public void setRecordPath(final String path) throws RemoteException { |
| 948 | getExecutor().execute(new SipRunnable() { |
| 949 | @Override |
| 950 | protected void doRun() throws SameThreadException, RemoteException { |
| 951 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 952 | configurationManagerJNI.setRecordPath(path); |
| 953 | } |
| 954 | }); |
| 955 | } |
| 956 | |
| 957 | @Override |
| 958 | public void sendTextMessage(final String callID, final String message, final String from) throws RemoteException { |
| 959 | getExecutor().execute(new SipRunnable() { |
| 960 | @Override |
| 961 | protected void doRun() throws SameThreadException, RemoteException { |
| 962 | Log.i(TAG, "SipService.sendTextMessage() thread running..."); |
| 963 | callManagerJNI.sendTextMessage(callID, message, from); |
| 964 | } |
| 965 | }); |
| 966 | |
| 967 | } |
| 968 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 969 | @Override |
| 970 | public List getAudioCodecList(String accountID) throws RemoteException { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 971 | // class AudioCodecList extends SipRunnableWithReturn { |
| 972 | // |
| 973 | // @Override |
| 974 | // protected IntVect doRun() throws SameThreadException { |
| 975 | // Log.i(TAG, "SipService.getAudioCodecList() thread running..."); |
| 976 | // return configurationManagerJNI.getAudioCodecList(); |
| 977 | // } |
| 978 | // } |
| 979 | // |
| 980 | // AudioCodecList runInstance = new AudioCodecList(); |
| 981 | // getExecutor().execute(runInstance); |
| 982 | // while (!runInstance.isDone()) { |
| 983 | // Log.w(TAG, "Waiting for getAudioCodecList"); |
| 984 | // } |
| 985 | // IntVect swigmap = (IntVect) runInstance.getVal(); |
| 986 | // |
| 987 | // ArrayList<Integer> codecs = AudioHandler.convertSwigToNative(swigmap); |
| 988 | // |
| 989 | // return codecs; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 990 | return null; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 991 | } |
| 992 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 993 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 994 | public HashMap<String, SipCall> getCallList() throws RemoteException { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 995 | // class CallList extends SipRunnableWithReturn { |
| 996 | // |
| 997 | // @Override |
| 998 | // protected StringVect doRun() throws SameThreadException { |
| 999 | // Log.i(TAG, "SipService.getCallList() thread running..."); |
| 1000 | // return callManagerJNI.getCallList(); |
| 1001 | // } |
| 1002 | // } |
| 1003 | // |
| 1004 | // CallList runInstance = new CallList(); |
| 1005 | // getExecutor().execute(runInstance); |
| 1006 | // while (!runInstance.isDone()) { |
| 1007 | // Log.w(TAG, "Waiting for getAudioCodecList"); |
| 1008 | // } |
| 1009 | // StringVect swigmap = (StringVect) runInstance.getVal(); |
| 1010 | // |
| 1011 | // ArrayList<String> nativemap = new ArrayList<String>(); |
| 1012 | // for (int i = 0; i < swigmap.size(); ++i) { |
| 1013 | // |
| 1014 | // String t = swigmap.get(i); |
| 1015 | // nativemap.add(t); |
| 1016 | // } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 1017 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1018 | return getCurrent_calls(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 1021 | @Override |
| 1022 | public SipCall getCall(String callID) throws RemoteException { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1023 | return getCurrent_calls().get(callID); |
| 1024 | } |
| 1025 | |
| 1026 | /*********************** |
| 1027 | * Notification API |
| 1028 | ***********************/ |
| 1029 | @Override |
| 1030 | public void createNotification() throws RemoteException { |
| 1031 | makeNotification(); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1032 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | @Override |
| 1036 | public void destroyNotification() throws RemoteException { |
| 1037 | removeNotification(); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1038 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1039 | } |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1040 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1041 | private int NOTIFICATION_ID = new Random().nextInt(1000); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1042 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1043 | private void makeNotification() { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1044 | if (current_calls.size() == 0) { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1045 | return; |
| 1046 | } |
| 1047 | Intent notificationIntent = new Intent(getApplicationContext(), SFLPhoneHomeActivity.class); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1048 | PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 007, notificationIntent, |
| 1049 | PendingIntent.FLAG_UPDATE_CURRENT); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1050 | |
| 1051 | NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE); |
| 1052 | |
| 1053 | NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext()); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1054 | // |
| 1055 | // builder.setContent(view); |
| 1056 | builder.setContentIntent(contentIntent).setOngoing(true).setSmallIcon(R.drawable.ic_launcher) |
| 1057 | .setContentTitle(getCurrent_calls().size() + " ongoing calls").setTicker("Pending calls").setWhen(System.currentTimeMillis()) |
| 1058 | .setAutoCancel(false); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1059 | builder.setPriority(NotificationCompat.PRIORITY_MAX); |
| 1060 | Notification n = builder.build(); |
| 1061 | |
| 1062 | nm.notify(NOTIFICATION_ID, n); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1063 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | public void removeNotification() { |
| 1067 | NotificationManager nm = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE); |
| 1068 | nm.cancel(NOTIFICATION_ID); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 1071 | @Override |
| 1072 | public Conference getCurrentCall() throws RemoteException { |
| 1073 | for(SipCall i : current_calls.values()){ |
| 1074 | if(i.isOngoing()){ |
| 1075 | Conference tmp = new Conference("-1"); |
| 1076 | tmp.getParticipants().add(i); |
| 1077 | return tmp; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | if(!current_confs.isEmpty()){ |
| 1082 | return (Conference) current_confs.values().toArray()[0]; |
| 1083 | } |
| 1084 | return null; |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 1089 | |
| 1090 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 1091 | |
| 1092 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 1093 | }; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 1094 | } |