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