Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.service; |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 2 | |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 3 | import android.content.Intent; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 4 | import android.os.Bundle; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 5 | import android.util.Log; |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 6 | import org.sflphone.account.AccountDetailSrtp; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 7 | import org.sflphone.client.CallActivity; |
| 8 | import org.sflphone.model.*; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 9 | import org.sflphone.utils.SwigNativeConverter; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 10 | |
| 11 | import java.util.ArrayList; |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 12 | import java.util.HashMap; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 13 | import java.util.Iterator; |
| 14 | import java.util.Map; |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 15 | |
| 16 | public class CallManagerCallBack extends Callback { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 17 | |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 18 | private static final String TAG = "CallManagerCallBack"; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 19 | private SipService mService; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 20 | |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 21 | static public final String CALL_STATE_CHANGED = "call-state-changed"; |
| 22 | static public final String INCOMING_CALL = "incoming-call"; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 23 | static public final String INCOMING_TEXT = "incoming-text"; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 24 | static public final String CONF_CREATED = "conf_created"; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 25 | static public final String CONF_REMOVED = "conf_removed"; |
| 26 | static public final String CONF_CHANGED = "conf_changed"; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 27 | static public final String RECORD_STATE_CHANGED = "record_state"; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 28 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 29 | static public final String ZRTP_ON = "secure_zrtp_on"; |
| 30 | static public final String ZRTP_OFF = "secure_zrtp_off"; |
| 31 | static public final String DISPLAY_SAS = "display_sas"; |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 32 | static public final String ZRTP_NEGOTIATION_FAILED = "zrtp_nego_failed"; |
| 33 | static public final String ZRTP_NOT_SUPPORTED = "zrtp_not_supported"; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 34 | |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 35 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 36 | public CallManagerCallBack(SipService context) { |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 37 | mService = context; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 38 | } |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 39 | |
| 40 | @Override |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 41 | public void on_call_state_changed(String callID, String newState) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 42 | Log.d(TAG, "on_call_state_changed : (" + callID + ", " + newState + ")"); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 43 | |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 44 | Conference toUpdate = findConference(callID); |
| 45 | |
| 46 | if (toUpdate == null) { |
| 47 | return; |
| 48 | } |
| 49 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 50 | Intent intent = new Intent(CALL_STATE_CHANGED); |
| 51 | intent.putExtra("CallID", callID); |
| 52 | intent.putExtra("State", newState); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 53 | |
Alexandre Lision | 707f908 | 2014-01-16 15:09:07 -0500 | [diff] [blame] | 54 | if (newState.equals("RINGING")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 55 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_RINGING); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 56 | } else if (newState.equals("CURRENT")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 57 | if(toUpdate.isRinging()){ |
| 58 | toUpdate.getCallById(callID).setTimestampStart_(System.currentTimeMillis()); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 59 | } |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 60 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_CURRENT); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 61 | } else if (newState.equals("HUNGUP")) { |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 62 | Log.d(TAG, "Hanging up " + callID); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 63 | SipCall call = toUpdate.getCallById(callID); |
| 64 | if (!toUpdate.hasMultipleParticipants()) { |
| 65 | if (toUpdate.isRinging() && toUpdate.isIncoming()) { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 66 | mService.mNotificationManager.publishMissedCallNotification(mService.getConferences().get(callID)); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 67 | } |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 68 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_HUNGUP); |
| 69 | mService.mHistoryManager.insertNewEntry(toUpdate); |
| 70 | mService.getConferences().remove(toUpdate.getId()); |
| 71 | Log.e(TAG, "Conferences :"+ mService.getConferences().size()); |
| 72 | Log.e(TAG, "toUpdate.getParticipants() :"+ toUpdate.getParticipants().size()); |
| 73 | } else { |
| 74 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_HUNGUP); |
| 75 | mService.mHistoryManager.insertNewEntry(call); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 76 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 77 | } else if (newState.equals("BUSY")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 78 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_BUSY); |
| 79 | mService.getConferences().remove(toUpdate.getId()); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 80 | } else if (newState.equals("FAILURE")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 81 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_FAILURE); |
| 82 | mService.getConferences().remove(toUpdate.getId()); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 83 | } else if (newState.equals("HOLD")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 84 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_HOLD); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 85 | } else if (newState.equals("UNHOLD")) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 86 | toUpdate.setCallState(callID, SipCall.state.CALL_STATE_CURRENT); |
| 87 | } |
| 88 | intent.putExtra("conference", toUpdate); |
| 89 | mService.sendBroadcast(intent); |
| 90 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 91 | |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 92 | private Conference findConference(String callID) { |
| 93 | Conference result = null; |
| 94 | if (mService.getConferences().get(callID) != null) { |
| 95 | result = mService.getConferences().get(callID); |
| 96 | } else { |
| 97 | Iterator<Map.Entry<String, Conference>> it = mService.getConferences().entrySet().iterator(); |
| 98 | while (it.hasNext()) { |
| 99 | Conference tmp = it.next().getValue(); |
| 100 | for (SipCall c : tmp.getParticipants()) { |
| 101 | if (c.getCallId().contentEquals(callID)) { |
| 102 | result = tmp; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 106 | } |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 107 | return result; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 111 | public void on_incoming_call(String accountID, String callID, String from) { |
| 112 | Log.d(TAG, "on_incoming_call(" + accountID + ", " + callID + ", " + from + ")"); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 113 | |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 114 | try { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 115 | StringMap details = mService.getConfigurationManagerJNI().getAccountDetails(accountID); |
| 116 | VectMap credentials = mService.getConfigurationManagerJNI().getCredentials(accountID); |
| 117 | Account acc = new Account(accountID, SwigNativeConverter.convertAccountToNative(details), SwigNativeConverter.convertCredentialsToNative(credentials)); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 118 | |
| 119 | Bundle args = new Bundle(); |
| 120 | args.putString(SipCall.ID, callID); |
| 121 | args.putParcelable(SipCall.ACCOUNT, acc); |
| 122 | args.putInt(SipCall.STATE, SipCall.state.CALL_STATE_RINGING); |
| 123 | args.putInt(SipCall.TYPE, SipCall.direction.CALL_TYPE_INCOMING); |
| 124 | |
| 125 | CallContact unknow = CallContact.ContactBuilder.buildUnknownContact(from); |
| 126 | args.putParcelable(SipCall.CONTACT, unknow); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 127 | |
| 128 | Intent toSend = new Intent(CallManagerCallBack.INCOMING_CALL); |
| 129 | toSend.setClass(mService, CallActivity.class); |
| 130 | toSend.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 131 | |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 132 | SipCall newCall = new SipCall(args); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 133 | |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 134 | newCall.setTimestampStart_(System.currentTimeMillis()); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 135 | |
| 136 | Conference toAdd = new Conference(newCall); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 137 | mService.getConferences().put(toAdd.getId(), toAdd); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 138 | |
| 139 | Bundle bundle = new Bundle(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 140 | bundle.putParcelable("conference", toAdd); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 141 | toSend.putExtra("resuming", false); |
| 142 | toSend.putExtras(bundle); |
| 143 | mService.startActivity(toSend); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 144 | mService.mMediaManager.startRing(""); |
| 145 | mService.mMediaManager.obtainAudioFocus(true); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 146 | } catch (Exception e) { |
| 147 | e.printStackTrace(); |
| 148 | } |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 149 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 150 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 151 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 152 | public void on_transfer_state_changed(String result) { |
| 153 | Log.w(TAG, "TRANSFER STATE CHANGED:" + result); |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 154 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 155 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 156 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 157 | public void on_conference_created(final String confID) { |
| 158 | Log.w(TAG, "CONFERENCE CREATED:" + confID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 159 | Intent intent = new Intent(CONF_CREATED); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 160 | Conference created = new Conference(confID); |
| 161 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 162 | StringVect all_participants = mService.getCallManagerJNI().getParticipantList(confID); |
| 163 | Log.w(TAG, "all_participants:" + all_participants.size()); |
| 164 | for (int i = 0; i < all_participants.size(); ++i) { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 165 | if (mService.getConferences().get(all_participants.get(i)) != null) { |
| 166 | created.addParticipant(mService.getConferences().get(all_participants.get(i)).getCallById(all_participants.get(i))); |
| 167 | mService.getConferences().remove(all_participants.get(i)); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 168 | } else { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 169 | Iterator<Map.Entry<String, Conference>> it = mService.getConferences().entrySet().iterator(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 170 | while (it.hasNext()) { |
| 171 | Conference tmp = it.next().getValue(); |
| 172 | for (SipCall c : tmp.getParticipants()) { |
| 173 | if (c.getCallId().contentEquals(all_participants.get(i))) { |
| 174 | created.addParticipant(c); |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 175 | mService.getConferences().get(tmp.getId()).removeParticipant(c); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 179 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 180 | } |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 181 | intent.putExtra("conference", created); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 182 | intent.putExtra("confID", created.getId()); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 183 | mService.getConferences().put(created.getId(), created); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 184 | mService.sendBroadcast(intent); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 185 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 186 | |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 187 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 188 | public void on_incoming_message(String ID, String from, String msg) { |
| 189 | Log.w(TAG, "on_incoming_message:" + msg); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 190 | Intent intent = new Intent(INCOMING_TEXT); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 191 | intent.putExtra("CallID", ID); |
| 192 | intent.putExtra("From", from); |
| 193 | intent.putExtra("Msg", msg); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 194 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 195 | if (mService.getConferences().get(ID) != null) { |
| 196 | mService.getConferences().get(ID).addSipMessage(new SipMessage(true, msg)); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 197 | intent.putExtra("conference", mService.getConferences().get(ID)); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 198 | } else { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 199 | Iterator<Map.Entry<String, Conference>> it = mService.getConferences().entrySet().iterator(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 200 | while (it.hasNext()) { |
| 201 | Conference tmp = it.next().getValue(); |
| 202 | for (SipCall c : tmp.getParticipants()) { |
| 203 | if (c.getCallId().contentEquals(ID)) { |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 204 | mService.getConferences().get(tmp.getId()).addSipMessage(new SipMessage(true, msg)); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 205 | intent.putExtra("conference", tmp); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 211 | mService.sendBroadcast(intent); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 212 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 213 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 214 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 215 | public void on_conference_removed(String confID) { |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 216 | Log.i(TAG, "on_conference_removed:"); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 217 | Intent intent = new Intent(CONF_REMOVED); |
| 218 | intent.putExtra("confID", confID); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 219 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 220 | Conference toReInsert = mService.getConferences().get(confID); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 221 | for (SipCall call : toReInsert.getParticipants()) { |
| 222 | mService.getConferences().put(call.getCallId(), new Conference(call)); |
| 223 | } |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 224 | intent.putExtra("conference", mService.getConferences().get(confID)); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 225 | mService.getConferences().remove(confID); |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 226 | mService.sendBroadcast(intent); |
| 227 | |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 228 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 229 | |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 230 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 231 | public void on_conference_state_changed(String confID, String state) { |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 232 | Log.i(TAG, "on_conference_state_changed:"); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 233 | Intent intent = new Intent(CONF_CHANGED); |
| 234 | intent.putExtra("confID", confID); |
| 235 | intent.putExtra("State", state); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 236 | |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 237 | |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 238 | Log.i(TAG, "Received:" + intent.getAction()); |
| 239 | Log.i(TAG, "State:" + state); |
| 240 | |
| 241 | Conference toModify = mService.getConferences().get(confID); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 242 | toModify.setCallState(confID, state); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 243 | |
| 244 | ArrayList<String> newParticipants = SwigNativeConverter.convertSwigToNative(mService.getCallManagerJNI().getParticipantList(intent.getStringExtra("confID"))); |
| 245 | |
| 246 | if (toModify.getParticipants().size() < newParticipants.size()) { |
| 247 | // We need to add the new participant to the conf |
| 248 | for (int i = 0; i < newParticipants.size(); ++i) { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 249 | if (toModify.getCallById(newParticipants.get(i)) == null) { |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 250 | mService.addCallToConference(toModify.getId(), newParticipants.get(i)); |
| 251 | } |
| 252 | } |
| 253 | } else if (toModify.getParticipants().size() > newParticipants.size()) { |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 254 | Log.i(TAG, "toModify.getParticipants().size() > newParticipants.size()"); |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 255 | for (SipCall participant : toModify.getParticipants()) { |
| 256 | if (!newParticipants.contains(participant.getCallId())) { |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 257 | mService.detachCallFromConference(toModify.getId(), participant); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 258 | break; |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 259 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 260 | } |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 261 | } |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 262 | |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 263 | mService.sendBroadcast(intent); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 264 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 265 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 266 | @Override |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 267 | public void on_record_playback_filepath(String id, String filename) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 268 | Intent intent = new Intent(RECORD_STATE_CHANGED); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 269 | intent.putExtra("callID", id); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 270 | intent.putExtra("file", filename); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame] | 271 | mService.sendBroadcast(intent); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 272 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 273 | |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 274 | @Override |
| 275 | public void on_secure_sdes_on(String callID) { |
| 276 | Log.i(TAG, "on_secure_sdes_on"); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void on_secure_sdes_off(String callID) { |
| 281 | Log.i(TAG, "on_secure_sdes_off"); |
| 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void on_secure_zrtp_on(String callID, String cipher) { |
| 286 | Log.i(TAG, "on_secure_zrtp_on"); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 287 | SipCall call = mService.getCallById(callID); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 288 | Bundle secureArgs = new Bundle(); |
| 289 | HashMap<String, String> details = SwigNativeConverter.convertAccountToNative(mService.getConfigurationManagerJNI().getAccountDetails(call.getAccount().getAccountID())); |
| 290 | secureArgs.putBoolean(SecureSipCall.DISPLAY_SAS, details.get(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS).contentEquals("true")); |
| 291 | secureArgs.putBoolean(SecureSipCall.DISPLAY_SAS_ONCE, details.get(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS_ONCE).contentEquals("true")); |
| 292 | secureArgs.putBoolean(SecureSipCall.DISPLAY_WARNING_ZRTP_NOT_SUPPORTED, details.get(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING).contentEquals("true")); |
| 293 | SecureSipCall replace = new SecureSipCall(call, secureArgs); |
| 294 | mService.replaceCall(replace); |
| 295 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 296 | Intent intent = new Intent(ZRTP_ON); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 297 | intent.putExtra("callID", replace.getCallId()); |
| 298 | intent.putExtra("conference", findConference(callID)); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 299 | mService.sendBroadcast(intent); |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void on_secure_zrtp_off(String callID) { |
| 304 | Log.i(TAG, "on_secure_zrtp_off"); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 305 | SipCall call = mService.getCallById(callID); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 306 | |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 307 | if (call != null && call instanceof SecureSipCall) { |
| 308 | SipCall replace = new SipCall(call.getBundle()); |
| 309 | mService.replaceCall(replace); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 310 | Intent intent = new Intent(ZRTP_OFF); |
| 311 | intent.putExtra("callID", callID); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 312 | intent.putExtra("conference", findConference(callID)); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 313 | mService.sendBroadcast(intent); |
| 314 | } |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 315 | |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public void on_show_sas(String callID, String sas, boolean verified) { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 320 | Log.i(TAG, "on_show_sas:" + sas); |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame^] | 321 | Log.i(TAG, "SAS Verified by zrtp layer:" + verified); |
| 322 | Log.i(TAG, "SAS Verified by zrtp layer:" + verified); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 323 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 324 | Intent intent = new Intent(DISPLAY_SAS); |
| 325 | intent.putExtra("callID", callID); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 326 | intent.putExtra("SAS", sas); |
| 327 | intent.putExtra("verified", verified); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 328 | SecureSipCall call = (SecureSipCall) mService.getCallById(callID); |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 329 | call.setSAS(sas); |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame^] | 330 | call.sasConfirmedByZrtpLayer(verified); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 331 | |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame^] | 332 | Log.i(TAG, "SAS needs to be displayed:" + call.getAccount().getSrtpDetails().getDetailBoolean(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS)); |
| 333 | if(call.getAccount().getSrtpDetails().getDetailBoolean(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS)) |
| 334 | call.setConfirmedSAS(false); |
| 335 | else |
| 336 | call.setConfirmedSAS(true); |
| 337 | |
| 338 | intent.putExtra("conference", findConference(callID)); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 339 | mService.sendBroadcast(intent); |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void on_zrtp_not_supported(String callID) { |
| 344 | Log.i(TAG, "on_zrtp_not_supported"); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 345 | Intent intent = new Intent(ZRTP_NOT_SUPPORTED); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 346 | intent.putExtra("callID", callID); |
| 347 | mService.sendBroadcast(intent); |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | @Override |
| 351 | public void on_zrtp_negociation_failed(String callID, String reason, String severity) { |
| 352 | Log.i(TAG, "on_zrtp_negociation_failed"); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 353 | Intent intent = new Intent(ZRTP_NEGOTIATION_FAILED); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 354 | intent.putExtra("callID", callID); |
| 355 | intent.putExtra("reason", reason); |
| 356 | intent.putExtra("severity", severity); |
| 357 | mService.sendBroadcast(intent); |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 358 | } |
| 359 | |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 360 | } |