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) |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 3 | * Copyright (C) 2004-2014 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 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 25 | package org.sflphone.service; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 26 | |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.HashMap; |
| 31 | import java.util.Iterator; |
| 32 | import java.util.List; |
| 33 | import java.util.Map; |
| 34 | import java.util.Map.Entry; |
| 35 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 36 | import android.app.Service; |
| 37 | import android.content.Intent; |
| 38 | import android.os.*; |
| 39 | import android.util.Log; |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 40 | import org.sflphone.history.HistoryManager; |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 41 | import org.sflphone.model.*; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 42 | import org.sflphone.utils.MediaManager; |
Alexandre Lision | e004544 | 2013-10-25 09:16:19 -0400 | [diff] [blame] | 43 | import org.sflphone.utils.SipNotifications; |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 44 | import org.sflphone.utils.SwigNativeConverter; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 45 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 46 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 47 | public class SipService extends Service { |
| 48 | |
| 49 | static final String TAG = "SipService"; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 50 | private SipServiceExecutor mExecutor; |
| 51 | private static HandlerThread executorThread; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 52 | |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 53 | private Handler handler = new Handler(); |
| 54 | private static int POLLING_TIMEOUT = 500; |
| 55 | private Runnable pollEvents = new Runnable() { |
| 56 | @Override |
| 57 | public void run() { |
| 58 | SFLPhoneservice.sflph_poll_events(); |
| 59 | handler.postDelayed(this, POLLING_TIMEOUT); |
| 60 | } |
| 61 | }; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 62 | private boolean isPjSipStackStarted = false; |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 63 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 64 | protected SipNotifications mNotificationManager; |
| 65 | protected HistoryManager mHistoryManager; |
| 66 | protected MediaManager mMediaManager; |
Alexandre Lision | e004544 | 2013-10-25 09:16:19 -0400 | [diff] [blame] | 67 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 68 | private HashMap<String, Conference> mConferences = new HashMap<String, Conference>(); |
Alexandre Lision | 7b15170 | 2014-09-04 10:07:34 -0400 | [diff] [blame] | 69 | private ConfigurationManagerCallback configurationCallback; |
| 70 | private CallManagerCallBack callManagerCallBack; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 71 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 72 | public HashMap<String, Conference> getConferences() { |
| 73 | return mConferences; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 74 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 75 | |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 76 | public void addCallToConference(String confId, String callId) { |
| 77 | if(mConferences.get(callId) != null){ |
| 78 | // We add a simple call to a conference |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 79 | Log.i(TAG, "// We add a simple call to a conference"); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 80 | mConferences.get(confId).addParticipant(mConferences.get(callId).getParticipants().get(0)); |
| 81 | mConferences.remove(callId); |
| 82 | } else { |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 83 | Log.i(TAG, "addCallToConference"); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 84 | for (Entry<String, Conference> stringConferenceEntry : mConferences.entrySet()) { |
| 85 | Conference tmp = stringConferenceEntry.getValue(); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 86 | for (SipCall c : tmp.getParticipants()) { |
| 87 | if (c.getCallId().contentEquals(callId)) { |
| 88 | mConferences.get(confId).addParticipant(c); |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 89 | mConferences.get(tmp.getId()).removeParticipant(c); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 96 | public void detachCallFromConference(String confId, SipCall call) { |
| 97 | Log.i(TAG, "detachCallFromConference"); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 98 | Conference separate = new Conference(call); |
| 99 | mConferences.put(separate.getId(), separate); |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 100 | mConferences.get(confId).removeParticipant(call); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 101 | } |
| 102 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 103 | @Override |
| 104 | public boolean onUnbind(Intent i) { |
| 105 | super.onUnbind(i); |
| 106 | Log.i(TAG, "onUnbind(intent)"); |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 107 | return true; |
| 108 | } |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 109 | |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 110 | @Override |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 111 | public void onRebind(Intent i) { |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 112 | super.onRebind(i); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* called once by startService() */ |
| 116 | @Override |
| 117 | public void onCreate() { |
| 118 | Log.i(TAG, "onCreated"); |
| 119 | super.onCreate(); |
| 120 | |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 121 | getExecutor().execute(new StartRunnable()); |
Alexandre Lision | e004544 | 2013-10-25 09:16:19 -0400 | [diff] [blame] | 122 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 123 | mNotificationManager = new SipNotifications(this); |
| 124 | mMediaManager = new MediaManager(this); |
| 125 | mHistoryManager = new HistoryManager(this); |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 126 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 127 | mNotificationManager.onServiceCreate(); |
| 128 | mMediaManager.startService(); |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 129 | |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 130 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 131 | |
| 132 | /* called for each startService() */ |
| 133 | @Override |
| 134 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 135 | Log.i(TAG, "onStarted"); |
| 136 | super.onStartCommand(intent, flags, startId); |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 137 | return START_STICKY; /* started and stopped explicitly */ |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void onDestroy() { |
Alexandre Lision | 5221499 | 2013-10-28 17:41:23 -0400 | [diff] [blame] | 142 | Log.i(TAG, "onDestroy"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 143 | /* called once by stopService() */ |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 144 | mNotificationManager.onServiceDestroy(); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 145 | mMediaManager.stopService(); |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 146 | getExecutor().execute(new FinalizeRunnable()); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 147 | super.onDestroy(); |
| 148 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public IBinder onBind(Intent arg0) { |
| 153 | Log.i(TAG, "onBound"); |
| 154 | return mBinder; |
| 155 | } |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 156 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 157 | private static Looper createLooper() { |
| 158 | if (executorThread == null) { |
| 159 | Log.d(TAG, "Creating new handler thread"); |
| 160 | // ADT gives a fake warning due to bad parse rule. |
| 161 | executorThread = new HandlerThread("SipService.Executor"); |
| 162 | executorThread.start(); |
| 163 | } |
| 164 | return executorThread.getLooper(); |
| 165 | } |
| 166 | |
| 167 | public SipServiceExecutor getExecutor() { |
| 168 | // create mExecutor lazily |
| 169 | if (mExecutor == null) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 170 | mExecutor = new SipServiceExecutor(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 171 | } |
| 172 | return mExecutor; |
| 173 | } |
| 174 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 175 | public SipCall getCallById(String callID) { |
| 176 | if (getConferences().get(callID) != null) { |
| 177 | return getConferences().get(callID).getCallById(callID); |
| 178 | } else { |
| 179 | // Check if call is in a conference |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 180 | for (Entry<String, Conference> stringConferenceEntry : getConferences().entrySet()) { |
| 181 | Conference tmp = stringConferenceEntry.getValue(); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 182 | SipCall c = tmp.getCallById(callID); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 183 | if (c != null) |
| 184 | return c; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | return null; |
| 188 | } |
| 189 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 190 | // Executes immediate tasks in a single executorThread. |
| 191 | public static class SipServiceExecutor extends Handler { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 192 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 193 | SipServiceExecutor() { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 194 | super(createLooper()); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | public void execute(Runnable task) { |
| 198 | // TODO: add wakelock |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 199 | Message.obtain(SipServiceExecutor.this, 0/* don't care */, task).sendToTarget(); |
Alexandre Lision | cdec595 | 2013-07-17 14:18:22 -0400 | [diff] [blame] | 200 | Log.w(TAG, "SenT!"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void handleMessage(Message msg) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 205 | Log.w(TAG, "handleMessage"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 206 | if (msg.obj instanceof Runnable) { |
| 207 | executeInternal((Runnable) msg.obj); |
| 208 | } else { |
| 209 | Log.w(TAG, "can't handle msg: " + msg); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | private void executeInternal(Runnable task) { |
| 214 | try { |
| 215 | task.run(); |
| 216 | } catch (Throwable t) { |
| 217 | Log.e(TAG, "run task: " + task, t); |
| 218 | } |
| 219 | } |
| 220 | } |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 221 | |
| 222 | private void stopDaemon() { |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 223 | handler.removeCallbacks(pollEvents); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 224 | SFLPhoneservice.sflph_fini(); |
| 225 | isPjSipStackStarted = false; |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 226 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 227 | |
| 228 | private void startPjSipStack() throws SameThreadException { |
| 229 | if (isPjSipStackStarted) |
| 230 | return; |
| 231 | |
| 232 | try { |
| 233 | System.loadLibrary("gnustl_shared"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 234 | System.loadLibrary("crypto"); |
| 235 | System.loadLibrary("ssl"); |
Alexandre Lision | 399db75 | 2014-09-03 10:27:56 -0400 | [diff] [blame] | 236 | System.loadLibrary("codec_ulaw"); |
| 237 | System.loadLibrary("codec_alaw"); |
| 238 | System.loadLibrary("codec_speex_nb"); |
| 239 | System.loadLibrary("codec_speex_ub"); |
| 240 | System.loadLibrary("codec_speex_wb"); |
| 241 | System.loadLibrary("codec_g729"); |
| 242 | System.loadLibrary("codec_gsm"); |
| 243 | System.loadLibrary("codec_opus"); |
| 244 | System.loadLibrary("sflphonejni"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 245 | isPjSipStackStarted = true; |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 246 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 247 | } catch (UnsatisfiedLinkError e) { |
| 248 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 249 | isPjSipStackStarted = false; |
| 250 | return; |
| 251 | } catch (Exception e) { |
| 252 | Log.e(TAG, "Problem with the current Pj stack...", e); |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 253 | isPjSipStackStarted = false; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Alexandre Lision | 7b15170 | 2014-09-04 10:07:34 -0400 | [diff] [blame] | 256 | configurationCallback = new ConfigurationManagerCallback(this); |
| 257 | callManagerCallBack = new CallManagerCallBack(this); |
| 258 | SFLPhoneservice.init(configurationCallback, callManagerCallBack); |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 259 | handler.postDelayed(pollEvents, POLLING_TIMEOUT); |
| 260 | Log.i(TAG, "PjSIPStack started"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | // Enforce same thread contract to ensure we do not call from somewhere else |
| 264 | public class SameThreadException extends Exception { |
| 265 | private static final long serialVersionUID = -905639124232613768L; |
| 266 | |
| 267 | public SameThreadException() { |
| 268 | super("Should be launched from a single worker thread"); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | public abstract static class SipRunnable implements Runnable { |
| 273 | protected abstract void doRun() throws SameThreadException, RemoteException; |
| 274 | |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 275 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 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 | |
Alexandre Lision | fab23f8 | 2013-11-01 11:22:30 -0400 | [diff] [blame] | 287 | public abstract class SipRunnableWithReturn implements Runnable { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 288 | Object obj = null; |
| 289 | boolean done = false; |
| 290 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 291 | protected abstract Object doRun() throws SameThreadException, RemoteException; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 292 | |
| 293 | public Object getVal() { |
| 294 | return obj; |
| 295 | } |
| 296 | |
| 297 | public boolean isDone() { |
| 298 | return done; |
| 299 | } |
| 300 | |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 301 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 302 | public void run() { |
| 303 | try { |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 304 | if (isPjSipStackStarted) |
Alexandre Lision | fab23f8 | 2013-11-01 11:22:30 -0400 | [diff] [blame] | 305 | obj = doRun(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 306 | done = true; |
| 307 | } catch (SameThreadException e) { |
| 308 | Log.e(TAG, "Not done from same thread"); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 309 | } catch (RemoteException e) { |
| 310 | Log.e(TAG, e.toString()); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | class StartRunnable extends SipRunnable { |
| 316 | @Override |
| 317 | protected void doRun() throws SameThreadException { |
| 318 | startPjSipStack(); |
| 319 | } |
| 320 | } |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 321 | |
Alexandre Lision | dd68f65 | 2013-10-28 11:00:12 -0400 | [diff] [blame] | 322 | class FinalizeRunnable extends SipRunnable { |
| 323 | @Override |
| 324 | protected void doRun() throws SameThreadException { |
| 325 | stopDaemon(); |
| 326 | } |
| 327 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 328 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 329 | /* ************************************ |
Alexandre Lision | 9abb7c9 | 2014-08-04 19:22:55 -0400 | [diff] [blame] | 330 | * |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 331 | * Implement public interface for the service |
Alexandre Lision | 9abb7c9 | 2014-08-04 19:22:55 -0400 | [diff] [blame] | 332 | * |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 333 | * ********************************* |
| 334 | */ |
| 335 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 336 | private final ISipService.Stub mBinder = new ISipService.Stub() { |
| 337 | |
| 338 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 339 | public void placeCall(final SipCall call) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 340 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 341 | getExecutor().execute(new SipRunnable() { |
| 342 | @Override |
| 343 | protected void doRun() throws SameThreadException { |
| 344 | Log.i(TAG, "SipService.placeCall() thread running..."); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 345 | Conference toAdd; |
| 346 | if(call.getAccount().useSecureLayer()){ |
Alexandre Lision | 2cd17d3 | 2014-02-27 15:57:20 -0500 | [diff] [blame] | 347 | SecureSipCall secureCall = new SecureSipCall(call); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 348 | toAdd = new Conference(secureCall); |
| 349 | } else { |
| 350 | toAdd = new Conference(call); |
| 351 | } |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 352 | mConferences.put(toAdd.getId(), toAdd); |
| 353 | mMediaManager.obtainAudioFocus(false); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 354 | SFLPhoneservice.sflph_call_place(call.getAccount().getAccountID(), call.getCallId(), call.getmContact().getPhones().get(0).getNumber()); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 355 | } |
| 356 | }); |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public void refuse(final String callID) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 361 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 362 | getExecutor().execute(new SipRunnable() { |
| 363 | @Override |
| 364 | protected void doRun() throws SameThreadException { |
| 365 | Log.i(TAG, "SipService.refuse() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 366 | SFLPhoneservice.sflph_call_refuse(callID); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 367 | } |
| 368 | }); |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void accept(final String callID) { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 373 | mMediaManager.stopRing(); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 374 | getExecutor().execute(new SipRunnable() { |
| 375 | @Override |
| 376 | protected void doRun() throws SameThreadException { |
Tristan Matthews | 40cf25e | 2013-07-24 13:45:15 -0400 | [diff] [blame] | 377 | Log.i(TAG, "SipService.accept() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 378 | SFLPhoneservice.sflph_call_accept(callID); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 379 | mMediaManager.RouteToInternalSpeaker(); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 380 | } |
| 381 | }); |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void hangUp(final String callID) { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 386 | mMediaManager.stopRing(); |
Alexandre Lision | 2cd17d3 | 2014-02-27 15:57:20 -0500 | [diff] [blame] | 387 | Log.e(TAG, "HANGING UP"); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 388 | getExecutor().execute(new SipRunnable() { |
| 389 | @Override |
| 390 | protected void doRun() throws SameThreadException { |
| 391 | Log.i(TAG, "SipService.hangUp() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 392 | SFLPhoneservice.sflph_call_hang_up(callID); |
Alexandre Lision | 3c37dca | 2014-02-21 14:13:26 -0500 | [diff] [blame] | 393 | removeCall(callID); |
Alexandre Lision | 3c37dca | 2014-02-21 14:13:26 -0500 | [diff] [blame] | 394 | if(mConferences.size() == 0) { |
| 395 | Log.i(TAG, "No more calls!"); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 396 | mMediaManager.abandonAudioFocus(); |
Alexandre Lision | 3c37dca | 2014-02-21 14:13:26 -0500 | [diff] [blame] | 397 | } |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 398 | } |
| 399 | }); |
| 400 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 401 | |
| 402 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 403 | public void hold(final String callID) { |
| 404 | getExecutor().execute(new SipRunnable() { |
| 405 | @Override |
| 406 | protected void doRun() throws SameThreadException { |
| 407 | Log.i(TAG, "SipService.hold() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 408 | SFLPhoneservice.sflph_call_hold(callID); |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 409 | } |
| 410 | }); |
| 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void unhold(final String callID) { |
| 415 | getExecutor().execute(new SipRunnable() { |
| 416 | @Override |
| 417 | protected void doRun() throws SameThreadException { |
| 418 | Log.i(TAG, "SipService.unhold() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 419 | SFLPhoneservice.sflph_call_unhold(callID); |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 420 | } |
| 421 | }); |
| 422 | } |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 423 | |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 424 | @Override |
| 425 | public HashMap<String, String> getCallDetails(String callID) throws RemoteException { |
| 426 | class CallDetails extends SipRunnableWithReturn { |
| 427 | private String id; |
| 428 | |
| 429 | CallDetails(String callID) { |
| 430 | id = callID; |
| 431 | } |
| 432 | |
| 433 | @Override |
| 434 | protected StringMap doRun() throws SameThreadException { |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 435 | Log.i(TAG, "SipService.getCallDetails() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 436 | return SFLPhoneservice.sflph_call_get_call_details(id); |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | CallDetails runInstance = new CallDetails(callID); |
| 441 | getExecutor().execute(runInstance); |
| 442 | |
| 443 | while (!runInstance.isDone()) { |
| 444 | } |
| 445 | StringMap swigmap = (StringMap) runInstance.getVal(); |
| 446 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 447 | return SwigNativeConverter.convertCallDetailsToNative(swigmap); |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 448 | } |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 449 | |
| 450 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 451 | public void setAudioPlugin(final String audioPlugin) { |
| 452 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 453 | @Override |
| 454 | protected void doRun() throws SameThreadException { |
| 455 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 456 | SFLPhoneservice.sflph_config_set_audio_plugin(audioPlugin); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 457 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 458 | }); |
| 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public String getCurrentAudioOutputPlugin() { |
| 463 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 464 | @Override |
| 465 | protected String doRun() throws SameThreadException { |
| 466 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 467 | return SFLPhoneservice.sflph_config_get_current_audio_output_plugin(); |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 468 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 469 | } |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 470 | |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 471 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 472 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 473 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 474 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 475 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 476 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 477 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 478 | |
| 479 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 480 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 481 | class AccountList extends SipRunnableWithReturn { |
| 482 | @Override |
| 483 | protected StringVect doRun() throws SameThreadException { |
| 484 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 485 | return SFLPhoneservice.sflph_config_get_account_list(); |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 486 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 487 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 488 | AccountList runInstance = new AccountList(); |
| 489 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 490 | while (!runInstance.isDone()) { |
| 491 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 492 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 493 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 494 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 495 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 496 | for (int i = 0; i < swigvect.size(); i++) |
| 497 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 498 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 499 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 500 | } |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 501 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 502 | @Override |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 503 | public void setAccountOrder(final String order) { |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 504 | getExecutor().execute(new SipRunnable() { |
| 505 | @Override |
| 506 | protected void doRun() throws SameThreadException { |
| 507 | Log.i(TAG, "SipService.setAccountsOrder() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 508 | SFLPhoneservice.sflph_config_set_accounts_order(order); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 509 | } |
| 510 | }); |
| 511 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 512 | |
| 513 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 514 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 515 | class AccountDetails extends SipRunnableWithReturn { |
| 516 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 517 | |
| 518 | AccountDetails(String accountId) { |
| 519 | id = accountId; |
| 520 | } |
| 521 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 522 | @Override |
| 523 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 524 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 525 | return SFLPhoneservice.sflph_config_get_account_details(id); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 526 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 527 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 528 | |
| 529 | AccountDetails runInstance = new AccountDetails(accountID); |
| 530 | getExecutor().execute(runInstance); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 531 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 532 | while (!runInstance.isDone()) { |
| 533 | } |
| 534 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 535 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 536 | return SwigNativeConverter.convertAccountToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 537 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 538 | |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 539 | @SuppressWarnings("unchecked") |
| 540 | // Hashmap runtime cast |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 541 | @Override |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 542 | public void setAccountDetails(final String accountId, final Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 543 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 544 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 545 | final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 546 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 547 | getExecutor().execute(new SipRunnable() { |
| 548 | @Override |
| 549 | protected void doRun() throws SameThreadException { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 550 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 551 | SFLPhoneservice.sflph_config_set_account_details(accountId, swigmap); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 552 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 553 | } |
| 554 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 555 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 558 | @Override |
| 559 | public Map getAccountTemplate() throws RemoteException { |
| 560 | class AccountTemplate extends SipRunnableWithReturn { |
| 561 | |
| 562 | @Override |
| 563 | protected StringMap doRun() throws SameThreadException { |
| 564 | Log.i(TAG, "SipService.getAccountTemplate() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 565 | return SFLPhoneservice.sflph_config_get_account_template(); |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
| 569 | AccountTemplate runInstance = new AccountTemplate(); |
| 570 | getExecutor().execute(runInstance); |
| 571 | |
| 572 | while (!runInstance.isDone()) { |
| 573 | } |
| 574 | StringMap swigmap = (StringMap) runInstance.getVal(); |
| 575 | |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 576 | return SwigNativeConverter.convertAccountToNative(swigmap); |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 577 | } |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 578 | |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 579 | @SuppressWarnings("unchecked") |
| 580 | // Hashmap runtime cast |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 581 | @Override |
| 582 | public String addAccount(Map map) { |
| 583 | class AddAccount extends SipRunnableWithReturn { |
| 584 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 585 | |
| 586 | AddAccount(StringMap m) { |
| 587 | map = m; |
| 588 | } |
| 589 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 590 | @Override |
| 591 | protected String doRun() throws SameThreadException { |
Alexandre Lision | c8397da | 2014-04-16 15:03:22 -0400 | [diff] [blame] | 592 | Log.i(TAG, "SipService.addAccount() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 593 | return SFLPhoneservice.sflph_config_add_account(map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 594 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 595 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 596 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 597 | final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 598 | |
| 599 | AddAccount runInstance = new AddAccount(swigmap); |
| 600 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 601 | while (!runInstance.isDone()) { |
| 602 | } |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 603 | return (String) runInstance.getVal(); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void removeAccount(final String accountId) { |
| 608 | getExecutor().execute(new SipRunnable() { |
| 609 | @Override |
| 610 | protected void doRun() throws SameThreadException { |
| 611 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 612 | SFLPhoneservice.sflph_config_remove_account(accountId); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 613 | } |
| 614 | }); |
| 615 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 616 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 617 | /************************* |
| 618 | * Transfer related API |
| 619 | *************************/ |
| 620 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 621 | @Override |
| 622 | public void transfer(final String callID, final String to) throws RemoteException { |
| 623 | getExecutor().execute(new SipRunnable() { |
| 624 | @Override |
| 625 | protected void doRun() throws SameThreadException, RemoteException { |
| 626 | Log.i(TAG, "SipService.transfer() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 627 | if (SFLPhoneservice.sflph_call_transfer(callID, to)) { |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 628 | Bundle bundle = new Bundle(); |
| 629 | bundle.putString("CallID", callID); |
| 630 | bundle.putString("State", "HUNGUP"); |
| 631 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 632 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 633 | sendBroadcast(intent); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 634 | } else |
| 635 | Log.i(TAG, "NOT OK"); |
| 636 | } |
| 637 | }); |
| 638 | |
| 639 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 640 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 641 | @Override |
| 642 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 643 | getExecutor().execute(new SipRunnable() { |
| 644 | @Override |
| 645 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 646 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 647 | if (SFLPhoneservice.sflph_call_attended_transfer(transferID, targetID)) { |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 648 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 649 | } else |
| 650 | Log.i(TAG, "NOT OK"); |
| 651 | } |
| 652 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 653 | |
| 654 | } |
| 655 | |
| 656 | /************************* |
| 657 | * Conference related API |
| 658 | *************************/ |
| 659 | |
| 660 | @Override |
| 661 | public void removeConference(final String confID) throws RemoteException { |
| 662 | getExecutor().execute(new SipRunnable() { |
| 663 | @Override |
| 664 | protected void doRun() throws SameThreadException, RemoteException { |
| 665 | Log.i(TAG, "SipService.createConference() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 666 | SFLPhoneservice.sflph_call_remove_conference(confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 667 | } |
| 668 | }); |
| 669 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 673 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 674 | getExecutor().execute(new SipRunnable() { |
| 675 | @Override |
| 676 | protected void doRun() throws SameThreadException, RemoteException { |
| 677 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 678 | SFLPhoneservice.sflph_call_join_participant(sel_callID, drag_callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 679 | // Generate a CONF_CREATED callback |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 680 | } |
| 681 | }); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 682 | Log.i(TAG, "After joining participants"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 683 | } |
| 684 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 685 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 686 | public void addParticipant(final SipCall call, final String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 687 | getExecutor().execute(new SipRunnable() { |
| 688 | @Override |
| 689 | protected void doRun() throws SameThreadException, RemoteException { |
| 690 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 691 | SFLPhoneservice.sflph_call_add_participant(call.getCallId(), confID); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 692 | mConferences.get(confID).getParticipants().add(call); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 693 | } |
| 694 | }); |
| 695 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 699 | public void addMainParticipant(final String confID) throws RemoteException { |
| 700 | getExecutor().execute(new SipRunnable() { |
| 701 | @Override |
| 702 | protected void doRun() throws SameThreadException, RemoteException { |
| 703 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 704 | SFLPhoneservice.sflph_call_add_main_participant(confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 705 | } |
| 706 | }); |
| 707 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 711 | public void detachParticipant(final String callID) throws RemoteException { |
| 712 | getExecutor().execute(new SipRunnable() { |
| 713 | @Override |
| 714 | protected void doRun() throws SameThreadException, RemoteException { |
| 715 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 716 | Log.i(TAG, "Detaching " + callID); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 717 | Iterator<Entry<String, Conference>> it = mConferences.entrySet().iterator(); |
| 718 | Log.i(TAG, "mConferences size " + mConferences.size()); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 719 | while (it.hasNext()) { |
| 720 | Conference tmp = it.next().getValue(); |
| 721 | Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants"); |
| 722 | if (tmp.contains(callID)) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 723 | Conference toDetach = new Conference(tmp.getCallById(callID)); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 724 | mConferences.put(toDetach.getId(), toDetach); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 725 | Log.i(TAG, "Call found and put in current_calls"); |
| 726 | } |
| 727 | } |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 728 | SFLPhoneservice.sflph_call_detach_participant(callID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 729 | } |
| 730 | }); |
| 731 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 735 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 736 | getExecutor().execute(new SipRunnable() { |
| 737 | @Override |
| 738 | protected void doRun() throws SameThreadException, RemoteException { |
| 739 | Log.i(TAG, "SipService.joinConference() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 740 | SFLPhoneservice.sflph_call_join_conference(sel_confID, drag_confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 741 | } |
| 742 | }); |
| 743 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 747 | public void hangUpConference(final String confID) throws RemoteException { |
Alexandre Lision | 2cd17d3 | 2014-02-27 15:57:20 -0500 | [diff] [blame] | 748 | Log.e(TAG, "HANGING UP CONF"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 749 | getExecutor().execute(new SipRunnable() { |
| 750 | @Override |
| 751 | protected void doRun() throws SameThreadException, RemoteException { |
| 752 | Log.i(TAG, "SipService.joinConference() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 753 | SFLPhoneservice.sflph_call_hang_up_conference(confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 754 | } |
| 755 | }); |
| 756 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 760 | public void holdConference(final String confID) throws RemoteException { |
| 761 | getExecutor().execute(new SipRunnable() { |
| 762 | @Override |
| 763 | protected void doRun() throws SameThreadException, RemoteException { |
| 764 | Log.i(TAG, "SipService.holdConference() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 765 | SFLPhoneservice.sflph_call_hold_conference(confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 766 | } |
| 767 | }); |
| 768 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 772 | public void unholdConference(final String confID) throws RemoteException { |
| 773 | getExecutor().execute(new SipRunnable() { |
| 774 | @Override |
| 775 | protected void doRun() throws SameThreadException, RemoteException { |
| 776 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 777 | SFLPhoneservice.sflph_call_unhold_conference(confID); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 778 | } |
| 779 | }); |
| 780 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 781 | } |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 782 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 783 | @Override |
| 784 | public boolean isConferenceParticipant(final String callID) throws RemoteException { |
| 785 | class IsParticipant extends SipRunnableWithReturn { |
| 786 | |
| 787 | @Override |
| 788 | protected Boolean doRun() throws SameThreadException { |
| 789 | Log.i(TAG, "SipService.isRecording() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 790 | return SFLPhoneservice.sflph_call_is_conference_participant(callID); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | IsParticipant runInstance = new IsParticipant(); |
| 795 | getExecutor().execute(runInstance); |
| 796 | while (!runInstance.isDone()) { |
| 797 | } |
| 798 | |
| 799 | return (Boolean) runInstance.getVal(); |
| 800 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 801 | |
| 802 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 803 | public HashMap<String, Conference> getConferenceList() throws RemoteException { |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 804 | // class ConfList extends SipRunnableWithReturn { |
| 805 | // @Override |
| 806 | // protected StringVect doRun() throws SameThreadException { |
| 807 | // Log.i(TAG, "SipService.getConferenceList() thread running..."); |
| 808 | // return callManagerJNI.getConferenceList(); |
| 809 | // } |
| 810 | // } |
| 811 | // ; |
| 812 | // ConfList runInstance = new ConfList(); |
| 813 | // getExecutor().execute(runInstance); |
| 814 | // while (!runInstance.isDone()) { |
| 815 | // // Log.w(TAG, "Waiting for getConferenceList"); |
| 816 | // } |
| 817 | // StringVect swigvect = (StringVect) runInstance.getVal(); |
| 818 | // |
| 819 | // ArrayList<String> nativelist = new ArrayList<String>(); |
| 820 | // |
| 821 | // for (int i = 0; i < swigvect.size(); i++) |
| 822 | // nativelist.add(swigvect.get(i)); |
| 823 | // |
| 824 | // return nativelist; |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 825 | return mConferences; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 829 | public List getParticipantList(final String confID) throws RemoteException { |
| 830 | class PartList extends SipRunnableWithReturn { |
| 831 | @Override |
| 832 | protected StringVect doRun() throws SameThreadException { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 833 | Log.i(TAG, "SipService.getParticipantList() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 834 | return SFLPhoneservice.sflph_call_get_participant_list(confID); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | ; |
| 838 | PartList runInstance = new PartList(); |
| 839 | getExecutor().execute(runInstance); |
| 840 | while (!runInstance.isDone()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 841 | Log.w(TAG, "getParticipantList"); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 842 | } |
| 843 | StringVect swigvect = (StringVect) runInstance.getVal(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 844 | Log.w(TAG, "After that"); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 845 | ArrayList<String> nativelist = new ArrayList<String>(); |
| 846 | |
| 847 | for (int i = 0; i < swigvect.size(); i++) |
| 848 | nativelist.add(swigvect.get(i)); |
| 849 | |
| 850 | return nativelist; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 851 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 852 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 853 | @Override |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 854 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 855 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 856 | return null; |
| 857 | } |
| 858 | |
| 859 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 860 | public String getConferenceDetails(final String callID) throws RemoteException { |
| 861 | class ConfDetails extends SipRunnableWithReturn { |
| 862 | @Override |
| 863 | protected StringMap doRun() throws SameThreadException { |
Alexandre Lision | c8397da | 2014-04-16 15:03:22 -0400 | [diff] [blame] | 864 | Log.i(TAG, "SipService.getConferenceDetails() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 865 | return SFLPhoneservice.sflph_call_get_conference_details(callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 866 | } |
| 867 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 868 | ConfDetails runInstance = new ConfDetails(); |
| 869 | getExecutor().execute(runInstance); |
| 870 | while (!runInstance.isDone()) { |
| 871 | // Log.w(TAG, "Waiting for getConferenceList"); |
| 872 | } |
| 873 | StringMap swigvect = (StringMap) runInstance.getVal(); |
| 874 | |
| 875 | return swigvect.get("CONF_STATE"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 876 | } |
| 877 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 878 | @Override |
| 879 | public String getRecordPath() throws RemoteException { |
| 880 | class RecordPath extends SipRunnableWithReturn { |
| 881 | |
| 882 | @Override |
| 883 | protected String doRun() throws SameThreadException { |
| 884 | Log.i(TAG, "SipService.getRecordPath() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 885 | return SFLPhoneservice.sflph_config_get_record_path(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
| 889 | RecordPath runInstance = new RecordPath(); |
| 890 | getExecutor().execute(runInstance); |
| 891 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 892 | // Log.w(TAG, "Waiting for getRecordPath"); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 893 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 894 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 895 | return (String) runInstance.getVal(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | @Override |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 899 | public boolean toggleRecordingCall(final String id) throws RemoteException { |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 900 | |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 901 | class ToggleRecording extends SipRunnableWithReturn { |
| 902 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 903 | @Override |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 904 | protected Boolean doRun() throws SameThreadException { |
| 905 | Log.i(TAG, "SipService.toggleRecordingCall() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 906 | boolean result = SFLPhoneservice.sflph_call_toggle_recording(id); |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 907 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 908 | if (getConferences().containsKey(id)) { |
| 909 | getConferences().get(id).setRecording(result); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 910 | } else { |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 911 | for (Conference c : getConferences().values()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 912 | if (c.getCallById(id) != null) |
| 913 | c.getCallById(id).setRecording(result); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | return result; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 917 | } |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | ToggleRecording runInstance = new ToggleRecording(); |
| 921 | getExecutor().execute(runInstance); |
| 922 | while (!runInstance.isDone()) { |
| 923 | } |
| 924 | |
| 925 | return (Boolean) runInstance.getVal(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 926 | |
| 927 | } |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 928 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 929 | @Override |
| 930 | public boolean startRecordedFilePlayback(final String filepath) throws RemoteException { |
| 931 | getExecutor().execute(new SipRunnable() { |
| 932 | @Override |
| 933 | protected void doRun() throws SameThreadException, RemoteException { |
| 934 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 935 | SFLPhoneservice.sflph_call_play_recorded_file(filepath); |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 936 | } |
| 937 | }); |
| 938 | return false; |
| 939 | } |
| 940 | |
| 941 | @Override |
| 942 | public void stopRecordedFilePlayback(final String filepath) throws RemoteException { |
| 943 | getExecutor().execute(new SipRunnable() { |
| 944 | @Override |
| 945 | protected void doRun() throws SameThreadException, RemoteException { |
| 946 | Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 947 | SFLPhoneservice.sflph_call_stop_recorded_file(filepath); |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 948 | } |
| 949 | }); |
| 950 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 951 | |
| 952 | @Override |
| 953 | public void setRecordPath(final String path) throws RemoteException { |
| 954 | getExecutor().execute(new SipRunnable() { |
| 955 | @Override |
| 956 | protected void doRun() throws SameThreadException, RemoteException { |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 957 | Log.i(TAG, "SipService.setRecordPath() " + path + " thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 958 | SFLPhoneservice.sflph_config_set_record_path(path); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 959 | } |
| 960 | }); |
| 961 | } |
| 962 | |
| 963 | @Override |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 964 | public void sendTextMessage(final String callID, final SipMessage message) throws RemoteException { |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 965 | getExecutor().execute(new SipRunnable() { |
| 966 | @Override |
| 967 | protected void doRun() throws SameThreadException, RemoteException { |
| 968 | Log.i(TAG, "SipService.sendTextMessage() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 969 | SFLPhoneservice.sflph_call_send_text_message(callID, message.comment); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 970 | if (getConferences().get(callID) != null) |
| 971 | getConferences().get(callID).addSipMessage(message); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 972 | } |
| 973 | }); |
| 974 | |
| 975 | } |
| 976 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 977 | @Override |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 978 | public List getAudioCodecList(final String accountID) throws RemoteException { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 979 | class AudioCodecList extends SipRunnableWithReturn { |
| 980 | |
| 981 | @Override |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 982 | protected ArrayList<Codec> doRun() throws SameThreadException { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 983 | Log.i(TAG, "SipService.getAudioCodecList() thread running..."); |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 984 | ArrayList<Codec> results = new ArrayList<Codec>(); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 985 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 986 | IntVect active_payloads = SFLPhoneservice.sflph_config_get_active_audio_codec_list(accountID); |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 987 | for (int i = 0; i < active_payloads.size(); ++i) { |
| 988 | |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 989 | results.add(new Codec(active_payloads.get(i), SFLPhoneservice.sflph_config_get_audio_codec_details(active_payloads.get(i)), true)); |
Alexandre Lision | e004544 | 2013-10-25 09:16:19 -0400 | [diff] [blame] | 990 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 991 | } |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 992 | IntVect payloads = SFLPhoneservice.sflph_config_get_audio_codec_list(); |
Alexandre Lision | 039a3cf | 2013-10-16 17:44:57 -0400 | [diff] [blame] | 993 | |
| 994 | for (int i = 0; i < payloads.size(); ++i) { |
| 995 | boolean isActive = false; |
| 996 | for (Codec co : results) { |
| 997 | if (co.getPayload().toString().contentEquals(String.valueOf(payloads.get(i)))) |
| 998 | isActive = true; |
| 999 | |
| 1000 | } |
| 1001 | if (isActive) |
| 1002 | continue; |
| 1003 | else |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1004 | results.add(new Codec(payloads.get(i), SFLPhoneservice.sflph_config_get_audio_codec_details(payloads.get(i)), false)); |
Alexandre Lision | 039a3cf | 2013-10-16 17:44:57 -0400 | [diff] [blame] | 1005 | |
| 1006 | } |
| 1007 | |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1008 | return results; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | AudioCodecList runInstance = new AudioCodecList(); |
| 1013 | getExecutor().execute(runInstance); |
| 1014 | while (!runInstance.isDone()) { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1015 | } |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1016 | return (ArrayList<Codec>) runInstance.getVal(); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 1019 | @Override |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1020 | public Map getRingtoneList() throws RemoteException { |
| 1021 | class RingtoneList extends SipRunnableWithReturn { |
| 1022 | |
| 1023 | @Override |
| 1024 | protected StringMap doRun() throws SameThreadException { |
| 1025 | Log.i(TAG, "SipService.getRingtoneList() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1026 | return SFLPhoneservice.sflph_config_get_ringtone_list(); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | RingtoneList runInstance = new RingtoneList(); |
| 1031 | getExecutor().execute(runInstance); |
| 1032 | while (!runInstance.isDone()) { |
| 1033 | } |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1034 | StringMap ringtones = (StringMap) runInstance.getVal(); |
| 1035 | |
| 1036 | for (int i = 0; i < ringtones.size(); ++i) { |
| 1037 | // Log.i(TAG,"ringtones "+i+" "+ ringtones.); |
| 1038 | } |
| 1039 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1040 | return null; |
| 1041 | } |
| 1042 | |
| 1043 | @Override |
Alexandre Lision | 1e61e30 | 2014-04-10 15:05:03 -0400 | [diff] [blame] | 1044 | public boolean checkForPrivateKey(final String pemPath) throws RemoteException { |
| 1045 | class hasPrivateKey extends SipRunnableWithReturn { |
| 1046 | |
| 1047 | @Override |
| 1048 | protected Boolean doRun() throws SameThreadException { |
| 1049 | Log.i(TAG, "SipService.isCaptureMuted() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1050 | return SFLPhoneservice.sflph_config_check_for_private_key(pemPath); |
Alexandre Lision | 1e61e30 | 2014-04-10 15:05:03 -0400 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | hasPrivateKey runInstance = new hasPrivateKey(); |
| 1055 | getExecutor().execute(runInstance); |
| 1056 | while (!runInstance.isDone()) { |
| 1057 | } |
| 1058 | |
| 1059 | return (Boolean) runInstance.getVal(); |
| 1060 | } |
| 1061 | |
| 1062 | @Override |
| 1063 | public boolean checkCertificateValidity(final String pemPath) throws RemoteException { |
| 1064 | class isValid extends SipRunnableWithReturn { |
| 1065 | |
| 1066 | @Override |
| 1067 | protected Boolean doRun() throws SameThreadException { |
| 1068 | Log.i(TAG, "SipService.isCaptureMuted() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1069 | return SFLPhoneservice.sflph_config_check_certificate_validity(pemPath, pemPath); |
Alexandre Lision | 1e61e30 | 2014-04-10 15:05:03 -0400 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | isValid runInstance = new isValid(); |
| 1074 | getExecutor().execute(runInstance); |
| 1075 | while (!runInstance.isDone()) { |
| 1076 | } |
| 1077 | |
| 1078 | return (Boolean) runInstance.getVal(); |
| 1079 | } |
| 1080 | |
| 1081 | @Override |
| 1082 | public boolean checkHostnameCertificate(final String certificatePath, final String host, final String port) throws RemoteException { |
| 1083 | class isValid extends SipRunnableWithReturn { |
| 1084 | |
| 1085 | @Override |
| 1086 | protected Boolean doRun() throws SameThreadException { |
| 1087 | Log.i(TAG, "SipService.isCaptureMuted() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1088 | return SFLPhoneservice.sflph_config_check_hostname_certificate(host, port); |
Alexandre Lision | 1e61e30 | 2014-04-10 15:05:03 -0400 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | isValid runInstance = new isValid(); |
| 1093 | getExecutor().execute(runInstance); |
| 1094 | while (!runInstance.isDone()) { |
| 1095 | } |
| 1096 | |
| 1097 | return (Boolean) runInstance.getVal(); |
| 1098 | } |
| 1099 | |
| 1100 | @Override |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1101 | public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException { |
| 1102 | getExecutor().execute(new SipRunnable() { |
| 1103 | @Override |
| 1104 | protected void doRun() throws SameThreadException, RemoteException { |
| 1105 | Log.i(TAG, "SipService.setActiveAudioCodecList() thread running..."); |
| 1106 | StringVect list = new StringVect(); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1107 | for (Object codec : codecs) { |
| 1108 | list.add((String) codec); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1109 | } |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1110 | SFLPhoneservice.sflph_config_set_active_audio_codec_list(list, accountID); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1111 | } |
| 1112 | }); |
| 1113 | } |
| 1114 | |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1115 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 1116 | @Override |
| 1117 | public Conference getCurrentCall() throws RemoteException { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1118 | for (Conference conf : mConferences.values()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 1119 | if (conf.isIncoming()) |
| 1120 | return conf; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 1121 | } |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 1122 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1123 | for (Conference conf : mConferences.values()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 1124 | if (conf.isOnGoing()) |
| 1125 | return conf; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 1126 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 1127 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 1128 | return null; |
| 1129 | } |
| 1130 | |
Alexandre Lision | 64dc8c0 | 2013-09-25 15:32:25 -0400 | [diff] [blame] | 1131 | @Override |
| 1132 | public void playDtmf(final String key) throws RemoteException { |
| 1133 | getExecutor().execute(new SipRunnable() { |
| 1134 | @Override |
| 1135 | protected void doRun() throws SameThreadException, RemoteException { |
| 1136 | Log.i(TAG, "SipService.playDtmf() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1137 | SFLPhoneservice.sflph_call_play_dtmf(key); |
Alexandre Lision | 64dc8c0 | 2013-09-25 15:32:25 -0400 | [diff] [blame] | 1138 | } |
| 1139 | }); |
| 1140 | } |
| 1141 | |
Alexandre Lision | 6ae652d | 2013-09-26 16:39:20 -0400 | [diff] [blame] | 1142 | @Override |
| 1143 | public List getConcurrentCalls() throws RemoteException { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1144 | return new ArrayList(mConferences.values()); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 1145 | } |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 1146 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 1147 | @Override |
| 1148 | public Conference getConference(String id) throws RemoteException { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1149 | return mConferences.get(id); |
Alexandre Lision | 6ae652d | 2013-09-26 16:39:20 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
Alexandre Lision | 4fb2262 | 2013-10-21 16:26:33 -0400 | [diff] [blame] | 1152 | @Override |
Alexandre Lision | 31e3090 | 2013-11-08 15:16:59 -0500 | [diff] [blame] | 1153 | public void setMuted(final boolean mute) throws RemoteException { |
| 1154 | getExecutor().execute(new SipRunnable() { |
| 1155 | @Override |
| 1156 | protected void doRun() throws SameThreadException, RemoteException { |
| 1157 | Log.i(TAG, "SipService.setMuted() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1158 | SFLPhoneservice.sflph_config_mute_capture(mute); |
Alexandre Lision | 31e3090 | 2013-11-08 15:16:59 -0500 | [diff] [blame] | 1159 | } |
| 1160 | }); |
| 1161 | } |
| 1162 | |
| 1163 | @Override |
| 1164 | public boolean isCaptureMuted() throws RemoteException { |
| 1165 | class IsMuted extends SipRunnableWithReturn { |
| 1166 | |
| 1167 | @Override |
| 1168 | protected Boolean doRun() throws SameThreadException { |
| 1169 | Log.i(TAG, "SipService.isCaptureMuted() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1170 | return SFLPhoneservice.sflph_config_is_capture_muted(); |
Alexandre Lision | 31e3090 | 2013-11-08 15:16:59 -0500 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | IsMuted runInstance = new IsMuted(); |
| 1175 | getExecutor().execute(runInstance); |
| 1176 | while (!runInstance.isDone()) { |
| 1177 | } |
| 1178 | |
| 1179 | return (Boolean) runInstance.getVal(); |
| 1180 | } |
| 1181 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1182 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 1183 | public void confirmSAS(final String callID) throws RemoteException { |
| 1184 | getExecutor().execute(new SipRunnable() { |
| 1185 | @Override |
| 1186 | protected void doRun() throws SameThreadException, RemoteException { |
| 1187 | Log.i(TAG, "SipService.confirmSAS() thread running..."); |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame] | 1188 | SecureSipCall call = (SecureSipCall) getCallById(callID); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 1189 | call.setSASConfirmed(true); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1190 | SFLPhoneservice.sflph_call_set_sas_verified(callID); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 1191 | } |
| 1192 | }); |
| 1193 | } |
| 1194 | |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame] | 1195 | |
| 1196 | @Override |
| 1197 | public List getTlsSupportedMethods(){ |
| 1198 | class TlsMethods extends SipRunnableWithReturn { |
| 1199 | |
| 1200 | @Override |
| 1201 | protected List doRun() throws SameThreadException { |
| 1202 | Log.i(TAG, "SipService.getCredentials() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1203 | StringVect map = SFLPhoneservice.sflph_config_get_supported_tls_method(); |
| 1204 | return SwigNativeConverter.convertSwigToNative(map); |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | TlsMethods runInstance = new TlsMethods(); |
| 1209 | getExecutor().execute(runInstance); |
| 1210 | while (!runInstance.isDone()) { |
| 1211 | } |
| 1212 | return (List) runInstance.getVal(); |
| 1213 | } |
| 1214 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 1215 | @Override |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1216 | public List getCredentials(final String accountID) throws RemoteException { |
| 1217 | class Credentials extends SipRunnableWithReturn { |
| 1218 | |
| 1219 | @Override |
| 1220 | protected List doRun() throws SameThreadException { |
| 1221 | Log.i(TAG, "SipService.getCredentials() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1222 | VectMap map = SFLPhoneservice.sflph_config_get_credentials(accountID); |
| 1223 | return SwigNativeConverter.convertCredentialsToNative(map); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | Credentials runInstance = new Credentials(); |
| 1228 | getExecutor().execute(runInstance); |
| 1229 | while (!runInstance.isDone()) { |
| 1230 | } |
| 1231 | return (List) runInstance.getVal(); |
| 1232 | } |
| 1233 | |
| 1234 | @Override |
| 1235 | public void setCredentials(final String accountID, final List creds) throws RemoteException { |
| 1236 | getExecutor().execute(new SipRunnable() { |
| 1237 | @Override |
| 1238 | protected void doRun() throws SameThreadException, RemoteException { |
| 1239 | Log.i(TAG, "SipService.setCredentials() thread running..."); |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 1240 | ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds; |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1241 | SFLPhoneservice.sflph_config_set_credentials(accountID, SwigNativeConverter.convertFromNativeToSwig(creds)); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1242 | } |
| 1243 | }); |
| 1244 | } |
| 1245 | |
Alexandre Lision | 3e2a1d0 | 2013-11-19 17:23:00 -0500 | [diff] [blame] | 1246 | @Override |
| 1247 | public void registerAllAccounts() throws RemoteException { |
| 1248 | getExecutor().execute(new SipRunnable() { |
| 1249 | @Override |
| 1250 | protected void doRun() throws SameThreadException, RemoteException { |
| 1251 | Log.i(TAG, "SipService.registerAllAccounts() thread running..."); |
Alexandre Lision | fc91a46 | 2014-08-07 18:21:07 -0400 | [diff] [blame] | 1252 | SFLPhoneservice.sflph_config_register_all_accounts(); |
Alexandre Lision | 3e2a1d0 | 2013-11-19 17:23:00 -0500 | [diff] [blame] | 1253 | } |
| 1254 | }); |
| 1255 | } |
| 1256 | |
Alexandre Lision | 5f733bc | 2013-12-04 13:10:30 -0500 | [diff] [blame] | 1257 | @Override |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1258 | public void toggleSpeakerPhone(boolean toggle) throws RemoteException { |
| 1259 | if (toggle) |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1260 | mMediaManager.RouteToSpeaker(); |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1261 | else |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1262 | mMediaManager.RouteToInternalSpeaker(); |
Alexandre Lision | 5f733bc | 2013-12-04 13:10:30 -0500 | [diff] [blame] | 1263 | } |
| 1264 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 1265 | }; |
Alexandre Lision | 3c37dca | 2014-02-21 14:13:26 -0500 | [diff] [blame] | 1266 | |
| 1267 | private void removeCall(String callID) { |
| 1268 | Conference conf = findConference(callID); |
| 1269 | if(conf == null) |
| 1270 | return; |
| 1271 | if(conf.getParticipants().size() == 1) |
| 1272 | getConferences().remove(conf.getId()); |
| 1273 | else |
| 1274 | conf.removeParticipant(conf.getCallById(callID)); |
| 1275 | } |
| 1276 | |
| 1277 | protected Conference findConference(String callID) { |
| 1278 | Conference result = null; |
| 1279 | if (getConferences().get(callID) != null) { |
| 1280 | result = getConferences().get(callID); |
| 1281 | } else { |
Alexandre Lision | 96a1ef0 | 2014-09-03 15:28:08 -0400 | [diff] [blame] | 1282 | for (Entry<String, Conference> stringConferenceEntry : getConferences().entrySet()) { |
| 1283 | Conference tmp = stringConferenceEntry.getValue(); |
Alexandre Lision | 3c37dca | 2014-02-21 14:13:26 -0500 | [diff] [blame] | 1284 | for (SipCall c : tmp.getParticipants()) { |
| 1285 | if (c.getCallId().contentEquals(callID)) { |
| 1286 | result = tmp; |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | return result; |
| 1292 | } |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1293 | } |