Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 20 | import android.app.Service; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.Looper; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 27 | import android.os.Message; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 28 | import android.telephony.DisconnectCause; |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 29 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 30 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 31 | import com.android.internal.telecom.IConnectionService; |
| 32 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 33 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 34 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 35 | import java.util.ArrayList; |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 36 | import java.util.Collection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 37 | import java.util.Collections; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 38 | import java.util.HashMap; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 39 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 40 | import java.util.Map; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 41 | import java.util.UUID; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 44 | * A {@link android.app.Service} that provides telephone connections to processes running on an |
| 45 | * Android device. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 46 | */ |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 47 | public abstract class ConnectionService extends Service { |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 48 | /** |
| 49 | * The {@link Intent} that must be declared as handled by the service. |
| 50 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 51 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 52 | public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService"; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 53 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 54 | // Flag controlling whether PII is emitted into the logs |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 55 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 56 | |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 57 | private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 58 | private static final int MSG_CREATE_CONNECTION = 2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 59 | private static final int MSG_ABORT = 3; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 60 | private static final int MSG_ANSWER = 4; |
| 61 | private static final int MSG_REJECT = 5; |
| 62 | private static final int MSG_DISCONNECT = 6; |
| 63 | private static final int MSG_HOLD = 7; |
| 64 | private static final int MSG_UNHOLD = 8; |
| 65 | private static final int MSG_ON_AUDIO_STATE_CHANGED = 9; |
| 66 | private static final int MSG_PLAY_DTMF_TONE = 10; |
| 67 | private static final int MSG_STOP_DTMF_TONE = 11; |
| 68 | private static final int MSG_CONFERENCE = 12; |
| 69 | private static final int MSG_SPLIT_FROM_CONFERENCE = 13; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 70 | private static final int MSG_ON_POST_DIAL_CONTINUE = 14; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 71 | private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 72 | private static final int MSG_ANSWER_VIDEO = 17; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 73 | private static final int MSG_MERGE_CONFERENCE = 18; |
| 74 | private static final int MSG_SWAP_CONFERENCE = 19; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 75 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 76 | private static Connection sNullConnection; |
| 77 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 78 | private final Map<String, Connection> mConnectionById = new HashMap<>(); |
| 79 | private final Map<Connection, String> mIdByConnection = new HashMap<>(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 80 | private final Map<String, Conference> mConferenceById = new HashMap<>(); |
| 81 | private final Map<Conference, String> mIdByConference = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 82 | private final RemoteConnectionManager mRemoteConnectionManager = |
| 83 | new RemoteConnectionManager(this); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 84 | private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 85 | private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 86 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 87 | private boolean mAreAccountsInitialized = false; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 88 | private Conference sNullConference; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 89 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 90 | private final IBinder mBinder = new IConnectionService.Stub() { |
| 91 | @Override |
| 92 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 93 | mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
| 94 | } |
| 95 | |
| 96 | public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 97 | mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 101 | public void createConnection( |
| 102 | PhoneAccountHandle connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 103 | String id, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 104 | ConnectionRequest request, |
| 105 | boolean isIncoming) { |
| 106 | SomeArgs args = SomeArgs.obtain(); |
| 107 | args.arg1 = connectionManagerPhoneAccount; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 108 | args.arg2 = id; |
| 109 | args.arg3 = request; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 110 | args.argi1 = isIncoming ? 1 : 0; |
| 111 | mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void abort(String callId) { |
| 116 | mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget(); |
| 117 | } |
| 118 | |
| 119 | @Override |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 120 | /** @hide */ |
| 121 | public void answerVideo(String callId, int videoState) { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 122 | SomeArgs args = SomeArgs.obtain(); |
| 123 | args.arg1 = callId; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 124 | args.argi1 = videoState; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 125 | mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget(); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void answer(String callId) { |
| 130 | mHandler.obtainMessage(MSG_ANSWER, callId).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void reject(String callId) { |
| 135 | mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget(); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void disconnect(String callId) { |
| 140 | mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget(); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public void hold(String callId) { |
| 145 | mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget(); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void unhold(String callId) { |
| 150 | mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget(); |
| 151 | } |
| 152 | |
| 153 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 154 | public void onAudioStateChanged(String callId, AudioState audioState) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 155 | SomeArgs args = SomeArgs.obtain(); |
| 156 | args.arg1 = callId; |
| 157 | args.arg2 = audioState; |
| 158 | mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget(); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void playDtmfTone(String callId, char digit) { |
| 163 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget(); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void stopDtmfTone(String callId) { |
| 168 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget(); |
| 169 | } |
| 170 | |
| 171 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 172 | public void conference(String callId1, String callId2) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 173 | SomeArgs args = SomeArgs.obtain(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 174 | args.arg1 = callId1; |
| 175 | args.arg2 = callId2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 176 | mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget(); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public void splitFromConference(String callId) { |
| 181 | mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget(); |
| 182 | } |
| 183 | |
| 184 | @Override |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 185 | public void mergeConference(String callId) { |
| 186 | mHandler.obtainMessage(MSG_MERGE_CONFERENCE, callId).sendToTarget(); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void swapConference(String callId) { |
| 191 | mHandler.obtainMessage(MSG_SWAP_CONFERENCE, callId).sendToTarget(); |
| 192 | } |
| 193 | |
| 194 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 195 | public void onPostDialContinue(String callId, boolean proceed) { |
| 196 | SomeArgs args = SomeArgs.obtain(); |
| 197 | args.arg1 = callId; |
| 198 | args.argi1 = proceed ? 1 : 0; |
| 199 | mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget(); |
| 200 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 204 | @Override |
| 205 | public void handleMessage(Message msg) { |
| 206 | switch (msg.what) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 207 | case MSG_ADD_CONNECTION_SERVICE_ADAPTER: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 208 | mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj); |
| 209 | onAdapterAttached(); |
| 210 | break; |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 211 | case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: |
| 212 | mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj); |
| 213 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 214 | case MSG_CREATE_CONNECTION: { |
| 215 | SomeArgs args = (SomeArgs) msg.obj; |
| 216 | try { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 217 | final PhoneAccountHandle connectionManagerPhoneAccount = |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 218 | (PhoneAccountHandle) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 219 | final String id = (String) args.arg2; |
| 220 | final ConnectionRequest request = (ConnectionRequest) args.arg3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 221 | final boolean isIncoming = args.argi1 == 1; |
| 222 | if (!mAreAccountsInitialized) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 223 | Log.d(this, "Enqueueing pre-init request %s", id); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 224 | mPreInitializationConnectionRequests.add(new Runnable() { |
| 225 | @Override |
| 226 | public void run() { |
| 227 | createConnection( |
| 228 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 229 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 230 | request, |
| 231 | isIncoming); |
| 232 | } |
| 233 | }); |
| 234 | } else { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 235 | createConnection( |
| 236 | connectionManagerPhoneAccount, |
| 237 | id, |
| 238 | request, |
| 239 | isIncoming); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 240 | } |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 241 | } finally { |
| 242 | args.recycle(); |
| 243 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 244 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 245 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 246 | case MSG_ABORT: |
| 247 | abort((String) msg.obj); |
| 248 | break; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 249 | case MSG_ANSWER: |
| 250 | answer((String) msg.obj); |
| 251 | break; |
| 252 | case MSG_ANSWER_VIDEO: { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 253 | SomeArgs args = (SomeArgs) msg.obj; |
| 254 | try { |
| 255 | String callId = (String) args.arg1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 256 | int videoState = args.argi1; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 257 | answerVideo(callId, videoState); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 258 | } finally { |
| 259 | args.recycle(); |
| 260 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 261 | break; |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 262 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 263 | case MSG_REJECT: |
| 264 | reject((String) msg.obj); |
| 265 | break; |
| 266 | case MSG_DISCONNECT: |
| 267 | disconnect((String) msg.obj); |
| 268 | break; |
| 269 | case MSG_HOLD: |
| 270 | hold((String) msg.obj); |
| 271 | break; |
| 272 | case MSG_UNHOLD: |
| 273 | unhold((String) msg.obj); |
| 274 | break; |
| 275 | case MSG_ON_AUDIO_STATE_CHANGED: { |
| 276 | SomeArgs args = (SomeArgs) msg.obj; |
| 277 | try { |
| 278 | String callId = (String) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 279 | AudioState audioState = (AudioState) args.arg2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 280 | onAudioStateChanged(callId, audioState); |
| 281 | } finally { |
| 282 | args.recycle(); |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | case MSG_PLAY_DTMF_TONE: |
| 287 | playDtmfTone((String) msg.obj, (char) msg.arg1); |
| 288 | break; |
| 289 | case MSG_STOP_DTMF_TONE: |
| 290 | stopDtmfTone((String) msg.obj); |
| 291 | break; |
| 292 | case MSG_CONFERENCE: { |
| 293 | SomeArgs args = (SomeArgs) msg.obj; |
| 294 | try { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 295 | String callId1 = (String) args.arg1; |
| 296 | String callId2 = (String) args.arg2; |
| 297 | conference(callId1, callId2); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 298 | } finally { |
| 299 | args.recycle(); |
| 300 | } |
| 301 | break; |
| 302 | } |
| 303 | case MSG_SPLIT_FROM_CONFERENCE: |
| 304 | splitFromConference((String) msg.obj); |
| 305 | break; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 306 | case MSG_MERGE_CONFERENCE: |
| 307 | mergeConference((String) msg.obj); |
| 308 | break; |
| 309 | case MSG_SWAP_CONFERENCE: |
| 310 | swapConference((String) msg.obj); |
| 311 | break; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 312 | case MSG_ON_POST_DIAL_CONTINUE: { |
| 313 | SomeArgs args = (SomeArgs) msg.obj; |
| 314 | try { |
| 315 | String callId = (String) args.arg1; |
| 316 | boolean proceed = (args.argi1 == 1); |
| 317 | onPostDialContinue(callId, proceed); |
| 318 | } finally { |
| 319 | args.recycle(); |
| 320 | } |
| 321 | break; |
| 322 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 323 | default: |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | }; |
| 328 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 329 | private final Conference.Listener mConferenceListener = new Conference.Listener() { |
| 330 | @Override |
| 331 | public void onStateChanged(Conference conference, int oldState, int newState) { |
| 332 | String id = mIdByConference.get(conference); |
| 333 | switch (newState) { |
| 334 | case Connection.STATE_ACTIVE: |
| 335 | mAdapter.setActive(id); |
| 336 | break; |
| 337 | case Connection.STATE_HOLDING: |
| 338 | mAdapter.setOnHold(id); |
| 339 | break; |
| 340 | case Connection.STATE_DISCONNECTED: |
| 341 | // handled by onDisconnected |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public void onDisconnected(Conference conference, int cause, String message) { |
| 348 | String id = mIdByConference.get(conference); |
| 349 | mAdapter.setDisconnected(id, cause, message); |
| 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public void onConnectionAdded(Conference conference, Connection connection) { |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public void onConnectionRemoved(Conference conference, Connection connection) { |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void onDestroyed(Conference conference) { |
| 362 | removeConference(conference); |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void onCapabilitiesChanged(Conference conference, int capabilities) { |
| 367 | String id = mIdByConference.get(conference); |
| 368 | Log.d(this, "call capabilities: conference: %s", |
| 369 | PhoneCapabilities.toString(capabilities)); |
| 370 | mAdapter.setCallCapabilities(id, capabilities); |
| 371 | } |
| 372 | }; |
| 373 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 374 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 375 | @Override |
| 376 | public void onStateChanged(Connection c, int state) { |
| 377 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 378 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 379 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 380 | case Connection.STATE_ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 381 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 382 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 383 | case Connection.STATE_DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 384 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 385 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 386 | case Connection.STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 387 | // Handled in onDisconnected() |
| 388 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 389 | case Connection.STATE_HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 390 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 391 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 392 | case Connection.STATE_NEW: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 393 | // Nothing to tell Telecom |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 394 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 395 | case Connection.STATE_RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 396 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public void onDisconnected(Connection c, int cause, String message) { |
| 403 | String id = mIdByConnection.get(c); |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 404 | Log.d(this, "Adapter set disconnected %d %s", cause, message); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 405 | mAdapter.setDisconnected(id, cause, message); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 409 | public void onVideoStateChanged(Connection c, int videoState) { |
| 410 | String id = mIdByConnection.get(c); |
| 411 | Log.d(this, "Adapter set video state %d", videoState); |
| 412 | mAdapter.setVideoState(id, videoState); |
| 413 | } |
| 414 | |
| 415 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 416 | public void onAddressChanged(Connection c, Uri address, int presentation) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 417 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 418 | mAdapter.setAddress(id, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public void onCallerDisplayNameChanged( |
| 423 | Connection c, String callerDisplayName, int presentation) { |
| 424 | String id = mIdByConnection.get(c); |
| 425 | mAdapter.setCallerDisplayName(id, callerDisplayName, presentation); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 429 | public void onDestroyed(Connection c) { |
| 430 | removeConnection(c); |
| 431 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 432 | |
| 433 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 434 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 435 | String id = mIdByConnection.get(c); |
| 436 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 437 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 441 | public void onRingbackRequested(Connection c, boolean ringback) { |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 442 | String id = mIdByConnection.get(c); |
| 443 | Log.d(this, "Adapter onRingback %b", ringback); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 444 | mAdapter.setRingbackRequested(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 445 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 446 | |
| 447 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 448 | public void onCallCapabilitiesChanged(Connection c, int capabilities) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 449 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 450 | Log.d(this, "capabilities: parcelableconnection: %s", |
| 451 | PhoneCapabilities.toString(capabilities)); |
| 452 | mAdapter.setCallCapabilities(id, capabilities); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 455 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 456 | public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) { |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 457 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 458 | mAdapter.setVideoProvider(id, videoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 459 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 460 | |
| 461 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 462 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) { |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 463 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 464 | mAdapter.setIsVoipAudioMode(id, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 465 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 466 | |
| 467 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 468 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 469 | String id = mIdByConnection.get(c); |
| 470 | mAdapter.setStatusHints(id, statusHints); |
| 471 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 472 | |
| 473 | @Override |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 474 | public void onConferenceableConnectionsChanged( |
| 475 | Connection connection, List<Connection> conferenceableConnections) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 476 | mAdapter.setConferenceableConnections( |
| 477 | mIdByConnection.get(connection), |
| 478 | createConnectionIdList(conferenceableConnections)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 479 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 480 | |
| 481 | @Override |
| 482 | public void onConferenceChanged(Connection connection, Conference conference) { |
| 483 | String id = mIdByConnection.get(connection); |
| 484 | if (id != null) { |
| 485 | String conferenceId = null; |
| 486 | if (conference != null) { |
| 487 | conferenceId = mIdByConference.get(conference); |
| 488 | } |
| 489 | mAdapter.setIsConferenced(id, conferenceId); |
| 490 | } |
| 491 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 492 | }; |
| 493 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 494 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 495 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 496 | public final IBinder onBind(Intent intent) { |
| 497 | return mBinder; |
| 498 | } |
| 499 | |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 500 | /** {@inheritDoc} */ |
| 501 | @Override |
| 502 | public boolean onUnbind(Intent intent) { |
| 503 | endAllConnections(); |
| 504 | return super.onUnbind(intent); |
| 505 | } |
| 506 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 507 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 508 | * This can be used by telecom to either create a new outgoing call or attach to an existing |
| 509 | * incoming call. In either case, telecom will cycle through a set of services and call |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 510 | * createConnection util a connection service cancels the process or completes it successfully. |
| 511 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 512 | private void createConnection( |
| 513 | final PhoneAccountHandle callManagerAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 514 | final String callId, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 515 | final ConnectionRequest request, |
| 516 | boolean isIncoming) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 517 | Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " + |
| 518 | "isIncoming: %b", callManagerAccount, callId, request, isIncoming); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 519 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 520 | Connection connection = isIncoming |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 521 | ? onCreateIncomingConnection(callManagerAccount, request) |
| 522 | : onCreateOutgoingConnection(callManagerAccount, request); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 523 | Log.d(this, "createConnection, connection: %s", connection); |
| 524 | if (connection == null) { |
| 525 | connection = Connection.createFailedConnection(DisconnectCause.OUTGOING_FAILURE, null); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 526 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 527 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 528 | if (connection.getState() != Connection.STATE_DISCONNECTED) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 529 | addConnection(callId, connection); |
| 530 | } |
| 531 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 532 | Uri address = connection.getAddress(); |
| 533 | String number = address == null ? "null" : address.getSchemeSpecificPart(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 534 | Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s", |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 535 | Connection.toLogSafePhoneNumber(number), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 536 | Connection.stateToString(connection.getState()), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 537 | PhoneCapabilities.toString(connection.getCallCapabilities())); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 538 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 539 | Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 540 | mAdapter.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 541 | callId, |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 542 | request, |
| 543 | new ParcelableConnection( |
| 544 | request.getAccountHandle(), |
| 545 | connection.getState(), |
| 546 | connection.getCallCapabilities(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 547 | connection.getAddress(), |
| 548 | connection.getAddressPresentation(), |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 549 | connection.getCallerDisplayName(), |
| 550 | connection.getCallerDisplayNamePresentation(), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 551 | connection.getVideoProvider() == null ? |
| 552 | null : connection.getVideoProvider().getInterface(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 553 | connection.getVideoState(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 554 | connection.isRingbackRequested(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 555 | connection.getAudioModeIsVoip(), |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 556 | connection.getStatusHints(), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 557 | connection.getDisconnectCause(), |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 558 | connection.getDisconnectMessage(), |
| 559 | createConnectionIdList(connection.getConferenceableConnections()))); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 562 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 563 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 564 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 567 | private void answerVideo(String callId, int videoState) { |
| 568 | Log.d(this, "answerVideo %s", callId); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 569 | findConnectionForAction(callId, "answer").onAnswer(videoState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 572 | private void answer(String callId) { |
| 573 | Log.d(this, "answer %s", callId); |
| 574 | findConnectionForAction(callId, "answer").onAnswer(); |
| 575 | } |
| 576 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 577 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 578 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 579 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 582 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 583 | Log.d(this, "disconnect %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 584 | if (mConnectionById.containsKey(callId)) { |
| 585 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
| 586 | } else { |
| 587 | findConferenceForAction(callId, "disconnect").onDisconnect(); |
| 588 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 591 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 592 | Log.d(this, "hold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 593 | if (mConnectionById.containsKey(callId)) { |
| 594 | findConnectionForAction(callId, "hold").onHold(); |
| 595 | } else { |
| 596 | findConferenceForAction(callId, "hold").onHold(); |
| 597 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 600 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 601 | Log.d(this, "unhold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 602 | if (mConnectionById.containsKey(callId)) { |
| 603 | findConnectionForAction(callId, "unhold").onUnhold(); |
| 604 | } else { |
| 605 | findConferenceForAction(callId, "unhold").onUnhold(); |
| 606 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 609 | private void onAudioStateChanged(String callId, AudioState audioState) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 610 | Log.d(this, "onAudioStateChanged %s %s", callId, audioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame^] | 611 | if (mConnectionById.containsKey(callId)) { |
| 612 | findConnectionForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 613 | } else { |
| 614 | findConferenceForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 615 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 618 | private void playDtmfTone(String callId, char digit) { |
| 619 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame^] | 620 | if (mConnectionById.containsKey(callId)) { |
| 621 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 622 | } else { |
| 623 | findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 624 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | private void stopDtmfTone(String callId) { |
| 628 | Log.d(this, "stopDtmfTone %s", callId); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame^] | 629 | if (mConnectionById.containsKey(callId)) { |
| 630 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 631 | } else { |
| 632 | findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 633 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 636 | private void conference(String callId1, String callId2) { |
| 637 | Log.d(this, "conference %s, %s", callId1, callId2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 638 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 639 | Connection connection1 = findConnectionForAction(callId1, "conference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 640 | if (connection1 == getNullConnection()) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 641 | Log.w(this, "Connection1 missing in conference request %s.", callId1); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 642 | return; |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 645 | Connection connection2 = findConnectionForAction(callId2, "conference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 646 | if (connection2 == getNullConnection()) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 647 | Log.w(this, "Connection2 missing in conference request %s.", callId2); |
| 648 | return; |
| 649 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 650 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 651 | onConference(connection1, connection2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 654 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 655 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 656 | |
| 657 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 658 | if (connection == getNullConnection()) { |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 659 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 660 | return; |
| 661 | } |
| 662 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 663 | Conference conference = connection.getConference(); |
| 664 | if (conference != null) { |
| 665 | conference.onSeparate(connection); |
| 666 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 669 | private void mergeConference(String callId) { |
| 670 | Log.d(this, "mergeConference(%s)", callId); |
| 671 | Conference conference = findConferenceForAction(callId, "mergeConference"); |
| 672 | if (conference != null) { |
| 673 | conference.onMerge(); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | private void swapConference(String callId) { |
| 678 | Log.d(this, "swapConference(%s)", callId); |
| 679 | Conference conference = findConferenceForAction(callId, "swapConference"); |
| 680 | if (conference != null) { |
| 681 | conference.onSwap(); |
| 682 | } |
| 683 | } |
| 684 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 685 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 686 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 687 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 690 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 691 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 692 | // No need to query again if we already did it. |
| 693 | return; |
| 694 | } |
| 695 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 696 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 697 | @Override |
| 698 | public void onResult( |
| 699 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 700 | final List<IBinder> services) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 701 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 702 | @Override |
| 703 | public void run() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 704 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 705 | mRemoteConnectionManager.addConnectionService( |
| 706 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 707 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 708 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 709 | onAccountsInitialized(); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 710 | Log.d(this, "remote connection services found: " + services); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 711 | } |
| 712 | }); |
| 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public void onError() { |
| 717 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 718 | @Override |
| 719 | public void run() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 720 | mAreAccountsInitialized = true; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 721 | } |
| 722 | }); |
| 723 | } |
| 724 | }); |
| 725 | } |
| 726 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 727 | /** |
| 728 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 729 | * incoming request. This is used to attach to existing incoming calls. |
| 730 | * |
| 731 | * @param connectionManagerPhoneAccount See description at |
| 732 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 733 | * @param request Details about the incoming call. |
| 734 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 735 | * not handle the call. |
| 736 | */ |
| 737 | public final RemoteConnection createRemoteIncomingConnection( |
| 738 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 739 | ConnectionRequest request) { |
| 740 | return mRemoteConnectionManager.createRemoteConnection( |
| 741 | connectionManagerPhoneAccount, request, true); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 745 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 746 | * outgoing request. This is used to initiate new outgoing calls. |
| 747 | * |
| 748 | * @param connectionManagerPhoneAccount See description at |
| 749 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 750 | * @param request Details about the incoming call. |
| 751 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 752 | * not handle the call. |
| 753 | */ |
| 754 | public final RemoteConnection createRemoteOutgoingConnection( |
| 755 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 756 | ConnectionRequest request) { |
| 757 | return mRemoteConnectionManager.createRemoteConnection( |
| 758 | connectionManagerPhoneAccount, request, false); |
| 759 | } |
| 760 | |
| 761 | /** |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 762 | * Adds two {@code RemoteConnection}s to some {@code RemoteConference}. |
| 763 | */ |
| 764 | public final void conferenceRemoteConnections( |
| 765 | RemoteConnection a, |
| 766 | RemoteConnection b) { |
| 767 | mRemoteConnectionManager.conferenceRemoteConnections(a, b); |
| 768 | } |
| 769 | |
| 770 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 771 | * Adds a new conference call. When a conference call is created either as a result of an |
| 772 | * explicit request via {@link #onConference} or otherwise, the connection service should supply |
| 773 | * an instance of {@link Conference} by invoking this method. A conference call provided by this |
| 774 | * method will persist until {@link Conference#destroy} is invoked on the conference instance. |
| 775 | * |
| 776 | * @param conference The new conference object. |
| 777 | */ |
| 778 | public final void addConference(Conference conference) { |
| 779 | String id = addConferenceInternal(conference); |
| 780 | if (id != null) { |
| 781 | List<String> connectionIds = new ArrayList<>(2); |
| 782 | for (Connection connection : conference.getConnections()) { |
| 783 | if (mIdByConnection.containsKey(connection)) { |
| 784 | connectionIds.add(mIdByConnection.get(connection)); |
| 785 | } |
| 786 | } |
| 787 | ParcelableConference parcelableConference = new ParcelableConference( |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 788 | conference.getPhoneAccountHandle(), |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 789 | conference.getState(), |
| 790 | conference.getCapabilities(), |
| 791 | connectionIds); |
| 792 | mAdapter.addConferenceCall(id, parcelableConference); |
| 793 | |
| 794 | // Go through any child calls and set the parent. |
| 795 | for (Connection connection : conference.getConnections()) { |
| 796 | String connectionId = mIdByConnection.get(connection); |
| 797 | if (connectionId != null) { |
| 798 | mAdapter.setIsConferenced(connectionId, id); |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 805 | * Returns all the active {@code Connection}s for which this {@code ConnectionService} |
| 806 | * has taken responsibility. |
| 807 | * |
| 808 | * @return A collection of {@code Connection}s created by this {@code ConnectionService}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 809 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 810 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 811 | return mConnectionById.values(); |
| 812 | } |
| 813 | |
| 814 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 815 | * Create a {@code Connection} given an incoming request. This is used to attach to existing |
| 816 | * incoming calls. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 817 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 818 | * @param connectionManagerPhoneAccount See description at |
| 819 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 820 | * @param request Details about the incoming call. |
| 821 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 822 | * not handle the call. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 823 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 824 | public Connection onCreateIncomingConnection( |
| 825 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 826 | ConnectionRequest request) { |
| 827 | return null; |
| 828 | } |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 829 | |
| 830 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 831 | * Create a {@code Connection} given an outgoing request. This is used to initiate new |
| 832 | * outgoing calls. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 833 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 834 | * @param connectionManagerPhoneAccount The connection manager account to use for managing |
| 835 | * this call. |
| 836 | * <p> |
| 837 | * If this parameter is not {@code null}, it means that this {@code ConnectionService} |
| 838 | * has registered one or more {@code PhoneAccount}s having |
| 839 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain |
| 840 | * one of these {@code PhoneAccount}s, while the {@code request} will contain another |
| 841 | * (usually but not always distinct) {@code PhoneAccount} to be used for actually |
| 842 | * making the connection. |
| 843 | * <p> |
| 844 | * If this parameter is {@code null}, it means that this {@code ConnectionService} is |
| 845 | * being asked to make a direct connection. The |
| 846 | * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be |
| 847 | * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for |
| 848 | * making the connection. |
| 849 | * @param request Details about the outgoing call. |
| 850 | * @return The {@code Connection} object to satisfy this call, or the result of an invocation |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 851 | * of {@link Connection#createFailedConnection(int, String)} to not handle the call. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 852 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 853 | public Connection onCreateOutgoingConnection( |
| 854 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 855 | ConnectionRequest request) { |
| 856 | return null; |
| 857 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 858 | |
| 859 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 860 | * Conference two specified connections. Invoked when the user has made a request to merge the |
| 861 | * specified connections into a conference call. In response, the connection service should |
| 862 | * create an instance of {@link Conference} and pass it into {@link #addConference}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 863 | * |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 864 | * @param connection1 A connection to merge into a conference call. |
| 865 | * @param connection2 A connection to merge into a conference call. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 866 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 867 | public void onConference(Connection connection1, Connection connection2) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 868 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 869 | public void onRemoteConferenceAdded(RemoteConference conference) {} |
| 870 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 871 | /** |
| 872 | * @hide |
| 873 | */ |
| 874 | public boolean containsConference(Conference conference) { |
| 875 | return mIdByConference.containsKey(conference); |
| 876 | } |
| 877 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 878 | /** {@hide} */ |
| 879 | void addRemoteConference(RemoteConference remoteConference) { |
| 880 | onRemoteConferenceAdded(remoteConference); |
| 881 | } |
| 882 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 883 | private void onAccountsInitialized() { |
| 884 | mAreAccountsInitialized = true; |
| 885 | for (Runnable r : mPreInitializationConnectionRequests) { |
| 886 | r.run(); |
| 887 | } |
| 888 | mPreInitializationConnectionRequests.clear(); |
| 889 | } |
| 890 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 891 | private void addConnection(String callId, Connection connection) { |
| 892 | mConnectionById.put(callId, connection); |
| 893 | mIdByConnection.put(connection, callId); |
| 894 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 895 | connection.setConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | private void removeConnection(Connection connection) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 899 | String id = mIdByConnection.get(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 900 | connection.unsetConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 901 | connection.removeConnectionListener(mConnectionListener); |
| 902 | mConnectionById.remove(mIdByConnection.get(connection)); |
| 903 | mIdByConnection.remove(connection); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 904 | mAdapter.removeCall(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 907 | private String addConferenceInternal(Conference conference) { |
| 908 | if (mIdByConference.containsKey(conference)) { |
| 909 | Log.w(this, "Re-adding an existing conference: %s.", conference); |
| 910 | } else if (conference != null) { |
| 911 | String id = UUID.randomUUID().toString(); |
| 912 | mConferenceById.put(id, conference); |
| 913 | mIdByConference.put(conference, id); |
| 914 | conference.addListener(mConferenceListener); |
| 915 | return id; |
| 916 | } |
| 917 | |
| 918 | return null; |
| 919 | } |
| 920 | |
| 921 | private void removeConference(Conference conference) { |
| 922 | if (mIdByConference.containsKey(conference)) { |
| 923 | conference.removeListener(mConferenceListener); |
| 924 | |
| 925 | String id = mIdByConference.get(conference); |
| 926 | mConferenceById.remove(id); |
| 927 | mIdByConference.remove(conference); |
| 928 | mAdapter.removeCall(id); |
| 929 | } |
| 930 | } |
| 931 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 932 | private Connection findConnectionForAction(String callId, String action) { |
| 933 | if (mConnectionById.containsKey(callId)) { |
| 934 | return mConnectionById.get(callId); |
| 935 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 936 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 937 | return getNullConnection(); |
| 938 | } |
| 939 | |
| 940 | static synchronized Connection getNullConnection() { |
| 941 | if (sNullConnection == null) { |
| 942 | sNullConnection = new Connection() {}; |
| 943 | } |
| 944 | return sNullConnection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 945 | } |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 946 | |
| 947 | private Conference findConferenceForAction(String conferenceId, String action) { |
| 948 | if (mConferenceById.containsKey(conferenceId)) { |
| 949 | return mConferenceById.get(conferenceId); |
| 950 | } |
| 951 | Log.w(this, "%s - Cannot find conference %s", action, conferenceId); |
| 952 | return getNullConference(); |
| 953 | } |
| 954 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 955 | private List<String> createConnectionIdList(List<Connection> connections) { |
| 956 | List<String> ids = new ArrayList<>(); |
| 957 | for (Connection c : connections) { |
| 958 | if (mIdByConnection.containsKey(c)) { |
| 959 | ids.add(mIdByConnection.get(c)); |
| 960 | } |
| 961 | } |
| 962 | Collections.sort(ids); |
| 963 | return ids; |
| 964 | } |
| 965 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 966 | private Conference getNullConference() { |
| 967 | if (sNullConference == null) { |
| 968 | sNullConference = new Conference(null) {}; |
| 969 | } |
| 970 | return sNullConference; |
| 971 | } |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 972 | |
| 973 | private void endAllConnections() { |
| 974 | // Unbound from telecomm. We should end all connections and conferences. |
| 975 | for (Connection connection : mIdByConnection.keySet()) { |
| 976 | // only operate on top-level calls. Conference calls will be removed on their own. |
| 977 | if (connection.getConference() == null) { |
| 978 | connection.onDisconnect(); |
| 979 | } |
| 980 | } |
| 981 | for (Conference conference : mIdByConference.keySet()) { |
| 982 | conference.onDisconnect(); |
| 983 | } |
| 984 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 985 | } |