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