blob: cfb5b65a79769abc743e1ca27cbf331db4b5b14f [file] [log] [blame]
Santos Cordon63a84242013-07-23 13:32:52 -07001/*
2 * Copyright (C) 2013 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
17package com.android.phone;
18
Santos Cordon63a84242013-07-23 13:32:52 -070019import android.os.AsyncResult;
20import android.os.Handler;
21import android.os.Message;
Santos Cordon4ad64cd2013-08-15 00:36:14 -070022import android.os.SystemProperties;
Christine Chenaf2fd0a2013-09-13 16:27:40 -070023import android.telephony.PhoneNumberUtils;
Santos Cordone38b1ff2013-08-07 12:12:16 -070024import android.text.TextUtils;
25import android.util.Log;
Santos Cordon63a84242013-07-23 13:32:52 -070026
Santos Cordona3d05142013-07-29 11:25:17 -070027import com.android.internal.telephony.CallManager;
Santos Cordon63a84242013-07-23 13:32:52 -070028import com.android.internal.telephony.Connection;
Santos Cordoneead6ec2013-08-07 22:16:33 -070029import com.android.internal.telephony.Phone;
Santos Cordona3d05142013-07-29 11:25:17 -070030import com.android.internal.telephony.PhoneConstants;
Santos Cordona5d5db82013-09-15 13:00:34 -070031import com.android.internal.telephony.TelephonyCapabilities;
32import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
Santos Cordon69a69192013-08-22 14:25:42 -070033import com.android.phone.CallGatewayManager.RawGatewayInfo;
Santos Cordon995c8162013-07-29 09:22:22 -070034import com.android.services.telephony.common.Call;
Santos Cordon26e7b242013-08-07 21:15:45 -070035import com.android.services.telephony.common.Call.Capabilities;
Santos Cordona3d05142013-07-29 11:25:17 -070036import com.android.services.telephony.common.Call.State;
Santos Cordon63a84242013-07-23 13:32:52 -070037
Yorke Lee814da302013-08-30 16:01:07 -070038import com.google.android.collect.Maps;
39import com.google.common.base.Preconditions;
40import com.google.common.collect.ImmutableMap;
41import com.google.common.collect.ImmutableSortedSet;
Santos Cordonad1ed6d2013-09-16 03:04:23 -070042import com.google.common.collect.Lists;
Yorke Lee814da302013-08-30 16:01:07 -070043
Santos Cordon63a84242013-07-23 13:32:52 -070044import java.util.ArrayList;
Santos Cordonad1ed6d2013-09-16 03:04:23 -070045import java.util.Collections;
Santos Cordon63a84242013-07-23 13:32:52 -070046import java.util.HashMap;
47import java.util.List;
Santos Cordon249efd02013-08-05 03:33:56 -070048import java.util.Map.Entry;
Santos Cordon63a84242013-07-23 13:32:52 -070049import java.util.concurrent.atomic.AtomicInteger;
50
51/**
52 * Creates a Call model from Call state and data received from the telephony
53 * layer. The telephony layer maintains 3 conceptual objects: Phone, Call,
54 * Connection.
55 *
56 * Phone represents the radio and there is an implementation per technology
57 * type such as GSMPhone, SipPhone, CDMAPhone, etc. Generally, we will only ever
58 * deal with one instance of this object for the lifetime of this class.
59 *
60 * There are 3 Call instances that exist for the lifetime of this class which
61 * are created by CallTracker. The three are RingingCall, ForegroundCall, and
62 * BackgroundCall.
63 *
64 * A Connection most closely resembles what the layperson would consider a call.
65 * A Connection is created when a user dials and it is "owned" by one of the
66 * three Call instances. Which of the three Calls owns the Connection changes
67 * as the Connection goes between ACTIVE, HOLD, RINGING, and other states.
68 *
69 * This class models a new Call class from Connection objects received from
70 * the telephony layer. We use Connection references as identifiers for a call;
71 * new reference = new call.
72 *
Christine Chen91db67d2013-09-18 12:01:11 -070073 * TODO: Create a new Call class to replace the simple call Id ints
Santos Cordon63a84242013-07-23 13:32:52 -070074 * being used currently.
75 *
76 * The new Call models are parcellable for transfer via the CallHandlerService
77 * API.
78 */
79public class CallModeler extends Handler {
80
81 private static final String TAG = CallModeler.class.getSimpleName();
Santos Cordon4ad64cd2013-08-15 00:36:14 -070082 private static final boolean DBG =
83 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
Santos Cordon63a84242013-07-23 13:32:52 -070084
85 private static final int CALL_ID_START_VALUE = 1;
Santos Cordon63a84242013-07-23 13:32:52 -070086
Santos Cordon998f42b2013-08-02 16:13:12 -070087 private final CallStateMonitor mCallStateMonitor;
88 private final CallManager mCallManager;
Santos Cordon69a69192013-08-22 14:25:42 -070089 private final CallGatewayManager mCallGatewayManager;
Santos Cordon998f42b2013-08-02 16:13:12 -070090 private final HashMap<Connection, Call> mCallMap = Maps.newHashMap();
Santos Cordon4ad64cd2013-08-15 00:36:14 -070091 private final HashMap<Connection, Call> mConfCallMap = Maps.newHashMap();
Santos Cordon998f42b2013-08-02 16:13:12 -070092 private final AtomicInteger mNextCallId = new AtomicInteger(CALL_ID_START_VALUE);
Christine Chendaf7bf62013-08-05 19:12:31 -070093 private final ArrayList<Listener> mListeners = new ArrayList<Listener>();
Christine Chenee09a492013-08-06 16:02:29 -070094 private RejectWithTextMessageManager mRejectWithTextMessageManager;
Santos Cordona5d5db82013-09-15 13:00:34 -070095 private Connection mCdmaIncomingConnection;
Santos Cordonad1ed6d2013-09-16 03:04:23 -070096 private Connection mCdmaOutgoingConnection;
Santos Cordon63a84242013-07-23 13:32:52 -070097
Christine Chenee09a492013-08-06 16:02:29 -070098 public CallModeler(CallStateMonitor callStateMonitor, CallManager callManager,
Santos Cordon69a69192013-08-22 14:25:42 -070099 RejectWithTextMessageManager rejectWithTextMessageManager,
100 CallGatewayManager callGatewayManager) {
Santos Cordon63a84242013-07-23 13:32:52 -0700101 mCallStateMonitor = callStateMonitor;
Santos Cordona3d05142013-07-29 11:25:17 -0700102 mCallManager = callManager;
Christine Chenee09a492013-08-06 16:02:29 -0700103 mRejectWithTextMessageManager = rejectWithTextMessageManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700104 mCallGatewayManager = callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700105
106 mCallStateMonitor.addListener(this);
107 }
108
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700109 @Override
Santos Cordon63a84242013-07-23 13:32:52 -0700110 public void handleMessage(Message msg) {
111 switch(msg.what) {
112 case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700113 // We let the CallNotifier handle the new ringing connection first. When the custom
114 // ringtone and send_to_voicemail settings are retrieved, CallNotifier will directly
115 // call CallModeler's onNewRingingConnection.
Santos Cordon63a84242013-07-23 13:32:52 -0700116 break;
117 case CallStateMonitor.PHONE_DISCONNECT:
Santos Cordona5d5db82013-09-15 13:00:34 -0700118 onDisconnect((Connection) ((AsyncResult) msg.obj).result);
Santos Cordon995c8162013-07-29 09:22:22 -0700119 break;
120 case CallStateMonitor.PHONE_STATE_CHANGED:
121 onPhoneStateChanged((AsyncResult) msg.obj);
122 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700123 case CallStateMonitor.PHONE_ON_DIAL_CHARS:
124 onPostDialChars((AsyncResult) msg.obj, (char) msg.arg1);
125 break;
Santos Cordon63a84242013-07-23 13:32:52 -0700126 default:
127 break;
128 }
129 }
130
Christine Chendaf7bf62013-08-05 19:12:31 -0700131 public void addListener(Listener listener) {
Santos Cordon63a84242013-07-23 13:32:52 -0700132 Preconditions.checkNotNull(listener);
Christine Chendaf7bf62013-08-05 19:12:31 -0700133 Preconditions.checkNotNull(mListeners);
Christine Chen4748abd2013-08-07 15:44:15 -0700134 if (!mListeners.contains(listener)) {
135 mListeners.add(listener);
136 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700137 }
138
139 public List<Call> getFullList() {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700140 final List<Call> calls =
141 Lists.newArrayListWithCapacity(mCallMap.size() + mConfCallMap.size());
142 calls.addAll(mCallMap.values());
143 calls.addAll(mConfCallMap.values());
144 return calls;
Santos Cordon63a84242013-07-23 13:32:52 -0700145 }
146
Santos Cordon249efd02013-08-05 03:33:56 -0700147 public CallResult getCallWithId(int callId) {
148 // max 8 connections, so this should be fast even through we are traversing the entire map.
149 for (Entry<Connection, Call> entry : mCallMap.entrySet()) {
150 if (entry.getValue().getCallId() == callId) {
151 return new CallResult(entry.getValue(), entry.getKey());
152 }
153 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700154
155 for (Entry<Connection, Call> entry : mConfCallMap.entrySet()) {
156 if (entry.getValue().getCallId() == callId) {
Christine Chen69050202013-09-14 15:36:35 -0700157 return new CallResult(entry.getValue(), entry.getKey());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700158 }
159 }
Santos Cordon249efd02013-08-05 03:33:56 -0700160 return null;
161 }
162
Santos Cordonaf763a12013-08-19 20:04:58 -0700163 public boolean hasLiveCall() {
164 return hasLiveCallInternal(mCallMap) ||
165 hasLiveCallInternal(mConfCallMap);
166 }
167
Santos Cordona5d5db82013-09-15 13:00:34 -0700168 public void onCdmaCallWaiting(CdmaCallWaitingNotification callWaitingInfo) {
169 // We dont get the traditional onIncomingCall notification for cdma call waiting,
170 // but the Connection does actually exist. We need to find it in the set of ringing calls
171 // and pass it through our normal incoming logic.
172 final com.android.internal.telephony.Call teleCall =
173 mCallManager.getFirstActiveRingingCall();
174
175 if (teleCall.getState() == com.android.internal.telephony.Call.State.WAITING) {
176 Connection connection = teleCall.getLatestConnection();
177
178 if (connection != null) {
179 String number = connection.getAddress();
180 if (number != null && number.equals(callWaitingInfo.number)) {
181 Call call = onNewRingingConnection(connection);
182 mCdmaIncomingConnection = connection;
183 return;
184 }
185 }
186 }
187
188 Log.e(TAG, "CDMA Call waiting notification without a matching connection.");
189 }
190
191 public void onCdmaCallWaitingReject() {
192 // Cdma call was rejected...
193 if (mCdmaIncomingConnection != null) {
194 onDisconnect(mCdmaIncomingConnection);
195 mCdmaIncomingConnection = null;
196 } else {
197 Log.e(TAG, "CDMA Call waiting rejection without an incoming call.");
198 }
199 }
200
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700201 /**
202 * CDMA Calls have no sense of "dialing" state. For outgoing calls 3way calls we want to
203 * mimick this state so that the the UI can notify the user that there is a "dialing"
204 * call.
205 */
206 public void setCdmaOutgoing3WayCall(Connection connection) {
207 boolean wasSet = mCdmaOutgoingConnection != null;
208
209 mCdmaOutgoingConnection = connection;
210
211 // If we reset the connection, that mean we can now tell the user that the call is actually
212 // part of the conference call and move it out of the dialing state. To do this, issue a
213 // new update completely.
214 if (wasSet && mCdmaOutgoingConnection == null) {
215 onPhoneStateChanged(null);
216 }
217 }
218
Santos Cordonaf763a12013-08-19 20:04:58 -0700219 private boolean hasLiveCallInternal(HashMap<Connection, Call> map) {
220 for (Call call : map.values()) {
221 final int state = call.getState();
222 if (state == Call.State.ACTIVE ||
223 state == Call.State.CALL_WAITING ||
224 state == Call.State.CONFERENCED ||
225 state == Call.State.DIALING ||
Santos Cordonce02f3a2013-09-19 01:58:42 -0700226 state == Call.State.REDIALING ||
Santos Cordonaf763a12013-08-19 20:04:58 -0700227 state == Call.State.INCOMING ||
Christine Chen3e0f0412013-09-18 20:33:49 -0700228 state == Call.State.ONHOLD ||
229 state == Call.State.DISCONNECTING) {
Santos Cordonaf763a12013-08-19 20:04:58 -0700230 return true;
231 }
232 }
233 return false;
234 }
235
Santos Cordon2b73bd62013-08-27 14:53:43 -0700236 public boolean hasOutstandingActiveOrDialingCall() {
237 return hasOutstandingActiveOrDialingCallInternal(mCallMap) ||
238 hasOutstandingActiveOrDialingCallInternal(mConfCallMap);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700239 }
240
Santos Cordon2b73bd62013-08-27 14:53:43 -0700241 private static boolean hasOutstandingActiveOrDialingCallInternal(
242 HashMap<Connection, Call> map) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700243 for (Call call : map.values()) {
244 final int state = call.getState();
Santos Cordonce02f3a2013-09-19 01:58:42 -0700245 if (state == Call.State.ACTIVE || Call.State.isDialing(state)) {
Santos Cordon2eaff902013-08-05 04:37:55 -0700246 return true;
247 }
248 }
249
250 return false;
251 }
252
Chiao Cheng3f015c92013-09-06 15:56:27 -0700253
254 /**
255 * Handles the POST_ON_DIAL_CHARS message from the Phone (see our call to
256 * mPhone.setOnPostDialCharacter() above.)
257 *
258 * TODO: NEED TO TEST THIS SEQUENCE now that we no longer handle "dialable" key events here in
259 * the InCallScreen: we do directly to the Dialer UI instead. Similarly, we may now need to go
260 * directly to the Dialer to handle POST_ON_DIAL_CHARS too.
261 */
262 private void onPostDialChars(AsyncResult r, char ch) {
263 final Connection c = (Connection) r.result;
264
265 if (c != null) {
266 final Connection.PostDialState state = (Connection.PostDialState) r.userObj;
267
268 switch (state) {
Chiao Cheng3f015c92013-09-06 15:56:27 -0700269 case WAIT:
270 final Call call = getCallFromMap(mCallMap, c, false);
271 if (call == null) {
272 Log.i(TAG, "Call no longer exists. Skipping onPostDialWait().");
273 } else {
274 for (Listener mListener : mListeners) {
Yorke Leede41f672013-09-19 13:46:55 -0700275 mListener.onPostDialAction(state, call.getCallId(),
276 c.getRemainingPostDialString(), ch);
Chiao Cheng3f015c92013-09-06 15:56:27 -0700277 }
278 }
279 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700280 default:
Yorke Leede41f672013-09-19 13:46:55 -0700281 // This is primarily to cause the DTMFTonePlayer to play local tones.
282 // Other listeners simply perform no-ops.
283 for (Listener mListener : mListeners) {
284 mListener.onPostDialAction(state, 0, "", ch);
285 }
Chiao Cheng3f015c92013-09-06 15:56:27 -0700286 break;
287 }
288 }
289 }
290
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700291 /* package */ Call onNewRingingConnection(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700292 Log.i(TAG, "onNewRingingConnection");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700293 final Call call = getCallFromMap(mCallMap, conn, true);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700294
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700295 if (call != null) {
296 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700297
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700298 for (int i = 0; i < mListeners.size(); ++i) {
299 mListeners.get(i).onIncoming(call);
Christine Chenee09a492013-08-06 16:02:29 -0700300 }
Santos Cordon63a84242013-07-23 13:32:52 -0700301 }
Santos Cordona5d5db82013-09-15 13:00:34 -0700302
303 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700304 }
305
Santos Cordona5d5db82013-09-15 13:00:34 -0700306 private void onDisconnect(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700307 Log.i(TAG, "onDisconnect");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700308 final Call call = getCallFromMap(mCallMap, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700309
Santos Cordon995c8162013-07-29 09:22:22 -0700310 if (call != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700311 final boolean wasConferenced = call.getState() == State.CONFERENCED;
312
313 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700314
Christine Chendaf7bf62013-08-05 19:12:31 -0700315 for (int i = 0; i < mListeners.size(); ++i) {
316 mListeners.get(i).onDisconnect(call);
Santos Cordon63a84242013-07-23 13:32:52 -0700317 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700318
319 // If it was a conferenced call, we need to run the entire update
320 // to make the proper changes to parent conference calls.
321 if (wasConferenced) {
322 onPhoneStateChanged(null);
323 }
324
325 mCallMap.remove(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700326 }
327 }
328
Santos Cordona3d05142013-07-29 11:25:17 -0700329 /**
330 * Called when the phone state changes.
Santos Cordona3d05142013-07-29 11:25:17 -0700331 */
Santos Cordon995c8162013-07-29 09:22:22 -0700332 private void onPhoneStateChanged(AsyncResult r) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700333 Log.i(TAG, "onPhoneStateChanged: ");
Santos Cordon998f42b2013-08-02 16:13:12 -0700334 final List<Call> updatedCalls = Lists.newArrayList();
335 doUpdate(false, updatedCalls);
336
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700337 if (updatedCalls.size() > 0) {
338 for (int i = 0; i < mListeners.size(); ++i) {
339 mListeners.get(i).onUpdate(updatedCalls);
340 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700341 }
342 }
343
344
345 /**
346 * Go through the Calls from CallManager and return the list of calls that were updated.
347 * Or, the full list if requested.
348 */
349 private void doUpdate(boolean fullUpdate, List<Call> out) {
Santos Cordona3d05142013-07-29 11:25:17 -0700350 final List<com.android.internal.telephony.Call> telephonyCalls = Lists.newArrayList();
351 telephonyCalls.addAll(mCallManager.getRingingCalls());
352 telephonyCalls.addAll(mCallManager.getForegroundCalls());
353 telephonyCalls.addAll(mCallManager.getBackgroundCalls());
354
Santos Cordona3d05142013-07-29 11:25:17 -0700355 // Cycle through all the Connections on all the Calls. Update our Call objects
356 // to reflect any new state and send the updated Call objects to the handler service.
357 for (com.android.internal.telephony.Call telephonyCall : telephonyCalls) {
Santos Cordona3d05142013-07-29 11:25:17 -0700358
359 for (Connection connection : telephonyCall.getConnections()) {
Christine Chen3e0f0412013-09-18 20:33:49 -0700360 if (DBG) Log.d(TAG, "connection: " + connection + connection.getState());
Santos Cordona5d5db82013-09-15 13:00:34 -0700361
Santos Cordon12a03aa2013-09-12 23:34:05 -0700362 // We only send updates for live calls which are not incoming (ringing).
363 // Disconnected and incoming calls are handled by onDisconnect and
364 // onNewRingingConnection.
Christine Chen3e0f0412013-09-18 20:33:49 -0700365 boolean shouldUpdate =
366 connection.getState() !=
367 com.android.internal.telephony.Call.State.DISCONNECTED &&
368 connection.getState() !=
369 com.android.internal.telephony.Call.State.IDLE &&
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700370 !connection.getState().isRinging();
371
372 // New connections return a Call with INVALID state, which does not translate to
Santos Cordone38b1ff2013-08-07 12:12:16 -0700373 // a state in the internal.telephony.Call object. This ensures that staleness
374 // check below fails and we always add the item to the update list if it is new.
Santos Cordon12a03aa2013-09-12 23:34:05 -0700375 final Call call = getCallFromMap(mCallMap, connection, shouldUpdate /* create */);
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700376
Santos Cordon12a03aa2013-09-12 23:34:05 -0700377 if (call == null || !shouldUpdate) {
Santos Cordona5d5db82013-09-15 13:00:34 -0700378 if (DBG) Log.d(TAG, "update skipped");
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700379 continue;
380 }
Santos Cordona3d05142013-07-29 11:25:17 -0700381
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700382 boolean changed = updateCallFromConnection(call, connection, false);
Santos Cordon2b73bd62013-08-27 14:53:43 -0700383
Santos Cordone38b1ff2013-08-07 12:12:16 -0700384 if (fullUpdate || changed) {
Santos Cordon998f42b2013-08-02 16:13:12 -0700385 out.add(call);
Santos Cordona3d05142013-07-29 11:25:17 -0700386 }
387 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700388
389 // We do a second loop to address conference call scenarios. We do this as a separate
390 // loop to ensure all child calls are up to date before we start updating the parent
391 // conference calls.
392 for (Connection connection : telephonyCall.getConnections()) {
393 updateForConferenceCalls(connection, out);
394 }
395
Santos Cordona3d05142013-07-29 11:25:17 -0700396 }
Santos Cordona3d05142013-07-29 11:25:17 -0700397 }
398
Santos Cordone38b1ff2013-08-07 12:12:16 -0700399 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700400 * Checks to see if the connection is the first connection in a conference call.
401 * If it is a conference call, we will create a new Conference Call object or
402 * update the existing conference call object for that connection.
403 * If it is not a conference call but a previous associated conference call still exists,
404 * we mark it as idle and remove it from the map.
405 * In both cases above, we add the Calls to be updated to the UI.
406 * @param connection The connection object to check.
407 * @param updatedCalls List of 'updated' calls that will be sent to the UI.
408 */
409 private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
410 // We consider this connection a conference connection if the call it
Yorke Leecd3f9692013-09-14 13:51:27 -0700411 // belongs to is a multiparty call AND it is the first live connection.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700412 final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
Yorke Leecd3f9692013-09-14 13:51:27 -0700413 getEarliestLiveConnection(connection.getCall()) == connection;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700414
415 boolean changed = false;
416
417 // If this connection is the main connection for the conference call, then create or update
418 // a Call object for that conference call.
419 if (isConferenceCallConnection) {
420 final Call confCall = getCallFromMap(mConfCallMap, connection, true);
421 changed = updateCallFromConnection(confCall, connection, true);
422
423 if (changed) {
424 updatedCalls.add(confCall);
425 }
426
427 if (DBG) Log.d(TAG, "Updating a conference call: " + confCall);
428
429 // It is possible that through a conference call split, there may be lingering conference
430 // calls where this connection was the main connection. We clean those up here.
431 } else {
432 final Call oldConfCall = getCallFromMap(mConfCallMap, connection, false);
433
434 // We found a conference call for this connection, which is no longer a conference call.
435 // Kill it!
436 if (oldConfCall != null) {
437 if (DBG) Log.d(TAG, "Cleaning up an old conference call: " + oldConfCall);
438 mConfCallMap.remove(connection);
439 oldConfCall.setState(State.IDLE);
440 changed = true;
441
442 // add to the list of calls to update
443 updatedCalls.add(oldConfCall);
444 }
445 }
446
447 return changed;
448 }
449
Yorke Leecd3f9692013-09-14 13:51:27 -0700450 private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
451 final List<Connection> connections = call.getConnections();
452 final int size = connections.size();
453 Connection earliestConn = null;
454 long earliestTime = Long.MAX_VALUE;
455 for (int i = 0; i < size; i++) {
456 final Connection connection = connections.get(i);
457 if (!connection.isAlive()) continue;
458 final long time = connection.getCreateTime();
459 if (time < earliestTime) {
460 earliestTime = time;
461 earliestConn = connection;
462 }
463 }
464 return earliestConn;
465 }
466
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700467 /**
Santos Cordon69a69192013-08-22 14:25:42 -0700468 * Sets the new call state onto the call and performs some additional logic
469 * associated with setting the state.
470 */
471 private void setNewState(Call call, int newState, Connection connection) {
472 Preconditions.checkState(call.getState() != newState);
473
474 // When starting an outgoing call, we need to grab gateway information
475 // for the call, if available, and set it.
476 final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
477
Santos Cordonce02f3a2013-09-19 01:58:42 -0700478 if (Call.State.isDialing(newState)) {
Santos Cordon69a69192013-08-22 14:25:42 -0700479 if (!info.isEmpty()) {
480 call.setGatewayNumber(info.getFormattedGatewayNumber());
481 call.setGatewayPackage(info.packageName);
482 }
483 } else if (!Call.State.isConnected(newState)) {
484 mCallGatewayManager.clearGatewayData(connection);
485 }
486
487 call.setState(newState);
488 }
489
490 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700491 * Updates the Call properties to match the state of the connection object
492 * that it represents.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700493 * @param call The call object to update.
494 * @param connection The connection object from which to update call.
495 * @param isForConference There are slight differences in how we populate data for conference
496 * calls. This boolean tells us which method to use.
Santos Cordone38b1ff2013-08-07 12:12:16 -0700497 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700498 private boolean updateCallFromConnection(Call call, Connection connection,
499 boolean isForConference) {
Santos Cordone38b1ff2013-08-07 12:12:16 -0700500 boolean changed = false;
501
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700502 final int newState = translateStateFromTelephony(connection, isForConference);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700503
504 if (call.getState() != newState) {
Santos Cordon69a69192013-08-22 14:25:42 -0700505 setNewState(call, newState, connection);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700506 changed = true;
507 }
508
Santos Cordone38b1ff2013-08-07 12:12:16 -0700509 final Call.DisconnectCause newDisconnectCause =
510 translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
511 if (call.getDisconnectCause() != newDisconnectCause) {
512 call.setDisconnectCause(newDisconnectCause);
513 changed = true;
514 }
515
Santos Cordonbbe8ecf2013-08-13 15:26:18 -0700516 final long oldConnectTime = call.getConnectTime();
517 if (oldConnectTime != connection.getConnectTime()) {
518 call.setConnectTime(connection.getConnectTime());
519 changed = true;
520 }
521
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700522 if (!isForConference) {
Santos Cordon69a69192013-08-22 14:25:42 -0700523 // Number
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700524 final String oldNumber = call.getNumber();
Santos Cordon69a69192013-08-22 14:25:42 -0700525 String newNumber = connection.getAddress();
526 RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
527 if (!info.isEmpty()) {
528 newNumber = info.trueNumber;
529 }
530 if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
531 call.setNumber(newNumber);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700532 changed = true;
533 }
534
Santos Cordon69a69192013-08-22 14:25:42 -0700535 // Number presentation
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700536 final int newNumberPresentation = connection.getNumberPresentation();
537 if (call.getNumberPresentation() != newNumberPresentation) {
538 call.setNumberPresentation(newNumberPresentation);
539 changed = true;
540 }
541
Santos Cordon69a69192013-08-22 14:25:42 -0700542 // Name
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700543 final String oldCnapName = call.getCnapName();
544 if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
545 call.setCnapName(connection.getCnapName());
546 changed = true;
547 }
Santos Cordon69a69192013-08-22 14:25:42 -0700548
549 // Name Presentation
550 final int newCnapNamePresentation = connection.getCnapNamePresentation();
551 if (call.getCnapNamePresentation() != newCnapNamePresentation) {
552 call.setCnapNamePresentation(newCnapNamePresentation);
553 changed = true;
554 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700555 } else {
556
557 // update the list of children by:
558 // 1) Saving the old set
559 // 2) Removing all children
560 // 3) Adding the correct children into the Call
561 // 4) Comparing the new children set with the old children set
562 ImmutableSortedSet<Integer> oldSet = call.getChildCallIds();
563 call.removeAllChildren();
564
565 if (connection.getCall() != null) {
566 for (Connection childConn : connection.getCall().getConnections()) {
567 final Call childCall = getCallFromMap(mCallMap, childConn, false);
568 if (childCall != null && childConn.isAlive()) {
569 call.addChildId(childCall.getCallId());
570 }
571 }
572 }
Christine Chen45277022013-09-05 10:55:37 -0700573 changed |= !oldSet.equals(call.getChildCallIds());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700574 }
575
Santos Cordoneead6ec2013-08-07 22:16:33 -0700576 /**
577 * !!! Uses values from connection and call collected above so this part must be last !!!
578 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700579 final int newCapabilities = getCapabilitiesFor(connection, call, isForConference);
Santos Cordon26e7b242013-08-07 21:15:45 -0700580 if (call.getCapabilities() != newCapabilities) {
581 call.setCapabilities(newCapabilities);
582 changed = true;
583 }
584
Santos Cordone38b1ff2013-08-07 12:12:16 -0700585 return changed;
586 }
587
Santos Cordon26e7b242013-08-07 21:15:45 -0700588 /**
589 * Returns a mask of capabilities for the connection such as merge, hold, etc.
590 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700591 private int getCapabilitiesFor(Connection connection, Call call, boolean isForConference) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700592 final boolean callIsActive = (call.getState() == Call.State.ACTIVE);
593 final Phone phone = connection.getCall().getPhone();
594
Santos Cordoneead6ec2013-08-07 22:16:33 -0700595 boolean canAddCall = false;
596 boolean canMergeCall = false;
597 boolean canSwapCall = false;
Yorke Lee814da302013-08-30 16:01:07 -0700598 boolean canRespondViaText = false;
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700599 boolean canMute = false;
600
601 final boolean supportHold = PhoneUtils.okToSupportHold(mCallManager);
Christine Chen94853bc2013-09-17 16:53:33 -0700602 final boolean canHold = (supportHold ? PhoneUtils.okToHoldCall(mCallManager) : false);
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700603 final boolean genericConf = isForConference &&
604 (connection.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
Santos Cordoneead6ec2013-08-07 22:16:33 -0700605
606 // only applies to active calls
607 if (callIsActive) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700608 canMergeCall = PhoneUtils.okToMergeCalls(mCallManager);
609 canSwapCall = PhoneUtils.okToSwapCalls(mCallManager);
610 }
611
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700612 canAddCall = PhoneUtils.okToAddCall(mCallManager);
613
614 // "Mute": only enabled when the foreground call is ACTIVE.
615 // (It's meaningless while on hold, or while DIALING/ALERTING.)
616 // It's also explicitly disabled during emergency calls or if
617 // emergency callback mode (ECM) is active.
618 boolean isEmergencyCall = false;
619 if (connection != null) {
620 isEmergencyCall = PhoneNumberUtils.isLocalEmergencyNumber(connection.getAddress(),
621 phone.getContext());
622 }
623 boolean isECM = PhoneUtils.isPhoneInEcm(phone);
624 if (isEmergencyCall || isECM) { // disable "Mute" item
625 canMute = false;
626 } else {
627 canMute = callIsActive;
628 }
629
Yorke Lee814da302013-08-30 16:01:07 -0700630 canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
631 connection);
632
Santos Cordoneead6ec2013-08-07 22:16:33 -0700633 // special rules section!
634 // CDMA always has Add
635 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
636 canAddCall = true;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700637 }
638
Santos Cordon26e7b242013-08-07 21:15:45 -0700639 int retval = 0x0;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700640 if (canHold) {
Santos Cordon26e7b242013-08-07 21:15:45 -0700641 retval |= Capabilities.HOLD;
642 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700643 if (supportHold) {
644 retval |= Capabilities.SUPPORT_HOLD;
645 }
Santos Cordoneead6ec2013-08-07 22:16:33 -0700646 if (canAddCall) {
647 retval |= Capabilities.ADD_CALL;
648 }
649 if (canMergeCall) {
650 retval |= Capabilities.MERGE_CALLS;
651 }
652 if (canSwapCall) {
653 retval |= Capabilities.SWAP_CALLS;
654 }
Yorke Lee814da302013-08-30 16:01:07 -0700655 if (canRespondViaText) {
656 retval |= Capabilities.RESPOND_VIA_TEXT;
657 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700658 if (canMute) {
659 retval |= Capabilities.MUTE;
660 }
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700661 if (genericConf) {
662 retval |= Capabilities.GENERIC_CONFERENCE;
663 }
Yorke Lee814da302013-08-30 16:01:07 -0700664
Santos Cordon26e7b242013-08-07 21:15:45 -0700665 return retval;
666 }
667
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700668 /**
669 * Returns true if the Connection is part of a multiparty call.
670 * We do this by checking the isMultiparty() method of the telephony.Call object and also
671 * checking to see if more than one of it's children is alive.
672 */
673 private boolean isPartOfLiveConferenceCall(Connection connection) {
674 if (connection.getCall() != null && connection.getCall().isMultiparty()) {
675 int count = 0;
676 for (Connection currConn : connection.getCall().getConnections()) {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700677
678 // Only count connections which are alive and never cound the special
679 // "dialing" 3way call for CDMA calls.
680 if (currConn.isAlive() && currConn != mCdmaOutgoingConnection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700681 count++;
682 if (count >= 2) {
683 return true;
684 }
685 }
686 }
687 }
688 return false;
689 }
690
691 private int translateStateFromTelephony(Connection connection, boolean isForConference) {
692
Santos Cordonce02f3a2013-09-19 01:58:42 -0700693 com.android.internal.telephony.Call.State connState = connection.getState();
694
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700695 // For the "fake" outgoing CDMA call, we need to always treat it as an outgoing call.
696 if (mCdmaOutgoingConnection == connection) {
Santos Cordonce02f3a2013-09-19 01:58:42 -0700697 connState = com.android.internal.telephony.Call.State.DIALING;
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700698 }
699
Santos Cordona3d05142013-07-29 11:25:17 -0700700 int retval = State.IDLE;
Santos Cordonce02f3a2013-09-19 01:58:42 -0700701 switch (connState) {
Santos Cordona3d05142013-07-29 11:25:17 -0700702 case ACTIVE:
703 retval = State.ACTIVE;
704 break;
705 case INCOMING:
706 retval = State.INCOMING;
707 break;
708 case DIALING:
709 case ALERTING:
Santos Cordonce02f3a2013-09-19 01:58:42 -0700710 if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
711 retval = State.REDIALING;
712 } else {
713 retval = State.DIALING;
714 }
Santos Cordona3d05142013-07-29 11:25:17 -0700715 break;
716 case WAITING:
717 retval = State.CALL_WAITING;
718 break;
719 case HOLDING:
720 retval = State.ONHOLD;
721 break;
Santos Cordone38b1ff2013-08-07 12:12:16 -0700722 case DISCONNECTING:
Christine Chen3e0f0412013-09-18 20:33:49 -0700723 retval = State.DISCONNECTING;
724 break;
725 case DISCONNECTED:
Santos Cordone38b1ff2013-08-07 12:12:16 -0700726 retval = State.DISCONNECTED;
Santos Cordona3d05142013-07-29 11:25:17 -0700727 default:
728 }
729
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700730 // If we are dealing with a potential child call (not the parent conference call),
731 // the check to see if we have to set the state to CONFERENCED.
732 if (!isForConference) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700733 // if the connection is part of a multiparty call, and it is live,
734 // annotate it with CONFERENCED state instead.
735 if (isPartOfLiveConferenceCall(connection) && connection.isAlive()) {
736 return State.CONFERENCED;
737 }
738 }
739
Santos Cordona3d05142013-07-29 11:25:17 -0700740 return retval;
Santos Cordon995c8162013-07-29 09:22:22 -0700741 }
742
Santos Cordone38b1ff2013-08-07 12:12:16 -0700743 private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
744 ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
745 .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
746 .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
747 .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
748 Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
749 .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
750 Call.DisconnectCause.CDMA_ACCESS_FAILURE)
751 .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
752 .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
753 .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
754 Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
755 .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
756 Call.DisconnectCause.CDMA_NOT_EMERGENCY)
757 .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
758 .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
759 .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
760 Call.DisconnectCause.CDMA_RETRY_ORDER)
761 .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
762 .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
763 .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
764 .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
765 Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
766 .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
767 Call.DisconnectCause.CS_RESTRICTED_NORMAL)
768 .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
769 Call.DisconnectCause.ERROR_UNSPECIFIED)
770 .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
771 .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
772 .put(Connection.DisconnectCause.INCOMING_MISSED,
773 Call.DisconnectCause.INCOMING_MISSED)
774 .put(Connection.DisconnectCause.INCOMING_REJECTED,
775 Call.DisconnectCause.INCOMING_REJECTED)
776 .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
777 Call.DisconnectCause.INVALID_CREDENTIALS)
778 .put(Connection.DisconnectCause.INVALID_NUMBER,
779 Call.DisconnectCause.INVALID_NUMBER)
780 .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
781 .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
782 .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
783 .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
784 .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
785 .put(Connection.DisconnectCause.NOT_DISCONNECTED,
786 Call.DisconnectCause.NOT_DISCONNECTED)
787 .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
788 Call.DisconnectCause.NUMBER_UNREACHABLE)
789 .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
790 .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
791 .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
792 .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
793 .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
794 Call.DisconnectCause.SERVER_UNREACHABLE)
795 .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
796 .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
797 Call.DisconnectCause.UNOBTAINABLE_NUMBER)
798 .build();
799
800 private Call.DisconnectCause translateDisconnectCauseFromTelephony(
801 Connection.DisconnectCause causeSource) {
802
803 if (CAUSE_MAP.containsKey(causeSource)) {
804 return CAUSE_MAP.get(causeSource);
805 }
806
807 return Call.DisconnectCause.UNKNOWN;
808 }
809
Santos Cordon63a84242013-07-23 13:32:52 -0700810 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700811 * Gets an existing callId for a connection, or creates one if none exists.
812 * This function does NOT set any of the Connection data onto the Call class.
813 * A separate call to updateCallFromConnection must be made for that purpose.
Santos Cordon63a84242013-07-23 13:32:52 -0700814 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700815 private Call getCallFromMap(HashMap<Connection, Call> map, Connection conn,
816 boolean createIfMissing) {
Santos Cordon995c8162013-07-29 09:22:22 -0700817 Call call = null;
Santos Cordon63a84242013-07-23 13:32:52 -0700818
819 // Find the call id or create if missing and requested.
820 if (conn != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700821 if (map.containsKey(conn)) {
822 call = map.get(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700823 } else if (createIfMissing) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700824 call = createNewCall();
825 map.put(conn, call);
Santos Cordon63a84242013-07-23 13:32:52 -0700826 }
827 }
Santos Cordon995c8162013-07-29 09:22:22 -0700828 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700829 }
830
831 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700832 * Creates a brand new connection for the call.
833 */
834 private Call createNewCall() {
835 int callId;
836 int newNextCallId;
837 do {
838 callId = mNextCallId.get();
839
840 // protect against overflow
841 newNextCallId = (callId == Integer.MAX_VALUE ?
842 CALL_ID_START_VALUE : callId + 1);
843
844 // Keep looping if the change was not atomic OR the value is already taken.
845 // The call to containsValue() is linear, however, most devices support a
846 // maximum of 7 connections so it's not expensive.
847 } while (!mNextCallId.compareAndSet(callId, newNextCallId));
848
849 return new Call(callId);
850 }
851
852 /**
Santos Cordon63a84242013-07-23 13:32:52 -0700853 * Listener interface for changes to Calls.
854 */
855 public interface Listener {
Santos Cordon995c8162013-07-29 09:22:22 -0700856 void onDisconnect(Call call);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700857 void onIncoming(Call call);
858 void onUpdate(List<Call> calls);
Yorke Leede41f672013-09-19 13:46:55 -0700859 void onPostDialAction(Connection.PostDialState state, int callId, String remainingChars,
860 char c);
Santos Cordon63a84242013-07-23 13:32:52 -0700861 }
Santos Cordon249efd02013-08-05 03:33:56 -0700862
863 /**
864 * Result class for accessing a call by connection.
865 */
866 public static class CallResult {
867 public Call mCall;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700868 public Call mActionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700869 public Connection mConnection;
870
871 private CallResult(Call call, Connection connection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700872 this(call, call, connection);
873 }
874
875 private CallResult(Call call, Call actionableCall, Connection connection) {
Santos Cordon249efd02013-08-05 03:33:56 -0700876 mCall = call;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700877 mActionableCall = actionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700878 mConnection = connection;
879 }
880
881 public Call getCall() {
882 return mCall;
883 }
884
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700885 // The call that should be used for call actions like hanging up.
886 public Call getActionableCall() {
887 return mActionableCall;
888 }
889
Santos Cordon249efd02013-08-05 03:33:56 -0700890 public Connection getConnection() {
891 return mConnection;
892 }
893 }
Santos Cordon63a84242013-07-23 13:32:52 -0700894}