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