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