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 | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 425 | if(mConferences.size() == 0) |
| 426 | mMediaManager.abandonAudioFocus(); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 427 | } |
| 428 | }); |
| 429 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 430 | |
| 431 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 432 | public void hold(final String callID) { |
| 433 | getExecutor().execute(new SipRunnable() { |
| 434 | @Override |
| 435 | protected void doRun() throws SameThreadException { |
| 436 | Log.i(TAG, "SipService.hold() thread running..."); |
| 437 | callManagerJNI.hold(callID); |
| 438 | } |
| 439 | }); |
| 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void unhold(final String callID) { |
| 444 | getExecutor().execute(new SipRunnable() { |
| 445 | @Override |
| 446 | protected void doRun() throws SameThreadException { |
| 447 | Log.i(TAG, "SipService.unhold() thread running..."); |
| 448 | callManagerJNI.unhold(callID); |
| 449 | } |
| 450 | }); |
| 451 | } |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 452 | |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 453 | @Override |
| 454 | public HashMap<String, String> getCallDetails(String callID) throws RemoteException { |
| 455 | class CallDetails extends SipRunnableWithReturn { |
| 456 | private String id; |
| 457 | |
| 458 | CallDetails(String callID) { |
| 459 | id = callID; |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | protected StringMap doRun() throws SameThreadException { |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 464 | Log.i(TAG, "SipService.getCallDetails() thread running..."); |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 465 | return callManagerJNI.getCallDetails(id); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | CallDetails runInstance = new CallDetails(callID); |
| 470 | getExecutor().execute(runInstance); |
| 471 | |
| 472 | while (!runInstance.isDone()) { |
| 473 | } |
| 474 | StringMap swigmap = (StringMap) runInstance.getVal(); |
| 475 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 476 | HashMap<String, String> nativemap = SwigNativeConverter.convertCallDetailsToNative(swigmap); |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 477 | |
| 478 | return nativemap; |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 479 | |
Alexandre Lision | 6711ab2 | 2013-09-16 15:15:38 -0400 | [diff] [blame] | 480 | } |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 481 | |
| 482 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 483 | public void setAudioPlugin(final String audioPlugin) { |
| 484 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 485 | @Override |
| 486 | protected void doRun() throws SameThreadException { |
| 487 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
| 488 | configurationManagerJNI.setAudioPlugin(audioPlugin); |
| 489 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 490 | }); |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public String getCurrentAudioOutputPlugin() { |
| 495 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 496 | @Override |
| 497 | protected String doRun() throws SameThreadException { |
| 498 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
| 499 | return configurationManagerJNI.getCurrentAudioOutputPlugin(); |
| 500 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 501 | } |
| 502 | ; |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 503 | |
| 504 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 505 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 506 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 507 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 508 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 509 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 510 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 511 | |
| 512 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 513 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 514 | class AccountList extends SipRunnableWithReturn { |
| 515 | @Override |
| 516 | protected StringVect doRun() throws SameThreadException { |
| 517 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 518 | return configurationManagerJNI.getAccountList(); |
| 519 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 520 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 521 | AccountList runInstance = new AccountList(); |
Alexandre Lision | cdec595 | 2013-07-17 14:18:22 -0400 | [diff] [blame] | 522 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 523 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 524 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 525 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 526 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 527 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 528 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 529 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 530 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 531 | for (int i = 0; i < swigvect.size(); i++) |
| 532 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 533 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 534 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 535 | } |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 536 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 537 | @Override |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 538 | public void setAccountOrder(final String order) { |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 539 | getExecutor().execute(new SipRunnable() { |
| 540 | @Override |
| 541 | protected void doRun() throws SameThreadException { |
| 542 | Log.i(TAG, "SipService.setAccountsOrder() thread running..."); |
| 543 | configurationManagerJNI.setAccountsOrder(order); |
| 544 | } |
| 545 | }); |
| 546 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 547 | |
| 548 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 549 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 550 | class AccountDetails extends SipRunnableWithReturn { |
| 551 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 552 | |
| 553 | AccountDetails(String accountId) { |
| 554 | id = accountId; |
| 555 | } |
| 556 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 557 | @Override |
| 558 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 559 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 560 | return configurationManagerJNI.getAccountDetails(id); |
| 561 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 562 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 563 | |
| 564 | AccountDetails runInstance = new AccountDetails(accountID); |
| 565 | getExecutor().execute(runInstance); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 566 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 567 | while (!runInstance.isDone()) { |
| 568 | } |
| 569 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 570 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 571 | HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 572 | |
| 573 | return nativemap; |
| 574 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 575 | |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 576 | @SuppressWarnings("unchecked") |
| 577 | // Hashmap runtime cast |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 578 | @Override |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 579 | public void setAccountDetails(final String accountId, final Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 580 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 581 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 582 | final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 583 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 584 | getExecutor().execute(new SipRunnable() { |
| 585 | @Override |
| 586 | protected void doRun() throws SameThreadException { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 587 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 588 | configurationManagerJNI.setAccountDetails(accountId, swigmap); |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 589 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 590 | } |
| 591 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 592 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 595 | @Override |
| 596 | public Map getAccountTemplate() throws RemoteException { |
| 597 | class AccountTemplate extends SipRunnableWithReturn { |
| 598 | |
| 599 | @Override |
| 600 | protected StringMap doRun() throws SameThreadException { |
| 601 | Log.i(TAG, "SipService.getAccountTemplate() thread running..."); |
| 602 | return configurationManagerJNI.getAccountTemplate(); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | AccountTemplate runInstance = new AccountTemplate(); |
| 607 | getExecutor().execute(runInstance); |
| 608 | |
| 609 | while (!runInstance.isDone()) { |
| 610 | } |
| 611 | StringMap swigmap = (StringMap) runInstance.getVal(); |
| 612 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 613 | HashMap<String, String> nativemap = SwigNativeConverter.convertAccountToNative(swigmap); |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 614 | |
| 615 | return nativemap; |
| 616 | } |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 617 | |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 618 | @SuppressWarnings("unchecked") |
| 619 | // Hashmap runtime cast |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 620 | @Override |
| 621 | public String addAccount(Map map) { |
| 622 | class AddAccount extends SipRunnableWithReturn { |
| 623 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 624 | |
| 625 | AddAccount(StringMap m) { |
| 626 | map = m; |
| 627 | } |
| 628 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 629 | @Override |
| 630 | protected String doRun() throws SameThreadException { |
| 631 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
| 632 | return configurationManagerJNI.addAccount(map); |
| 633 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 634 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 635 | |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 636 | final StringMap swigmap = SwigNativeConverter.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 637 | |
| 638 | AddAccount runInstance = new AddAccount(swigmap); |
| 639 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 640 | while (!runInstance.isDone()) { |
| 641 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 642 | String accountId = (String) runInstance.getVal(); |
| 643 | |
| 644 | return accountId; |
| 645 | } |
| 646 | |
| 647 | @Override |
| 648 | public void removeAccount(final String accountId) { |
| 649 | getExecutor().execute(new SipRunnable() { |
| 650 | @Override |
| 651 | protected void doRun() throws SameThreadException { |
| 652 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 653 | configurationManagerJNI.removeAccount(accountId); |
| 654 | } |
| 655 | }); |
| 656 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 657 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 658 | /************************* |
| 659 | * Transfer related API |
| 660 | *************************/ |
| 661 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 662 | @Override |
| 663 | public void transfer(final String callID, final String to) throws RemoteException { |
| 664 | getExecutor().execute(new SipRunnable() { |
| 665 | @Override |
| 666 | protected void doRun() throws SameThreadException, RemoteException { |
| 667 | Log.i(TAG, "SipService.transfer() thread running..."); |
| 668 | if (callManagerJNI.transfer(callID, to)) { |
| 669 | Bundle bundle = new Bundle(); |
| 670 | bundle.putString("CallID", callID); |
| 671 | bundle.putString("State", "HUNGUP"); |
| 672 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 673 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 674 | sendBroadcast(intent); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 675 | } else |
| 676 | Log.i(TAG, "NOT OK"); |
| 677 | } |
| 678 | }); |
| 679 | |
| 680 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 681 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 682 | @Override |
| 683 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 684 | getExecutor().execute(new SipRunnable() { |
| 685 | @Override |
| 686 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 687 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 688 | if (callManagerJNI.attendedTransfer(transferID, targetID)) { |
| 689 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 690 | } else |
| 691 | Log.i(TAG, "NOT OK"); |
| 692 | } |
| 693 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 694 | |
| 695 | } |
| 696 | |
| 697 | /************************* |
| 698 | * Conference related API |
| 699 | *************************/ |
| 700 | |
| 701 | @Override |
| 702 | public void removeConference(final String confID) throws RemoteException { |
| 703 | getExecutor().execute(new SipRunnable() { |
| 704 | @Override |
| 705 | protected void doRun() throws SameThreadException, RemoteException { |
| 706 | Log.i(TAG, "SipService.createConference() thread running..."); |
| 707 | callManagerJNI.removeConference(confID); |
| 708 | } |
| 709 | }); |
| 710 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 714 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 715 | getExecutor().execute(new SipRunnable() { |
| 716 | @Override |
| 717 | protected void doRun() throws SameThreadException, RemoteException { |
| 718 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
| 719 | callManagerJNI.joinParticipant(sel_callID, drag_callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 720 | // Generate a CONF_CREATED callback |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 721 | } |
| 722 | }); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 723 | Log.i(TAG, "After joining participants"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 724 | } |
| 725 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 726 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 727 | public void addParticipant(final SipCall call, final String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 728 | getExecutor().execute(new SipRunnable() { |
| 729 | @Override |
| 730 | protected void doRun() throws SameThreadException, RemoteException { |
| 731 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 732 | callManagerJNI.addParticipant(call.getCallId(), confID); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 733 | mConferences.get(confID).getParticipants().add(call); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 734 | } |
| 735 | }); |
| 736 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 740 | public void addMainParticipant(final String confID) throws RemoteException { |
| 741 | getExecutor().execute(new SipRunnable() { |
| 742 | @Override |
| 743 | protected void doRun() throws SameThreadException, RemoteException { |
| 744 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
| 745 | callManagerJNI.addMainParticipant(confID); |
| 746 | } |
| 747 | }); |
| 748 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 752 | public void detachParticipant(final String callID) throws RemoteException { |
| 753 | getExecutor().execute(new SipRunnable() { |
| 754 | @Override |
| 755 | protected void doRun() throws SameThreadException, RemoteException { |
| 756 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 757 | Log.i(TAG, "Detaching " + callID); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 758 | Iterator<Entry<String, Conference>> it = mConferences.entrySet().iterator(); |
| 759 | Log.i(TAG, "mConferences size " + mConferences.size()); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 760 | while (it.hasNext()) { |
| 761 | Conference tmp = it.next().getValue(); |
| 762 | Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants"); |
| 763 | if (tmp.contains(callID)) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 764 | Conference toDetach = new Conference(tmp.getCallById(callID)); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 765 | mConferences.put(toDetach.getId(), toDetach); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 766 | Log.i(TAG, "Call found and put in current_calls"); |
| 767 | } |
| 768 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 769 | callManagerJNI.detachParticipant(callID); |
| 770 | } |
| 771 | }); |
| 772 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 776 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 777 | getExecutor().execute(new SipRunnable() { |
| 778 | @Override |
| 779 | protected void doRun() throws SameThreadException, RemoteException { |
| 780 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 781 | callManagerJNI.joinConference(sel_confID, drag_confID); |
| 782 | } |
| 783 | }); |
| 784 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 788 | public void hangUpConference(final String confID) throws RemoteException { |
| 789 | getExecutor().execute(new SipRunnable() { |
| 790 | @Override |
| 791 | protected void doRun() throws SameThreadException, RemoteException { |
| 792 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 793 | callManagerJNI.hangUpConference(confID); |
| 794 | } |
| 795 | }); |
| 796 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 800 | public void holdConference(final String confID) throws RemoteException { |
| 801 | getExecutor().execute(new SipRunnable() { |
| 802 | @Override |
| 803 | protected void doRun() throws SameThreadException, RemoteException { |
| 804 | Log.i(TAG, "SipService.holdConference() thread running..."); |
| 805 | callManagerJNI.holdConference(confID); |
| 806 | } |
| 807 | }); |
| 808 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 812 | public void unholdConference(final String confID) throws RemoteException { |
| 813 | getExecutor().execute(new SipRunnable() { |
| 814 | @Override |
| 815 | protected void doRun() throws SameThreadException, RemoteException { |
| 816 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
| 817 | callManagerJNI.unholdConference(confID); |
| 818 | } |
| 819 | }); |
| 820 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 821 | } |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 822 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 823 | @Override |
| 824 | public boolean isConferenceParticipant(final String callID) throws RemoteException { |
| 825 | class IsParticipant extends SipRunnableWithReturn { |
| 826 | |
| 827 | @Override |
| 828 | protected Boolean doRun() throws SameThreadException { |
| 829 | Log.i(TAG, "SipService.isRecording() thread running..."); |
| 830 | return callManagerJNI.isConferenceParticipant(callID); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | IsParticipant runInstance = new IsParticipant(); |
| 835 | getExecutor().execute(runInstance); |
| 836 | while (!runInstance.isDone()) { |
| 837 | } |
| 838 | |
| 839 | return (Boolean) runInstance.getVal(); |
| 840 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 841 | |
| 842 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 843 | public HashMap<String, Conference> getConferenceList() throws RemoteException { |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 844 | // class ConfList extends SipRunnableWithReturn { |
| 845 | // @Override |
| 846 | // protected StringVect doRun() throws SameThreadException { |
| 847 | // Log.i(TAG, "SipService.getConferenceList() thread running..."); |
| 848 | // return callManagerJNI.getConferenceList(); |
| 849 | // } |
| 850 | // } |
| 851 | // ; |
| 852 | // ConfList runInstance = new ConfList(); |
| 853 | // getExecutor().execute(runInstance); |
| 854 | // while (!runInstance.isDone()) { |
| 855 | // // Log.w(TAG, "Waiting for getConferenceList"); |
| 856 | // } |
| 857 | // StringVect swigvect = (StringVect) runInstance.getVal(); |
| 858 | // |
| 859 | // ArrayList<String> nativelist = new ArrayList<String>(); |
| 860 | // |
| 861 | // for (int i = 0; i < swigvect.size(); i++) |
| 862 | // nativelist.add(swigvect.get(i)); |
| 863 | // |
| 864 | // return nativelist; |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 865 | return mConferences; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 869 | public List getParticipantList(final String confID) throws RemoteException { |
| 870 | class PartList extends SipRunnableWithReturn { |
| 871 | @Override |
| 872 | protected StringVect doRun() throws SameThreadException { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 873 | Log.i(TAG, "SipService.getParticipantList() thread running..."); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 874 | return callManagerJNI.getParticipantList(confID); |
| 875 | } |
| 876 | } |
| 877 | ; |
| 878 | PartList runInstance = new PartList(); |
| 879 | getExecutor().execute(runInstance); |
| 880 | while (!runInstance.isDone()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 881 | Log.w(TAG, "getParticipantList"); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 882 | } |
| 883 | StringVect swigvect = (StringVect) runInstance.getVal(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 884 | Log.w(TAG, "After that"); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 885 | ArrayList<String> nativelist = new ArrayList<String>(); |
| 886 | |
| 887 | for (int i = 0; i < swigvect.size(); i++) |
| 888 | nativelist.add(swigvect.get(i)); |
| 889 | |
| 890 | return nativelist; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 891 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 892 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 893 | @Override |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 894 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 895 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 896 | return null; |
| 897 | } |
| 898 | |
| 899 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 900 | public String getConferenceDetails(final String callID) throws RemoteException { |
| 901 | class ConfDetails extends SipRunnableWithReturn { |
| 902 | @Override |
| 903 | protected StringMap doRun() throws SameThreadException { |
| 904 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 905 | return callManagerJNI.getConferenceDetails(callID); |
| 906 | } |
| 907 | } |
| 908 | ; |
| 909 | ConfDetails runInstance = new ConfDetails(); |
| 910 | getExecutor().execute(runInstance); |
| 911 | while (!runInstance.isDone()) { |
| 912 | // Log.w(TAG, "Waiting for getConferenceList"); |
| 913 | } |
| 914 | StringMap swigvect = (StringMap) runInstance.getVal(); |
| 915 | |
| 916 | return swigvect.get("CONF_STATE"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 917 | } |
| 918 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 919 | @Override |
| 920 | public String getRecordPath() throws RemoteException { |
| 921 | class RecordPath extends SipRunnableWithReturn { |
| 922 | |
| 923 | @Override |
| 924 | protected String doRun() throws SameThreadException { |
| 925 | Log.i(TAG, "SipService.getRecordPath() thread running..."); |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 926 | return configurationManagerJNI.getRecordPath(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | RecordPath runInstance = new RecordPath(); |
| 931 | getExecutor().execute(runInstance); |
| 932 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 933 | // Log.w(TAG, "Waiting for getRecordPath"); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 934 | } |
| 935 | String path = (String) runInstance.getVal(); |
| 936 | |
| 937 | return path; |
| 938 | } |
| 939 | |
| 940 | @Override |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 941 | public boolean toggleRecordingCall(final String id) throws RemoteException { |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 942 | |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 943 | class ToggleRecording extends SipRunnableWithReturn { |
| 944 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 945 | @Override |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 946 | protected Boolean doRun() throws SameThreadException { |
| 947 | Log.i(TAG, "SipService.toggleRecordingCall() thread running..."); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 948 | boolean result = callManagerJNI.toggleRecording(id); |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 949 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 950 | if (getConferences().containsKey(id)) { |
| 951 | getConferences().get(id).setRecording(result); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 952 | } else { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 953 | Iterator<Conference> it = getConferences().values().iterator(); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 954 | while (it.hasNext()) { |
| 955 | Conference c = it.next(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 956 | if (c.getCallById(id) != null) |
| 957 | c.getCallById(id).setRecording(result); |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | return result; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 961 | } |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | ToggleRecording runInstance = new ToggleRecording(); |
| 965 | getExecutor().execute(runInstance); |
| 966 | while (!runInstance.isDone()) { |
| 967 | } |
| 968 | |
| 969 | return (Boolean) runInstance.getVal(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 970 | |
| 971 | } |
Alexandre Lision | 6781719 | 2013-07-18 12:04:30 -0400 | [diff] [blame] | 972 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 973 | @Override |
| 974 | public boolean startRecordedFilePlayback(final String filepath) throws RemoteException { |
| 975 | getExecutor().execute(new SipRunnable() { |
| 976 | @Override |
| 977 | protected void doRun() throws SameThreadException, RemoteException { |
| 978 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 979 | callManagerJNI.startRecordedFilePlayback(filepath); |
| 980 | } |
| 981 | }); |
| 982 | return false; |
| 983 | } |
| 984 | |
| 985 | @Override |
| 986 | public void stopRecordedFilePlayback(final String filepath) throws RemoteException { |
| 987 | getExecutor().execute(new SipRunnable() { |
| 988 | @Override |
| 989 | protected void doRun() throws SameThreadException, RemoteException { |
| 990 | Log.i(TAG, "SipService.stopRecordedFilePlayback() thread running..."); |
| 991 | callManagerJNI.stopRecordedFilePlayback(filepath); |
| 992 | } |
| 993 | }); |
| 994 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 995 | |
| 996 | @Override |
| 997 | public void setRecordPath(final String path) throws RemoteException { |
| 998 | getExecutor().execute(new SipRunnable() { |
| 999 | @Override |
| 1000 | protected void doRun() throws SameThreadException, RemoteException { |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 1001 | Log.i(TAG, "SipService.setRecordPath() " + path + " thread running..."); |
Adrien Béraud | 9360f24 | 2013-09-19 11:07:42 +1000 | [diff] [blame] | 1002 | configurationManagerJNI.setRecordPath(path); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 1003 | } |
| 1004 | }); |
| 1005 | } |
| 1006 | |
| 1007 | @Override |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 1008 | public void sendTextMessage(final String callID, final SipMessage message) throws RemoteException { |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 1009 | getExecutor().execute(new SipRunnable() { |
| 1010 | @Override |
| 1011 | protected void doRun() throws SameThreadException, RemoteException { |
| 1012 | Log.i(TAG, "SipService.sendTextMessage() thread running..."); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 1013 | callManagerJNI.sendTextMessage(callID, message.comment); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1014 | if (getConferences().get(callID) != null) |
| 1015 | getConferences().get(callID).addSipMessage(message); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 1016 | } |
| 1017 | }); |
| 1018 | |
| 1019 | } |
| 1020 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 1021 | @Override |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1022 | public List getAudioCodecList(final String accountID) throws RemoteException { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1023 | class AudioCodecList extends SipRunnableWithReturn { |
| 1024 | |
| 1025 | @Override |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 1026 | protected ArrayList<Codec> doRun() throws SameThreadException { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1027 | Log.i(TAG, "SipService.getAudioCodecList() thread running..."); |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1028 | ArrayList<Codec> results = new ArrayList<Codec>(); |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1029 | |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1030 | IntVect active_payloads = configurationManagerJNI.getActiveAudioCodecList(accountID); |
| 1031 | for (int i = 0; i < active_payloads.size(); ++i) { |
| 1032 | |
Alexandre Lision | 039a3cf | 2013-10-16 17:44:57 -0400 | [diff] [blame] | 1033 | 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] | 1034 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1035 | } |
Alexandre Lision | 039a3cf | 2013-10-16 17:44:57 -0400 | [diff] [blame] | 1036 | IntVect payloads = configurationManagerJNI.getAudioCodecList(); |
| 1037 | |
| 1038 | for (int i = 0; i < payloads.size(); ++i) { |
| 1039 | boolean isActive = false; |
| 1040 | for (Codec co : results) { |
| 1041 | if (co.getPayload().toString().contentEquals(String.valueOf(payloads.get(i)))) |
| 1042 | isActive = true; |
| 1043 | |
| 1044 | } |
| 1045 | if (isActive) |
| 1046 | continue; |
| 1047 | else |
| 1048 | results.add(new Codec(payloads.get(i), configurationManagerJNI.getAudioCodecDetails(payloads.get(i)), false)); |
| 1049 | |
| 1050 | } |
| 1051 | |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1052 | return results; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | AudioCodecList runInstance = new AudioCodecList(); |
| 1057 | getExecutor().execute(runInstance); |
| 1058 | while (!runInstance.isDone()) { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1059 | } |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 1060 | ArrayList<Codec> codecs = (ArrayList<Codec>) runInstance.getVal(); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 1061 | return codecs; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 1064 | @Override |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1065 | public Map getRingtoneList() throws RemoteException { |
| 1066 | class RingtoneList extends SipRunnableWithReturn { |
| 1067 | |
| 1068 | @Override |
| 1069 | protected StringMap doRun() throws SameThreadException { |
| 1070 | Log.i(TAG, "SipService.getRingtoneList() thread running..."); |
| 1071 | return configurationManagerJNI.getRingtoneList(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | RingtoneList runInstance = new RingtoneList(); |
| 1076 | getExecutor().execute(runInstance); |
| 1077 | while (!runInstance.isDone()) { |
| 1078 | } |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 1079 | StringMap ringtones = (StringMap) runInstance.getVal(); |
| 1080 | |
| 1081 | for (int i = 0; i < ringtones.size(); ++i) { |
| 1082 | // Log.i(TAG,"ringtones "+i+" "+ ringtones.); |
| 1083 | } |
| 1084 | |
Alexandre Lision | 4cf7870 | 2013-10-16 13:43:23 -0400 | [diff] [blame] | 1085 | return null; |
| 1086 | } |
| 1087 | |
| 1088 | @Override |
| 1089 | public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException { |
| 1090 | getExecutor().execute(new SipRunnable() { |
| 1091 | @Override |
| 1092 | protected void doRun() throws SameThreadException, RemoteException { |
| 1093 | Log.i(TAG, "SipService.setActiveAudioCodecList() thread running..."); |
| 1094 | StringVect list = new StringVect(); |
| 1095 | for (int i = 0; i < codecs.size(); ++i) { |
| 1096 | list.add((String) codecs.get(i)); |
| 1097 | } |
| 1098 | configurationManagerJNI.setActiveAudioCodecList(list, accountID); |
| 1099 | } |
| 1100 | }); |
| 1101 | } |
| 1102 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1103 | /*********************** |
| 1104 | * Notification API |
| 1105 | ***********************/ |
| 1106 | @Override |
| 1107 | public void createNotification() throws RemoteException { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1108 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | @Override |
| 1112 | public void destroyNotification() throws RemoteException { |
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1113 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 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..."); |
| 1137 | callManagerJNI.playDTMF(key); |
| 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 |
| 1153 | public String getCurrentAudioCodecName(String callID) throws RemoteException { |
| 1154 | return callManagerJNI.getCurrentAudioCodecName(callID); |
| 1155 | } |
| 1156 | |
Alexandre Lision | 31e3090 | 2013-11-08 15:16:59 -0500 | [diff] [blame] | 1157 | @Override |
| 1158 | public void setMuted(final boolean mute) throws RemoteException { |
| 1159 | getExecutor().execute(new SipRunnable() { |
| 1160 | @Override |
| 1161 | protected void doRun() throws SameThreadException, RemoteException { |
| 1162 | Log.i(TAG, "SipService.setMuted() thread running..."); |
| 1163 | configurationManagerJNI.muteCapture(mute); |
| 1164 | } |
| 1165 | }); |
| 1166 | } |
| 1167 | |
| 1168 | @Override |
| 1169 | public boolean isCaptureMuted() throws RemoteException { |
| 1170 | class IsMuted extends SipRunnableWithReturn { |
| 1171 | |
| 1172 | @Override |
| 1173 | protected Boolean doRun() throws SameThreadException { |
| 1174 | Log.i(TAG, "SipService.isCaptureMuted() thread running..."); |
| 1175 | return configurationManagerJNI.isCaptureMuted(); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | IsMuted runInstance = new IsMuted(); |
| 1180 | getExecutor().execute(runInstance); |
| 1181 | while (!runInstance.isDone()) { |
| 1182 | } |
| 1183 | |
| 1184 | return (Boolean) runInstance.getVal(); |
| 1185 | } |
| 1186 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1187 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 1188 | public void confirmSAS(final String callID) throws RemoteException { |
| 1189 | getExecutor().execute(new SipRunnable() { |
| 1190 | @Override |
| 1191 | protected void doRun() throws SameThreadException, RemoteException { |
| 1192 | Log.i(TAG, "SipService.confirmSAS() thread running..."); |
| 1193 | callManagerJNI.setSASVerified(callID); |
| 1194 | } |
| 1195 | }); |
| 1196 | } |
| 1197 | |
| 1198 | @Override |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1199 | public List getCredentials(final String accountID) throws RemoteException { |
| 1200 | class Credentials extends SipRunnableWithReturn { |
| 1201 | |
| 1202 | @Override |
| 1203 | protected List doRun() throws SameThreadException { |
| 1204 | Log.i(TAG, "SipService.getCredentials() thread running..."); |
| 1205 | VectMap map = configurationManagerJNI.getCredentials(accountID); |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 1206 | ArrayList<HashMap<String, String>> result = SwigNativeConverter.convertCredentialsToNative(map); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1207 | return result; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | Credentials runInstance = new Credentials(); |
| 1212 | getExecutor().execute(runInstance); |
| 1213 | while (!runInstance.isDone()) { |
| 1214 | } |
| 1215 | return (List) runInstance.getVal(); |
| 1216 | } |
| 1217 | |
| 1218 | @Override |
| 1219 | public void setCredentials(final String accountID, final List creds) throws RemoteException { |
| 1220 | getExecutor().execute(new SipRunnable() { |
| 1221 | @Override |
| 1222 | protected void doRun() throws SameThreadException, RemoteException { |
| 1223 | Log.i(TAG, "SipService.setCredentials() thread running..."); |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 1224 | ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds; |
Alexandre Lision | 2aae48d | 2013-12-04 13:50:38 -0500 | [diff] [blame] | 1225 | configurationManagerJNI.setCredentials(accountID, SwigNativeConverter.convertFromNativeToSwig(creds)); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 1226 | } |
| 1227 | }); |
| 1228 | } |
| 1229 | |
Alexandre Lision | 3e2a1d0 | 2013-11-19 17:23:00 -0500 | [diff] [blame] | 1230 | @Override |
| 1231 | public void registerAllAccounts() throws RemoteException { |
| 1232 | getExecutor().execute(new SipRunnable() { |
| 1233 | @Override |
| 1234 | protected void doRun() throws SameThreadException, RemoteException { |
| 1235 | Log.i(TAG, "SipService.registerAllAccounts() thread running..."); |
| 1236 | configurationManagerJNI.registerAllAccounts(); |
| 1237 | } |
| 1238 | }); |
| 1239 | } |
| 1240 | |
Alexandre Lision | 5f733bc | 2013-12-04 13:10:30 -0500 | [diff] [blame] | 1241 | @Override |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1242 | public void toggleSpeakerPhone(boolean toggle) throws RemoteException { |
| 1243 | if (toggle) |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1244 | mMediaManager.RouteToSpeaker(); |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1245 | else |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 1246 | mMediaManager.RouteToInternalSpeaker(); |
Alexandre Lision | 5f733bc | 2013-12-04 13:10:30 -0500 | [diff] [blame] | 1247 | } |
| 1248 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 1249 | }; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 1250 | } |