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