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