blob: 51d3a3753364a6b1c21a538f2b105042fe409582 [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>();
Santos Cordona5d5db82013-09-15 13:00:34 -070094 private Connection mCdmaIncomingConnection;
Santos Cordonad1ed6d2013-09-16 03:04:23 -070095 private Connection mCdmaOutgoingConnection;
Santos Cordon63a84242013-07-23 13:32:52 -070096
Christine Chenee09a492013-08-06 16:02:29 -070097 public CallModeler(CallStateMonitor callStateMonitor, CallManager callManager,
Santos Cordon69a69192013-08-22 14:25:42 -070098 CallGatewayManager callGatewayManager) {
Santos Cordon63a84242013-07-23 13:32:52 -070099 mCallStateMonitor = callStateMonitor;
Santos Cordona3d05142013-07-29 11:25:17 -0700100 mCallManager = callManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700101 mCallGatewayManager = callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700102
103 mCallStateMonitor.addListener(this);
104 }
105
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700106 @Override
Santos Cordon63a84242013-07-23 13:32:52 -0700107 public void handleMessage(Message msg) {
108 switch(msg.what) {
109 case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700110 // We let the CallNotifier handle the new ringing connection first. When the custom
111 // ringtone and send_to_voicemail settings are retrieved, CallNotifier will directly
112 // call CallModeler's onNewRingingConnection.
Santos Cordon63a84242013-07-23 13:32:52 -0700113 break;
114 case CallStateMonitor.PHONE_DISCONNECT:
Santos Cordona5d5db82013-09-15 13:00:34 -0700115 onDisconnect((Connection) ((AsyncResult) msg.obj).result);
Santos Cordon995c8162013-07-29 09:22:22 -0700116 break;
Santos Cordon54fdb592013-09-19 05:16:18 -0700117 case CallStateMonitor.PHONE_UNKNOWN_CONNECTION_APPEARED:
118 // fall through
Santos Cordon995c8162013-07-29 09:22:22 -0700119 case CallStateMonitor.PHONE_STATE_CHANGED:
120 onPhoneStateChanged((AsyncResult) msg.obj);
121 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700122 case CallStateMonitor.PHONE_ON_DIAL_CHARS:
123 onPostDialChars((AsyncResult) msg.obj, (char) msg.arg1);
124 break;
Santos Cordon63a84242013-07-23 13:32:52 -0700125 default:
126 break;
127 }
128 }
129
Christine Chendaf7bf62013-08-05 19:12:31 -0700130 public void addListener(Listener listener) {
Santos Cordon63a84242013-07-23 13:32:52 -0700131 Preconditions.checkNotNull(listener);
Christine Chendaf7bf62013-08-05 19:12:31 -0700132 Preconditions.checkNotNull(mListeners);
Christine Chen4748abd2013-08-07 15:44:15 -0700133 if (!mListeners.contains(listener)) {
134 mListeners.add(listener);
135 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700136 }
137
138 public List<Call> getFullList() {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700139 final List<Call> calls =
140 Lists.newArrayListWithCapacity(mCallMap.size() + mConfCallMap.size());
141 calls.addAll(mCallMap.values());
142 calls.addAll(mConfCallMap.values());
143 return calls;
Santos Cordon63a84242013-07-23 13:32:52 -0700144 }
145
Santos Cordon249efd02013-08-05 03:33:56 -0700146 public CallResult getCallWithId(int callId) {
147 // max 8 connections, so this should be fast even through we are traversing the entire map.
148 for (Entry<Connection, Call> entry : mCallMap.entrySet()) {
149 if (entry.getValue().getCallId() == callId) {
150 return new CallResult(entry.getValue(), entry.getKey());
151 }
152 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700153
154 for (Entry<Connection, Call> entry : mConfCallMap.entrySet()) {
155 if (entry.getValue().getCallId() == callId) {
Christine Chen69050202013-09-14 15:36:35 -0700156 return new CallResult(entry.getValue(), entry.getKey());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700157 }
158 }
Santos Cordon249efd02013-08-05 03:33:56 -0700159 return null;
160 }
161
Santos Cordonaf763a12013-08-19 20:04:58 -0700162 public boolean hasLiveCall() {
163 return hasLiveCallInternal(mCallMap) ||
164 hasLiveCallInternal(mConfCallMap);
165 }
166
Santos Cordona5d5db82013-09-15 13:00:34 -0700167 public void onCdmaCallWaiting(CdmaCallWaitingNotification callWaitingInfo) {
168 // We dont get the traditional onIncomingCall notification for cdma call waiting,
169 // but the Connection does actually exist. We need to find it in the set of ringing calls
170 // and pass it through our normal incoming logic.
171 final com.android.internal.telephony.Call teleCall =
172 mCallManager.getFirstActiveRingingCall();
173
174 if (teleCall.getState() == com.android.internal.telephony.Call.State.WAITING) {
175 Connection connection = teleCall.getLatestConnection();
176
177 if (connection != null) {
178 String number = connection.getAddress();
179 if (number != null && number.equals(callWaitingInfo.number)) {
180 Call call = onNewRingingConnection(connection);
181 mCdmaIncomingConnection = connection;
182 return;
183 }
184 }
185 }
186
187 Log.e(TAG, "CDMA Call waiting notification without a matching connection.");
188 }
189
190 public void onCdmaCallWaitingReject() {
191 // Cdma call was rejected...
192 if (mCdmaIncomingConnection != null) {
193 onDisconnect(mCdmaIncomingConnection);
194 mCdmaIncomingConnection = null;
195 } else {
196 Log.e(TAG, "CDMA Call waiting rejection without an incoming call.");
197 }
198 }
199
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700200 /**
201 * CDMA Calls have no sense of "dialing" state. For outgoing calls 3way calls we want to
202 * mimick this state so that the the UI can notify the user that there is a "dialing"
203 * call.
204 */
205 public void setCdmaOutgoing3WayCall(Connection connection) {
206 boolean wasSet = mCdmaOutgoingConnection != null;
207
208 mCdmaOutgoingConnection = connection;
209
210 // If we reset the connection, that mean we can now tell the user that the call is actually
211 // part of the conference call and move it out of the dialing state. To do this, issue a
212 // new update completely.
213 if (wasSet && mCdmaOutgoingConnection == null) {
214 onPhoneStateChanged(null);
215 }
216 }
217
Santos Cordonaf763a12013-08-19 20:04:58 -0700218 private boolean hasLiveCallInternal(HashMap<Connection, Call> map) {
219 for (Call call : map.values()) {
220 final int state = call.getState();
221 if (state == Call.State.ACTIVE ||
222 state == Call.State.CALL_WAITING ||
223 state == Call.State.CONFERENCED ||
224 state == Call.State.DIALING ||
Santos Cordonce02f3a2013-09-19 01:58:42 -0700225 state == Call.State.REDIALING ||
Santos Cordonaf763a12013-08-19 20:04:58 -0700226 state == Call.State.INCOMING ||
Christine Chen3e0f0412013-09-18 20:33:49 -0700227 state == Call.State.ONHOLD ||
228 state == Call.State.DISCONNECTING) {
Santos Cordonaf763a12013-08-19 20:04:58 -0700229 return true;
230 }
231 }
232 return false;
233 }
234
Santos Cordon2b73bd62013-08-27 14:53:43 -0700235 public boolean hasOutstandingActiveOrDialingCall() {
236 return hasOutstandingActiveOrDialingCallInternal(mCallMap) ||
237 hasOutstandingActiveOrDialingCallInternal(mConfCallMap);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700238 }
239
Santos Cordon2b73bd62013-08-27 14:53:43 -0700240 private static boolean hasOutstandingActiveOrDialingCallInternal(
241 HashMap<Connection, Call> map) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700242 for (Call call : map.values()) {
243 final int state = call.getState();
Santos Cordonce02f3a2013-09-19 01:58:42 -0700244 if (state == Call.State.ACTIVE || Call.State.isDialing(state)) {
Santos Cordon2eaff902013-08-05 04:37:55 -0700245 return true;
246 }
247 }
248
249 return false;
250 }
251
Chiao Cheng3f015c92013-09-06 15:56:27 -0700252
253 /**
254 * Handles the POST_ON_DIAL_CHARS message from the Phone (see our call to
255 * mPhone.setOnPostDialCharacter() above.)
256 *
257 * TODO: NEED TO TEST THIS SEQUENCE now that we no longer handle "dialable" key events here in
258 * the InCallScreen: we do directly to the Dialer UI instead. Similarly, we may now need to go
259 * directly to the Dialer to handle POST_ON_DIAL_CHARS too.
260 */
261 private void onPostDialChars(AsyncResult r, char ch) {
262 final Connection c = (Connection) r.result;
263
264 if (c != null) {
265 final Connection.PostDialState state = (Connection.PostDialState) r.userObj;
266
267 switch (state) {
Chiao Cheng3f015c92013-09-06 15:56:27 -0700268 case WAIT:
269 final Call call = getCallFromMap(mCallMap, c, false);
270 if (call == null) {
271 Log.i(TAG, "Call no longer exists. Skipping onPostDialWait().");
272 } else {
273 for (Listener mListener : mListeners) {
Yorke Leede41f672013-09-19 13:46:55 -0700274 mListener.onPostDialAction(state, call.getCallId(),
275 c.getRemainingPostDialString(), ch);
Chiao Cheng3f015c92013-09-06 15:56:27 -0700276 }
277 }
278 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700279 default:
Yorke Leede41f672013-09-19 13:46:55 -0700280 // This is primarily to cause the DTMFTonePlayer to play local tones.
281 // Other listeners simply perform no-ops.
282 for (Listener mListener : mListeners) {
283 mListener.onPostDialAction(state, 0, "", ch);
284 }
Chiao Cheng3f015c92013-09-06 15:56:27 -0700285 break;
286 }
287 }
288 }
289
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700290 /* package */ Call onNewRingingConnection(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700291 Log.i(TAG, "onNewRingingConnection");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700292 final Call call = getCallFromMap(mCallMap, conn, true);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700293
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700294 if (call != null) {
295 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700296
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700297 for (int i = 0; i < mListeners.size(); ++i) {
298 mListeners.get(i).onIncoming(call);
Christine Chenee09a492013-08-06 16:02:29 -0700299 }
Santos Cordon63a84242013-07-23 13:32:52 -0700300 }
Santos Cordona5d5db82013-09-15 13:00:34 -0700301
302 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700303 }
304
Santos Cordona5d5db82013-09-15 13:00:34 -0700305 private void onDisconnect(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700306 Log.i(TAG, "onDisconnect");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700307 final Call call = getCallFromMap(mCallMap, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700308
Santos Cordon995c8162013-07-29 09:22:22 -0700309 if (call != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700310 final boolean wasConferenced = call.getState() == State.CONFERENCED;
311
312 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700313
Christine Chendaf7bf62013-08-05 19:12:31 -0700314 for (int i = 0; i < mListeners.size(); ++i) {
315 mListeners.get(i).onDisconnect(call);
Santos Cordon63a84242013-07-23 13:32:52 -0700316 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700317
318 // If it was a conferenced call, we need to run the entire update
319 // to make the proper changes to parent conference calls.
320 if (wasConferenced) {
321 onPhoneStateChanged(null);
322 }
323
324 mCallMap.remove(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700325 }
326 }
327
Santos Cordona3d05142013-07-29 11:25:17 -0700328 /**
329 * Called when the phone state changes.
Santos Cordona3d05142013-07-29 11:25:17 -0700330 */
Santos Cordon995c8162013-07-29 09:22:22 -0700331 private void onPhoneStateChanged(AsyncResult r) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700332 Log.i(TAG, "onPhoneStateChanged: ");
Santos Cordon998f42b2013-08-02 16:13:12 -0700333 final List<Call> updatedCalls = Lists.newArrayList();
334 doUpdate(false, updatedCalls);
335
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700336 if (updatedCalls.size() > 0) {
337 for (int i = 0; i < mListeners.size(); ++i) {
338 mListeners.get(i).onUpdate(updatedCalls);
339 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700340 }
341 }
342
343
344 /**
345 * Go through the Calls from CallManager and return the list of calls that were updated.
346 * Or, the full list if requested.
347 */
348 private void doUpdate(boolean fullUpdate, List<Call> out) {
Santos Cordona3d05142013-07-29 11:25:17 -0700349 final List<com.android.internal.telephony.Call> telephonyCalls = Lists.newArrayList();
350 telephonyCalls.addAll(mCallManager.getRingingCalls());
351 telephonyCalls.addAll(mCallManager.getForegroundCalls());
352 telephonyCalls.addAll(mCallManager.getBackgroundCalls());
353
Santos Cordona3d05142013-07-29 11:25:17 -0700354 // Cycle through all the Connections on all the Calls. Update our Call objects
355 // to reflect any new state and send the updated Call objects to the handler service.
356 for (com.android.internal.telephony.Call telephonyCall : telephonyCalls) {
Santos Cordona3d05142013-07-29 11:25:17 -0700357
358 for (Connection connection : telephonyCall.getConnections()) {
Christine Chen3e0f0412013-09-18 20:33:49 -0700359 if (DBG) Log.d(TAG, "connection: " + connection + connection.getState());
Santos Cordona5d5db82013-09-15 13:00:34 -0700360
Santos Cordon12a03aa2013-09-12 23:34:05 -0700361 // We only send updates for live calls which are not incoming (ringing).
362 // Disconnected and incoming calls are handled by onDisconnect and
363 // onNewRingingConnection.
Christine Chen3e0f0412013-09-18 20:33:49 -0700364 boolean shouldUpdate =
365 connection.getState() !=
366 com.android.internal.telephony.Call.State.DISCONNECTED &&
367 connection.getState() !=
368 com.android.internal.telephony.Call.State.IDLE &&
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700369 !connection.getState().isRinging();
370
371 // New connections return a Call with INVALID state, which does not translate to
Santos Cordone38b1ff2013-08-07 12:12:16 -0700372 // a state in the internal.telephony.Call object. This ensures that staleness
373 // check below fails and we always add the item to the update list if it is new.
Santos Cordon12a03aa2013-09-12 23:34:05 -0700374 final Call call = getCallFromMap(mCallMap, connection, shouldUpdate /* create */);
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700375
Santos Cordon12a03aa2013-09-12 23:34:05 -0700376 if (call == null || !shouldUpdate) {
Santos Cordona5d5db82013-09-15 13:00:34 -0700377 if (DBG) Log.d(TAG, "update skipped");
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700378 continue;
379 }
Santos Cordona3d05142013-07-29 11:25:17 -0700380
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700381 boolean changed = updateCallFromConnection(call, connection, false);
Santos Cordon2b73bd62013-08-27 14:53:43 -0700382
Santos Cordone38b1ff2013-08-07 12:12:16 -0700383 if (fullUpdate || changed) {
Santos Cordon998f42b2013-08-02 16:13:12 -0700384 out.add(call);
Santos Cordona3d05142013-07-29 11:25:17 -0700385 }
386 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700387
388 // We do a second loop to address conference call scenarios. We do this as a separate
389 // loop to ensure all child calls are up to date before we start updating the parent
390 // conference calls.
391 for (Connection connection : telephonyCall.getConnections()) {
392 updateForConferenceCalls(connection, out);
393 }
394
Santos Cordona3d05142013-07-29 11:25:17 -0700395 }
Santos Cordona3d05142013-07-29 11:25:17 -0700396 }
397
Santos Cordone38b1ff2013-08-07 12:12:16 -0700398 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700399 * Checks to see if the connection is the first connection in a conference call.
400 * If it is a conference call, we will create a new Conference Call object or
401 * update the existing conference call object for that connection.
402 * If it is not a conference call but a previous associated conference call still exists,
403 * we mark it as idle and remove it from the map.
404 * In both cases above, we add the Calls to be updated to the UI.
405 * @param connection The connection object to check.
406 * @param updatedCalls List of 'updated' calls that will be sent to the UI.
407 */
408 private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
409 // We consider this connection a conference connection if the call it
Yorke Leecd3f9692013-09-14 13:51:27 -0700410 // belongs to is a multiparty call AND it is the first live connection.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700411 final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
Yorke Leecd3f9692013-09-14 13:51:27 -0700412 getEarliestLiveConnection(connection.getCall()) == connection;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700413
414 boolean changed = false;
415
416 // If this connection is the main connection for the conference call, then create or update
417 // a Call object for that conference call.
418 if (isConferenceCallConnection) {
419 final Call confCall = getCallFromMap(mConfCallMap, connection, true);
420 changed = updateCallFromConnection(confCall, connection, true);
421
422 if (changed) {
423 updatedCalls.add(confCall);
424 }
425
426 if (DBG) Log.d(TAG, "Updating a conference call: " + confCall);
427
428 // It is possible that through a conference call split, there may be lingering conference
429 // calls where this connection was the main connection. We clean those up here.
430 } else {
431 final Call oldConfCall = getCallFromMap(mConfCallMap, connection, false);
432
433 // We found a conference call for this connection, which is no longer a conference call.
434 // Kill it!
435 if (oldConfCall != null) {
436 if (DBG) Log.d(TAG, "Cleaning up an old conference call: " + oldConfCall);
437 mConfCallMap.remove(connection);
438 oldConfCall.setState(State.IDLE);
439 changed = true;
440
441 // add to the list of calls to update
442 updatedCalls.add(oldConfCall);
443 }
444 }
445
446 return changed;
447 }
448
Yorke Leecd3f9692013-09-14 13:51:27 -0700449 private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
450 final List<Connection> connections = call.getConnections();
451 final int size = connections.size();
452 Connection earliestConn = null;
453 long earliestTime = Long.MAX_VALUE;
454 for (int i = 0; i < size; i++) {
455 final Connection connection = connections.get(i);
456 if (!connection.isAlive()) continue;
457 final long time = connection.getCreateTime();
458 if (time < earliestTime) {
459 earliestTime = time;
460 earliestConn = connection;
461 }
462 }
463 return earliestConn;
464 }
465
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700466 /**
Santos Cordon69a69192013-08-22 14:25:42 -0700467 * Sets the new call state onto the call and performs some additional logic
468 * associated with setting the state.
469 */
470 private void setNewState(Call call, int newState, Connection connection) {
471 Preconditions.checkState(call.getState() != newState);
472
473 // When starting an outgoing call, we need to grab gateway information
474 // for the call, if available, and set it.
475 final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
476
Santos Cordonce02f3a2013-09-19 01:58:42 -0700477 if (Call.State.isDialing(newState)) {
Santos Cordon69a69192013-08-22 14:25:42 -0700478 if (!info.isEmpty()) {
479 call.setGatewayNumber(info.getFormattedGatewayNumber());
480 call.setGatewayPackage(info.packageName);
481 }
482 } else if (!Call.State.isConnected(newState)) {
483 mCallGatewayManager.clearGatewayData(connection);
484 }
485
486 call.setState(newState);
487 }
488
489 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700490 * Updates the Call properties to match the state of the connection object
491 * that it represents.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700492 * @param call The call object to update.
493 * @param connection The connection object from which to update call.
494 * @param isForConference There are slight differences in how we populate data for conference
495 * calls. This boolean tells us which method to use.
Santos Cordone38b1ff2013-08-07 12:12:16 -0700496 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700497 private boolean updateCallFromConnection(Call call, Connection connection,
498 boolean isForConference) {
Santos Cordone38b1ff2013-08-07 12:12:16 -0700499 boolean changed = false;
500
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700501 final int newState = translateStateFromTelephony(connection, isForConference);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700502
503 if (call.getState() != newState) {
Santos Cordon69a69192013-08-22 14:25:42 -0700504 setNewState(call, newState, connection);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700505 changed = true;
506 }
507
Santos Cordone38b1ff2013-08-07 12:12:16 -0700508 final Call.DisconnectCause newDisconnectCause =
509 translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
510 if (call.getDisconnectCause() != newDisconnectCause) {
511 call.setDisconnectCause(newDisconnectCause);
512 changed = true;
513 }
514
Santos Cordonbbe8ecf2013-08-13 15:26:18 -0700515 final long oldConnectTime = call.getConnectTime();
516 if (oldConnectTime != connection.getConnectTime()) {
517 call.setConnectTime(connection.getConnectTime());
518 changed = true;
519 }
520
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700521 if (!isForConference) {
Santos Cordon69a69192013-08-22 14:25:42 -0700522 // Number
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700523 final String oldNumber = call.getNumber();
Santos Cordon69a69192013-08-22 14:25:42 -0700524 String newNumber = connection.getAddress();
525 RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
526 if (!info.isEmpty()) {
527 newNumber = info.trueNumber;
528 }
529 if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
530 call.setNumber(newNumber);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700531 changed = true;
532 }
533
Santos Cordon69a69192013-08-22 14:25:42 -0700534 // Number presentation
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700535 final int newNumberPresentation = connection.getNumberPresentation();
536 if (call.getNumberPresentation() != newNumberPresentation) {
537 call.setNumberPresentation(newNumberPresentation);
538 changed = true;
539 }
540
Santos Cordon69a69192013-08-22 14:25:42 -0700541 // Name
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700542 final String oldCnapName = call.getCnapName();
543 if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
544 call.setCnapName(connection.getCnapName());
545 changed = true;
546 }
Santos Cordon69a69192013-08-22 14:25:42 -0700547
548 // Name Presentation
549 final int newCnapNamePresentation = connection.getCnapNamePresentation();
550 if (call.getCnapNamePresentation() != newCnapNamePresentation) {
551 call.setCnapNamePresentation(newCnapNamePresentation);
552 changed = true;
553 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700554 } else {
555
556 // update the list of children by:
557 // 1) Saving the old set
558 // 2) Removing all children
559 // 3) Adding the correct children into the Call
560 // 4) Comparing the new children set with the old children set
561 ImmutableSortedSet<Integer> oldSet = call.getChildCallIds();
562 call.removeAllChildren();
563
564 if (connection.getCall() != null) {
565 for (Connection childConn : connection.getCall().getConnections()) {
566 final Call childCall = getCallFromMap(mCallMap, childConn, false);
567 if (childCall != null && childConn.isAlive()) {
568 call.addChildId(childCall.getCallId());
569 }
570 }
571 }
Christine Chen45277022013-09-05 10:55:37 -0700572 changed |= !oldSet.equals(call.getChildCallIds());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700573 }
574
Santos Cordoneead6ec2013-08-07 22:16:33 -0700575 /**
576 * !!! Uses values from connection and call collected above so this part must be last !!!
577 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700578 final int newCapabilities = getCapabilitiesFor(connection, call, isForConference);
Santos Cordon26e7b242013-08-07 21:15:45 -0700579 if (call.getCapabilities() != newCapabilities) {
580 call.setCapabilities(newCapabilities);
581 changed = true;
582 }
583
Santos Cordone38b1ff2013-08-07 12:12:16 -0700584 return changed;
585 }
586
Santos Cordon26e7b242013-08-07 21:15:45 -0700587 /**
588 * Returns a mask of capabilities for the connection such as merge, hold, etc.
589 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700590 private int getCapabilitiesFor(Connection connection, Call call, boolean isForConference) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700591 final boolean callIsActive = (call.getState() == Call.State.ACTIVE);
592 final Phone phone = connection.getCall().getPhone();
593
Santos Cordoneead6ec2013-08-07 22:16:33 -0700594 boolean canAddCall = false;
595 boolean canMergeCall = false;
596 boolean canSwapCall = false;
Yorke Lee814da302013-08-30 16:01:07 -0700597 boolean canRespondViaText = false;
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700598 boolean canMute = false;
599
600 final boolean supportHold = PhoneUtils.okToSupportHold(mCallManager);
Christine Chen94853bc2013-09-17 16:53:33 -0700601 final boolean canHold = (supportHold ? PhoneUtils.okToHoldCall(mCallManager) : false);
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700602 final boolean genericConf = isForConference &&
603 (connection.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
Santos Cordoneead6ec2013-08-07 22:16:33 -0700604
605 // only applies to active calls
606 if (callIsActive) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700607 canMergeCall = PhoneUtils.okToMergeCalls(mCallManager);
608 canSwapCall = PhoneUtils.okToSwapCalls(mCallManager);
609 }
610
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700611 canAddCall = PhoneUtils.okToAddCall(mCallManager);
612
613 // "Mute": only enabled when the foreground call is ACTIVE.
614 // (It's meaningless while on hold, or while DIALING/ALERTING.)
615 // It's also explicitly disabled during emergency calls or if
616 // emergency callback mode (ECM) is active.
617 boolean isEmergencyCall = false;
618 if (connection != null) {
619 isEmergencyCall = PhoneNumberUtils.isLocalEmergencyNumber(connection.getAddress(),
620 phone.getContext());
621 }
622 boolean isECM = PhoneUtils.isPhoneInEcm(phone);
623 if (isEmergencyCall || isECM) { // disable "Mute" item
624 canMute = false;
625 } else {
626 canMute = callIsActive;
627 }
628
Yorke Lee814da302013-08-30 16:01:07 -0700629 canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
630 connection);
631
Santos Cordoneead6ec2013-08-07 22:16:33 -0700632 // special rules section!
633 // CDMA always has Add
634 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
635 canAddCall = true;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700636 }
637
Santos Cordon26e7b242013-08-07 21:15:45 -0700638 int retval = 0x0;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700639 if (canHold) {
Santos Cordon26e7b242013-08-07 21:15:45 -0700640 retval |= Capabilities.HOLD;
641 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700642 if (supportHold) {
643 retval |= Capabilities.SUPPORT_HOLD;
644 }
Santos Cordoneead6ec2013-08-07 22:16:33 -0700645 if (canAddCall) {
646 retval |= Capabilities.ADD_CALL;
647 }
648 if (canMergeCall) {
649 retval |= Capabilities.MERGE_CALLS;
650 }
651 if (canSwapCall) {
652 retval |= Capabilities.SWAP_CALLS;
653 }
Yorke Lee814da302013-08-30 16:01:07 -0700654 if (canRespondViaText) {
655 retval |= Capabilities.RESPOND_VIA_TEXT;
656 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700657 if (canMute) {
658 retval |= Capabilities.MUTE;
659 }
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700660 if (genericConf) {
661 retval |= Capabilities.GENERIC_CONFERENCE;
662 }
Yorke Lee814da302013-08-30 16:01:07 -0700663
Santos Cordon26e7b242013-08-07 21:15:45 -0700664 return retval;
665 }
666
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700667 /**
668 * Returns true if the Connection is part of a multiparty call.
669 * We do this by checking the isMultiparty() method of the telephony.Call object and also
670 * checking to see if more than one of it's children is alive.
671 */
672 private boolean isPartOfLiveConferenceCall(Connection connection) {
673 if (connection.getCall() != null && connection.getCall().isMultiparty()) {
674 int count = 0;
675 for (Connection currConn : connection.getCall().getConnections()) {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700676
677 // Only count connections which are alive and never cound the special
678 // "dialing" 3way call for CDMA calls.
679 if (currConn.isAlive() && currConn != mCdmaOutgoingConnection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700680 count++;
681 if (count >= 2) {
682 return true;
683 }
684 }
685 }
686 }
687 return false;
688 }
689
690 private int translateStateFromTelephony(Connection connection, boolean isForConference) {
691
Santos Cordonce02f3a2013-09-19 01:58:42 -0700692 com.android.internal.telephony.Call.State connState = connection.getState();
693
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700694 // For the "fake" outgoing CDMA call, we need to always treat it as an outgoing call.
695 if (mCdmaOutgoingConnection == connection) {
Santos Cordonce02f3a2013-09-19 01:58:42 -0700696 connState = com.android.internal.telephony.Call.State.DIALING;
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700697 }
698
Santos Cordona3d05142013-07-29 11:25:17 -0700699 int retval = State.IDLE;
Santos Cordonce02f3a2013-09-19 01:58:42 -0700700 switch (connState) {
Santos Cordona3d05142013-07-29 11:25:17 -0700701 case ACTIVE:
702 retval = State.ACTIVE;
703 break;
704 case INCOMING:
705 retval = State.INCOMING;
706 break;
707 case DIALING:
708 case ALERTING:
Santos Cordonce02f3a2013-09-19 01:58:42 -0700709 if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
710 retval = State.REDIALING;
711 } else {
712 retval = State.DIALING;
713 }
Santos Cordona3d05142013-07-29 11:25:17 -0700714 break;
715 case WAITING:
716 retval = State.CALL_WAITING;
717 break;
718 case HOLDING:
719 retval = State.ONHOLD;
720 break;
Santos Cordone38b1ff2013-08-07 12:12:16 -0700721 case DISCONNECTING:
Christine Chen3e0f0412013-09-18 20:33:49 -0700722 retval = State.DISCONNECTING;
723 break;
724 case DISCONNECTED:
Santos Cordone38b1ff2013-08-07 12:12:16 -0700725 retval = State.DISCONNECTED;
Santos Cordona3d05142013-07-29 11:25:17 -0700726 default:
727 }
728
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700729 // If we are dealing with a potential child call (not the parent conference call),
730 // the check to see if we have to set the state to CONFERENCED.
731 if (!isForConference) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700732 // if the connection is part of a multiparty call, and it is live,
733 // annotate it with CONFERENCED state instead.
734 if (isPartOfLiveConferenceCall(connection) && connection.isAlive()) {
735 return State.CONFERENCED;
736 }
737 }
738
Santos Cordona3d05142013-07-29 11:25:17 -0700739 return retval;
Santos Cordon995c8162013-07-29 09:22:22 -0700740 }
741
Santos Cordone38b1ff2013-08-07 12:12:16 -0700742 private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
743 ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
744 .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
745 .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
746 .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
747 Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
748 .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
749 Call.DisconnectCause.CDMA_ACCESS_FAILURE)
750 .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
751 .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
752 .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
753 Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
754 .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
755 Call.DisconnectCause.CDMA_NOT_EMERGENCY)
756 .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
757 .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
758 .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
759 Call.DisconnectCause.CDMA_RETRY_ORDER)
760 .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
761 .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
762 .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
763 .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
764 Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
765 .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
766 Call.DisconnectCause.CS_RESTRICTED_NORMAL)
767 .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
768 Call.DisconnectCause.ERROR_UNSPECIFIED)
769 .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
770 .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
771 .put(Connection.DisconnectCause.INCOMING_MISSED,
772 Call.DisconnectCause.INCOMING_MISSED)
773 .put(Connection.DisconnectCause.INCOMING_REJECTED,
774 Call.DisconnectCause.INCOMING_REJECTED)
775 .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
776 Call.DisconnectCause.INVALID_CREDENTIALS)
777 .put(Connection.DisconnectCause.INVALID_NUMBER,
778 Call.DisconnectCause.INVALID_NUMBER)
779 .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
780 .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
781 .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
782 .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
783 .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
784 .put(Connection.DisconnectCause.NOT_DISCONNECTED,
785 Call.DisconnectCause.NOT_DISCONNECTED)
786 .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
787 Call.DisconnectCause.NUMBER_UNREACHABLE)
788 .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
789 .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
790 .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
791 .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
792 .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
793 Call.DisconnectCause.SERVER_UNREACHABLE)
794 .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
795 .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
796 Call.DisconnectCause.UNOBTAINABLE_NUMBER)
797 .build();
798
799 private Call.DisconnectCause translateDisconnectCauseFromTelephony(
800 Connection.DisconnectCause causeSource) {
801
802 if (CAUSE_MAP.containsKey(causeSource)) {
803 return CAUSE_MAP.get(causeSource);
804 }
805
806 return Call.DisconnectCause.UNKNOWN;
807 }
808
Santos Cordon63a84242013-07-23 13:32:52 -0700809 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700810 * Gets an existing callId for a connection, or creates one if none exists.
811 * This function does NOT set any of the Connection data onto the Call class.
812 * A separate call to updateCallFromConnection must be made for that purpose.
Santos Cordon63a84242013-07-23 13:32:52 -0700813 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700814 private Call getCallFromMap(HashMap<Connection, Call> map, Connection conn,
815 boolean createIfMissing) {
Santos Cordon995c8162013-07-29 09:22:22 -0700816 Call call = null;
Santos Cordon63a84242013-07-23 13:32:52 -0700817
818 // Find the call id or create if missing and requested.
819 if (conn != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700820 if (map.containsKey(conn)) {
821 call = map.get(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700822 } else if (createIfMissing) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700823 call = createNewCall();
824 map.put(conn, call);
Santos Cordon63a84242013-07-23 13:32:52 -0700825 }
826 }
Santos Cordon995c8162013-07-29 09:22:22 -0700827 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700828 }
829
830 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700831 * Creates a brand new connection for the call.
832 */
833 private Call createNewCall() {
834 int callId;
835 int newNextCallId;
836 do {
837 callId = mNextCallId.get();
838
839 // protect against overflow
840 newNextCallId = (callId == Integer.MAX_VALUE ?
841 CALL_ID_START_VALUE : callId + 1);
842
843 // Keep looping if the change was not atomic OR the value is already taken.
844 // The call to containsValue() is linear, however, most devices support a
845 // maximum of 7 connections so it's not expensive.
846 } while (!mNextCallId.compareAndSet(callId, newNextCallId));
847
848 return new Call(callId);
849 }
850
851 /**
Santos Cordon63a84242013-07-23 13:32:52 -0700852 * Listener interface for changes to Calls.
853 */
854 public interface Listener {
Santos Cordon995c8162013-07-29 09:22:22 -0700855 void onDisconnect(Call call);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700856 void onIncoming(Call call);
857 void onUpdate(List<Call> calls);
Yorke Leede41f672013-09-19 13:46:55 -0700858 void onPostDialAction(Connection.PostDialState state, int callId, String remainingChars,
859 char c);
Santos Cordon63a84242013-07-23 13:32:52 -0700860 }
Santos Cordon249efd02013-08-05 03:33:56 -0700861
862 /**
863 * Result class for accessing a call by connection.
864 */
865 public static class CallResult {
866 public Call mCall;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700867 public Call mActionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700868 public Connection mConnection;
869
870 private CallResult(Call call, Connection connection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700871 this(call, call, connection);
872 }
873
874 private CallResult(Call call, Call actionableCall, Connection connection) {
Santos Cordon249efd02013-08-05 03:33:56 -0700875 mCall = call;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700876 mActionableCall = actionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700877 mConnection = connection;
878 }
879
880 public Call getCall() {
881 return mCall;
882 }
883
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700884 // The call that should be used for call actions like hanging up.
885 public Call getActionableCall() {
886 return mActionableCall;
887 }
888
Santos Cordon249efd02013-08-05 03:33:56 -0700889 public Connection getConnection() {
890 return mConnection;
891 }
892 }
Santos Cordon63a84242013-07-23 13:32:52 -0700893}