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) |
| 3 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 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 | */ |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 25 | package com.savoirfairelinux.sflphone.service; |
| 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 | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 30 | import java.util.List; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 31 | import java.util.Map; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 32 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 33 | import android.app.Service; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
| 35 | import android.content.Context; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 36 | import android.content.Intent; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 37 | import android.content.IntentFilter; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 38 | import android.os.Bundle; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 39 | import android.os.Handler; |
| 40 | import android.os.HandlerThread; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 41 | import android.os.IBinder; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 42 | import android.os.Looper; |
| 43 | import android.os.Message; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 44 | import android.os.Parcelable; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 46 | import android.os.Vibrator; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 47 | import android.support.v4.content.LocalBroadcastManager; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 48 | import android.util.Log; |
| 49 | import android.widget.Toast; |
| 50 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | import com.savoirfairelinux.sflphone.account.AccountDetailsHandler; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 52 | import com.savoirfairelinux.sflphone.account.AudioHandler; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.account.HistoryHandler; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 54 | import com.savoirfairelinux.sflphone.client.SFLphoneApplication; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.model.CallContact; |
| 56 | import com.savoirfairelinux.sflphone.model.SipCall; |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 57 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 58 | public class SipService extends Service { |
| 59 | |
| 60 | static final String TAG = "SipService"; |
| 61 | static final int DELAY = 5000; /* 5 sec */ |
| 62 | private boolean runFlag = false; |
| 63 | private SipServiceThread sipServiceThread; |
Emeric Vigier | 84e05da | 2012-09-20 14:53:05 -0400 | [diff] [blame] | 64 | private SFLphoneApplication sflphoneApp; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 65 | private SipServiceExecutor mExecutor; |
| 66 | private static HandlerThread executorThread; |
| 67 | private CallManagerJNI callManagerJNI; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 68 | private CallManagerCallBack callManagerCallBack; |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 69 | private ConfigurationManagerJNI configurationManagerJNI; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 70 | private ConfigurationManagerCallback configurationManagerCallback; |
Emeric Vigier | 0007dee | 2012-09-24 11:35:58 -0400 | [diff] [blame] | 71 | private ManagerImpl managerImpl; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 72 | private boolean isPjSipStackStarted = false; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 73 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 74 | HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>(); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 75 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 76 | private BroadcastReceiver IncomingReceiver = new BroadcastReceiver() { |
| 77 | |
| 78 | @Override |
| 79 | public void onReceive(Context context, Intent intent) { |
| 80 | // Get instance of Vibrator from current Context |
| 81 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 82 | if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) { |
| 83 | Log.i(TAG, "Received" + intent.getAction()); |
| 84 | } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_LOADED)) { |
| 85 | Log.i(TAG, "Received" + intent.getAction()); |
| 86 | } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) { |
| 87 | Log.i(TAG, "Received" + intent.getAction()); |
| 88 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_TEXT)) { |
| 89 | Log.i(TAG, "Received" + intent.getAction()); |
| 90 | sendBroadcast(intent); |
| 91 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 92 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newcall"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 93 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 94 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 95 | callBuilder.startCallCreation(b.getString("CallID")).setAccountID(b.getString("AccountID")) |
| 96 | .setCallState(SipCall.state.CALL_STATE_RINGING).setCallType(SipCall.state.CALL_TYPE_INCOMING); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 97 | callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(b.getString("From"))); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 98 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 99 | Intent toSend = new Intent(CallManagerCallBack.INCOMING_CALL); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 100 | try { |
| 101 | SipCall newCall = callBuilder.build(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 102 | toSend.putExtra("newcall", newCall); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 103 | current_calls.put(newCall.getCallId(), newCall); |
| 104 | sendBroadcast(toSend); |
| 105 | } catch (Exception e) { |
| 106 | Log.e(TAG, e.toString()); |
| 107 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 108 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 109 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 110 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 111 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 112 | String newState = b.getString("State"); |
| 113 | if (newState.equals("INCOMING")) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 114 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_INCOMING); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 115 | } else if (newState.equals("RINGING")) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 116 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_RINGING); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 117 | } else if (newState.equals("CURRENT")) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 118 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 119 | } else if (newState.equals("HUNGUP")) { |
| 120 | current_calls.remove(b.getString("CallID")); |
| 121 | } else if (newState.equals("BUSY")) { |
| 122 | current_calls.remove(b.getString("CallID")); |
| 123 | } else if (newState.equals("FAILURE")) { |
| 124 | current_calls.remove(b.getString("CallID")); |
| 125 | } else if (newState.equals("HOLD")) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 126 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_HOLD); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 127 | } else if (newState.equals("UNHOLD")) { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 128 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 129 | } else { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 130 | current_calls.get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_NONE); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 131 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 132 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 133 | sendBroadcast(intent); |
| 134 | } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { |
| 135 | Log.i(TAG, "Received" + intent.getAction()); |
| 136 | Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| 137 | mVibrator.vibrate(300); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | @Override |
| 144 | public boolean onUnbind(Intent i) { |
| 145 | super.onUnbind(i); |
| 146 | Log.i(TAG, "onUnbind(intent)"); |
| 147 | return false; |
| 148 | |
| 149 | } |
| 150 | |
| 151 | /* called once by startService() */ |
| 152 | @Override |
| 153 | public void onCreate() { |
| 154 | Log.i(TAG, "onCreated"); |
| 155 | super.onCreate(); |
| 156 | |
| 157 | sflphoneApp = (SFLphoneApplication) getApplication(); |
| 158 | sipServiceThread = new SipServiceThread(); |
| 159 | |
| 160 | IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED); |
| 161 | callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 162 | callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED); |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 163 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
| 164 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
| 165 | callFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_LOADED); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 166 | callFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 167 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 168 | LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver, callFilter); |
| 169 | getExecutor().execute(new StartRunnable()); |
| 170 | } |
| 171 | |
| 172 | /* called for each startService() */ |
| 173 | @Override |
| 174 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 175 | Log.i(TAG, "onStarted"); |
| 176 | super.onStartCommand(intent, flags, startId); |
| 177 | |
| 178 | if (!runFlag) { |
| 179 | sipServiceThread.start(); |
| 180 | runFlag = true; |
| 181 | sflphoneApp.setServiceRunning(true); |
| 182 | Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show(); |
| 183 | } |
| 184 | |
| 185 | return START_STICKY; /* started and stopped explicitly */ |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public void onDestroy() { |
| 190 | /* called once by stopService() */ |
| 191 | sipServiceThread.interrupt(); |
| 192 | sipServiceThread = null; |
| 193 | runFlag = false; |
| 194 | sflphoneApp.setServiceRunning(false); |
| 195 | Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show(); |
| 196 | super.onDestroy(); |
| 197 | |
| 198 | Log.i(TAG, "onDestroyed"); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public IBinder onBind(Intent arg0) { |
| 203 | Log.i(TAG, "onBound"); |
| 204 | return mBinder; |
| 205 | } |
| 206 | |
| 207 | private static Looper createLooper() { |
| 208 | if (executorThread == null) { |
| 209 | Log.d(TAG, "Creating new handler thread"); |
| 210 | // ADT gives a fake warning due to bad parse rule. |
| 211 | executorThread = new HandlerThread("SipService.Executor"); |
| 212 | executorThread.start(); |
| 213 | } |
| 214 | return executorThread.getLooper(); |
| 215 | } |
| 216 | |
| 217 | public SipServiceExecutor getExecutor() { |
| 218 | // create mExecutor lazily |
| 219 | if (mExecutor == null) { |
| 220 | mExecutor = new SipServiceExecutor(this); |
| 221 | } |
| 222 | return mExecutor; |
| 223 | } |
| 224 | |
| 225 | // Executes immediate tasks in a single executorThread. |
| 226 | public static class SipServiceExecutor extends Handler { |
| 227 | WeakReference<SipService> handlerService; |
| 228 | |
| 229 | SipServiceExecutor(SipService s) { |
| 230 | super(createLooper()); |
| 231 | handlerService = new WeakReference<SipService>(s); |
| 232 | } |
| 233 | |
| 234 | public void execute(Runnable task) { |
| 235 | // TODO: add wakelock |
| 236 | Message.obtain(this, 0/* don't care */, task).sendToTarget(); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void handleMessage(Message msg) { |
| 241 | if (msg.obj instanceof Runnable) { |
| 242 | executeInternal((Runnable) msg.obj); |
| 243 | } else { |
| 244 | Log.w(TAG, "can't handle msg: " + msg); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | private void executeInternal(Runnable task) { |
| 249 | try { |
| 250 | task.run(); |
| 251 | } catch (Throwable t) { |
| 252 | Log.e(TAG, "run task: " + task, t); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | private void startPjSipStack() throws SameThreadException { |
| 258 | if (isPjSipStackStarted) |
| 259 | return; |
| 260 | |
| 261 | try { |
| 262 | System.loadLibrary("gnustl_shared"); |
| 263 | System.loadLibrary("expat"); |
| 264 | System.loadLibrary("yaml"); |
| 265 | System.loadLibrary("ccgnu2"); |
| 266 | System.loadLibrary("crypto"); |
| 267 | System.loadLibrary("ssl"); |
| 268 | System.loadLibrary("ccrtp1"); |
| 269 | System.loadLibrary("dbus"); |
| 270 | System.loadLibrary("dbus-c++-1"); |
| 271 | System.loadLibrary("samplerate"); |
| 272 | System.loadLibrary("codec_ulaw"); |
| 273 | System.loadLibrary("codec_alaw"); |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 274 | System.loadLibrary("codec_g722"); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 275 | System.loadLibrary("speexresampler"); |
| 276 | System.loadLibrary("sflphone"); |
| 277 | isPjSipStackStarted = true; |
| 278 | } catch (UnsatisfiedLinkError e) { |
| 279 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 280 | isPjSipStackStarted = false; |
| 281 | return; |
| 282 | } catch (Exception e) { |
| 283 | Log.e(TAG, "Problem with the current Pj stack...", e); |
| 284 | } |
| 285 | |
| 286 | /* get unique instance of managerImpl */ |
| 287 | managerImpl = SFLPhoneservice.instance(); |
| 288 | |
| 289 | /* set static AppPath before calling manager.init */ |
| 290 | managerImpl.setPath(sflphoneApp.getAppPath()); |
| 291 | |
| 292 | callManagerJNI = new CallManagerJNI(); |
| 293 | callManagerCallBack = new CallManagerCallBack(this); |
| 294 | SFLPhoneservice.setCallbackObject(callManagerCallBack); |
| 295 | |
| 296 | configurationManagerJNI = new ConfigurationManagerJNI(); |
| 297 | configurationManagerCallback = new ConfigurationManagerCallback(this); |
| 298 | SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback); |
| 299 | |
| 300 | managerImpl.init(""); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | // Enforce same thread contract to ensure we do not call from somewhere else |
| 305 | public class SameThreadException extends Exception { |
| 306 | private static final long serialVersionUID = -905639124232613768L; |
| 307 | |
| 308 | public SameThreadException() { |
| 309 | super("Should be launched from a single worker thread"); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | public abstract static class SipRunnable implements Runnable { |
| 314 | protected abstract void doRun() throws SameThreadException, RemoteException; |
| 315 | |
| 316 | public void run() { |
| 317 | try { |
| 318 | doRun(); |
| 319 | } catch (SameThreadException e) { |
| 320 | Log.e(TAG, "Not done from same thread"); |
| 321 | } catch (RemoteException e) { |
| 322 | Log.e(TAG, e.toString()); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | public abstract static class SipRunnableWithReturn implements Runnable { |
| 328 | Object obj = null; |
| 329 | boolean done = false; |
| 330 | |
| 331 | protected abstract Object doRun() throws SameThreadException; |
| 332 | |
| 333 | public Object getVal() { |
| 334 | return obj; |
| 335 | } |
| 336 | |
| 337 | public boolean isDone() { |
| 338 | return done; |
| 339 | } |
| 340 | |
| 341 | public void run() { |
| 342 | try { |
| 343 | obj = doRun(); |
| 344 | done = true; |
| 345 | } catch (SameThreadException e) { |
| 346 | Log.e(TAG, "Not done from same thread"); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | class StartRunnable extends SipRunnable { |
| 352 | @Override |
| 353 | protected void doRun() throws SameThreadException { |
| 354 | startPjSipStack(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | private class SipServiceThread extends Thread { |
| 359 | |
| 360 | public SipServiceThread() { |
| 361 | super("sipServiceThread"); |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public void run() { |
| 366 | Log.i(TAG, "SipService thread running..."); |
| 367 | SipService sipService = SipService.this; |
| 368 | while (sipService.runFlag) { |
| 369 | try { |
| 370 | Thread.sleep(DELAY); |
| 371 | } catch (InterruptedException e) { |
| 372 | sipService.runFlag = false; |
| 373 | Log.w(TAG, "service thread interrupted!"); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /* ************************************ |
| 380 | * |
| 381 | * Implement public interface for the service |
| 382 | * |
| 383 | * |
| 384 | * ********************************** |
| 385 | */ |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 386 | private final ISipService.Stub mBinder = new ISipService.Stub() { |
| 387 | |
| 388 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 389 | public void placeCall(final SipCall call) { |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 390 | getExecutor().execute(new SipRunnable() { |
| 391 | @Override |
| 392 | protected void doRun() throws SameThreadException { |
| 393 | Log.i(TAG, "SipService.placeCall() thread running..."); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 394 | callManagerJNI.placeCall(call.getAccountID(), call.getCallId(), call.getContacts().get(0).getPhones().get(0).getNumber()); |
| 395 | current_calls.put(call.getCallId(), call); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 396 | } |
| 397 | }); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void refuse(final String callID) { |
| 402 | getExecutor().execute(new SipRunnable() { |
| 403 | @Override |
| 404 | protected void doRun() throws SameThreadException { |
| 405 | Log.i(TAG, "SipService.refuse() thread running..."); |
| 406 | callManagerJNI.refuse(callID); |
| 407 | } |
| 408 | }); |
| 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void accept(final String callID) { |
| 413 | getExecutor().execute(new SipRunnable() { |
| 414 | @Override |
| 415 | protected void doRun() throws SameThreadException { |
| 416 | Log.i(TAG, "SipService.placeCall() thread running..."); |
| 417 | callManagerJNI.accept(callID); |
| 418 | } |
| 419 | }); |
| 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public void hangUp(final String callID) { |
| 424 | getExecutor().execute(new SipRunnable() { |
| 425 | @Override |
| 426 | protected void doRun() throws SameThreadException { |
| 427 | Log.i(TAG, "SipService.hangUp() thread running..."); |
| 428 | callManagerJNI.hangUp(callID); |
| 429 | } |
| 430 | }); |
| 431 | } |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 432 | |
| 433 | @Override |
Alexandre Savard | e9dc899 | 2012-10-26 12:12:27 -0400 | [diff] [blame] | 434 | public void hold(final String callID) { |
| 435 | getExecutor().execute(new SipRunnable() { |
| 436 | @Override |
| 437 | protected void doRun() throws SameThreadException { |
| 438 | Log.i(TAG, "SipService.hold() thread running..."); |
| 439 | callManagerJNI.hold(callID); |
| 440 | } |
| 441 | }); |
| 442 | } |
| 443 | |
| 444 | @Override |
| 445 | public void unhold(final String callID) { |
| 446 | getExecutor().execute(new SipRunnable() { |
| 447 | @Override |
| 448 | protected void doRun() throws SameThreadException { |
| 449 | Log.i(TAG, "SipService.unhold() thread running..."); |
| 450 | callManagerJNI.unhold(callID); |
| 451 | } |
| 452 | }); |
| 453 | } |
| 454 | |
| 455 | @Override |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 456 | public void setAudioPlugin(final String audioPlugin) { |
| 457 | getExecutor().execute(new SipRunnable() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 458 | @Override |
| 459 | protected void doRun() throws SameThreadException { |
| 460 | Log.i(TAG, "SipService.setAudioPlugin() thread running..."); |
| 461 | configurationManagerJNI.setAudioPlugin(audioPlugin); |
| 462 | } |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 463 | }); |
| 464 | } |
| 465 | |
| 466 | @Override |
| 467 | public String getCurrentAudioOutputPlugin() { |
| 468 | class CurrentAudioPlugin extends SipRunnableWithReturn { |
| 469 | @Override |
| 470 | protected String doRun() throws SameThreadException { |
| 471 | Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); |
| 472 | return configurationManagerJNI.getCurrentAudioOutputPlugin(); |
| 473 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 474 | } |
| 475 | ; |
Alexandre Savard | 31d27c6 | 2012-10-04 16:05:08 -0400 | [diff] [blame] | 476 | |
| 477 | CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); |
| 478 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 479 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 480 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 481 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 482 | return (String) runInstance.getVal(); |
Alexandre Savard | c1b08fe | 2012-09-25 16:24:47 -0400 | [diff] [blame] | 483 | } |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 484 | |
| 485 | @Override |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 486 | public ArrayList<String> getAccountList() { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 487 | class AccountList extends SipRunnableWithReturn { |
| 488 | @Override |
| 489 | protected StringVect doRun() throws SameThreadException { |
| 490 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 491 | return configurationManagerJNI.getAccountList(); |
| 492 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 493 | } |
| 494 | ; |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 495 | AccountList runInstance = new AccountList(); |
| 496 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 497 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 498 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 499 | } |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 500 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 501 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 502 | ArrayList<String> nativelist = new ArrayList<String>(); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 503 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 504 | for (int i = 0; i < swigvect.size(); i++) |
| 505 | nativelist.add(swigvect.get(i)); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 506 | |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 507 | return nativelist; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 508 | } |
Alexandre Savard | 6b85e7e | 2012-09-27 15:43:14 -0400 | [diff] [blame] | 509 | |
| 510 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 511 | public HashMap<String, String> getAccountDetails(final String accountID) { |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 512 | class AccountDetails extends SipRunnableWithReturn { |
| 513 | private String id; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 514 | |
| 515 | AccountDetails(String accountId) { |
| 516 | id = accountId; |
| 517 | } |
| 518 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 519 | @Override |
| 520 | protected StringMap doRun() throws SameThreadException { |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 521 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 522 | return configurationManagerJNI.getAccountDetails(id); |
| 523 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 524 | } |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 525 | |
| 526 | AccountDetails runInstance = new AccountDetails(accountID); |
| 527 | getExecutor().execute(runInstance); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 528 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 529 | while (!runInstance.isDone()) { |
| 530 | } |
| 531 | StringMap swigmap = (StringMap) runInstance.getVal(); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 532 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 533 | HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap); |
Alexandre Savard | 713a34d | 2012-09-26 15:50:41 -0400 | [diff] [blame] | 534 | |
| 535 | return nativemap; |
| 536 | } |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 537 | |
| 538 | @Override |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 539 | public void setAccountDetails(final String accountId, Map map) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 540 | HashMap<String, String> nativemap = (HashMap<String, String>) map; |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 541 | |
Alexandre Savard | 3bbb479 | 2012-10-05 11:30:01 -0400 | [diff] [blame] | 542 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap); |
Alexandre Savard | 718d49f | 2012-10-02 15:17:13 -0400 | [diff] [blame] | 543 | |
Alexandre Savard | 7a2b220 | 2012-10-04 17:07:33 -0400 | [diff] [blame] | 544 | getExecutor().execute(new SipRunnable() { |
| 545 | @Override |
| 546 | protected void doRun() throws SameThreadException { |
| 547 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 548 | configurationManagerJNI.setAccountDetails(accountId, swigmap); |
| 549 | } |
| 550 | }); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 551 | } |
| 552 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 553 | @Override |
| 554 | public String addAccount(Map map) { |
| 555 | class AddAccount extends SipRunnableWithReturn { |
| 556 | StringMap map; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 557 | |
| 558 | AddAccount(StringMap m) { |
| 559 | map = m; |
| 560 | } |
| 561 | |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 562 | @Override |
| 563 | protected String doRun() throws SameThreadException { |
| 564 | Log.i(TAG, "SipService.getAccountDetails() thread running..."); |
| 565 | return configurationManagerJNI.addAccount(map); |
| 566 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 567 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 568 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 569 | final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map); |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 570 | |
| 571 | AddAccount runInstance = new AddAccount(swigmap); |
| 572 | getExecutor().execute(runInstance); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 573 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 574 | // Log.e(TAG, "Waiting for Nofing"); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 575 | } |
Alexandre Savard | 4603657 | 2012-10-05 13:56:49 -0400 | [diff] [blame] | 576 | String accountId = (String) runInstance.getVal(); |
| 577 | |
| 578 | return accountId; |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | public void removeAccount(final String accountId) { |
| 583 | getExecutor().execute(new SipRunnable() { |
| 584 | @Override |
| 585 | protected void doRun() throws SameThreadException { |
| 586 | Log.i(TAG, "SipService.setAccountDetails() thread running..."); |
| 587 | configurationManagerJNI.removeAccount(accountId); |
| 588 | } |
| 589 | }); |
| 590 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 591 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 592 | @Override |
| 593 | public ArrayList<HashMap<String, String>> getHistory() throws RemoteException { |
| 594 | class History extends SipRunnableWithReturn { |
| 595 | |
| 596 | @Override |
| 597 | protected VectMap doRun() throws SameThreadException { |
| 598 | Log.i(TAG, "SipService.getHistory() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 599 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 600 | return configurationManagerJNI.getHistory(); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | History runInstance = new History(); |
| 605 | getExecutor().execute(runInstance); |
| 606 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 607 | // Log.w(TAG, "Waiting for getHistory"); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 608 | } |
| 609 | VectMap swigmap = (VectMap) runInstance.getVal(); |
| 610 | |
| 611 | ArrayList<HashMap<String, String>> nativemap = HistoryHandler.convertSwigToNative(swigmap); |
| 612 | |
| 613 | return nativemap; |
| 614 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 615 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 616 | /************************* |
| 617 | * Transfer related API |
| 618 | *************************/ |
| 619 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 620 | @Override |
| 621 | public void transfer(final String callID, final String to) throws RemoteException { |
| 622 | getExecutor().execute(new SipRunnable() { |
| 623 | @Override |
| 624 | protected void doRun() throws SameThreadException, RemoteException { |
| 625 | Log.i(TAG, "SipService.transfer() thread running..."); |
| 626 | if (callManagerJNI.transfer(callID, to)) { |
| 627 | Bundle bundle = new Bundle(); |
| 628 | bundle.putString("CallID", callID); |
| 629 | bundle.putString("State", "HUNGUP"); |
| 630 | Intent intent = new Intent(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 631 | intent.putExtra(CallManagerCallBack.SIGNAL_NAME, CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 632 | intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 633 | sendBroadcast(intent); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 634 | } else |
| 635 | Log.i(TAG, "NOT OK"); |
| 636 | } |
| 637 | }); |
| 638 | |
| 639 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 640 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 641 | @Override |
| 642 | public void attendedTransfer(final String transferID, final String targetID) throws RemoteException { |
| 643 | getExecutor().execute(new SipRunnable() { |
| 644 | @Override |
| 645 | protected void doRun() throws SameThreadException, RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 646 | Log.i(TAG, "SipService.attendedTransfer() thread running..."); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 647 | if (callManagerJNI.attendedTransfer(transferID, targetID)) { |
| 648 | Log.i(TAG, "OK"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 649 | } else |
| 650 | Log.i(TAG, "NOT OK"); |
| 651 | } |
| 652 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 653 | |
| 654 | } |
| 655 | |
| 656 | /************************* |
| 657 | * Conference related API |
| 658 | *************************/ |
| 659 | |
| 660 | @Override |
| 661 | public void removeConference(final String confID) throws RemoteException { |
| 662 | getExecutor().execute(new SipRunnable() { |
| 663 | @Override |
| 664 | protected void doRun() throws SameThreadException, RemoteException { |
| 665 | Log.i(TAG, "SipService.createConference() thread running..."); |
| 666 | callManagerJNI.removeConference(confID); |
| 667 | } |
| 668 | }); |
| 669 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 673 | public void joinParticipant(final String sel_callID, final String drag_callID) throws RemoteException { |
| 674 | getExecutor().execute(new SipRunnable() { |
| 675 | @Override |
| 676 | protected void doRun() throws SameThreadException, RemoteException { |
| 677 | Log.i(TAG, "SipService.joinParticipant() thread running..."); |
| 678 | callManagerJNI.joinParticipant(sel_callID, drag_callID); |
| 679 | } |
| 680 | }); |
| 681 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 685 | public void createConfFromParticipantList(final List participants) throws RemoteException { |
| 686 | getExecutor().execute(new SipRunnable() { |
| 687 | @Override |
| 688 | protected void doRun() throws SameThreadException, RemoteException { |
| 689 | Log.i(TAG, "SipService.createConfFromParticipantList() thread running..."); |
| 690 | // callManagerJNI.createConfFromParticipantList(participants); |
| 691 | } |
| 692 | }); |
| 693 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 697 | public void addParticipant(final String callID, final String confID) throws RemoteException { |
| 698 | getExecutor().execute(new SipRunnable() { |
| 699 | @Override |
| 700 | protected void doRun() throws SameThreadException, RemoteException { |
| 701 | Log.i(TAG, "SipService.addParticipant() thread running..."); |
| 702 | callManagerJNI.addParticipant(callID, confID); |
| 703 | } |
| 704 | }); |
| 705 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 709 | public void addMainParticipant(final String confID) throws RemoteException { |
| 710 | getExecutor().execute(new SipRunnable() { |
| 711 | @Override |
| 712 | protected void doRun() throws SameThreadException, RemoteException { |
| 713 | Log.i(TAG, "SipService.addMainParticipant() thread running..."); |
| 714 | callManagerJNI.addMainParticipant(confID); |
| 715 | } |
| 716 | }); |
| 717 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 721 | public void detachParticipant(final String callID) throws RemoteException { |
| 722 | getExecutor().execute(new SipRunnable() { |
| 723 | @Override |
| 724 | protected void doRun() throws SameThreadException, RemoteException { |
| 725 | Log.i(TAG, "SipService.detachParticipant() thread running..."); |
| 726 | callManagerJNI.detachParticipant(callID); |
| 727 | } |
| 728 | }); |
| 729 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 733 | public void joinConference(final String sel_confID, final String drag_confID) throws RemoteException { |
| 734 | getExecutor().execute(new SipRunnable() { |
| 735 | @Override |
| 736 | protected void doRun() throws SameThreadException, RemoteException { |
| 737 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 738 | callManagerJNI.joinConference(sel_confID, drag_confID); |
| 739 | } |
| 740 | }); |
| 741 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 745 | public void hangUpConference(final String confID) throws RemoteException { |
| 746 | getExecutor().execute(new SipRunnable() { |
| 747 | @Override |
| 748 | protected void doRun() throws SameThreadException, RemoteException { |
| 749 | Log.i(TAG, "SipService.joinConference() thread running..."); |
| 750 | callManagerJNI.hangUpConference(confID); |
| 751 | } |
| 752 | }); |
| 753 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 757 | public void holdConference(final String confID) throws RemoteException { |
| 758 | getExecutor().execute(new SipRunnable() { |
| 759 | @Override |
| 760 | protected void doRun() throws SameThreadException, RemoteException { |
| 761 | Log.i(TAG, "SipService.holdConference() thread running..."); |
| 762 | callManagerJNI.holdConference(confID); |
| 763 | } |
| 764 | }); |
| 765 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 769 | public void unholdConference(final String confID) throws RemoteException { |
| 770 | getExecutor().execute(new SipRunnable() { |
| 771 | @Override |
| 772 | protected void doRun() throws SameThreadException, RemoteException { |
| 773 | Log.i(TAG, "SipService.unholdConference() thread running..."); |
| 774 | callManagerJNI.unholdConference(confID); |
| 775 | } |
| 776 | }); |
| 777 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public List getConferenceList() throws RemoteException { |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 782 | class ConfList extends SipRunnableWithReturn { |
| 783 | @Override |
| 784 | protected StringVect doRun() throws SameThreadException { |
| 785 | Log.i(TAG, "SipService.getAccountList() thread running..."); |
| 786 | return callManagerJNI.getConferenceList(); |
| 787 | } |
| 788 | } |
| 789 | ; |
| 790 | ConfList runInstance = new ConfList(); |
| 791 | getExecutor().execute(runInstance); |
| 792 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 793 | // Log.w(TAG, "Waiting for getConferenceList"); |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 794 | } |
| 795 | StringVect swigvect = (StringVect) runInstance.getVal(); |
| 796 | |
| 797 | ArrayList<String> nativelist = new ArrayList<String>(); |
| 798 | |
| 799 | for (int i = 0; i < swigvect.size(); i++) |
| 800 | nativelist.add(swigvect.get(i)); |
| 801 | |
| 802 | return nativelist; |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public List getParticipantList(String confID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 807 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 808 | return null; |
| 809 | } |
| 810 | |
| 811 | @Override |
| 812 | public String getConferenceId(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 813 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 814 | return null; |
| 815 | } |
| 816 | |
| 817 | @Override |
| 818 | public Map getConferenceDetails(String callID) throws RemoteException { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 819 | Log.e(TAG, "getConferenceList not implemented"); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 820 | return null; |
| 821 | } |
| 822 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 823 | @Override |
| 824 | public String getRecordPath() throws RemoteException { |
| 825 | class RecordPath extends SipRunnableWithReturn { |
| 826 | |
| 827 | @Override |
| 828 | protected String doRun() throws SameThreadException { |
| 829 | Log.i(TAG, "SipService.getRecordPath() thread running..."); |
| 830 | return configurationManagerJNI.getRecordPath(); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | RecordPath runInstance = new RecordPath(); |
| 835 | getExecutor().execute(runInstance); |
| 836 | while (!runInstance.isDone()) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 837 | // Log.w(TAG, "Waiting for getRecordPath"); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 838 | } |
| 839 | String path = (String) runInstance.getVal(); |
| 840 | |
| 841 | return path; |
| 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public void setRecordingCall(final String id) throws RemoteException { |
| 846 | getExecutor().execute(new SipRunnable() { |
| 847 | @Override |
| 848 | protected void doRun() throws SameThreadException, RemoteException { |
| 849 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 850 | callManagerJNI.setRecordingCall(id); |
| 851 | } |
| 852 | }); |
| 853 | |
| 854 | } |
| 855 | |
| 856 | @Override |
| 857 | public void setRecordPath(final String path) throws RemoteException { |
| 858 | getExecutor().execute(new SipRunnable() { |
| 859 | @Override |
| 860 | protected void doRun() throws SameThreadException, RemoteException { |
| 861 | Log.i(TAG, "SipService.setRecordingCall() thread running..."); |
| 862 | configurationManagerJNI.setRecordPath(path); |
| 863 | } |
| 864 | }); |
| 865 | } |
| 866 | |
| 867 | @Override |
| 868 | public void sendTextMessage(final String callID, final String message, final String from) throws RemoteException { |
| 869 | getExecutor().execute(new SipRunnable() { |
| 870 | @Override |
| 871 | protected void doRun() throws SameThreadException, RemoteException { |
| 872 | Log.i(TAG, "SipService.sendTextMessage() thread running..."); |
| 873 | callManagerJNI.sendTextMessage(callID, message, from); |
| 874 | } |
| 875 | }); |
| 876 | |
| 877 | } |
| 878 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 879 | @Override |
| 880 | public List getAudioCodecList(String accountID) throws RemoteException { |
| 881 | class AudioCodecList extends SipRunnableWithReturn { |
| 882 | |
| 883 | @Override |
| 884 | protected IntVect doRun() throws SameThreadException { |
| 885 | Log.i(TAG, "SipService.getAudioCodecList() thread running..."); |
| 886 | return configurationManagerJNI.getAudioCodecList(); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | AudioCodecList runInstance = new AudioCodecList(); |
| 891 | getExecutor().execute(runInstance); |
| 892 | while (!runInstance.isDone()) { |
| 893 | Log.w(TAG, "Waiting for getAudioCodecList"); |
| 894 | } |
| 895 | IntVect swigmap = (IntVect) runInstance.getVal(); |
| 896 | |
| 897 | ArrayList<Integer> codecs = AudioHandler.convertSwigToNative(swigmap); |
| 898 | |
| 899 | return codecs; |
| 900 | } |
| 901 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 902 | @Override |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 903 | public HashMap<String, SipCall> getCallList() throws RemoteException { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 904 | // class CallList extends SipRunnableWithReturn { |
| 905 | // |
| 906 | // @Override |
| 907 | // protected StringVect doRun() throws SameThreadException { |
| 908 | // Log.i(TAG, "SipService.getCallList() thread running..."); |
| 909 | // return callManagerJNI.getCallList(); |
| 910 | // } |
| 911 | // } |
| 912 | // |
| 913 | // CallList runInstance = new CallList(); |
| 914 | // getExecutor().execute(runInstance); |
| 915 | // while (!runInstance.isDone()) { |
| 916 | // Log.w(TAG, "Waiting for getAudioCodecList"); |
| 917 | // } |
| 918 | // StringVect swigmap = (StringVect) runInstance.getVal(); |
| 919 | // |
| 920 | // ArrayList<String> nativemap = new ArrayList<String>(); |
| 921 | // for (int i = 0; i < swigmap.size(); ++i) { |
| 922 | // |
| 923 | // String t = swigmap.get(i); |
| 924 | // nativemap.add(t); |
| 925 | // } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 926 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 927 | return current_calls; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 928 | } |
| 929 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame^] | 930 | @Override |
| 931 | public SipCall getCall(String callID) throws RemoteException { |
| 932 | return current_calls.get(callID); |
| 933 | } |
| 934 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 935 | }; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 936 | } |