Alexandre Lision | 81ef750 | 2013-12-11 17:29:49 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | 81ef750 | 2013-12-11 17:29:49 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 31 | package org.sflphone.receivers; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 32 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 33 | import java.util.ArrayList; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 34 | import java.util.HashMap; |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 35 | import java.util.Iterator; |
| 36 | import java.util.Map.Entry; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 37 | |
Alexandre Lision | 47a7204 | 2013-12-10 10:43:02 -0500 | [diff] [blame] | 38 | import org.sflphone.client.CallActivity; |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 39 | import org.sflphone.model.Account; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 40 | import org.sflphone.model.CallContact; |
| 41 | import org.sflphone.model.Conference; |
| 42 | import org.sflphone.model.SipCall; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 43 | import org.sflphone.model.SipMessage; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 44 | import org.sflphone.service.CallManagerCallBack; |
| 45 | import org.sflphone.service.ConfigurationManagerCallback; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 46 | import org.sflphone.service.ISipService.Stub; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 47 | import org.sflphone.service.ServiceConstants; |
| 48 | import org.sflphone.service.SipService; |
| 49 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 50 | import android.content.BroadcastReceiver; |
| 51 | import android.content.Context; |
| 52 | import android.content.Intent; |
| 53 | import android.os.Bundle; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 54 | import android.os.RemoteException; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 55 | import android.util.Log; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 56 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 57 | public class IncomingReceiver extends BroadcastReceiver { |
| 58 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 59 | static final String TAG = IncomingReceiver.class.getSimpleName(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 60 | |
| 61 | SipService callback; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 62 | Stub mBinder; |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 63 | |
| 64 | public IncomingReceiver(SipService client, Stub bind) { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 65 | callback = client; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 66 | mBinder = bind; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 67 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 68 | |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 69 | @SuppressWarnings("unchecked") |
| 70 | // Hashmap runtime cast |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 71 | @Override |
| 72 | public void onReceive(Context context, Intent intent) { |
| 73 | |
| 74 | if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 75 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 76 | Log.i(TAG, "Received" + intent.getAction()); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 77 | callback.sendBroadcast(intent); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 78 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 79 | } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 80 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 81 | Log.i(TAG, "Received" + intent.getAction()); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 82 | callback.sendBroadcast(intent); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 83 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 84 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_TEXT)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 85 | |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 86 | Bundle extra = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 87 | Log.i(TAG, "Received" + intent.getAction()); |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 88 | if (callback.getCurrent_calls().get(extra.getString("CallID")) != null) { |
| 89 | callback.getCurrent_calls().get(extra.get("CallID")).addSipMessage(new SipMessage(true, extra.getString("Msg"))); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 90 | } else if (callback.getCurrent_confs().get(extra.getString("CallID")) != null) { |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 91 | callback.getCurrent_confs().get(extra.get("CallID")).addSipMessage(new SipMessage(true, extra.getString("Msg"))); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 92 | } else |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 93 | return; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 94 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 95 | callback.sendBroadcast(intent); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 96 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 97 | } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { |
| 98 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newcall"); |
| 99 | |
| 100 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 101 | |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 102 | Account acc; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 103 | try { |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 104 | HashMap<String, String> details = (HashMap<String, String>) mBinder.getAccountDetails(b.getString("AccountID")); |
| 105 | ArrayList<HashMap<String, String>> credentials = (ArrayList<HashMap<String, String>>) mBinder |
| 106 | .getCredentials(b.getString("AccountID")); |
| 107 | acc = new Account(b.getString("AccountID"), details, credentials); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 108 | callBuilder.startCallCreation(b.getString("CallID")).setAccount(acc).setCallState(SipCall.state.CALL_STATE_RINGING) |
| 109 | .setCallType(SipCall.state.CALL_TYPE_INCOMING); |
| 110 | callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(b.getString("From"))); |
| 111 | |
| 112 | Intent toSend = new Intent(CallManagerCallBack.INCOMING_CALL); |
Alexandre Lision | 47a7204 | 2013-12-10 10:43:02 -0500 | [diff] [blame] | 113 | toSend.setClass(callback, CallActivity.class); |
| 114 | toSend.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 115 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 116 | SipCall newCall = callBuilder.build(); |
| 117 | toSend.putExtra("newcall", newCall); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 118 | HashMap<String, String> callDetails = (HashMap<String, String>) mBinder.getCallDetails(b.getString("CallID")); |
Alexandre Lision | 47a7204 | 2013-12-10 10:43:02 -0500 | [diff] [blame] | 119 | |
| 120 | newCall.setTimestamp_start(Long.parseLong(callDetails.get(ServiceConstants.call.TIMESTAMP_START))); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 121 | callback.getCurrent_calls().put(newCall.getCallId(), newCall); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 122 | // callback.sendBroadcast(toSend); |
Alexandre Lision | 47a7204 | 2013-12-10 10:43:02 -0500 | [diff] [blame] | 123 | Bundle bundle = new Bundle(); |
| 124 | Conference tmp = new Conference("-1"); |
| 125 | |
| 126 | tmp.getParticipants().add(newCall); |
| 127 | |
| 128 | bundle.putParcelable("conference", tmp); |
| 129 | toSend.putExtra("resuming", false); |
| 130 | toSend.putExtras(bundle); |
| 131 | callback.startActivity(toSend); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 132 | callback.mediaManager.startRing(""); |
Alexandre Lision | baeeb21 | 2013-12-09 12:54:47 -0500 | [diff] [blame] | 133 | callback.mediaManager.obtainAudioFocus(true); |
Alexandre Lision | 3ee516e | 2013-10-07 17:32:15 -0400 | [diff] [blame] | 134 | } catch (RemoteException e1) { |
| 135 | e1.printStackTrace(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 136 | } catch (Exception e) { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 137 | e.printStackTrace(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
| 141 | |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 142 | Log.i(TAG, "Received " + intent.getAction()); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 143 | Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 144 | String newState = b.getString("State"); |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 145 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 146 | try { |
| 147 | if (callback.getCurrent_calls().get(b.getString("CallID")) != null && mBinder.isConferenceParticipant(b.getString("CallID"))) { |
| 148 | callback.getCurrent_calls().remove(b.getString("CallID")); |
| 149 | } |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 150 | } catch (RemoteException e1) { |
| 151 | e1.printStackTrace(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 152 | } |
| 153 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 154 | if (newState.equals("INCOMING")) { |
| 155 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_INCOMING); |
| 156 | } else if (newState.equals("RINGING")) { |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 157 | try { |
| 158 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_RINGING); |
| 159 | } catch (NullPointerException e) { |
| 160 | if (callback.getCurrent_calls() == null) { |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | if (callback.getCurrent_calls().get(b.getString("CallID")) == null) { |
| 164 | Log.e(TAG, "get(b.getString(callID)) null"); |
| 165 | return; |
| 166 | } |
| 167 | } |
| 168 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 169 | } else if (newState.equals("CURRENT")) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 170 | if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { |
| 171 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 172 | } else { |
| 173 | // Check if call is in a conference |
| 174 | Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); |
| 175 | while (it.hasNext()) { |
| 176 | Conference tmp = it.next().getValue(); |
| 177 | for (SipCall c : tmp.getParticipants()) { |
| 178 | if (c.getCallId().contentEquals(b.getString("CallID"))) |
| 179 | c.setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 184 | } else if (newState.equals("HUNGUP")) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 185 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 186 | if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 187 | |
| 188 | if (callback.getCurrent_calls().get(b.getString("CallID")).isRinging() |
| 189 | && callback.getCurrent_calls().get(b.getString("CallID")).isIncoming()) |
Alexandre Lision | 81ef750 | 2013-12-11 17:29:49 -0500 | [diff] [blame] | 190 | callback.notificationManager.publishMissedCallNotification(callback.getCurrent_calls().get(b.getString("CallID"))); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 191 | callback.getCurrent_calls().remove(b.getString("CallID")); |
| 192 | } else { |
| 193 | ArrayList<Conference> it = new ArrayList<Conference>(callback.getCurrent_confs().values()); |
| 194 | |
| 195 | boolean found = false; |
| 196 | int i = 0; |
| 197 | while (!found && i < it.size()) { |
| 198 | Conference tmp = it.get(i); |
| 199 | |
| 200 | for (int j = 0; j < tmp.getParticipants().size(); ++j) { |
| 201 | if (tmp.getParticipants().get(j).getCallId().contentEquals(b.getString("CallID"))) { |
| 202 | callback.getCurrent_confs().get(tmp.getId()).getParticipants().remove(tmp.getParticipants().get(j)); |
| 203 | found = true; |
| 204 | } |
| 205 | |
| 206 | } |
| 207 | ++i; |
| 208 | |
| 209 | } |
| 210 | } |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 211 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 212 | callback.sendBroadcast(intent); |
| 213 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 214 | } else if (newState.equals("BUSY")) { |
| 215 | callback.getCurrent_calls().remove(b.getString("CallID")); |
| 216 | } else if (newState.equals("FAILURE")) { |
| 217 | callback.getCurrent_calls().remove(b.getString("CallID")); |
| 218 | } else if (newState.equals("HOLD")) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 219 | if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { |
| 220 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_HOLD); |
| 221 | } else { |
| 222 | // Check if call is in a conference |
| 223 | Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 224 | while (it.hasNext()) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 225 | Conference tmp = it.next().getValue(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 226 | for (SipCall c : tmp.getParticipants()) { |
| 227 | if (c.getCallId().contentEquals(b.getString("CallID"))) |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 228 | c.setCallState(SipCall.state.CALL_STATE_HOLD); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | } |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 232 | } else if (newState.equals("UNHOLD")) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 233 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 234 | if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { |
| 235 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); |
| 236 | } else { |
| 237 | // Check if call is in a conference |
| 238 | Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 239 | while (it.hasNext()) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 240 | Conference tmp = it.next().getValue(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 241 | for (SipCall c : tmp.getParticipants()) { |
| 242 | if (c.getCallId().contentEquals(b.getString("CallID"))) |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 243 | c.setCallState(SipCall.state.CALL_STATE_CURRENT); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 247 | } else { |
| 248 | callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_NONE); |
| 249 | } |
| 250 | |
| 251 | callback.sendBroadcast(intent); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 252 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 253 | } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 254 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 255 | Log.i(TAG, "Received" + intent.getAction()); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 256 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 257 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CREATED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 258 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 259 | Log.i(TAG, "Received" + intent.getAction()); |
| 260 | Conference created = new Conference(intent.getStringExtra("confID")); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 261 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 262 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 263 | ArrayList<String> all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 264 | for (String participant : all_participants) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 265 | created.getParticipants().add(callback.getCurrent_calls().get(participant)); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 266 | callback.getCurrent_calls().remove(participant); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 267 | } |
| 268 | Intent toSend = new Intent(CallManagerCallBack.CONF_CREATED); |
| 269 | toSend.putExtra("newconf", created); |
| 270 | callback.getCurrent_confs().put(intent.getStringExtra("confID"), created); |
| 271 | callback.sendBroadcast(toSend); |
| 272 | } catch (RemoteException e1) { |
| 273 | e1.printStackTrace(); |
| 274 | } |
| 275 | Log.i(TAG, "current_confs size " + callback.getCurrent_confs().size()); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 276 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 277 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_REMOVED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 278 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 279 | Log.i(TAG, "Received" + intent.getAction()); |
| 280 | Conference toDestroy = callback.getCurrent_confs().get(intent.getStringExtra("confID")); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 281 | for (int i = 0; i < toDestroy.getParticipants().size(); ++i) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 282 | callback.getCurrent_calls().put(toDestroy.getParticipants().get(i).getCallId(), toDestroy.getParticipants().get(i)); |
| 283 | } |
| 284 | callback.getCurrent_confs().remove(intent.getStringExtra("confID")); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 285 | callback.sendBroadcast(intent); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 286 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 287 | } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CHANGED)) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 288 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 289 | ArrayList<String> all_participants; |
| 290 | try { |
| 291 | all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); |
| 292 | for (String participant : all_participants) { |
| 293 | if (callback.getCurrent_confs().get(intent.getStringExtra("confID")).getParticipants().size() < all_participants.size() |
| 294 | && callback.getCurrent_calls().get(participant) != null) { // We need to add the new participant to the conf |
| 295 | callback.getCurrent_confs().get(intent.getStringExtra("confID")).getParticipants() |
| 296 | .add(callback.getCurrent_calls().get(participant)); |
| 297 | callback.getCurrent_calls().remove(participant); |
| 298 | callback.getCurrent_confs().get(intent.getStringExtra("confID")).setState(intent.getStringExtra("State")); |
| 299 | callback.sendBroadcast(intent); |
| 300 | return; |
| 301 | } |
| 302 | } |
| 303 | } catch (RemoteException e) { |
| 304 | e.printStackTrace(); |
| 305 | } |
| 306 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 307 | Log.i(TAG, "Received" + intent.getAction()); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 308 | if (callback.getCurrent_confs().get(intent.getStringExtra("confID")) != null) { |
| 309 | |
| 310 | callback.getCurrent_confs().get(intent.getStringExtra("confID")).setState(intent.getStringExtra("State")); |
| 311 | callback.sendBroadcast(intent); |
| 312 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 313 | |
| 314 | } else if (intent.getAction().contentEquals(CallManagerCallBack.RECORD_STATE_CHANGED)) { |
| 315 | |
| 316 | Log.i(TAG, "Received" + intent.getAction()); |
| 317 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 318 | // try { |
| 319 | // if (callback.getCurrent_confs().get(intent.getStringExtra("id")) != null) { |
| 320 | // callback.getCurrent_confs().get(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); |
| 321 | // } else if (callback.getCurrent_calls().get(intent.getStringExtra("id")) != null) { |
| 322 | // callback.getCurrent_calls().get(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); |
| 323 | // } else { |
| 324 | // // A call in a conference has been put on hold |
| 325 | // Iterator<Conference> it = callback.getCurrent_confs().values().iterator(); |
| 326 | // while (it.hasNext()) { |
| 327 | // Conference c = it.next(); |
| 328 | // if (c.getCall(intent.getStringExtra("id")) != null) |
| 329 | // c.getCall(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); |
| 330 | // } |
| 331 | // } |
| 332 | // // Re sending the same intent to the app |
| 333 | // callback.sendBroadcast(intent); |
| 334 | // ; |
| 335 | // } catch (RemoteException e) { |
| 336 | // // TODO Auto-generated catch block |
| 337 | // e.printStackTrace(); |
| 338 | // } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 339 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | } |
| 343 | } |