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