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