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