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