blob: 23f442a0297a8d75326f7f7135d0f7a87e695c1e [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;
Santos Cordon54fdb592013-09-19 05:16:18 -0700120 case CallStateMonitor.PHONE_UNKNOWN_CONNECTION_APPEARED:
121 // fall through
Santos Cordon995c8162013-07-29 09:22:22 -0700122 case CallStateMonitor.PHONE_STATE_CHANGED:
123 onPhoneStateChanged((AsyncResult) msg.obj);
124 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700125 case CallStateMonitor.PHONE_ON_DIAL_CHARS:
126 onPostDialChars((AsyncResult) msg.obj, (char) msg.arg1);
127 break;
Santos Cordon63a84242013-07-23 13:32:52 -0700128 default:
129 break;
130 }
131 }
132
Christine Chendaf7bf62013-08-05 19:12:31 -0700133 public void addListener(Listener listener) {
Santos Cordon63a84242013-07-23 13:32:52 -0700134 Preconditions.checkNotNull(listener);
Christine Chendaf7bf62013-08-05 19:12:31 -0700135 Preconditions.checkNotNull(mListeners);
Christine Chen4748abd2013-08-07 15:44:15 -0700136 if (!mListeners.contains(listener)) {
137 mListeners.add(listener);
138 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700139 }
140
141 public List<Call> getFullList() {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700142 final List<Call> calls =
143 Lists.newArrayListWithCapacity(mCallMap.size() + mConfCallMap.size());
144 calls.addAll(mCallMap.values());
145 calls.addAll(mConfCallMap.values());
146 return calls;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 }
148
Santos Cordon249efd02013-08-05 03:33:56 -0700149 public CallResult getCallWithId(int callId) {
150 // max 8 connections, so this should be fast even through we are traversing the entire map.
151 for (Entry<Connection, Call> entry : mCallMap.entrySet()) {
152 if (entry.getValue().getCallId() == callId) {
153 return new CallResult(entry.getValue(), entry.getKey());
154 }
155 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700156
157 for (Entry<Connection, Call> entry : mConfCallMap.entrySet()) {
158 if (entry.getValue().getCallId() == callId) {
Christine Chen69050202013-09-14 15:36:35 -0700159 return new CallResult(entry.getValue(), entry.getKey());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700160 }
161 }
Santos Cordon249efd02013-08-05 03:33:56 -0700162 return null;
163 }
164
Santos Cordonaf763a12013-08-19 20:04:58 -0700165 public boolean hasLiveCall() {
166 return hasLiveCallInternal(mCallMap) ||
167 hasLiveCallInternal(mConfCallMap);
168 }
169
Santos Cordona5d5db82013-09-15 13:00:34 -0700170 public void onCdmaCallWaiting(CdmaCallWaitingNotification callWaitingInfo) {
171 // We dont get the traditional onIncomingCall notification for cdma call waiting,
172 // but the Connection does actually exist. We need to find it in the set of ringing calls
173 // and pass it through our normal incoming logic.
174 final com.android.internal.telephony.Call teleCall =
175 mCallManager.getFirstActiveRingingCall();
176
177 if (teleCall.getState() == com.android.internal.telephony.Call.State.WAITING) {
178 Connection connection = teleCall.getLatestConnection();
179
180 if (connection != null) {
181 String number = connection.getAddress();
182 if (number != null && number.equals(callWaitingInfo.number)) {
183 Call call = onNewRingingConnection(connection);
184 mCdmaIncomingConnection = connection;
185 return;
186 }
187 }
188 }
189
190 Log.e(TAG, "CDMA Call waiting notification without a matching connection.");
191 }
192
193 public void onCdmaCallWaitingReject() {
194 // Cdma call was rejected...
195 if (mCdmaIncomingConnection != null) {
196 onDisconnect(mCdmaIncomingConnection);
197 mCdmaIncomingConnection = null;
198 } else {
199 Log.e(TAG, "CDMA Call waiting rejection without an incoming call.");
200 }
201 }
202
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700203 /**
204 * CDMA Calls have no sense of "dialing" state. For outgoing calls 3way calls we want to
205 * mimick this state so that the the UI can notify the user that there is a "dialing"
206 * call.
207 */
208 public void setCdmaOutgoing3WayCall(Connection connection) {
209 boolean wasSet = mCdmaOutgoingConnection != null;
210
211 mCdmaOutgoingConnection = connection;
212
213 // If we reset the connection, that mean we can now tell the user that the call is actually
214 // part of the conference call and move it out of the dialing state. To do this, issue a
215 // new update completely.
216 if (wasSet && mCdmaOutgoingConnection == null) {
217 onPhoneStateChanged(null);
218 }
219 }
220
Santos Cordonaf763a12013-08-19 20:04:58 -0700221 private boolean hasLiveCallInternal(HashMap<Connection, Call> map) {
222 for (Call call : map.values()) {
223 final int state = call.getState();
224 if (state == Call.State.ACTIVE ||
225 state == Call.State.CALL_WAITING ||
226 state == Call.State.CONFERENCED ||
227 state == Call.State.DIALING ||
Santos Cordonce02f3a2013-09-19 01:58:42 -0700228 state == Call.State.REDIALING ||
Santos Cordonaf763a12013-08-19 20:04:58 -0700229 state == Call.State.INCOMING ||
Christine Chen3e0f0412013-09-18 20:33:49 -0700230 state == Call.State.ONHOLD ||
231 state == Call.State.DISCONNECTING) {
Santos Cordonaf763a12013-08-19 20:04:58 -0700232 return true;
233 }
234 }
235 return false;
236 }
237
Santos Cordon2b73bd62013-08-27 14:53:43 -0700238 public boolean hasOutstandingActiveOrDialingCall() {
239 return hasOutstandingActiveOrDialingCallInternal(mCallMap) ||
240 hasOutstandingActiveOrDialingCallInternal(mConfCallMap);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700241 }
242
Santos Cordon2b73bd62013-08-27 14:53:43 -0700243 private static boolean hasOutstandingActiveOrDialingCallInternal(
244 HashMap<Connection, Call> map) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700245 for (Call call : map.values()) {
246 final int state = call.getState();
Santos Cordonce02f3a2013-09-19 01:58:42 -0700247 if (state == Call.State.ACTIVE || Call.State.isDialing(state)) {
Santos Cordon2eaff902013-08-05 04:37:55 -0700248 return true;
249 }
250 }
251
252 return false;
253 }
254
Chiao Cheng3f015c92013-09-06 15:56:27 -0700255
256 /**
257 * Handles the POST_ON_DIAL_CHARS message from the Phone (see our call to
258 * mPhone.setOnPostDialCharacter() above.)
259 *
260 * TODO: NEED TO TEST THIS SEQUENCE now that we no longer handle "dialable" key events here in
261 * the InCallScreen: we do directly to the Dialer UI instead. Similarly, we may now need to go
262 * directly to the Dialer to handle POST_ON_DIAL_CHARS too.
263 */
264 private void onPostDialChars(AsyncResult r, char ch) {
265 final Connection c = (Connection) r.result;
266
267 if (c != null) {
268 final Connection.PostDialState state = (Connection.PostDialState) r.userObj;
269
270 switch (state) {
Chiao Cheng3f015c92013-09-06 15:56:27 -0700271 case WAIT:
272 final Call call = getCallFromMap(mCallMap, c, false);
273 if (call == null) {
274 Log.i(TAG, "Call no longer exists. Skipping onPostDialWait().");
275 } else {
276 for (Listener mListener : mListeners) {
Yorke Leede41f672013-09-19 13:46:55 -0700277 mListener.onPostDialAction(state, call.getCallId(),
278 c.getRemainingPostDialString(), ch);
Chiao Cheng3f015c92013-09-06 15:56:27 -0700279 }
280 }
281 break;
Chiao Cheng3f015c92013-09-06 15:56:27 -0700282 default:
Yorke Leede41f672013-09-19 13:46:55 -0700283 // This is primarily to cause the DTMFTonePlayer to play local tones.
284 // Other listeners simply perform no-ops.
285 for (Listener mListener : mListeners) {
286 mListener.onPostDialAction(state, 0, "", ch);
287 }
Chiao Cheng3f015c92013-09-06 15:56:27 -0700288 break;
289 }
290 }
291 }
292
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700293 /* package */ Call onNewRingingConnection(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700294 Log.i(TAG, "onNewRingingConnection");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700295 final Call call = getCallFromMap(mCallMap, conn, true);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700296
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700297 if (call != null) {
298 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700299
Christine Chenfb0cc2b2013-09-16 14:21:29 -0700300 for (int i = 0; i < mListeners.size(); ++i) {
301 mListeners.get(i).onIncoming(call);
Christine Chenee09a492013-08-06 16:02:29 -0700302 }
Santos Cordon63a84242013-07-23 13:32:52 -0700303 }
Santos Cordona5d5db82013-09-15 13:00:34 -0700304
305 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700306 }
307
Santos Cordona5d5db82013-09-15 13:00:34 -0700308 private void onDisconnect(Connection conn) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700309 Log.i(TAG, "onDisconnect");
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700310 final Call call = getCallFromMap(mCallMap, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700311
Santos Cordon995c8162013-07-29 09:22:22 -0700312 if (call != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700313 final boolean wasConferenced = call.getState() == State.CONFERENCED;
314
315 updateCallFromConnection(call, conn, false);
Santos Cordon63a84242013-07-23 13:32:52 -0700316
Christine Chendaf7bf62013-08-05 19:12:31 -0700317 for (int i = 0; i < mListeners.size(); ++i) {
318 mListeners.get(i).onDisconnect(call);
Santos Cordon63a84242013-07-23 13:32:52 -0700319 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700320
321 // If it was a conferenced call, we need to run the entire update
322 // to make the proper changes to parent conference calls.
323 if (wasConferenced) {
324 onPhoneStateChanged(null);
325 }
326
327 mCallMap.remove(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700328 }
329 }
330
Santos Cordona3d05142013-07-29 11:25:17 -0700331 /**
332 * Called when the phone state changes.
Santos Cordona3d05142013-07-29 11:25:17 -0700333 */
Santos Cordon995c8162013-07-29 09:22:22 -0700334 private void onPhoneStateChanged(AsyncResult r) {
Santos Cordon2b73bd62013-08-27 14:53:43 -0700335 Log.i(TAG, "onPhoneStateChanged: ");
Santos Cordon998f42b2013-08-02 16:13:12 -0700336 final List<Call> updatedCalls = Lists.newArrayList();
337 doUpdate(false, updatedCalls);
338
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700339 if (updatedCalls.size() > 0) {
340 for (int i = 0; i < mListeners.size(); ++i) {
341 mListeners.get(i).onUpdate(updatedCalls);
342 }
Santos Cordon998f42b2013-08-02 16:13:12 -0700343 }
344 }
345
346
347 /**
348 * Go through the Calls from CallManager and return the list of calls that were updated.
349 * Or, the full list if requested.
350 */
351 private void doUpdate(boolean fullUpdate, List<Call> out) {
Santos Cordona3d05142013-07-29 11:25:17 -0700352 final List<com.android.internal.telephony.Call> telephonyCalls = Lists.newArrayList();
353 telephonyCalls.addAll(mCallManager.getRingingCalls());
354 telephonyCalls.addAll(mCallManager.getForegroundCalls());
355 telephonyCalls.addAll(mCallManager.getBackgroundCalls());
356
Santos Cordona3d05142013-07-29 11:25:17 -0700357 // Cycle through all the Connections on all the Calls. Update our Call objects
358 // to reflect any new state and send the updated Call objects to the handler service.
359 for (com.android.internal.telephony.Call telephonyCall : telephonyCalls) {
Santos Cordona3d05142013-07-29 11:25:17 -0700360
361 for (Connection connection : telephonyCall.getConnections()) {
Christine Chen3e0f0412013-09-18 20:33:49 -0700362 if (DBG) Log.d(TAG, "connection: " + connection + connection.getState());
Santos Cordona5d5db82013-09-15 13:00:34 -0700363
Santos Cordon12a03aa2013-09-12 23:34:05 -0700364 // We only send updates for live calls which are not incoming (ringing).
365 // Disconnected and incoming calls are handled by onDisconnect and
366 // onNewRingingConnection.
Christine Chen3e0f0412013-09-18 20:33:49 -0700367 boolean shouldUpdate =
368 connection.getState() !=
369 com.android.internal.telephony.Call.State.DISCONNECTED &&
370 connection.getState() !=
371 com.android.internal.telephony.Call.State.IDLE &&
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700372 !connection.getState().isRinging();
373
374 // New connections return a Call with INVALID state, which does not translate to
Santos Cordone38b1ff2013-08-07 12:12:16 -0700375 // a state in the internal.telephony.Call object. This ensures that staleness
376 // check below fails and we always add the item to the update list if it is new.
Santos Cordon12a03aa2013-09-12 23:34:05 -0700377 final Call call = getCallFromMap(mCallMap, connection, shouldUpdate /* create */);
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700378
Santos Cordon12a03aa2013-09-12 23:34:05 -0700379 if (call == null || !shouldUpdate) {
Santos Cordona5d5db82013-09-15 13:00:34 -0700380 if (DBG) Log.d(TAG, "update skipped");
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700381 continue;
382 }
Santos Cordona3d05142013-07-29 11:25:17 -0700383
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700384 boolean changed = updateCallFromConnection(call, connection, false);
Santos Cordon2b73bd62013-08-27 14:53:43 -0700385
Santos Cordone38b1ff2013-08-07 12:12:16 -0700386 if (fullUpdate || changed) {
Santos Cordon998f42b2013-08-02 16:13:12 -0700387 out.add(call);
Santos Cordona3d05142013-07-29 11:25:17 -0700388 }
389 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700390
391 // We do a second loop to address conference call scenarios. We do this as a separate
392 // loop to ensure all child calls are up to date before we start updating the parent
393 // conference calls.
394 for (Connection connection : telephonyCall.getConnections()) {
395 updateForConferenceCalls(connection, out);
396 }
397
Santos Cordona3d05142013-07-29 11:25:17 -0700398 }
Santos Cordona3d05142013-07-29 11:25:17 -0700399 }
400
Santos Cordone38b1ff2013-08-07 12:12:16 -0700401 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700402 * Checks to see if the connection is the first connection in a conference call.
403 * If it is a conference call, we will create a new Conference Call object or
404 * update the existing conference call object for that connection.
405 * If it is not a conference call but a previous associated conference call still exists,
406 * we mark it as idle and remove it from the map.
407 * In both cases above, we add the Calls to be updated to the UI.
408 * @param connection The connection object to check.
409 * @param updatedCalls List of 'updated' calls that will be sent to the UI.
410 */
411 private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
412 // We consider this connection a conference connection if the call it
Yorke Leecd3f9692013-09-14 13:51:27 -0700413 // belongs to is a multiparty call AND it is the first live connection.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700414 final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
Yorke Leecd3f9692013-09-14 13:51:27 -0700415 getEarliestLiveConnection(connection.getCall()) == connection;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700416
417 boolean changed = false;
418
419 // If this connection is the main connection for the conference call, then create or update
420 // a Call object for that conference call.
421 if (isConferenceCallConnection) {
422 final Call confCall = getCallFromMap(mConfCallMap, connection, true);
423 changed = updateCallFromConnection(confCall, connection, true);
424
425 if (changed) {
426 updatedCalls.add(confCall);
427 }
428
429 if (DBG) Log.d(TAG, "Updating a conference call: " + confCall);
430
431 // It is possible that through a conference call split, there may be lingering conference
432 // calls where this connection was the main connection. We clean those up here.
433 } else {
434 final Call oldConfCall = getCallFromMap(mConfCallMap, connection, false);
435
436 // We found a conference call for this connection, which is no longer a conference call.
437 // Kill it!
438 if (oldConfCall != null) {
439 if (DBG) Log.d(TAG, "Cleaning up an old conference call: " + oldConfCall);
440 mConfCallMap.remove(connection);
441 oldConfCall.setState(State.IDLE);
442 changed = true;
443
444 // add to the list of calls to update
445 updatedCalls.add(oldConfCall);
446 }
447 }
448
449 return changed;
450 }
451
Yorke Leecd3f9692013-09-14 13:51:27 -0700452 private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
453 final List<Connection> connections = call.getConnections();
454 final int size = connections.size();
455 Connection earliestConn = null;
456 long earliestTime = Long.MAX_VALUE;
457 for (int i = 0; i < size; i++) {
458 final Connection connection = connections.get(i);
459 if (!connection.isAlive()) continue;
460 final long time = connection.getCreateTime();
461 if (time < earliestTime) {
462 earliestTime = time;
463 earliestConn = connection;
464 }
465 }
466 return earliestConn;
467 }
468
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700469 /**
Santos Cordon69a69192013-08-22 14:25:42 -0700470 * Sets the new call state onto the call and performs some additional logic
471 * associated with setting the state.
472 */
473 private void setNewState(Call call, int newState, Connection connection) {
474 Preconditions.checkState(call.getState() != newState);
475
476 // When starting an outgoing call, we need to grab gateway information
477 // for the call, if available, and set it.
478 final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
479
Santos Cordonce02f3a2013-09-19 01:58:42 -0700480 if (Call.State.isDialing(newState)) {
Santos Cordon69a69192013-08-22 14:25:42 -0700481 if (!info.isEmpty()) {
482 call.setGatewayNumber(info.getFormattedGatewayNumber());
483 call.setGatewayPackage(info.packageName);
484 }
485 } else if (!Call.State.isConnected(newState)) {
486 mCallGatewayManager.clearGatewayData(connection);
487 }
488
489 call.setState(newState);
490 }
491
492 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700493 * Updates the Call properties to match the state of the connection object
494 * that it represents.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700495 * @param call The call object to update.
496 * @param connection The connection object from which to update call.
497 * @param isForConference There are slight differences in how we populate data for conference
498 * calls. This boolean tells us which method to use.
Santos Cordone38b1ff2013-08-07 12:12:16 -0700499 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700500 private boolean updateCallFromConnection(Call call, Connection connection,
501 boolean isForConference) {
Santos Cordone38b1ff2013-08-07 12:12:16 -0700502 boolean changed = false;
503
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700504 final int newState = translateStateFromTelephony(connection, isForConference);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700505
506 if (call.getState() != newState) {
Santos Cordon69a69192013-08-22 14:25:42 -0700507 setNewState(call, newState, connection);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700508 changed = true;
509 }
510
Santos Cordone38b1ff2013-08-07 12:12:16 -0700511 final Call.DisconnectCause newDisconnectCause =
512 translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
513 if (call.getDisconnectCause() != newDisconnectCause) {
514 call.setDisconnectCause(newDisconnectCause);
515 changed = true;
516 }
517
Santos Cordonbbe8ecf2013-08-13 15:26:18 -0700518 final long oldConnectTime = call.getConnectTime();
519 if (oldConnectTime != connection.getConnectTime()) {
520 call.setConnectTime(connection.getConnectTime());
521 changed = true;
522 }
523
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700524 if (!isForConference) {
Santos Cordon69a69192013-08-22 14:25:42 -0700525 // Number
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700526 final String oldNumber = call.getNumber();
Santos Cordon69a69192013-08-22 14:25:42 -0700527 String newNumber = connection.getAddress();
528 RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
529 if (!info.isEmpty()) {
530 newNumber = info.trueNumber;
531 }
532 if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
533 call.setNumber(newNumber);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700534 changed = true;
535 }
536
Santos Cordon69a69192013-08-22 14:25:42 -0700537 // Number presentation
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700538 final int newNumberPresentation = connection.getNumberPresentation();
539 if (call.getNumberPresentation() != newNumberPresentation) {
540 call.setNumberPresentation(newNumberPresentation);
541 changed = true;
542 }
543
Santos Cordon69a69192013-08-22 14:25:42 -0700544 // Name
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700545 final String oldCnapName = call.getCnapName();
546 if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
547 call.setCnapName(connection.getCnapName());
548 changed = true;
549 }
Santos Cordon69a69192013-08-22 14:25:42 -0700550
551 // Name Presentation
552 final int newCnapNamePresentation = connection.getCnapNamePresentation();
553 if (call.getCnapNamePresentation() != newCnapNamePresentation) {
554 call.setCnapNamePresentation(newCnapNamePresentation);
555 changed = true;
556 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700557 } else {
558
559 // update the list of children by:
560 // 1) Saving the old set
561 // 2) Removing all children
562 // 3) Adding the correct children into the Call
563 // 4) Comparing the new children set with the old children set
564 ImmutableSortedSet<Integer> oldSet = call.getChildCallIds();
565 call.removeAllChildren();
566
567 if (connection.getCall() != null) {
568 for (Connection childConn : connection.getCall().getConnections()) {
569 final Call childCall = getCallFromMap(mCallMap, childConn, false);
570 if (childCall != null && childConn.isAlive()) {
571 call.addChildId(childCall.getCallId());
572 }
573 }
574 }
Christine Chen45277022013-09-05 10:55:37 -0700575 changed |= !oldSet.equals(call.getChildCallIds());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700576 }
577
Santos Cordoneead6ec2013-08-07 22:16:33 -0700578 /**
579 * !!! Uses values from connection and call collected above so this part must be last !!!
580 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700581 final int newCapabilities = getCapabilitiesFor(connection, call, isForConference);
Santos Cordon26e7b242013-08-07 21:15:45 -0700582 if (call.getCapabilities() != newCapabilities) {
583 call.setCapabilities(newCapabilities);
584 changed = true;
585 }
586
Santos Cordone38b1ff2013-08-07 12:12:16 -0700587 return changed;
588 }
589
Santos Cordon26e7b242013-08-07 21:15:45 -0700590 /**
591 * Returns a mask of capabilities for the connection such as merge, hold, etc.
592 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700593 private int getCapabilitiesFor(Connection connection, Call call, boolean isForConference) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700594 final boolean callIsActive = (call.getState() == Call.State.ACTIVE);
595 final Phone phone = connection.getCall().getPhone();
596
Santos Cordoneead6ec2013-08-07 22:16:33 -0700597 boolean canAddCall = false;
598 boolean canMergeCall = false;
599 boolean canSwapCall = false;
Yorke Lee814da302013-08-30 16:01:07 -0700600 boolean canRespondViaText = false;
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700601 boolean canMute = false;
602
603 final boolean supportHold = PhoneUtils.okToSupportHold(mCallManager);
Christine Chen94853bc2013-09-17 16:53:33 -0700604 final boolean canHold = (supportHold ? PhoneUtils.okToHoldCall(mCallManager) : false);
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700605 final boolean genericConf = isForConference &&
606 (connection.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
Santos Cordoneead6ec2013-08-07 22:16:33 -0700607
608 // only applies to active calls
609 if (callIsActive) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700610 canMergeCall = PhoneUtils.okToMergeCalls(mCallManager);
611 canSwapCall = PhoneUtils.okToSwapCalls(mCallManager);
612 }
613
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700614 canAddCall = PhoneUtils.okToAddCall(mCallManager);
615
616 // "Mute": only enabled when the foreground call is ACTIVE.
617 // (It's meaningless while on hold, or while DIALING/ALERTING.)
618 // It's also explicitly disabled during emergency calls or if
619 // emergency callback mode (ECM) is active.
620 boolean isEmergencyCall = false;
621 if (connection != null) {
622 isEmergencyCall = PhoneNumberUtils.isLocalEmergencyNumber(connection.getAddress(),
623 phone.getContext());
624 }
625 boolean isECM = PhoneUtils.isPhoneInEcm(phone);
626 if (isEmergencyCall || isECM) { // disable "Mute" item
627 canMute = false;
628 } else {
629 canMute = callIsActive;
630 }
631
Yorke Lee814da302013-08-30 16:01:07 -0700632 canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
633 connection);
634
Santos Cordoneead6ec2013-08-07 22:16:33 -0700635 // special rules section!
636 // CDMA always has Add
637 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
638 canAddCall = true;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700639 }
640
Santos Cordon26e7b242013-08-07 21:15:45 -0700641 int retval = 0x0;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700642 if (canHold) {
Santos Cordon26e7b242013-08-07 21:15:45 -0700643 retval |= Capabilities.HOLD;
644 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700645 if (supportHold) {
646 retval |= Capabilities.SUPPORT_HOLD;
647 }
Santos Cordoneead6ec2013-08-07 22:16:33 -0700648 if (canAddCall) {
649 retval |= Capabilities.ADD_CALL;
650 }
651 if (canMergeCall) {
652 retval |= Capabilities.MERGE_CALLS;
653 }
654 if (canSwapCall) {
655 retval |= Capabilities.SWAP_CALLS;
656 }
Yorke Lee814da302013-08-30 16:01:07 -0700657 if (canRespondViaText) {
658 retval |= Capabilities.RESPOND_VIA_TEXT;
659 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700660 if (canMute) {
661 retval |= Capabilities.MUTE;
662 }
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700663 if (genericConf) {
664 retval |= Capabilities.GENERIC_CONFERENCE;
665 }
Yorke Lee814da302013-08-30 16:01:07 -0700666
Santos Cordon26e7b242013-08-07 21:15:45 -0700667 return retval;
668 }
669
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700670 /**
671 * Returns true if the Connection is part of a multiparty call.
672 * We do this by checking the isMultiparty() method of the telephony.Call object and also
673 * checking to see if more than one of it's children is alive.
674 */
675 private boolean isPartOfLiveConferenceCall(Connection connection) {
676 if (connection.getCall() != null && connection.getCall().isMultiparty()) {
677 int count = 0;
678 for (Connection currConn : connection.getCall().getConnections()) {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700679
680 // Only count connections which are alive and never cound the special
681 // "dialing" 3way call for CDMA calls.
682 if (currConn.isAlive() && currConn != mCdmaOutgoingConnection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700683 count++;
684 if (count >= 2) {
685 return true;
686 }
687 }
688 }
689 }
690 return false;
691 }
692
693 private int translateStateFromTelephony(Connection connection, boolean isForConference) {
694
Santos Cordonce02f3a2013-09-19 01:58:42 -0700695 com.android.internal.telephony.Call.State connState = connection.getState();
696
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700697 // For the "fake" outgoing CDMA call, we need to always treat it as an outgoing call.
698 if (mCdmaOutgoingConnection == connection) {
Santos Cordonce02f3a2013-09-19 01:58:42 -0700699 connState = com.android.internal.telephony.Call.State.DIALING;
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700700 }
701
Santos Cordona3d05142013-07-29 11:25:17 -0700702 int retval = State.IDLE;
Santos Cordonce02f3a2013-09-19 01:58:42 -0700703 switch (connState) {
Santos Cordona3d05142013-07-29 11:25:17 -0700704 case ACTIVE:
705 retval = State.ACTIVE;
706 break;
707 case INCOMING:
708 retval = State.INCOMING;
709 break;
710 case DIALING:
711 case ALERTING:
Santos Cordonce02f3a2013-09-19 01:58:42 -0700712 if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
713 retval = State.REDIALING;
714 } else {
715 retval = State.DIALING;
716 }
Santos Cordona3d05142013-07-29 11:25:17 -0700717 break;
718 case WAITING:
719 retval = State.CALL_WAITING;
720 break;
721 case HOLDING:
722 retval = State.ONHOLD;
723 break;
Santos Cordone38b1ff2013-08-07 12:12:16 -0700724 case DISCONNECTING:
Christine Chen3e0f0412013-09-18 20:33:49 -0700725 retval = State.DISCONNECTING;
726 break;
727 case DISCONNECTED:
Santos Cordone38b1ff2013-08-07 12:12:16 -0700728 retval = State.DISCONNECTED;
Santos Cordona3d05142013-07-29 11:25:17 -0700729 default:
730 }
731
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700732 // If we are dealing with a potential child call (not the parent conference call),
733 // the check to see if we have to set the state to CONFERENCED.
734 if (!isForConference) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700735 // if the connection is part of a multiparty call, and it is live,
736 // annotate it with CONFERENCED state instead.
737 if (isPartOfLiveConferenceCall(connection) && connection.isAlive()) {
738 return State.CONFERENCED;
739 }
740 }
741
Santos Cordona3d05142013-07-29 11:25:17 -0700742 return retval;
Santos Cordon995c8162013-07-29 09:22:22 -0700743 }
744
Santos Cordone38b1ff2013-08-07 12:12:16 -0700745 private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
746 ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
747 .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
748 .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
749 .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
750 Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
751 .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
752 Call.DisconnectCause.CDMA_ACCESS_FAILURE)
753 .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
754 .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
755 .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
756 Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
757 .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
758 Call.DisconnectCause.CDMA_NOT_EMERGENCY)
759 .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
760 .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
761 .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
762 Call.DisconnectCause.CDMA_RETRY_ORDER)
763 .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
764 .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
765 .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
766 .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
767 Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
768 .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
769 Call.DisconnectCause.CS_RESTRICTED_NORMAL)
770 .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
771 Call.DisconnectCause.ERROR_UNSPECIFIED)
772 .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
773 .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
774 .put(Connection.DisconnectCause.INCOMING_MISSED,
775 Call.DisconnectCause.INCOMING_MISSED)
776 .put(Connection.DisconnectCause.INCOMING_REJECTED,
777 Call.DisconnectCause.INCOMING_REJECTED)
778 .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
779 Call.DisconnectCause.INVALID_CREDENTIALS)
780 .put(Connection.DisconnectCause.INVALID_NUMBER,
781 Call.DisconnectCause.INVALID_NUMBER)
782 .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
783 .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
784 .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
785 .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
786 .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
787 .put(Connection.DisconnectCause.NOT_DISCONNECTED,
788 Call.DisconnectCause.NOT_DISCONNECTED)
789 .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
790 Call.DisconnectCause.NUMBER_UNREACHABLE)
791 .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
792 .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
793 .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
794 .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
795 .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
796 Call.DisconnectCause.SERVER_UNREACHABLE)
797 .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
798 .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
799 Call.DisconnectCause.UNOBTAINABLE_NUMBER)
800 .build();
801
802 private Call.DisconnectCause translateDisconnectCauseFromTelephony(
803 Connection.DisconnectCause causeSource) {
804
805 if (CAUSE_MAP.containsKey(causeSource)) {
806 return CAUSE_MAP.get(causeSource);
807 }
808
809 return Call.DisconnectCause.UNKNOWN;
810 }
811
Santos Cordon63a84242013-07-23 13:32:52 -0700812 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700813 * Gets an existing callId for a connection, or creates one if none exists.
814 * This function does NOT set any of the Connection data onto the Call class.
815 * A separate call to updateCallFromConnection must be made for that purpose.
Santos Cordon63a84242013-07-23 13:32:52 -0700816 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700817 private Call getCallFromMap(HashMap<Connection, Call> map, Connection conn,
818 boolean createIfMissing) {
Santos Cordon995c8162013-07-29 09:22:22 -0700819 Call call = null;
Santos Cordon63a84242013-07-23 13:32:52 -0700820
821 // Find the call id or create if missing and requested.
822 if (conn != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700823 if (map.containsKey(conn)) {
824 call = map.get(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700825 } else if (createIfMissing) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700826 call = createNewCall();
827 map.put(conn, call);
Santos Cordon63a84242013-07-23 13:32:52 -0700828 }
829 }
Santos Cordon995c8162013-07-29 09:22:22 -0700830 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700831 }
832
833 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700834 * Creates a brand new connection for the call.
835 */
836 private Call createNewCall() {
837 int callId;
838 int newNextCallId;
839 do {
840 callId = mNextCallId.get();
841
842 // protect against overflow
843 newNextCallId = (callId == Integer.MAX_VALUE ?
844 CALL_ID_START_VALUE : callId + 1);
845
846 // Keep looping if the change was not atomic OR the value is already taken.
847 // The call to containsValue() is linear, however, most devices support a
848 // maximum of 7 connections so it's not expensive.
849 } while (!mNextCallId.compareAndSet(callId, newNextCallId));
850
851 return new Call(callId);
852 }
853
854 /**
Santos Cordon63a84242013-07-23 13:32:52 -0700855 * Listener interface for changes to Calls.
856 */
857 public interface Listener {
Santos Cordon995c8162013-07-29 09:22:22 -0700858 void onDisconnect(Call call);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700859 void onIncoming(Call call);
860 void onUpdate(List<Call> calls);
Yorke Leede41f672013-09-19 13:46:55 -0700861 void onPostDialAction(Connection.PostDialState state, int callId, String remainingChars,
862 char c);
Santos Cordon63a84242013-07-23 13:32:52 -0700863 }
Santos Cordon249efd02013-08-05 03:33:56 -0700864
865 /**
866 * Result class for accessing a call by connection.
867 */
868 public static class CallResult {
869 public Call mCall;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700870 public Call mActionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700871 public Connection mConnection;
872
873 private CallResult(Call call, Connection connection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700874 this(call, call, connection);
875 }
876
877 private CallResult(Call call, Call actionableCall, Connection connection) {
Santos Cordon249efd02013-08-05 03:33:56 -0700878 mCall = call;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700879 mActionableCall = actionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700880 mConnection = connection;
881 }
882
883 public Call getCall() {
884 return mCall;
885 }
886
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700887 // The call that should be used for call actions like hanging up.
888 public Call getActionableCall() {
889 return mActionableCall;
890 }
891
Santos Cordon249efd02013-08-05 03:33:56 -0700892 public Connection getConnection() {
893 return mConnection;
894 }
895 }
Santos Cordon63a84242013-07-23 13:32:52 -0700896}