blob: 716b688e3b025be7a74df8d92542c732d1a11c73 [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 Chendf19e452013-09-25 17:21:23 -0700364 final boolean shouldUpdate =
Christine Chen3e0f0412013-09-18 20:33:49 -0700365 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
Christine Chendf19e452013-09-25 17:21:23 -0700371 final boolean isDisconnecting = connection.getState() ==
372 com.android.internal.telephony.Call.State.DISCONNECTING;
373
374 // For disconnecting calls, we still need to send the update to the UI but we do
375 // not create a new call if the call did not exist.
376 final boolean shouldCreate = shouldUpdate && !isDisconnecting;
377
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700378 // New connections return a Call with INVALID state, which does not translate to
Santos Cordone38b1ff2013-08-07 12:12:16 -0700379 // a state in the internal.telephony.Call object. This ensures that staleness
380 // check below fails and we always add the item to the update list if it is new.
Christine Chendf19e452013-09-25 17:21:23 -0700381 final Call call = getCallFromMap(mCallMap, connection, shouldCreate /* create */);
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700382
Santos Cordon12a03aa2013-09-12 23:34:05 -0700383 if (call == null || !shouldUpdate) {
Santos Cordona5d5db82013-09-15 13:00:34 -0700384 if (DBG) Log.d(TAG, "update skipped");
Santos Cordon71d5c6e2013-09-05 21:34:33 -0700385 continue;
386 }
Santos Cordona3d05142013-07-29 11:25:17 -0700387
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700388 boolean changed = updateCallFromConnection(call, connection, false);
Santos Cordon2b73bd62013-08-27 14:53:43 -0700389
Santos Cordone38b1ff2013-08-07 12:12:16 -0700390 if (fullUpdate || changed) {
Santos Cordon998f42b2013-08-02 16:13:12 -0700391 out.add(call);
Santos Cordona3d05142013-07-29 11:25:17 -0700392 }
393 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700394
395 // We do a second loop to address conference call scenarios. We do this as a separate
396 // loop to ensure all child calls are up to date before we start updating the parent
397 // conference calls.
398 for (Connection connection : telephonyCall.getConnections()) {
399 updateForConferenceCalls(connection, out);
400 }
401
Santos Cordona3d05142013-07-29 11:25:17 -0700402 }
Santos Cordona3d05142013-07-29 11:25:17 -0700403 }
404
Santos Cordone38b1ff2013-08-07 12:12:16 -0700405 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700406 * Checks to see if the connection is the first connection in a conference call.
407 * If it is a conference call, we will create a new Conference Call object or
408 * update the existing conference call object for that connection.
409 * If it is not a conference call but a previous associated conference call still exists,
410 * we mark it as idle and remove it from the map.
411 * In both cases above, we add the Calls to be updated to the UI.
412 * @param connection The connection object to check.
413 * @param updatedCalls List of 'updated' calls that will be sent to the UI.
414 */
415 private boolean updateForConferenceCalls(Connection connection, List<Call> updatedCalls) {
416 // We consider this connection a conference connection if the call it
Yorke Leecd3f9692013-09-14 13:51:27 -0700417 // belongs to is a multiparty call AND it is the first live connection.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700418 final boolean isConferenceCallConnection = isPartOfLiveConferenceCall(connection) &&
Yorke Leecd3f9692013-09-14 13:51:27 -0700419 getEarliestLiveConnection(connection.getCall()) == connection;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700420
421 boolean changed = false;
422
423 // If this connection is the main connection for the conference call, then create or update
424 // a Call object for that conference call.
425 if (isConferenceCallConnection) {
426 final Call confCall = getCallFromMap(mConfCallMap, connection, true);
427 changed = updateCallFromConnection(confCall, connection, true);
428
429 if (changed) {
430 updatedCalls.add(confCall);
431 }
432
433 if (DBG) Log.d(TAG, "Updating a conference call: " + confCall);
434
435 // It is possible that through a conference call split, there may be lingering conference
436 // calls where this connection was the main connection. We clean those up here.
437 } else {
438 final Call oldConfCall = getCallFromMap(mConfCallMap, connection, false);
439
440 // We found a conference call for this connection, which is no longer a conference call.
441 // Kill it!
442 if (oldConfCall != null) {
443 if (DBG) Log.d(TAG, "Cleaning up an old conference call: " + oldConfCall);
444 mConfCallMap.remove(connection);
445 oldConfCall.setState(State.IDLE);
446 changed = true;
447
448 // add to the list of calls to update
449 updatedCalls.add(oldConfCall);
450 }
451 }
452
453 return changed;
454 }
455
Yorke Leecd3f9692013-09-14 13:51:27 -0700456 private Connection getEarliestLiveConnection(com.android.internal.telephony.Call call) {
457 final List<Connection> connections = call.getConnections();
458 final int size = connections.size();
459 Connection earliestConn = null;
460 long earliestTime = Long.MAX_VALUE;
461 for (int i = 0; i < size; i++) {
462 final Connection connection = connections.get(i);
463 if (!connection.isAlive()) continue;
464 final long time = connection.getCreateTime();
465 if (time < earliestTime) {
466 earliestTime = time;
467 earliestConn = connection;
468 }
469 }
470 return earliestConn;
471 }
472
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700473 /**
Santos Cordon69a69192013-08-22 14:25:42 -0700474 * Sets the new call state onto the call and performs some additional logic
475 * associated with setting the state.
476 */
477 private void setNewState(Call call, int newState, Connection connection) {
478 Preconditions.checkState(call.getState() != newState);
479
480 // When starting an outgoing call, we need to grab gateway information
481 // for the call, if available, and set it.
482 final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
483
Santos Cordonce02f3a2013-09-19 01:58:42 -0700484 if (Call.State.isDialing(newState)) {
Santos Cordon69a69192013-08-22 14:25:42 -0700485 if (!info.isEmpty()) {
486 call.setGatewayNumber(info.getFormattedGatewayNumber());
487 call.setGatewayPackage(info.packageName);
488 }
489 } else if (!Call.State.isConnected(newState)) {
490 mCallGatewayManager.clearGatewayData(connection);
491 }
492
493 call.setState(newState);
494 }
495
496 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700497 * Updates the Call properties to match the state of the connection object
498 * that it represents.
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700499 * @param call The call object to update.
500 * @param connection The connection object from which to update call.
501 * @param isForConference There are slight differences in how we populate data for conference
502 * calls. This boolean tells us which method to use.
Santos Cordone38b1ff2013-08-07 12:12:16 -0700503 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700504 private boolean updateCallFromConnection(Call call, Connection connection,
505 boolean isForConference) {
Santos Cordone38b1ff2013-08-07 12:12:16 -0700506 boolean changed = false;
507
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700508 final int newState = translateStateFromTelephony(connection, isForConference);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700509
510 if (call.getState() != newState) {
Santos Cordon69a69192013-08-22 14:25:42 -0700511 setNewState(call, newState, connection);
Santos Cordone38b1ff2013-08-07 12:12:16 -0700512 changed = true;
513 }
514
Santos Cordone38b1ff2013-08-07 12:12:16 -0700515 final Call.DisconnectCause newDisconnectCause =
516 translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
517 if (call.getDisconnectCause() != newDisconnectCause) {
518 call.setDisconnectCause(newDisconnectCause);
519 changed = true;
520 }
521
Santos Cordonbbe8ecf2013-08-13 15:26:18 -0700522 final long oldConnectTime = call.getConnectTime();
523 if (oldConnectTime != connection.getConnectTime()) {
524 call.setConnectTime(connection.getConnectTime());
525 changed = true;
526 }
527
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700528 if (!isForConference) {
Santos Cordon69a69192013-08-22 14:25:42 -0700529 // Number
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700530 final String oldNumber = call.getNumber();
Santos Cordon69a69192013-08-22 14:25:42 -0700531 String newNumber = connection.getAddress();
532 RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
533 if (!info.isEmpty()) {
534 newNumber = info.trueNumber;
535 }
536 if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
537 call.setNumber(newNumber);
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700538 changed = true;
539 }
540
Santos Cordon69a69192013-08-22 14:25:42 -0700541 // Number presentation
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700542 final int newNumberPresentation = connection.getNumberPresentation();
543 if (call.getNumberPresentation() != newNumberPresentation) {
544 call.setNumberPresentation(newNumberPresentation);
545 changed = true;
546 }
547
Santos Cordon69a69192013-08-22 14:25:42 -0700548 // Name
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700549 final String oldCnapName = call.getCnapName();
550 if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
551 call.setCnapName(connection.getCnapName());
552 changed = true;
553 }
Santos Cordon69a69192013-08-22 14:25:42 -0700554
555 // Name Presentation
556 final int newCnapNamePresentation = connection.getCnapNamePresentation();
557 if (call.getCnapNamePresentation() != newCnapNamePresentation) {
558 call.setCnapNamePresentation(newCnapNamePresentation);
559 changed = true;
560 }
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700561 } else {
562
563 // update the list of children by:
564 // 1) Saving the old set
565 // 2) Removing all children
566 // 3) Adding the correct children into the Call
567 // 4) Comparing the new children set with the old children set
568 ImmutableSortedSet<Integer> oldSet = call.getChildCallIds();
569 call.removeAllChildren();
570
571 if (connection.getCall() != null) {
572 for (Connection childConn : connection.getCall().getConnections()) {
573 final Call childCall = getCallFromMap(mCallMap, childConn, false);
574 if (childCall != null && childConn.isAlive()) {
575 call.addChildId(childCall.getCallId());
576 }
577 }
578 }
Christine Chen45277022013-09-05 10:55:37 -0700579 changed |= !oldSet.equals(call.getChildCallIds());
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700580 }
581
Santos Cordoneead6ec2013-08-07 22:16:33 -0700582 /**
583 * !!! Uses values from connection and call collected above so this part must be last !!!
584 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700585 final int newCapabilities = getCapabilitiesFor(connection, call, isForConference);
Santos Cordon26e7b242013-08-07 21:15:45 -0700586 if (call.getCapabilities() != newCapabilities) {
587 call.setCapabilities(newCapabilities);
588 changed = true;
589 }
590
Santos Cordone38b1ff2013-08-07 12:12:16 -0700591 return changed;
592 }
593
Santos Cordon26e7b242013-08-07 21:15:45 -0700594 /**
595 * Returns a mask of capabilities for the connection such as merge, hold, etc.
596 */
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700597 private int getCapabilitiesFor(Connection connection, Call call, boolean isForConference) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700598 final boolean callIsActive = (call.getState() == Call.State.ACTIVE);
599 final Phone phone = connection.getCall().getPhone();
600
Santos Cordoneead6ec2013-08-07 22:16:33 -0700601 boolean canAddCall = false;
602 boolean canMergeCall = false;
603 boolean canSwapCall = false;
Yorke Lee814da302013-08-30 16:01:07 -0700604 boolean canRespondViaText = false;
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700605 boolean canMute = false;
606
607 final boolean supportHold = PhoneUtils.okToSupportHold(mCallManager);
Christine Chen94853bc2013-09-17 16:53:33 -0700608 final boolean canHold = (supportHold ? PhoneUtils.okToHoldCall(mCallManager) : false);
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700609 final boolean genericConf = isForConference &&
610 (connection.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
Santos Cordoneead6ec2013-08-07 22:16:33 -0700611
612 // only applies to active calls
613 if (callIsActive) {
Santos Cordoneead6ec2013-08-07 22:16:33 -0700614 canMergeCall = PhoneUtils.okToMergeCalls(mCallManager);
615 canSwapCall = PhoneUtils.okToSwapCalls(mCallManager);
616 }
617
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700618 canAddCall = PhoneUtils.okToAddCall(mCallManager);
619
620 // "Mute": only enabled when the foreground call is ACTIVE.
621 // (It's meaningless while on hold, or while DIALING/ALERTING.)
622 // It's also explicitly disabled during emergency calls or if
623 // emergency callback mode (ECM) is active.
624 boolean isEmergencyCall = false;
625 if (connection != null) {
626 isEmergencyCall = PhoneNumberUtils.isLocalEmergencyNumber(connection.getAddress(),
627 phone.getContext());
628 }
629 boolean isECM = PhoneUtils.isPhoneInEcm(phone);
630 if (isEmergencyCall || isECM) { // disable "Mute" item
631 canMute = false;
632 } else {
633 canMute = callIsActive;
634 }
635
Yorke Lee814da302013-08-30 16:01:07 -0700636 canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
637 connection);
638
Santos Cordoneead6ec2013-08-07 22:16:33 -0700639 // special rules section!
640 // CDMA always has Add
641 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
642 canAddCall = true;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700643 }
644
Santos Cordon26e7b242013-08-07 21:15:45 -0700645 int retval = 0x0;
Santos Cordoneead6ec2013-08-07 22:16:33 -0700646 if (canHold) {
Santos Cordon26e7b242013-08-07 21:15:45 -0700647 retval |= Capabilities.HOLD;
648 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700649 if (supportHold) {
650 retval |= Capabilities.SUPPORT_HOLD;
651 }
Santos Cordoneead6ec2013-08-07 22:16:33 -0700652 if (canAddCall) {
653 retval |= Capabilities.ADD_CALL;
654 }
655 if (canMergeCall) {
656 retval |= Capabilities.MERGE_CALLS;
657 }
658 if (canSwapCall) {
659 retval |= Capabilities.SWAP_CALLS;
660 }
Yorke Lee814da302013-08-30 16:01:07 -0700661 if (canRespondViaText) {
662 retval |= Capabilities.RESPOND_VIA_TEXT;
663 }
Christine Chenaf2fd0a2013-09-13 16:27:40 -0700664 if (canMute) {
665 retval |= Capabilities.MUTE;
666 }
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700667 if (genericConf) {
668 retval |= Capabilities.GENERIC_CONFERENCE;
669 }
Yorke Lee814da302013-08-30 16:01:07 -0700670
Santos Cordon26e7b242013-08-07 21:15:45 -0700671 return retval;
672 }
673
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700674 /**
675 * Returns true if the Connection is part of a multiparty call.
676 * We do this by checking the isMultiparty() method of the telephony.Call object and also
677 * checking to see if more than one of it's children is alive.
678 */
679 private boolean isPartOfLiveConferenceCall(Connection connection) {
680 if (connection.getCall() != null && connection.getCall().isMultiparty()) {
681 int count = 0;
682 for (Connection currConn : connection.getCall().getConnections()) {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700683
684 // Only count connections which are alive and never cound the special
685 // "dialing" 3way call for CDMA calls.
686 if (currConn.isAlive() && currConn != mCdmaOutgoingConnection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700687 count++;
688 if (count >= 2) {
689 return true;
690 }
691 }
692 }
693 }
694 return false;
695 }
696
697 private int translateStateFromTelephony(Connection connection, boolean isForConference) {
698
Santos Cordonce02f3a2013-09-19 01:58:42 -0700699 com.android.internal.telephony.Call.State connState = connection.getState();
700
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700701 // For the "fake" outgoing CDMA call, we need to always treat it as an outgoing call.
702 if (mCdmaOutgoingConnection == connection) {
Santos Cordonce02f3a2013-09-19 01:58:42 -0700703 connState = com.android.internal.telephony.Call.State.DIALING;
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700704 }
705
Santos Cordona3d05142013-07-29 11:25:17 -0700706 int retval = State.IDLE;
Santos Cordonce02f3a2013-09-19 01:58:42 -0700707 switch (connState) {
Santos Cordona3d05142013-07-29 11:25:17 -0700708 case ACTIVE:
709 retval = State.ACTIVE;
710 break;
711 case INCOMING:
712 retval = State.INCOMING;
713 break;
714 case DIALING:
715 case ALERTING:
Santos Cordonce02f3a2013-09-19 01:58:42 -0700716 if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
717 retval = State.REDIALING;
718 } else {
719 retval = State.DIALING;
720 }
Santos Cordona3d05142013-07-29 11:25:17 -0700721 break;
722 case WAITING:
723 retval = State.CALL_WAITING;
724 break;
725 case HOLDING:
726 retval = State.ONHOLD;
727 break;
Santos Cordone38b1ff2013-08-07 12:12:16 -0700728 case DISCONNECTING:
Christine Chen3e0f0412013-09-18 20:33:49 -0700729 retval = State.DISCONNECTING;
730 break;
731 case DISCONNECTED:
Santos Cordone38b1ff2013-08-07 12:12:16 -0700732 retval = State.DISCONNECTED;
Santos Cordona3d05142013-07-29 11:25:17 -0700733 default:
734 }
735
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700736 // If we are dealing with a potential child call (not the parent conference call),
737 // the check to see if we have to set the state to CONFERENCED.
738 if (!isForConference) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700739 // if the connection is part of a multiparty call, and it is live,
740 // annotate it with CONFERENCED state instead.
741 if (isPartOfLiveConferenceCall(connection) && connection.isAlive()) {
742 return State.CONFERENCED;
743 }
744 }
745
Santos Cordona3d05142013-07-29 11:25:17 -0700746 return retval;
Santos Cordon995c8162013-07-29 09:22:22 -0700747 }
748
Santos Cordone38b1ff2013-08-07 12:12:16 -0700749 private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
750 ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
751 .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
752 .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
753 .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
754 Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
755 .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
756 Call.DisconnectCause.CDMA_ACCESS_FAILURE)
757 .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
758 .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
759 .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
760 Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
761 .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
762 Call.DisconnectCause.CDMA_NOT_EMERGENCY)
763 .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
764 .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
765 .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
766 Call.DisconnectCause.CDMA_RETRY_ORDER)
767 .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
768 .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
769 .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
770 .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
771 Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
772 .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
773 Call.DisconnectCause.CS_RESTRICTED_NORMAL)
774 .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
775 Call.DisconnectCause.ERROR_UNSPECIFIED)
776 .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
777 .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
778 .put(Connection.DisconnectCause.INCOMING_MISSED,
779 Call.DisconnectCause.INCOMING_MISSED)
780 .put(Connection.DisconnectCause.INCOMING_REJECTED,
781 Call.DisconnectCause.INCOMING_REJECTED)
782 .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
783 Call.DisconnectCause.INVALID_CREDENTIALS)
784 .put(Connection.DisconnectCause.INVALID_NUMBER,
785 Call.DisconnectCause.INVALID_NUMBER)
786 .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
787 .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
788 .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
789 .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
790 .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
791 .put(Connection.DisconnectCause.NOT_DISCONNECTED,
792 Call.DisconnectCause.NOT_DISCONNECTED)
793 .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
794 Call.DisconnectCause.NUMBER_UNREACHABLE)
795 .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
796 .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
797 .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
798 .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
799 .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
800 Call.DisconnectCause.SERVER_UNREACHABLE)
801 .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
802 .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
803 Call.DisconnectCause.UNOBTAINABLE_NUMBER)
804 .build();
805
806 private Call.DisconnectCause translateDisconnectCauseFromTelephony(
807 Connection.DisconnectCause causeSource) {
808
809 if (CAUSE_MAP.containsKey(causeSource)) {
810 return CAUSE_MAP.get(causeSource);
811 }
812
813 return Call.DisconnectCause.UNKNOWN;
814 }
815
Santos Cordon63a84242013-07-23 13:32:52 -0700816 /**
Santos Cordone38b1ff2013-08-07 12:12:16 -0700817 * Gets an existing callId for a connection, or creates one if none exists.
818 * This function does NOT set any of the Connection data onto the Call class.
819 * A separate call to updateCallFromConnection must be made for that purpose.
Santos Cordon63a84242013-07-23 13:32:52 -0700820 */
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700821 private Call getCallFromMap(HashMap<Connection, Call> map, Connection conn,
822 boolean createIfMissing) {
Santos Cordon995c8162013-07-29 09:22:22 -0700823 Call call = null;
Santos Cordon63a84242013-07-23 13:32:52 -0700824
825 // Find the call id or create if missing and requested.
826 if (conn != null) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700827 if (map.containsKey(conn)) {
828 call = map.get(conn);
Santos Cordon63a84242013-07-23 13:32:52 -0700829 } else if (createIfMissing) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700830 call = createNewCall();
831 map.put(conn, call);
Santos Cordon63a84242013-07-23 13:32:52 -0700832 }
833 }
Santos Cordon995c8162013-07-29 09:22:22 -0700834 return call;
Santos Cordon63a84242013-07-23 13:32:52 -0700835 }
836
837 /**
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700838 * Creates a brand new connection for the call.
839 */
840 private Call createNewCall() {
841 int callId;
842 int newNextCallId;
843 do {
844 callId = mNextCallId.get();
845
846 // protect against overflow
847 newNextCallId = (callId == Integer.MAX_VALUE ?
848 CALL_ID_START_VALUE : callId + 1);
849
850 // Keep looping if the change was not atomic OR the value is already taken.
851 // The call to containsValue() is linear, however, most devices support a
852 // maximum of 7 connections so it's not expensive.
853 } while (!mNextCallId.compareAndSet(callId, newNextCallId));
854
855 return new Call(callId);
856 }
857
858 /**
Santos Cordon63a84242013-07-23 13:32:52 -0700859 * Listener interface for changes to Calls.
860 */
861 public interface Listener {
Santos Cordon995c8162013-07-29 09:22:22 -0700862 void onDisconnect(Call call);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700863 void onIncoming(Call call);
864 void onUpdate(List<Call> calls);
Yorke Leede41f672013-09-19 13:46:55 -0700865 void onPostDialAction(Connection.PostDialState state, int callId, String remainingChars,
866 char c);
Santos Cordon63a84242013-07-23 13:32:52 -0700867 }
Santos Cordon249efd02013-08-05 03:33:56 -0700868
869 /**
870 * Result class for accessing a call by connection.
871 */
872 public static class CallResult {
873 public Call mCall;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700874 public Call mActionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700875 public Connection mConnection;
876
877 private CallResult(Call call, Connection connection) {
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700878 this(call, call, connection);
879 }
880
881 private CallResult(Call call, Call actionableCall, Connection connection) {
Santos Cordon249efd02013-08-05 03:33:56 -0700882 mCall = call;
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700883 mActionableCall = actionableCall;
Santos Cordon249efd02013-08-05 03:33:56 -0700884 mConnection = connection;
885 }
886
887 public Call getCall() {
888 return mCall;
889 }
890
Santos Cordon4ad64cd2013-08-15 00:36:14 -0700891 // The call that should be used for call actions like hanging up.
892 public Call getActionableCall() {
893 return mActionableCall;
894 }
895
Santos Cordon249efd02013-08-05 03:33:56 -0700896 public Connection getConnection() {
897 return mConnection;
898 }
899 }
Santos Cordon63a84242013-07-23 13:32:52 -0700900}