Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 19 | import android.os.Handler; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 20 | import android.os.Message; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 21 | import android.telecomm.CallInfo; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 22 | |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 23 | import com.android.internal.telecomm.ICallServiceAdapter; |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 24 | import com.google.android.collect.Sets; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 25 | import com.google.common.base.Strings; |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableList; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 27 | import com.android.internal.os.SomeArgs; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 28 | |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 29 | import java.util.Set; |
| 30 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 31 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 32 | * Used by call services to communicate with Telecomm. Each call service is given its own instance |
| 33 | * of the adapter for the lifetmie of the binding. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 34 | * TODO(santoscordon): Do we need Binder.clear/restoreCallingIdentity() in the service methods? |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 35 | */ |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 36 | public final class CallServiceAdapter extends ICallServiceAdapter.Stub { |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 37 | private static final int MSG_SET_IS_COMPATIBLE_WITH = 0; |
| 38 | private static final int MSG_NOTIFY_INCOMING_CALL = 1; |
| 39 | private static final int MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL = 2; |
| 40 | private static final int MSG_HANDLE_FAILED_OUTGOING_CALL = 3; |
| 41 | private static final int MSG_SET_ACTIVE = 4; |
| 42 | private static final int MSG_SET_RINGING = 5; |
| 43 | private static final int MSG_SET_DIALING = 6; |
| 44 | private static final int MSG_SET_DISCONNECTED = 7; |
| 45 | private static final int MSG_SET_ON_HOLD = 8; |
| 46 | |
| 47 | private final class CallServiceAdapterHandler extends Handler { |
| 48 | @Override |
| 49 | public void handleMessage(Message msg) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 50 | Call call; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 51 | switch (msg.what) { |
| 52 | case MSG_SET_IS_COMPATIBLE_WITH: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 53 | call = mCallIdMapper.getCall(msg.obj); |
| 54 | if (call != null && !call.isIncoming()) { |
| 55 | mOutgoingCallsManager.setIsCompatibleWith(call, |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 56 | msg.arg1 == 1 ? true : false); |
| 57 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 58 | Log.w(this, "Unknown call: %s, id: %s", call, msg.obj); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 59 | } |
| 60 | break; |
| 61 | case MSG_NOTIFY_INCOMING_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 62 | CallInfo clientCallInfo = (CallInfo) msg.obj; |
| 63 | call = mCallIdMapper.getCall(clientCallInfo.getId()); |
| 64 | if (call != null && mPendingCalls.remove(call) && call.isIncoming()) { |
| 65 | CallInfo callInfo = new CallInfo(null, clientCallInfo.getState(), |
| 66 | clientCallInfo.getHandle()); |
| 67 | mIncomingCallsManager.handleSuccessfulIncomingCall(call, callInfo); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 68 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 69 | Log.w(this, "Unknown incoming call: %s, id: %s", call, msg.obj); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 70 | } |
| 71 | break; |
| 72 | case MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 73 | call = mCallIdMapper.getCall(msg.obj); |
| 74 | if (call != null && mPendingCalls.remove(call) && !call.isIncoming()) { |
| 75 | mOutgoingCallsManager.handleSuccessfulCallAttempt(call); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 76 | } else { |
| 77 | // TODO(gilad): Figure out how to wire up the callService.abort() call. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 78 | Log.w(this, "Unknown outgoing call: %s, id: %s", call, msg.obj); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 79 | } |
| 80 | break; |
| 81 | case MSG_HANDLE_FAILED_OUTGOING_CALL: { |
| 82 | SomeArgs args = (SomeArgs) msg.obj; |
| 83 | try { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 84 | call = mCallIdMapper.getCall(args.arg1); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 85 | String reason = (String) args.arg2; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 86 | if (call != null && mPendingCalls.remove(call) && !call.isIncoming()) { |
| 87 | mOutgoingCallsManager.handleFailedCallAttempt(call, reason); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 88 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 89 | Log.w(this, "Unknown outgoing call: %s, id: %s", call, msg.obj); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 90 | } |
| 91 | } finally { |
| 92 | args.recycle(); |
| 93 | } |
| 94 | break; |
| 95 | } |
| 96 | case MSG_SET_ACTIVE: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 97 | call = mCallIdMapper.getCall(msg.obj); |
| 98 | if (call != null) { |
| 99 | mCallsManager.markCallAsActive(call); |
| 100 | } else { |
| 101 | Log.w(this, "Unknown call id: %s", msg.obj); |
| 102 | } |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 103 | break; |
| 104 | case MSG_SET_RINGING: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 105 | call = mCallIdMapper.getCall(msg.obj); |
| 106 | if (call != null) { |
| 107 | mCallsManager.markCallAsRinging(call); |
| 108 | } else { |
| 109 | Log.w(this, "Unknown call id: %s", msg.obj); |
| 110 | } |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 111 | break; |
| 112 | case MSG_SET_DIALING: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 113 | call = mCallIdMapper.getCall(msg.obj); |
| 114 | if (call != null) { |
| 115 | mCallsManager.markCallAsDialing(call); |
| 116 | } else { |
| 117 | Log.w(this, "Unknown call id: %s", msg.obj); |
| 118 | } |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 119 | break; |
| 120 | case MSG_SET_DISCONNECTED: { |
| 121 | SomeArgs args = (SomeArgs) msg.obj; |
| 122 | try { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 123 | call = mCallIdMapper.getCall(args.arg1); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 124 | String disconnectMessage = (String) args.arg2; |
| 125 | int disconnectCause = args.argi1; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 126 | if (call != null) { |
| 127 | mCallsManager.markCallAsDisconnected(call, disconnectCause, |
| 128 | disconnectMessage); |
| 129 | } else { |
| 130 | Log.w(this, "Unknown call id: %s", msg.obj); |
| 131 | } |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 132 | } finally { |
| 133 | args.recycle(); |
| 134 | } |
| 135 | break; |
| 136 | } |
| 137 | case MSG_SET_ON_HOLD: |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 138 | call = mCallIdMapper.getCall(msg.obj); |
| 139 | if (call != null) { |
| 140 | mCallsManager.markCallAsOnHold(call); |
| 141 | } else { |
| 142 | Log.w(this, "Unknown call id: %s", msg.obj); |
| 143 | } |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 144 | break; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 149 | private final CallsManager mCallsManager; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 150 | private final OutgoingCallsManager mOutgoingCallsManager; |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 151 | private final IncomingCallsManager mIncomingCallsManager; |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 152 | private final Handler mHandler = new CallServiceAdapterHandler(); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 153 | private final CallIdMapper mCallIdMapper; |
| 154 | private final Set<Call> mPendingCalls = Sets.newHashSet(); |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 155 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 156 | /** |
| 157 | * Persists the specified parameters. |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 158 | * |
| 159 | * @param outgoingCallsManager Manages the placing of outgoing calls. |
| 160 | * @param incomingCallsManager Manages the incoming call initialization flow. |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 161 | */ |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 162 | CallServiceAdapter( |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 163 | OutgoingCallsManager outgoingCallsManager, |
| 164 | IncomingCallsManager incomingCallsManager, |
| 165 | CallIdMapper callIdMapper) { |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 166 | ThreadUtil.checkOnMainThread(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 167 | mCallsManager = CallsManager.getInstance(); |
| 168 | mOutgoingCallsManager = outgoingCallsManager; |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 169 | mIncomingCallsManager = incomingCallsManager; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 170 | mCallIdMapper = callIdMapper; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 174 | @Override |
| 175 | public void setIsCompatibleWith(String callId, boolean isCompatible) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 176 | Log.v(this, "setIsCompatibleWith id: %d, isCompatible: %b", callId, isCompatible); |
| 177 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 178 | mHandler.obtainMessage(MSG_SET_IS_COMPATIBLE_WITH, isCompatible ? 1 : 0, 0, callId). |
| 179 | sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 182 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 183 | @Override |
| 184 | public void notifyIncomingCall(CallInfo callInfo) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 185 | mCallIdMapper.checkValidCallId(callInfo.getId()); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 186 | mHandler.obtainMessage(MSG_NOTIFY_INCOMING_CALL, callInfo).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 190 | @Override |
| 191 | public void handleSuccessfulOutgoingCall(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 192 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 193 | mHandler.obtainMessage(MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL, callId).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 197 | @Override |
| 198 | public void handleFailedOutgoingCall(String callId, String reason) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 199 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 200 | SomeArgs args = SomeArgs.obtain(); |
| 201 | args.arg1 = callId; |
| 202 | args.arg2 = reason; |
| 203 | mHandler.obtainMessage(MSG_HANDLE_FAILED_OUTGOING_CALL, args).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public void setActive(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 209 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 210 | mHandler.obtainMessage(MSG_SET_ACTIVE, callId).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 214 | @Override |
| 215 | public void setRinging(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 216 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 217 | mHandler.obtainMessage(MSG_SET_RINGING, callId).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 221 | @Override |
| 222 | public void setDialing(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 223 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 224 | mHandler.obtainMessage(MSG_SET_DIALING, callId).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 228 | @Override |
| 229 | public void setDisconnected( |
| 230 | String callId, int disconnectCause, String disconnectMessage) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 231 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 232 | SomeArgs args = SomeArgs.obtain(); |
| 233 | args.arg1 = callId; |
| 234 | args.arg2 = disconnectMessage; |
| 235 | args.argi1 = disconnectCause; |
| 236 | mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 239 | /** {@inheritDoc} */ |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 240 | @Override |
| 241 | public void setOnHold(String callId) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 242 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | 10ea460 | 2014-04-01 17:23:32 -0700 | [diff] [blame] | 243 | mHandler.obtainMessage(MSG_SET_ON_HOLD, callId).sendToTarget(); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 246 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 247 | * Adds the specified call to the list of pending calls. Only calls in this list which are |
| 248 | * outgoing will be handled by {@link #isCompatibleWith}, {@link handleSuccessfulOutgoingCall}, |
| 249 | * and {@link handleFailedOutgoingCall}. Similarly, only calls in this list which are incoming |
| 250 | * will be handled by {@link notifyIncomingCall}. |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 251 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 252 | void addPendingCall(Call call) { |
| 253 | mPendingCalls.add(call); |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 257 | * Removes the specified call from the list of pending calls. |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 258 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 259 | void removePendingCall(Call call) { |
| 260 | mPendingCalls.remove(call); |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 264 | * Called when the associated call service dies. |
| 265 | */ |
| 266 | void handleCallServiceDeath() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 267 | if (!mPendingCalls.isEmpty()) { |
| 268 | // Iterate through a copy because the code inside the loop will modify the original |
| 269 | // list. |
| 270 | for (Call call : ImmutableList.copyOf(mPendingCalls)) { |
| 271 | if (call.isIncoming()) { |
| 272 | mIncomingCallsManager.handleFailedIncomingCall(call); |
| 273 | } else { |
| 274 | mOutgoingCallsManager.handleFailedCallAttempt(call, |
| 275 | "Call service disconnected."); |
| 276 | } |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame^] | 279 | if (!mPendingCalls.isEmpty()) { |
| 280 | Log.wtf(this, "Pending calls did not get cleared."); |
| 281 | mPendingCalls.clear(); |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 284 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 285 | } |