blob: 104d815980d10a0f14c020c6362c227a56119ab5 [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 }
Christine Chen6af50e62013-09-26 15:05:57 -0700326 mCallManager.clearDisconnected();
Santos Cordon63a84242013-07-23 13:32:52 -0700327 }
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 Chendf19e452013-09-25 17:21:23 -0700365 final boolean shouldUpdate =
Christine Chen3e0f0412013-09-18 20:33:49 -0700366 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
Christine Chendf19e452013-09-25 17:21:23 -0700372 final boolean isDisconnecting = connection.getState() ==
373 com.android.internal.telephony.Call.State.DISCONNECTING;
374
375 // For disconnecting calls, we still need to send the update to the UI but we do
376 // not create a new call if the call did not exist.
377 final boolean shouldCreate = shouldUpdate && !isDisconnecting;
378
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700379 // New connections return a Call with INVALID state, which does not translate to
Santos Cordone38b1ff2013-08-07 12:12:16 -0700380 // a state in the internal.telephony.Call object. This ensures that staleness
381 // check below fails and we always add the item to the update list if it is new.
Christine Chendf19e452013-09-25 17:21:23 -0700382 final Call call = getCallFromMap(mCallMap, connection, shouldCreate /* create */);
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700383
Santos Cordon12a03aa2013-09-12 23:34:05 -0700384 if (call == null || !shouldUpdate) {
Santos Cordona5d5db82013-09-15 13:00:34 -0700385 if (DBG) Log.d(TAG, "update skipped");
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700386 continue;
387 }
Santos Cordona3d05142013-07-29 11:25:17 -0700388
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700389 boolean changed = updateCallFromConnection(call, connection, false);
Santos Cordon2b73bd62013-08-27 14:53:43 -0700390
Santos Cordone38b1ff2013-08-07 12:12:16 -0700391 if (fullUpdate || changed) {
Santos Cordon998f42b2013-08-02 16:13:12 -0700392 out.add(call);
Santos Cordona3d05142013-07-29 11:25:17 -0700393 }
394 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700395
396 // We do a second loop to address conference call scenarios. We do this as a separate
397 // loop to ensure all child calls are up to date before we start updating the parent
398 // conference calls.
399 for (Connection connection : telephonyCall.getConnections()) {
400 updateForConferenceCalls(connection, out);
401 }
402
Santos Cordona3d05142013-07-29 11:25:17 -0700403 }
Santos Cordona3d05142013-07-29 11:25:17 -0700404 }
405
Santos Cordone38b1ff2013-08-07 12:12:16 -0700406 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700407 * Checks to see if the connection is the first connection in a conference call.
408 * If it is a conference call, we will create a new Conference Call object or
409 * update the existing conference call object for that connection.
410 * If it is not a conference call but a previous associated conference call still exists,
411 * we mark it as idle and remove it from the map.
412 * In both cases above, we add the Calls to be updated to the UI.
413 * @param connection The connection object to check.
414 * @param updatedCalls List of 'updated' calls that will be sent to the UI.
415 */
416 private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
417 // We consider this connection a conference connection if the call it
Yorke Leecd3f9692013-09-14 13:51:27 -0700418 // belongs to is a multiparty call AND it is the first live connection.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700419 final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
Yorke Leecd3f9692013-09-14 13:51:27 -0700420 getEarliestLiveConnection(connection.getCall()) == connection;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700421
422 boolean changed = false;
423
424 // If this connection is the main connection for the conference call, then create or update
425 // a Call object for that conference call.
426 if (isConferenceCallConnection) {
427 final Call confCall = getCallFromMap(mConfCallMap, connection, true);
428 changed = updateCallFromConnection(confCall, connection, true);
429
430 if (changed) {
431 updatedCalls.add(confCall);
432 }
433
434 if (DBG) Log.d(TAG, "Updating a conference call: " + confCall);
435
436 // It is possible that through a conference call split, there may be lingering conference
437 // calls where this connection was the main connection. We clean those up here.
438 } else {
439 final Call oldConfCall = getCallFromMap(mConfCallMap, connection, false);
440
441 // We found a conference call for this connection, which is no longer a conference call.
442 // Kill it!
443 if (oldConfCall != null) {
444 if (DBG) Log.d(TAG, "Cleaning up an old conference call: " + oldConfCall);
445 mConfCallMap.remove(connection);
446 oldConfCall.setState(State.IDLE);
447 changed = true;
448
449 // add to the list of calls to update
450 updatedCalls.add(oldConfCall);
451 }
452 }
453
454 return changed;
455 }
456
Yorke Leecd3f9692013-09-14 13:51:27 -0700457 private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
458 final List<Connection> connections = call.getConnections();
459 final int size = connections.size();
460 Connection earliestConn = null;
461 long earliestTime = Long.MAX_VALUE;
462 for (int i = 0; i < size; i++) {
463 final Connection connection = connections.get(i);
464 if (!connection.isAlive()) continue;
465 final long time = connection.getCreateTime();
466 if (time < earliestTime) {
467 earliestTime = time;
468 earliestConn = connection;
469 }
470 }
471 return earliestConn;
472 }
473
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700474 /**
Santos Cordon69a69192013-08-22 14:25:42 -0700475 * Sets the new call state onto the call and performs some additional logic
476 * associated with setting the state.
477 */
478 private void setNewState(Call call, int newState, Connection connection) {
479 Preconditions.checkState(call.getState() != newState);
480
481 // When starting an outgoing call, we need to grab gateway information
482 // for the call, if available, and set it.
483 final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
484
Santos Cordonce02f3a2013-09-19 01:58:42 -0700485 if (Call.State.isDialing(newState)) {
Santos Cordon69a69192013-08-22 14:25:42 -0700486 if (!info.isEmpty()) {
487 call.setGatewayNumber(info.getFormattedGatewayNumber());
488 call.setGatewayPackage(info.packageName);
489 }
490 } else if (!Call.State.isConnected(newState)) {
491 mCallGatewayManager.clearGatewayData(connection);
492 }
493
494 call.setState(newState);
495 }
496
497 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700498 * Updates the Call properties to match the state of the connection object
499 * that it represents.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700500 * @param call The call object to update.
501 * @param connection The connection object from which to update call.
502 * @param isForConference There are slight differences in how we populate data for conference
503 * calls. This boolean tells us which method to use.
Santos Cordone38b1ff2013-08-07 12:12:16 -0700504 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700505 private boolean updateCallFromConnection(Call call, Connection connection,
506 boolean isForConference) {
Santos Cordone38b1ff2013-08-07 12:12:16 -0700507 boolean changed = false;
508
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700509 final int newState = translateStateFromTelephony(connection, isForConference);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700510
511 if (call.getState() != newState) {
Santos Cordon69a69192013-08-22 14:25:42 -0700512 setNewState(call, newState, connection);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700513 changed = true;
514 }
515
Santos Cordone38b1ff2013-08-07 12:12:16 -0700516 final Call.DisconnectCause newDisconnectCause =
517 translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
518 if (call.getDisconnectCause() != newDisconnectCause) {
519 call.setDisconnectCause(newDisconnectCause);
520 changed = true;
521 }
522
Santos Cordonbbe8ecf2013-08-13 15:26:18 -0700523 final long oldConnectTime = call.getConnectTime();
524 if (oldConnectTime != connection.getConnectTime()) {
525 call.setConnectTime(connection.getConnectTime());
526 changed = true;
527 }
528
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700529 if (!isForConference) {
Santos Cordon69a69192013-08-22 14:25:42 -0700530 // Number
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700531 final String oldNumber = call.getNumber();
Santos Cordon69a69192013-08-22 14:25:42 -0700532 String newNumber = connection.getAddress();
533 RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
534 if (!info.isEmpty()) {
535 newNumber = info.trueNumber;
536 }
537 if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
538 call.setNumber(newNumber);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700539 changed = true;
540 }
541
Santos Cordon69a69192013-08-22 14:25:42 -0700542 // Number presentation
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700543 final int newNumberPresentation = connection.getNumberPresentation();
544 if (call.getNumberPresentation() != newNumberPresentation) {
545 call.setNumberPresentation(newNumberPresentation);
546 changed = true;
547 }
548
Santos Cordon69a69192013-08-22 14:25:42 -0700549 // Name
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700550 final String oldCnapName = call.getCnapName();
551 if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
552 call.setCnapName(connection.getCnapName());
553 changed = true;
554 }
Santos Cordon69a69192013-08-22 14:25:42 -0700555
556 // Name Presentation
557 final int newCnapNamePresentation = connection.getCnapNamePresentation();
558 if (call.getCnapNamePresentation() != newCnapNamePresentation) {
559 call.setCnapNamePresentation(newCnapNamePresentation);
560 changed = true;
561 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700562 } else {
563
564 // update the list of children by:
565 // 1) Saving the old set
566 // 2) Removing all children
567 // 3) Adding the correct children into the Call
568 // 4) Comparing the new children set with the old children set
569 ImmutableSortedSet<Integer> oldSet = call.getChildCallIds();
570 call.removeAllChildren();
571
572 if (connection.getCall() != null) {
573 for (Connection childConn : connection.getCall().getConnections()) {
574 final Call childCall = getCallFromMap(mCallMap, childConn, false);
575 if (childCall != null && childConn.isAlive()) {
576 call.addChildId(childCall.getCallId());
577 }
578 }
579 }
Christine Chen45277022013-09-05 10:55:37 -0700580 changed |= !oldSet.equals(call.getChildCallIds());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700581 }
582
Santos Cordoneead6ec2013-08-07 22:16:33 -0700583 /**
584 * !!! Uses values from connection and call collected above so this part must be last !!!
585 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700586 final int newCapabilities = getCapabilitiesFor(connection, call, isForConference);
Santos Cordon26e7b242013-08-07 21:15:45 -0700587 if (call.getCapabilities() != newCapabilities) {
588 call.setCapabilities(newCapabilities);
589 changed = true;
590 }
591
Santos Cordone38b1ff2013-08-07 12:12:16 -0700592 return changed;
593 }
594
Santos Cordon26e7b242013-08-07 21:15:45 -0700595 /**
596 * Returns a mask of capabilities for the connection such as merge, hold, etc.
597 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700598 private int getCapabilitiesFor(Connection connection, Call call, boolean isForConference) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700599 final boolean callIsActive = (call.getState() == Call.State.ACTIVE);
600 final Phone phone = connection.getCall().getPhone();
601
Santos Cordoneead6ec2013-08-07 22:16:33 -0700602 boolean canAddCall = false;
603 boolean canMergeCall = false;
604 boolean canSwapCall = false;
Yorke Lee814da302013-08-30 16:01:07 -0700605 boolean canRespondViaText = false;
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700606 boolean canMute = false;
607
608 final boolean supportHold = PhoneUtils.okToSupportHold(mCallManager);
Christine Chen94853bc2013-09-17 16:53:33 -0700609 final boolean canHold = (supportHold ? PhoneUtils.okToHoldCall(mCallManager) : false);
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700610 final boolean genericConf = isForConference &&
611 (connection.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
Santos Cordoneead6ec2013-08-07 22:16:33 -0700612
613 // only applies to active calls
614 if (callIsActive) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700615 canMergeCall = PhoneUtils.okToMergeCalls(mCallManager);
616 canSwapCall = PhoneUtils.okToSwapCalls(mCallManager);
617 }
618
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700619 canAddCall = PhoneUtils.okToAddCall(mCallManager);
620
621 // "Mute": only enabled when the foreground call is ACTIVE.
622 // (It's meaningless while on hold, or while DIALING/ALERTING.)
623 // It's also explicitly disabled during emergency calls or if
624 // emergency callback mode (ECM) is active.
625 boolean isEmergencyCall = false;
626 if (connection != null) {
627 isEmergencyCall = PhoneNumberUtils.isLocalEmergencyNumber(connection.getAddress(),
628 phone.getContext());
629 }
630 boolean isECM = PhoneUtils.isPhoneInEcm(phone);
631 if (isEmergencyCall || isECM) { // disable "Mute" item
632 canMute = false;
633 } else {
634 canMute = callIsActive;
635 }
636
Yorke Lee814da302013-08-30 16:01:07 -0700637 canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
638 connection);
639
Santos Cordoneead6ec2013-08-07 22:16:33 -0700640 // special rules section!
641 // CDMA always has Add
642 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
643 canAddCall = true;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700644 }
645
Santos Cordon26e7b242013-08-07 21:15:45 -0700646 int retval = 0x0;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700647 if (canHold) {
Santos Cordon26e7b242013-08-07 21:15:45 -0700648 retval |= Capabilities.HOLD;
649 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700650 if (supportHold) {
651 retval |= Capabilities.SUPPORT_HOLD;
652 }
Santos Cordoneead6ec2013-08-07 22:16:33 -0700653 if (canAddCall) {
654 retval |= Capabilities.ADD_CALL;
655 }
656 if (canMergeCall) {
657 retval |= Capabilities.MERGE_CALLS;
658 }
659 if (canSwapCall) {
660 retval |= Capabilities.SWAP_CALLS;
661 }
Yorke Lee814da302013-08-30 16:01:07 -0700662 if (canRespondViaText) {
663 retval |= Capabilities.RESPOND_VIA_TEXT;
664 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700665 if (canMute) {
666 retval |= Capabilities.MUTE;
667 }
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700668 if (genericConf) {
669 retval |= Capabilities.GENERIC_CONFERENCE;
670 }
Yorke Lee814da302013-08-30 16:01:07 -0700671
Santos Cordon26e7b242013-08-07 21:15:45 -0700672 return retval;
673 }
674
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700675 /**
676 * Returns true if the Connection is part of a multiparty call.
677 * We do this by checking the isMultiparty() method of the telephony.Call object and also
678 * checking to see if more than one of it's children is alive.
679 */
680 private boolean isPartOfLiveConferenceCall(Connection connection) {
681 if (connection.getCall() != null && connection.getCall().isMultiparty()) {
682 int count = 0;
683 for (Connection currConn : connection.getCall().getConnections()) {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700684
685 // Only count connections which are alive and never cound the special
686 // "dialing" 3way call for CDMA calls.
687 if (currConn.isAlive() && currConn != mCdmaOutgoingConnection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700688 count++;
689 if (count >= 2) {
690 return true;
691 }
692 }
693 }
694 }
695 return false;
696 }
697
698 private int translateStateFromTelephony(Connection connection, boolean isForConference) {
699
Santos Cordonce02f3a2013-09-19 01:58:42 -0700700 com.android.internal.telephony.Call.State connState = connection.getState();
701
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700702 // For the "fake" outgoing CDMA call, we need to always treat it as an outgoing call.
703 if (mCdmaOutgoingConnection == connection) {
Santos Cordonce02f3a2013-09-19 01:58:42 -0700704 connState = com.android.internal.telephony.Call.State.DIALING;
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700705 }
706
Santos Cordona3d05142013-07-29 11:25:17 -0700707 int retval = State.IDLE;
Santos Cordonce02f3a2013-09-19 01:58:42 -0700708 switch (connState) {
Santos Cordona3d05142013-07-29 11:25:17 -0700709 case ACTIVE:
710 retval = State.ACTIVE;
711 break;
712 case INCOMING:
713 retval = State.INCOMING;
714 break;
715 case DIALING:
716 case ALERTING:
Santos Cordonce02f3a2013-09-19 01:58:42 -0700717 if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
718 retval = State.REDIALING;
719 } else {
720 retval = State.DIALING;
721 }
Santos Cordona3d05142013-07-29 11:25:17 -0700722 break;
723 case WAITING:
724 retval = State.CALL_WAITING;
725 break;
726 case HOLDING:
727 retval = State.ONHOLD;
728 break;
Santos Cordone38b1ff2013-08-07 12:12:16 -0700729 case DISCONNECTING:
Christine Chen3e0f0412013-09-18 20:33:49 -0700730 retval = State.DISCONNECTING;
731 break;
732 case DISCONNECTED:
Santos Cordone38b1ff2013-08-07 12:12:16 -0700733 retval = State.DISCONNECTED;
Santos Cordona3d05142013-07-29 11:25:17 -0700734 default:
735 }
736
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700737 // If we are dealing with a potential child call (not the parent conference call),
738 // the check to see if we have to set the state to CONFERENCED.
739 if (!isForConference) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700740 // if the connection is part of a multiparty call, and it is live,
741 // annotate it with CONFERENCED state instead.
742 if (isPartOfLiveConferenceCall(connection) && connection.isAlive()) {
743 return State.CONFERENCED;
744 }
745 }
746
Santos Cordona3d05142013-07-29 11:25:17 -0700747 return retval;
Santos Cordon995c8162013-07-29 09:22:22 -0700748 }
749
Santos Cordone38b1ff2013-08-07 12:12:16 -0700750 private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
751 ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
752 .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
753 .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
754 .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
755 Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
756 .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
757 Call.DisconnectCause.CDMA_ACCESS_FAILURE)
758 .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
759 .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
760 .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
761 Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
762 .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
763 Call.DisconnectCause.CDMA_NOT_EMERGENCY)
764 .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
765 .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
766 .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
767 Call.DisconnectCause.CDMA_RETRY_ORDER)
768 .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
769 .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
770 .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
771 .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
772 Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
773 .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
774 Call.DisconnectCause.CS_RESTRICTED_NORMAL)
775 .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
776 Call.DisconnectCause.ERROR_UNSPECIFIED)
777 .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
778 .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
779 .put(Connection.DisconnectCause.INCOMING_MISSED,
780 Call.DisconnectCause.INCOMING_MISSED)
781 .put(Connection.DisconnectCause.INCOMING_REJECTED,
782 Call.DisconnectCause.INCOMING_REJECTED)
783 .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
784 Call.DisconnectCause.INVALID_CREDENTIALS)
785 .put(Connection.DisconnectCause.INVALID_NUMBER,
786 Call.DisconnectCause.INVALID_NUMBER)
787 .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
788 .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
789 .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
790 .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
791 .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
792 .put(Connection.DisconnectCause.NOT_DISCONNECTED,
793 Call.DisconnectCause.NOT_DISCONNECTED)
794 .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
795 Call.DisconnectCause.NUMBER_UNREACHABLE)
796 .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
797 .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
798 .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
799 .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
800 .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
801 Call.DisconnectCause.SERVER_UNREACHABLE)
802 .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
803 .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
804 Call.DisconnectCause.UNOBTAINABLE_NUMBER)
805 .build();
806
807 private Call.DisconnectCause translateDisconnectCauseFromTelephony(
808 Connection.DisconnectCause causeSource) {
809
810 if (CAUSE_MAP.containsKey(causeSource)) {
811 return CAUSE_MAP.get(causeSource);
812 }
813
814 return Call.DisconnectCause.UNKNOWN;
815 }
816
Santos Cordon63a84242013-07-23 13:32:52 -0700817 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700818 * Gets an existing callId for a connection, or creates one if none exists.
819 * This function does NOT set any of the Connection data onto the Call class.
820 * A separate call to updateCallFromConnection must be made for that purpose.
Santos Cordon63a84242013-07-23 13:32:52 -0700821 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700822 private Call getCallFromMap(HashMap<Connection, Call> map, Connection conn,
823 boolean createIfMissing) {
Santos Cordon995c8162013-07-29 09:22:22 -0700824 Call call = null;
Santos Cordon63a84242013-07-23 13:32:52 -0700825
826 // Find the call id or create if missing and requested.
827 if (conn != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700828 if (map.containsKey(conn)) {
829 call = map.get(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700830 } else if (createIfMissing) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700831 call = createNewCall();
832 map.put(conn, call);
Santos Cordon63a84242013-07-23 13:32:52 -0700833 }
834 }
Santos Cordon995c8162013-07-29 09:22:22 -0700835 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700836 }
837
838 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700839 * Creates a brand new connection for the call.
840 */
841 private Call createNewCall() {
842 int callId;
843 int newNextCallId;
844 do {
845 callId = mNextCallId.get();
846
847 // protect against overflow
848 newNextCallId = (callId == Integer.MAX_VALUE ?
849 CALL_ID_START_VALUE : callId + 1);
850
851 // Keep looping if the change was not atomic OR the value is already taken.
852 // The call to containsValue() is linear, however, most devices support a
853 // maximum of 7 connections so it's not expensive.
854 } while (!mNextCallId.compareAndSet(callId, newNextCallId));
855
856 return new Call(callId);
857 }
858
859 /**
Santos Cordon63a84242013-07-23 13:32:52 -0700860 * Listener interface for changes to Calls.
861 */
862 public interface Listener {
Santos Cordon995c8162013-07-29 09:22:22 -0700863 void onDisconnect(Call call);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700864 void onIncoming(Call call);
865 void onUpdate(List<Call> calls);
Yorke Leede41f672013-09-19 13:46:55 -0700866 void onPostDialAction(Connection.PostDialState state, int callId, String remainingChars,
867 char c);
Santos Cordon63a84242013-07-23 13:32:52 -0700868 }
Santos Cordon249efd02013-08-05 03:33:56 -0700869
870 /**
871 * Result class for accessing a call by connection.
872 */
873 public static class CallResult {
874 public Call mCall;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700875 public Call mActionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700876 public Connection mConnection;
877
878 private CallResult(Call call, Connection connection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700879 this(call, call, connection);
880 }
881
882 private CallResult(Call call, Call actionableCall, Connection connection) {
Santos Cordon249efd02013-08-05 03:33:56 -0700883 mCall = call;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700884 mActionableCall = actionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700885 mConnection = connection;
886 }
887
888 public Call getCall() {
889 return mCall;
890 }
891
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700892 // The call that should be used for call actions like hanging up.
893 public Call getActionableCall() {
894 return mActionableCall;
895 }
896
Santos Cordon249efd02013-08-05 03:33:56 -0700897 public Connection getConnection() {
898 return mConnection;
899 }
900 }
Santos Cordon63a84242013-07-23 13:32:52 -0700901}