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