blob: d918241ce05d80327f0c74bcfbf41edd541053f8 [file] [log] [blame]
Santos Cordon8e8b8d22013-12-19 14:14:05 -08001/*
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
Tyler Gunn7cc70b42014-09-12 22:17:27 -070017package com.android.server.telecom;
Ben Gilad9f2bed32013-12-12 17:43:26 -080018
Tyler Gunn91d43cf2014-09-17 12:19:39 -070019import android.content.Context;
Sailesh Nepalce704b92014-03-17 18:31:43 -070020import android.net.Uri;
Evan Charltona05805b2014-03-05 08:21:46 -080021import android.os.Bundle;
Santos Cordonf193ba42014-09-12 06:37:39 -070022import android.provider.CallLog.Calls;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070023import android.telecom.AudioState;
24import android.telecom.CallState;
Andrew Lee701dc002014-09-11 21:29:12 -070025import android.telecom.DisconnectCause;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070026import android.telecom.GatewayInfo;
27import android.telecom.ParcelableConference;
Tyler Gunn5b452df2014-10-01 15:02:58 -070028import android.telecom.PhoneAccount;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070029import android.telecom.PhoneAccountHandle;
Santos Cordonf193ba42014-09-12 06:37:39 -070030import android.telecom.PhoneCapabilities;
Tyler Gunn5b452df2014-10-01 15:02:58 -070031import android.telecom.TelecomManager;
Sailesh Nepal8aa6a002014-09-12 10:52:49 -070032import android.telephony.TelephonyManager;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080033
Tyler Gunn91d43cf2014-09-17 12:19:39 -070034import com.android.internal.util.IndentingPrintWriter;
Sailesh Nepal810735e2014-03-18 18:15:46 -070035import com.google.common.collect.ImmutableCollection;
36import com.google.common.collect.ImmutableList;
Ben Gilad9f2bed32013-12-12 17:43:26 -080037
Jay Shraunera82c8f72014-08-14 15:49:16 -070038import java.util.Collections;
Ihab Awad5b281322014-09-25 18:25:29 -070039import java.util.HashSet;
Santos Cordon7cdb9092014-07-24 21:33:33 -070040import java.util.List;
Santos Cordonf193ba42014-09-12 06:37:39 -070041import java.util.Objects;
Santos Cordona56f2762014-03-24 15:55:53 -070042import java.util.Set;
Jay Shraunera82c8f72014-08-14 15:49:16 -070043import java.util.concurrent.ConcurrentHashMap;
Ben Gilad9f2bed32013-12-12 17:43:26 -080044
Ben Giladdd8c6082013-12-30 14:44:08 -080045/**
46 * Singleton.
47 *
Jay Shrauneracb91eb2014-08-08 16:04:53 -070048 * NOTE: by design most APIs are package private, use the relevant adapter/s to allow
Ben Giladdd8c6082013-12-30 14:44:08 -080049 * access from other packages specifically refraining from passing the CallsManager instance
Tyler Gunn7cc70b42014-09-12 22:17:27 -070050 * beyond the com.android.server.telecom package boundary.
Ben Giladdd8c6082013-12-30 14:44:08 -080051 */
Santos Cordon64c7e962014-07-02 15:15:27 -070052public final class CallsManager extends Call.ListenerBase {
Ben Gilada0d9f752014-02-26 11:49:03 -080053
Santos Cordondf399862014-08-06 04:39:15 -070054 // TODO: Consider renaming this CallsManagerPlugin.
Sailesh Nepal810735e2014-03-18 18:15:46 -070055 interface CallsManagerListener {
56 void onCallAdded(Call call);
57 void onCallRemoved(Call call);
Ihab Awad6fb37c82014-08-07 19:48:57 -070058 void onCallStateChanged(Call call, int oldState, int newState);
Sailesh Nepalc92c4362014-07-04 18:33:21 -070059 void onConnectionServiceChanged(
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070060 Call call,
Sailesh Nepalc92c4362014-07-04 18:33:21 -070061 ConnectionServiceWrapper oldService,
62 ConnectionServiceWrapper newService);
Sailesh Nepal810735e2014-03-18 18:15:46 -070063 void onIncomingCallAnswered(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070064 void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage);
Sailesh Nepal810735e2014-03-18 18:15:46 -070065 void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall);
Ihab Awad6fb37c82014-08-07 19:48:57 -070066 void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState);
Andrew Lee5be64bc2014-09-08 18:35:15 -070067 void onRingbackRequested(Call call, boolean ringback);
Santos Cordona1610702014-06-04 20:22:56 -070068 void onIsConferencedChanged(Call call);
Andrew Lee5be64bc2014-09-08 18:35:15 -070069 void onIsVoipAudioModeChanged(Call call);
Andrew Lee4a796602014-07-11 17:23:03 -070070 void onVideoStateChanged(Call call);
Sailesh Nepal810735e2014-03-18 18:15:46 -070071 }
72
Tyler Gunn91d43cf2014-09-17 12:19:39 -070073 /**
74 * Singleton instance of the {@link CallsManager}, initialized from {@link TelecomService}.
75 */
76 private static CallsManager INSTANCE = null;
77
78 private static final String TAG = "CallsManager";
Ben Gilad9f2bed32013-12-12 17:43:26 -080079
Santos Cordonf193ba42014-09-12 06:37:39 -070080 private static final int MAXIMUM_LIVE_CALLS = 1;
81 private static final int MAXIMUM_HOLD_CALLS = 1;
82 private static final int MAXIMUM_RINGING_CALLS = 1;
83 private static final int MAXIMUM_OUTGOING_CALLS = 1;
84
85 private static final int[] LIVE_CALL_STATES =
86 {CallState.CONNECTING, CallState.PRE_DIAL_WAIT, CallState.DIALING, CallState.ACTIVE};
87
88 private static final int[] OUTGOING_CALL_STATES =
89 {CallState.CONNECTING, CallState.PRE_DIAL_WAIT, CallState.DIALING};
90
Santos Cordon8e8b8d22013-12-19 14:14:05 -080091 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070092 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
93 * calls are added to the map and removed when the calls move to the disconnected state.
Jay Shraunera82c8f72014-08-14 15:49:16 -070094 *
95 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
96 * load factor before resizing, 1 means we only expect a single thread to
97 * access the map so make only a single shard
Santos Cordon681663d2014-01-30 04:32:15 -080098 */
Jay Shraunera82c8f72014-08-14 15:49:16 -070099 private final Set<Call> mCalls = Collections.newSetFromMap(
100 new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1));
Santos Cordon681663d2014-01-30 04:32:15 -0800101
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700102 private final ConnectionServiceRepository mConnectionServiceRepository;
103 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer;
104 private final InCallController mInCallController;
Santos Cordonf3671a62014-05-29 21:51:53 -0700105 private final CallAudioManager mCallAudioManager;
106 private final Ringer mRinger;
Jay Shraunera82c8f72014-08-14 15:49:16 -0700107 // For this set initial table size to 16 because we add 13 listeners in
108 // the CallsManager constructor.
109 private final Set<CallsManagerListener> mListeners = Collections.newSetFromMap(
110 new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1));
Santos Cordondeb8c892014-05-30 01:38:03 -0700111 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepalb88795a2014-07-15 14:53:27 -0700112 private final WiredHeadsetManager mWiredHeadsetManager;
113 private final TtyManager mTtyManager;
Yorke Leed1346872014-07-28 14:38:45 -0700114 private final ProximitySensorManager mProximitySensorManager;
Yorke Leef86db2e2014-09-12 17:56:48 -0700115 private final PhoneStateBroadcaster mPhoneStateBroadcaster;
Santos Cordonf193ba42014-09-12 06:37:39 -0700116 private final CallLogManager mCallLogManager;
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700117 private final Context mContext;
118 private final PhoneAccountRegistrar mPhoneAccountRegistrar;
119 private final MissedCallNotifier mMissedCallNotifier;
Ihab Awad5b281322014-09-25 18:25:29 -0700120 private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700121
122 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700123 * The call the user is currently interacting with. This is the call that should have audio
124 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800125 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700126 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800127
Santos Cordon766d04f2014-05-06 10:28:25 -0700128 /** Singleton accessor. */
129 static CallsManager getInstance() {
130 return INSTANCE;
131 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800132
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800133 /**
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700134 * Sets the static singleton instance.
135 *
136 * @param instance The instance to set.
137 */
138 static void initialize(CallsManager instance) {
139 INSTANCE = instance;
140 }
141
142 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700143 * Initializes the required Telecom components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800144 */
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700145 CallsManager(Context context, MissedCallNotifier missedCallNotifier,
146 PhoneAccountRegistrar phoneAccountRegistrar) {
147 mContext = context;
148 mPhoneAccountRegistrar = phoneAccountRegistrar;
149 mMissedCallNotifier = missedCallNotifier;
150 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this);
151 mWiredHeadsetManager = new WiredHeadsetManager(context);
152 mCallAudioManager = new CallAudioManager(context, statusBarNotifier, mWiredHeadsetManager);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700153 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700154 mRinger = new Ringer(mCallAudioManager, this, playerFactory, context);
155 mHeadsetMediaButton = new HeadsetMediaButton(context, this);
156 mTtyManager = new TtyManager(context, mWiredHeadsetManager);
157 mProximitySensorManager = new ProximitySensorManager(context);
Yorke Leef86db2e2014-09-12 17:56:48 -0700158 mPhoneStateBroadcaster = new PhoneStateBroadcaster();
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700159 mCallLogManager = new CallLogManager(context);
160 mInCallController = new InCallController(context);
161 mDtmfLocalTonePlayer = new DtmfLocalTonePlayer(context);
162 mConnectionServiceRepository = new ConnectionServiceRepository(mPhoneAccountRegistrar,
163 context);
Santos Cordonae193062014-05-21 21:21:49 -0700164
Santos Cordondeb8c892014-05-30 01:38:03 -0700165 mListeners.add(statusBarNotifier);
Santos Cordonf193ba42014-09-12 06:37:39 -0700166 mListeners.add(mCallLogManager);
Yorke Leef86db2e2014-09-12 17:56:48 -0700167 mListeners.add(mPhoneStateBroadcaster);
Santos Cordonf3671a62014-05-29 21:51:53 -0700168 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700169 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700170 mListeners.add(new RingbackPlayer(this, playerFactory));
171 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700172 mListeners.add(mCallAudioManager);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700173 mListeners.add(missedCallNotifier);
Santos Cordon92a2d812014-04-30 15:19:01 -0700174 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700175 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700176 mListeners.add(RespondViaSmsManager.getInstance());
Yorke Leed1346872014-07-28 14:38:45 -0700177 mListeners.add(mProximitySensorManager);
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800178 }
179
Santos Cordon766d04f2014-05-06 10:28:25 -0700180 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700181 public void onSuccessfulOutgoingCall(Call call, int callState) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700182 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700183
Tyler Gunncde2e502014-08-12 14:35:58 -0700184 setCallState(call, callState);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700185 if (!mCalls.contains(call)) {
186 // Call was not added previously in startOutgoingCall due to it being a potential MMI
187 // code, so add it now.
188 addCall(call);
189 }
190
191 // The call's ConnectionService has been updated.
192 for (CallsManagerListener listener : mListeners) {
193 listener.onConnectionServiceChanged(call, null, call.getConnectionService());
Santos Cordon766d04f2014-05-06 10:28:25 -0700194 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700195
196 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700197 }
198
199 @Override
Andrew Lee701dc002014-09-11 21:29:12 -0700200 public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) {
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700201 Log.v(this, "onFailedOutgoingCall, call: %s", call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700202
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700203 // TODO: Replace disconnect cause with more specific disconnect causes.
Andrew Lee701dc002014-09-11 21:29:12 -0700204 markCallAsDisconnected(call, disconnectCause);
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700205 }
206
207 @Override
Santos Cordonf193ba42014-09-12 06:37:39 -0700208 public void onSuccessfulIncomingCall(Call incomingCall) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700209 Log.d(this, "onSuccessfulIncomingCall");
Santos Cordonf193ba42014-09-12 06:37:39 -0700210 setCallState(incomingCall, CallState.RINGING);
211
212 if (hasMaximumRingingCalls()) {
213 incomingCall.reject(false, null);
214 // since the call was not added to the list of calls, we have to call the missed
215 // call notifier and the call logger manually.
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700216 mMissedCallNotifier.showMissedCallNotification(incomingCall);
Santos Cordonf193ba42014-09-12 06:37:39 -0700217 mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE);
218 } else {
219 addCall(incomingCall);
220 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700221 }
222
223 @Override
224 public void onFailedIncomingCall(Call call) {
Tyler Gunncde2e502014-08-12 14:35:58 -0700225 setCallState(call, CallState.DISCONNECTED);
Santos Cordon766d04f2014-05-06 10:28:25 -0700226 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800227 }
228
Ihab Awadcb387ac2014-05-28 16:49:38 -0700229 @Override
Andrew Lee5be64bc2014-09-08 18:35:15 -0700230 public void onRingbackRequested(Call call, boolean ringback) {
Ihab Awadcb387ac2014-05-28 16:49:38 -0700231 for (CallsManagerListener listener : mListeners) {
Andrew Lee5be64bc2014-09-08 18:35:15 -0700232 listener.onRingbackRequested(call, ringback);
Ihab Awadcb387ac2014-05-28 16:49:38 -0700233 }
234 }
235
Evan Charlton352105c2014-06-03 14:10:54 -0700236 @Override
237 public void onPostDialWait(Call call, String remaining) {
238 mInCallController.onPostDialWait(call, remaining);
239 }
240
Santos Cordona1610702014-06-04 20:22:56 -0700241 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700242 public void onParentChanged(Call call) {
243 for (CallsManagerListener listener : mListeners) {
244 listener.onIsConferencedChanged(call);
245 }
246 }
247
248 @Override
249 public void onChildrenChanged(Call call) {
250 for (CallsManagerListener listener : mListeners) {
251 listener.onIsConferencedChanged(call);
252 }
253 }
254
Ihab Awadff7493a2014-06-10 13:47:44 -0700255 @Override
Andrew Lee5be64bc2014-09-08 18:35:15 -0700256 public void onIsVoipAudioModeChanged(Call call) {
Sailesh Nepal7e669572014-07-08 21:29:12 -0700257 for (CallsManagerListener listener : mListeners) {
Andrew Lee5be64bc2014-09-08 18:35:15 -0700258 listener.onIsVoipAudioModeChanged(call);
Sailesh Nepal7e669572014-07-08 21:29:12 -0700259 }
260 }
261
Andrew Lee4a796602014-07-11 17:23:03 -0700262 @Override
263 public void onVideoStateChanged(Call call) {
264 for (CallsManagerListener listener : mListeners) {
265 listener.onVideoStateChanged(call);
266 }
267 }
268
Sailesh Nepal810735e2014-03-18 18:15:46 -0700269 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700270 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700271 }
272
273 Call getForegroundCall() {
274 return mForegroundCall;
275 }
276
Santos Cordonae193062014-05-21 21:21:49 -0700277 Ringer getRinger() {
278 return mRinger;
279 }
280
Santos Cordonf3671a62014-05-29 21:51:53 -0700281 InCallController getInCallController() {
282 return mInCallController;
283 }
284
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700285 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700286 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700287 if (call.isEmergencyCall()) {
288 return true;
289 }
290 }
291 return false;
292 }
293
Ihab Awad6fb37c82014-08-07 19:48:57 -0700294 AudioState getAudioState() {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700295 return mCallAudioManager.getAudioState();
296 }
297
Sailesh Nepalb88795a2014-07-15 14:53:27 -0700298 boolean isTtySupported() {
299 return mTtyManager.isTtySupported();
300 }
301
302 int getCurrentTtyMode() {
303 return mTtyManager.getCurrentTtyMode();
304 }
305
Santos Cordon68d1a6b2014-09-19 12:25:58 -0700306 void addListener(CallsManagerListener listener) {
307 mListeners.add(listener);
308 }
309
310 void removeListener(CallsManagerListener listener) {
311 mListeners.remove(listener);
312 }
313
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800314 /**
Sailesh Nepal664837f2014-07-14 16:31:51 -0700315 * Starts the process to attach the call to a connection service.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800316 *
Nancy Chenbc9ef172014-08-15 17:11:57 -0700317 * @param phoneAccountHandle The phone account which contains the component name of the
318 * connection service to use for this call.
Evan Charltona05805b2014-03-05 08:21:46 -0800319 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800320 */
Evan Charlton89176372014-07-19 18:23:09 -0700321 void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800322 Log.d(this, "processIncomingCallIntent");
Sailesh Nepal8aa6a002014-09-12 10:52:49 -0700323 Uri handle = extras.getParcelable(TelephonyManager.EXTRA_INCOMING_NUMBER);
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700324 Call call = new Call(
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700325 mContext,
Sailesh Nepal664837f2014-07-14 16:31:51 -0700326 mConnectionServiceRepository,
Sailesh Nepal8aa6a002014-09-12 10:52:49 -0700327 handle,
Sailesh Nepal664837f2014-07-14 16:31:51 -0700328 null /* gatewayInfo */,
Ihab Awadb78b2762014-07-25 15:16:23 -0700329 null /* connectionManagerPhoneAccount */,
Evan Charlton89176372014-07-19 18:23:09 -0700330 phoneAccountHandle,
Sailesh Nepal664837f2014-07-14 16:31:51 -0700331 true /* isIncoming */,
332 false /* isConference */);
333
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700334 call.setExtras(extras);
Santos Cordondf399862014-08-06 04:39:15 -0700335 // TODO: Move this to be a part of addCall()
Santos Cordon766d04f2014-05-06 10:28:25 -0700336 call.addListener(this);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700337 call.startCreateConnection(mPhoneAccountRegistrar);
Ben Gilada0d9f752014-02-26 11:49:03 -0800338 }
339
Nancy Chen0d3076c2014-07-30 14:45:44 -0700340 /**
341 * Kicks off the first steps to creating an outgoing call so that InCallUI can launch.
342 *
Nancy Chena9d91da2014-08-12 14:31:06 -0700343 * @param handle Handle to connect the call with.
Nancy Chenbc9ef172014-08-15 17:11:57 -0700344 * @param phoneAccountHandle The phone account which contains the component name of the
345 * connection service to use for this call.
346 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Nancy Chen0d3076c2014-07-30 14:45:44 -0700347 */
Nancy Chena9d91da2014-08-12 14:31:06 -0700348 Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras) {
Nancy Chen1c5926f2014-09-17 14:44:14 -0700349 // Create a call with original handle. The handle may be changed when the call is attached
350 // to a connection service, but in most cases will remain the same.
351 Call call = new Call(
352 mContext,
353 mConnectionServiceRepository,
354 handle,
355 null /* gatewayInfo */,
356 null /* connectionManagerPhoneAccount */,
357 null /* phoneAccountHandle */,
358 false /* isIncoming */,
359 false /* isConference */);
360
361 List<PhoneAccountHandle> accounts =
362 mPhoneAccountRegistrar.getCallCapablePhoneAccounts(handle.getScheme());
363
Nancy Chenbc9ef172014-08-15 17:11:57 -0700364 // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call
365 // as if a phoneAccount was not specified (does the default behavior instead).
Tyler Gunn8e0fef42014-09-08 18:34:44 -0700366 // Note: We will not attempt to dial with a requested phoneAccount if it is disabled.
Nancy Chenbc9ef172014-08-15 17:11:57 -0700367 if (phoneAccountHandle != null) {
Nancy Chen309198e2014-09-15 18:02:49 -0700368 if (!accounts.contains(phoneAccountHandle)) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700369 phoneAccountHandle = null;
370 }
371 }
372
373 if (phoneAccountHandle == null) {
Tyler Gunn84253572014-09-02 14:50:05 -0700374 // No preset account, check if default exists that supports the URI scheme for the
375 // handle.
Nancy Chenbc9ef172014-08-15 17:11:57 -0700376 PhoneAccountHandle defaultAccountHandle =
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700377 mPhoneAccountRegistrar.getDefaultOutgoingPhoneAccount(
Tyler Gunn84253572014-09-02 14:50:05 -0700378 handle.getScheme());
Nancy Chenbc9ef172014-08-15 17:11:57 -0700379 if (defaultAccountHandle != null) {
380 phoneAccountHandle = defaultAccountHandle;
381 }
382 }
383
Nancy Chen1c5926f2014-09-17 14:44:14 -0700384 call.setTargetPhoneAccount(phoneAccountHandle);
Nancy Chenbc9ef172014-08-15 17:11:57 -0700385
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700386 boolean isEmergencyCall = TelephonyUtil.shouldProcessAsEmergency(mContext,
387 call.getHandle());
Tyler Gunn5b452df2014-10-01 15:02:58 -0700388 boolean isPotentialInCallMMICode = isPotentialInCallMMICode(handle);
Santos Cordonf193ba42014-09-12 06:37:39 -0700389
390 // Do not support any more live calls. Our options are to move a call to hold, disconnect
391 // a call, or cancel this call altogether.
Tyler Gunn5b452df2014-10-01 15:02:58 -0700392 if (!isPotentialInCallMMICode && !makeRoomForOutgoingCall(call, isEmergencyCall)) {
Santos Cordonf193ba42014-09-12 06:37:39 -0700393 // just cancel at this point.
394 return null;
395 }
396
Nancy Chen1ccab202014-09-18 15:28:36 -0700397 if (phoneAccountHandle == null && accounts.size() > 1 && !isEmergencyCall) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700398 // This is the state where the user is expected to select an account
399 call.setState(CallState.PRE_DIAL_WAIT);
Nancy Chen1c5926f2014-09-17 14:44:14 -0700400 extras.putParcelableList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS, accounts);
Nancy Chenbc9ef172014-08-15 17:11:57 -0700401 } else {
402 call.setState(CallState.CONNECTING);
403 }
Nancy Chen0d3076c2014-07-30 14:45:44 -0700404
Nancy Chen1c5926f2014-09-17 14:44:14 -0700405 call.setExtras(extras);
406
Tyler Gunn5b452df2014-10-01 15:02:58 -0700407 if (isPotentialMMICode(handle) || isPotentialInCallMMICode) {
Yorke Leeb701f6d2014-08-12 14:04:19 -0700408 call.addListener(this);
Tyler Gunn5b452df2014-10-01 15:02:58 -0700409 } else {
410 addCall(call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700411 }
Nancy Chen0d3076c2014-07-30 14:45:44 -0700412
413 return call;
414 }
415
Ben Gilada0d9f752014-02-26 11:49:03 -0800416 /**
Yorke Lee33501632014-03-17 19:24:12 -0700417 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800418 *
Yorke Lee33501632014-03-17 19:24:12 -0700419 * @param handle Handle to connect the call with.
Yorke Lee33501632014-03-17 19:24:12 -0700420 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Nancy Chen53ceedc2014-07-08 18:56:51 -0700421 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700422 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Tyler Gunnc4abd912014-07-08 14:22:10 -0700423 * @param videoState The desired video state for the outgoing call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800424 */
Nancy Chenbc9ef172014-08-15 17:11:57 -0700425 void placeOutgoingCall(Call call, Uri handle, GatewayInfo gatewayInfo, boolean speakerphoneOn,
426 int videoState) {
Nancy Chen0d3076c2014-07-30 14:45:44 -0700427 if (call == null) {
428 // don't do anything if the call no longer exists
429 Log.i(this, "Canceling unknown call.");
Santos Cordonb7af09e2014-08-06 04:30:01 -0700430 return;
431 }
432
Nancy Chen201b4372014-09-08 14:18:24 -0700433 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayAddress();
Yorke Lee33501632014-03-17 19:24:12 -0700434
435 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700436 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700437 } else {
438 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
439 Log.pii(uriHandle), Log.pii(handle));
440 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700441
Nancy Chen0d3076c2014-07-30 14:45:44 -0700442 call.setHandle(uriHandle);
443 call.setGatewayInfo(gatewayInfo);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700444 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Tyler Gunnc4abd912014-07-08 14:22:10 -0700445 call.setVideoState(videoState);
Santos Cordon766d04f2014-05-06 10:28:25 -0700446
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700447 boolean isEmergencyCall = TelephonyUtil.shouldProcessAsEmergency(mContext,
448 call.getHandle());
Santos Cordonf193ba42014-09-12 06:37:39 -0700449 if (isEmergencyCall) {
Ihab Awad69eb0f52014-07-18 11:20:37 -0700450 // Emergency -- CreateConnectionProcessor will choose accounts automatically
Ihab Awadb78b2762014-07-25 15:16:23 -0700451 call.setTargetPhoneAccount(null);
Nancy Chen53ceedc2014-07-08 18:56:51 -0700452 }
Nancy Chend9de92c2014-07-21 16:09:13 -0700453
Santos Cordonf193ba42014-09-12 06:37:39 -0700454 if (call.getTargetPhoneAccount() != null || isEmergencyCall) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700455 // If the account has been set, proceed to place the outgoing call.
456 // Otherwise the connection will be initiated when the account is set by the user.
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700457 call.startCreateConnection(mPhoneAccountRegistrar);
Nancy Chend9de92c2014-07-21 16:09:13 -0700458 }
Yorke Leef98fb572014-03-05 10:56:55 -0800459 }
460
461 /**
Santos Cordona1610702014-06-04 20:22:56 -0700462 * Attempts to start a conference call for the specified call.
463 *
Santos Cordon12d61822014-07-29 16:02:20 -0700464 * @param call The call to conference.
465 * @param otherCall The other call to conference with.
Santos Cordona1610702014-06-04 20:22:56 -0700466 */
Santos Cordon12d61822014-07-29 16:02:20 -0700467 void conference(Call call, Call otherCall) {
Santos Cordon0fbe6322014-08-14 04:04:25 -0700468 call.conferenceWith(otherCall);
Santos Cordona1610702014-06-04 20:22:56 -0700469 }
470
471 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700472 * Instructs Telecom to answer the specified call. Intended to be invoked by the in-call
473 * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by
Santos Cordone3d76ab2014-01-28 17:25:20 -0800474 * the user opting to answer said call.
Andrew Lee38931d02014-07-16 10:17:36 -0700475 *
476 * @param call The call to answer.
477 * @param videoState The video state in which to answer the call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800478 */
Andrew Lee38931d02014-07-16 10:17:36 -0700479 void answerCall(Call call, int videoState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700480 if (!mCalls.contains(call)) {
481 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800482 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700483 // If the foreground call is not the ringing call and it is currently isActive() or
Ihab Awad6fb37c82014-08-07 19:48:57 -0700484 // STATE_DIALING, put it on hold before answering the call.
Santos Cordon40f78c22014-04-07 02:11:42 -0700485 if (mForegroundCall != null && mForegroundCall != call &&
486 (mForegroundCall.isActive() ||
487 mForegroundCall.getState() == CallState.DIALING)) {
Santos Cordonf193ba42014-09-12 06:37:39 -0700488 if (0 == (mForegroundCall.getCallCapabilities() & PhoneCapabilities.HOLD)) {
489 // This call does not support hold. If it is from a different connection
490 // service, then disconnect it, otherwise allow the connection service to
491 // figure out the right states.
492 if (mForegroundCall.getConnectionService() != call.getConnectionService()) {
493 mForegroundCall.disconnect();
494 }
495 } else {
496 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
497 mForegroundCall, call);
498 mForegroundCall.hold();
499 }
Santos Cordondf399862014-08-06 04:39:15 -0700500 // TODO: Wait until we get confirmation of the active call being
Santos Cordon40f78c22014-04-07 02:11:42 -0700501 // on-hold before answering the new call.
Santos Cordondf399862014-08-06 04:39:15 -0700502 // TODO: Import logic from CallManager.acceptCall()
Santos Cordon40f78c22014-04-07 02:11:42 -0700503 }
504
Santos Cordona56f2762014-03-24 15:55:53 -0700505 for (CallsManagerListener listener : mListeners) {
506 listener.onIncomingCallAnswered(call);
507 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800508
Santos Cordon61d0f702014-02-19 02:52:23 -0800509 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700510 // {@link #markCallAsActive}.
Andrew Lee38931d02014-07-16 10:17:36 -0700511 call.answer(videoState);
Santos Cordon61d0f702014-02-19 02:52:23 -0800512 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800513 }
514
515 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700516 * Instructs Telecom to reject the specified call. Intended to be invoked by the in-call
517 * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by
Santos Cordone3d76ab2014-01-28 17:25:20 -0800518 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800519 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700520 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700521 if (!mCalls.contains(call)) {
522 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800523 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700524 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700525 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700526 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700527 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800528 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800529 }
530
531 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700532 * Instructs Telecom to play the specified DTMF tone within the specified call.
Ihab Awad74549ec2014-03-10 15:33:25 -0700533 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700534 * @param digit The DTMF digit to play.
535 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700536 void playDtmfTone(Call call, char digit) {
537 if (!mCalls.contains(call)) {
538 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700539 } else {
540 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700541 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700542 }
543 }
544
545 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700546 * Instructs Telecom to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700547 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700548 void stopDtmfTone(Call call) {
549 if (!mCalls.contains(call)) {
550 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700551 } else {
552 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700553 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700554 }
555 }
556
557 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700558 * Instructs Telecom to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700559 */
Evan Charlton352105c2014-06-03 14:10:54 -0700560 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700561 if (!mCalls.contains(call)) {
562 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700563 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700564 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700565 }
566 }
567
568 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700569 * Instructs Telecom to disconnect the specified call. Intended to be invoked by the
Santos Cordone3d76ab2014-01-28 17:25:20 -0800570 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
571 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800572 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700573 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700574 Log.v(this, "disconnectCall %s", call);
575
Sailesh Nepale59bb192014-04-01 18:33:59 -0700576 if (!mCalls.contains(call)) {
577 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800578 } else {
Ihab Awad5b281322014-09-25 18:25:29 -0700579 mLocallyDisconnectingCalls.add(call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800580 call.disconnect();
581 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800582 }
Santos Cordon681663d2014-01-30 04:32:15 -0800583
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700584 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700585 * Instructs Telecom to disconnect all calls.
Tyler Gunn61b92102014-08-19 07:42:20 -0700586 */
587 void disconnectAllCalls() {
588 Log.v(this, "disconnectAllCalls");
589
590 for (Call call : mCalls) {
591 disconnectCall(call);
592 }
593 }
594
Nancy Chenbc9ef172014-08-15 17:11:57 -0700595
Tyler Gunn61b92102014-08-19 07:42:20 -0700596 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700597 * Instructs Telecom to put the specified call on hold. Intended to be invoked by the
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700598 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
599 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700600 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700601 void holdCall(Call call) {
602 if (!mCalls.contains(call)) {
603 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700604 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700605 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700606 call.hold();
607 }
608 }
609
610 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700611 * Instructs Telecom to release the specified call from hold. Intended to be invoked by
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700612 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
613 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700614 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700615 void unholdCall(Call call) {
616 if (!mCalls.contains(call)) {
617 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700618 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700619 Log.d(this, "unholding call: (%s)", call);
Sai Cheemalapati45b3e3f2014-08-15 09:33:00 -0700620 for (Call c : mCalls) {
621 if (c != null && c.isAlive() && c != call) {
622 c.hold();
623 }
624 }
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700625 call.unhold();
626 }
627 }
628
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700629 /** Called by the in-call UI to change the mute state. */
630 void mute(boolean shouldMute) {
631 mCallAudioManager.mute(shouldMute);
632 }
633
634 /**
635 * Called by the in-call UI to change the audio route, for example to change from earpiece to
636 * speaker phone.
637 */
638 void setAudioRoute(int route) {
639 mCallAudioManager.setAudioRoute(route);
640 }
641
Yorke Leed1346872014-07-28 14:38:45 -0700642 /** Called by the in-call UI to turn the proximity sensor on. */
643 void turnOnProximitySensor() {
644 mProximitySensorManager.turnOn();
645 }
646
647 /**
648 * Called by the in-call UI to turn the proximity sensor off.
649 * @param screenOnImmediately If true, the screen will be turned on immediately. Otherwise,
650 * the screen will be kept off until the proximity sensor goes negative.
651 */
652 void turnOffProximitySensor(boolean screenOnImmediately) {
653 mProximitySensorManager.turnOff(screenOnImmediately);
654 }
655
Evan Charlton89176372014-07-19 18:23:09 -0700656 void phoneAccountSelected(Call call, PhoneAccountHandle account) {
Nancy Chen53ceedc2014-07-08 18:56:51 -0700657 if (!mCalls.contains(call)) {
Santos Cordonf193ba42014-09-12 06:37:39 -0700658 Log.i(this, "Attempted to add account to unknown call %s", call);
Nancy Chen53ceedc2014-07-08 18:56:51 -0700659 } else {
Santos Cordonf193ba42014-09-12 06:37:39 -0700660 // TODO: There is an odd race condition here. Since NewOutgoingCallIntentBroadcaster and
661 // the PRE_DIAL_WAIT sequence run in parallel, if the user selects an account before the
662 // NEW_OUTGOING_CALL sequence finishes, we'll start the call immediately without
663 // respecting a rewritten number or a canceled number. This is unlikely since
664 // NEW_OUTGOING_CALL sequence, in practice, runs a lot faster than the user selecting
665 // a phone account from the in-call UI.
Ihab Awadb78b2762014-07-25 15:16:23 -0700666 call.setTargetPhoneAccount(account);
Santos Cordonf193ba42014-09-12 06:37:39 -0700667
668 // Note: emergency calls never go through account selection dialog so they never
669 // arrive here.
670 if (makeRoomForOutgoingCall(call, false /* isEmergencyCall */)) {
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700671 call.startCreateConnection(mPhoneAccountRegistrar);
Santos Cordonf193ba42014-09-12 06:37:39 -0700672 } else {
673 call.disconnect();
674 }
Nancy Chen53ceedc2014-07-08 18:56:51 -0700675 }
676 }
677
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700678 /** Called when the audio state changes. */
Ihab Awad6fb37c82014-08-07 19:48:57 -0700679 void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700680 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700681 for (CallsManagerListener listener : mListeners) {
682 listener.onAudioStateChanged(oldAudioState, newAudioState);
683 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700684 }
685
Sailesh Nepale59bb192014-04-01 18:33:59 -0700686 void markCallAsRinging(Call call) {
687 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800688 }
689
Sailesh Nepale59bb192014-04-01 18:33:59 -0700690 void markCallAsDialing(Call call) {
691 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800692 }
693
Sailesh Nepale59bb192014-04-01 18:33:59 -0700694 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700695 if (call.getConnectTimeMillis() == 0) {
696 call.setConnectTimeMillis(System.currentTimeMillis());
697 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700698 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700699
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700700 if (call.getStartWithSpeakerphoneOn()) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700701 setAudioRoute(AudioState.ROUTE_SPEAKER);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700702 }
Santos Cordon681663d2014-01-30 04:32:15 -0800703 }
704
Sailesh Nepale59bb192014-04-01 18:33:59 -0700705 void markCallAsOnHold(Call call) {
706 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700707 }
708
Santos Cordon049b7b62014-01-30 05:34:26 -0800709 /**
Santos Cordonf193ba42014-09-12 06:37:39 -0700710 * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the
711 * last live call, then also disconnect from the in-call controller.
Santos Cordon049b7b62014-01-30 05:34:26 -0800712 *
Andrew Lee701dc002014-09-11 21:29:12 -0700713 * @param disconnectCause The disconnect cause, see {@link android.telecomm.DisconnectCause}.
Santos Cordon049b7b62014-01-30 05:34:26 -0800714 */
Andrew Lee701dc002014-09-11 21:29:12 -0700715 void markCallAsDisconnected(Call call, DisconnectCause disconnectCause) {
716 call.setDisconnectCause(disconnectCause);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700717 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700718 }
719
Ben Gilada0d9f752014-02-26 11:49:03 -0800720 /**
Ihab Awada02bef52014-08-13 18:18:42 -0700721 * Removes an existing disconnected call, and notifies the in-call app.
722 */
723 void markCallAsRemoved(Call call) {
724 removeCall(call);
Ihab Awad5b281322014-09-25 18:25:29 -0700725 if (mLocallyDisconnectingCalls.contains(call)) {
726 mLocallyDisconnectingCalls.remove(call);
727 if (mForegroundCall != null && mForegroundCall.getState() == CallState.ON_HOLD) {
728 mForegroundCall.unhold();
729 }
730 }
Ihab Awada02bef52014-08-13 18:18:42 -0700731 }
732
733 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700734 * Cleans up any calls currently associated with the specified connection service when the
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700735 * service binder disconnects unexpectedly.
Santos Cordon4b2c1192014-03-19 18:15:38 -0700736 *
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700737 * @param service The connection service that disconnected.
Santos Cordon4b2c1192014-03-19 18:15:38 -0700738 */
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700739 void handleConnectionServiceDeath(ConnectionServiceWrapper service) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -0700740 if (service != null) {
Jay Shraunera82c8f72014-08-14 15:49:16 -0700741 for (Call call : mCalls) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -0700742 if (call.getConnectionService() == service) {
Andrew Lee701dc002014-09-11 21:29:12 -0700743 markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR));
Jay Shrauneracb91eb2014-08-08 16:04:53 -0700744 }
Santos Cordon4b2c1192014-03-19 18:15:38 -0700745 }
746 }
747 }
748
Santos Cordondeb8c892014-05-30 01:38:03 -0700749 boolean hasAnyCalls() {
750 return !mCalls.isEmpty();
751 }
752
Santos Cordonc7e85d42014-05-22 02:51:48 -0700753 boolean hasActiveOrHoldingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -0700754 return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -0700755 }
756
757 boolean hasRingingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -0700758 return getFirstCallWithState(CallState.RINGING) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -0700759 }
760
Santos Cordondeb8c892014-05-30 01:38:03 -0700761 boolean onMediaButton(int type) {
762 if (hasAnyCalls()) {
763 if (HeadsetMediaButton.SHORT_PRESS == type) {
764 Call ringingCall = getFirstCallWithState(CallState.RINGING);
765 if (ringingCall == null) {
766 mCallAudioManager.toggleMute();
767 return true;
768 } else {
Andrew Lee38931d02014-07-16 10:17:36 -0700769 ringingCall.answer(ringingCall.getVideoState());
Santos Cordondeb8c892014-05-30 01:38:03 -0700770 return true;
771 }
772 } else if (HeadsetMediaButton.LONG_PRESS == type) {
773 Log.d(this, "handleHeadsetHook: longpress -> hangup");
774 Call callToHangup = getFirstCallWithState(
775 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
776 if (callToHangup != null) {
777 callToHangup.disconnect();
778 return true;
779 }
780 }
781 }
782 return false;
783 }
784
785 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700786 * Checks to see if the specified call is the only high-level call and if so, enable the
787 * "Add-call" button. We allow you to add a second call but not a third or beyond.
788 *
789 * @param call The call to test for add-call.
790 * @return Whether the add-call feature should be enabled for the call.
791 */
792 protected boolean isAddCallCapable(Call call) {
793 if (call.getParentCall() != null) {
794 // Never true for child calls.
795 return false;
796 }
797
Andrew Leec11fcd92014-09-19 18:31:46 -0700798 // Use canManageConference as a mechanism to check if the call is CDMA.
799 // Disable "Add Call" for CDMA calls which are conference calls.
800 boolean canManageConference = PhoneCapabilities.MANAGE_CONFERENCE
801 == (call.getCallCapabilities() & PhoneCapabilities.MANAGE_CONFERENCE);
802 if (call.isConference() && !canManageConference) {
803 return false;
804 }
805
Santos Cordon10838c22014-06-11 17:36:04 -0700806 // Loop through all the other calls and there exists a top level (has no parent) call
807 // that is not the specified call, return false.
808 for (Call otherCall : mCalls) {
809 if (call != otherCall && otherCall.getParentCall() == null) {
810 return false;
811 }
812 }
813 return true;
814 }
815
Santos Cordon68d1a6b2014-09-19 12:25:58 -0700816 Call getRingingCall() {
817 return getFirstCallWithState(CallState.RINGING);
818 }
819
820 Call getActiveCall() {
821 return getFirstCallWithState(CallState.ACTIVE);
822 }
823
Nancy Chen05a9e402014-09-26 14:14:32 -0700824 Call getDialingCall() {
825 return getFirstCallWithState(CallState.DIALING);
Santos Cordon68d1a6b2014-09-19 12:25:58 -0700826 }
827
828 Call getHeldCall() {
829 return getFirstCallWithState(CallState.ON_HOLD);
830 }
831
Santos Cordonf193ba42014-09-12 06:37:39 -0700832 Call getFirstCallWithState(int... states) {
833 return getFirstCallWithState(null, states);
834 }
835
Santos Cordon10838c22014-06-11 17:36:04 -0700836 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700837 * Returns the first call that it finds with the given states. The states are treated as having
838 * priority order so that any call with the first state will be returned before any call with
839 * states listed later in the parameter list.
Santos Cordonf193ba42014-09-12 06:37:39 -0700840 *
841 * @param callToSkip Call that this method should skip while searching
Santos Cordondeb8c892014-05-30 01:38:03 -0700842 */
Santos Cordonf193ba42014-09-12 06:37:39 -0700843 Call getFirstCallWithState(Call callToSkip, int... states) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700844 for (int currentState : states) {
Santos Cordon23baed32014-06-27 14:45:39 -0700845 // check the foreground first
846 if (mForegroundCall != null && mForegroundCall.getState() == currentState) {
847 return mForegroundCall;
848 }
849
Santos Cordondeb8c892014-05-30 01:38:03 -0700850 for (Call call : mCalls) {
Santos Cordonf193ba42014-09-12 06:37:39 -0700851 if (Objects.equals(callToSkip, call)) {
852 continue;
853 }
854
855 // Only operate on top-level calls
856 if (call.getParentCall() != null) {
857 continue;
858 }
859
Santos Cordondeb8c892014-05-30 01:38:03 -0700860 if (currentState == call.getState()) {
861 return call;
862 }
863 }
864 }
865 return null;
866 }
867
Santos Cordon0fbe6322014-08-14 04:04:25 -0700868 Call createConferenceCall(
869 PhoneAccountHandle phoneAccount,
870 ParcelableConference parcelableConference) {
871 Call call = new Call(
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700872 mContext,
Santos Cordon0fbe6322014-08-14 04:04:25 -0700873 mConnectionServiceRepository,
874 null /* handle */,
875 null /* gatewayInfo */,
876 null /* connectionManagerPhoneAccount */,
877 phoneAccount,
878 false /* isIncoming */,
879 true /* isConference */);
880
881 setCallState(call, Call.getStateFromConnectionState(parcelableConference.getState()));
Yorke Lee03f51282014-09-11 09:49:26 -0700882 if (call.getState() == CallState.ACTIVE) {
883 call.setConnectTimeMillis(System.currentTimeMillis());
884 }
Santos Cordon0fbe6322014-08-14 04:04:25 -0700885 call.setCallCapabilities(parcelableConference.getCapabilities());
886
887 // TODO: Move this to be a part of addCall()
888 call.addListener(this);
889 addCall(call);
890 return call;
891 }
892
Yorke Leef86db2e2014-09-12 17:56:48 -0700893 /**
894 * @return the call state currently tracked by {@link PhoneStateBroadcaster}
895 */
896 int getCallState() {
897 return mPhoneStateBroadcaster.getCallState();
898 }
Nancy Chenbc9ef172014-08-15 17:11:57 -0700899
Santos Cordon4b2c1192014-03-19 18:15:38 -0700900 /**
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700901 * Retrieves the {@link PhoneAccountRegistrar}.
902 *
903 * @return The {@link PhoneAccountRegistrar}.
904 */
905 PhoneAccountRegistrar getPhoneAccountRegistrar() {
906 return mPhoneAccountRegistrar;
907 }
908
909 /**
910 * Retrieves the {@link MissedCallNotifier}
911 * @return The {@link MissedCallNotifier}.
912 */
913 MissedCallNotifier getMissedCallNotifier() {
914 return mMissedCallNotifier;
915 }
916
917 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800918 * Adds the specified call to the main list of live calls.
919 *
920 * @param call The call to add.
921 */
922 private void addCall(Call call) {
Yorke Leeb701f6d2014-08-12 14:04:19 -0700923 Log.v(this, "addCall(%s)", call);
924
925 call.addListener(this);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700926 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700927
Santos Cordondf399862014-08-06 04:39:15 -0700928 // TODO: Update mForegroundCall prior to invoking
Santos Cordon40f78c22014-04-07 02:11:42 -0700929 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700930 for (CallsManagerListener listener : mListeners) {
931 listener.onCallAdded(call);
932 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700933 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800934 }
935
Sailesh Nepal810735e2014-03-18 18:15:46 -0700936 private void removeCall(Call call) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700937 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700938
Santos Cordon672321e2014-08-21 14:38:58 -0700939 call.setParentCall(null); // need to clean up parent relationship before destroying.
Santos Cordon766d04f2014-05-06 10:28:25 -0700940 call.removeListener(this);
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700941 call.clearConnectionService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700942
943 boolean shouldNotify = false;
944 if (mCalls.contains(call)) {
945 mCalls.remove(call);
946 shouldNotify = true;
Santos Cordona56f2762014-03-24 15:55:53 -0700947 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800948
Sailesh Nepale59bb192014-04-01 18:33:59 -0700949 // Only broadcast changes for calls that are being tracked.
950 if (shouldNotify) {
951 for (CallsManagerListener listener : mListeners) {
952 listener.onCallRemoved(call);
953 }
954 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700955 }
956 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800957
Sailesh Nepal810735e2014-03-18 18:15:46 -0700958 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700959 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700960 *
961 * @param call The call.
962 * @param newState The new state of the call.
963 */
Ihab Awad6fb37c82014-08-07 19:48:57 -0700964 private void setCallState(Call call, int newState) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -0700965 if (call == null) {
966 return;
967 }
Ihab Awad6fb37c82014-08-07 19:48:57 -0700968 int oldState = call.getState();
Nancy Chen308ab8b2014-09-02 16:18:30 -0700969 Log.i(this, "setCallState %s -> %s, call: %s", CallState.toString(oldState),
970 CallState.toString(newState), call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700971 if (newState != oldState) {
972 // Unfortunately, in the telephony world the radio is king. So if the call notifies
973 // us that the call is in a particular state, we allow it even if it doesn't make
Ihab Awad6fb37c82014-08-07 19:48:57 -0700974 // sense (e.g., STATE_ACTIVE -> STATE_RINGING).
Santos Cordondf399862014-08-06 04:39:15 -0700975 // TODO: Consider putting a stop to the above and turning CallState
Sailesh Nepal810735e2014-03-18 18:15:46 -0700976 // into a well-defined state machine.
Santos Cordondf399862014-08-06 04:39:15 -0700977 // TODO: Define expected state transitions here, and log when an
Sailesh Nepal810735e2014-03-18 18:15:46 -0700978 // unexpected transition occurs.
979 call.setState(newState);
980
981 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700982 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700983 for (CallsManagerListener listener : mListeners) {
984 listener.onCallStateChanged(call, oldState, newState);
985 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700986 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800987 }
988 }
989 }
990
991 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700992 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800993 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700994 private void updateForegroundCall() {
995 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700996 for (Call call : mCalls) {
Santos Cordondf399862014-08-06 04:39:15 -0700997 // TODO: Foreground-ness needs to be explicitly set. No call, regardless
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700998 // of its state will be foreground by default and instead the connection service should
999 // be notified when its calls enter and exit foreground state. Foreground will mean that
Santos Cordon40f78c22014-04-07 02:11:42 -07001000 // the call should play audio and listen to microphone if it wants.
1001
Santos Cordonf193ba42014-09-12 06:37:39 -07001002 // Only top-level calls can be in foreground
1003 if (call.getParentCall() != null) {
1004 continue;
1005 }
1006
Santos Cordon40f78c22014-04-07 02:11:42 -07001007 // Active calls have priority.
1008 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -07001009 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -08001010 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -07001011 }
Santos Cordon40f78c22014-04-07 02:11:42 -07001012
1013 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -07001014 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -07001015 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -08001016 }
1017 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -08001018
Sailesh Nepal810735e2014-03-18 18:15:46 -07001019 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -07001020 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -07001021 Call oldForegroundCall = mForegroundCall;
1022 mForegroundCall = newForegroundCall;
Ihab Awad5b281322014-09-25 18:25:29 -07001023
Santos Cordona56f2762014-03-24 15:55:53 -07001024 for (CallsManagerListener listener : mListeners) {
1025 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
1026 }
Santos Cordon681663d2014-01-30 04:32:15 -08001027 }
1028 }
Yorke Leeb701f6d2014-08-12 14:04:19 -07001029
1030 private boolean isPotentialMMICode(Uri handle) {
1031 return (handle != null && handle.getSchemeSpecificPart() != null
1032 && handle.getSchemeSpecificPart().contains("#"));
1033 }
Santos Cordonf193ba42014-09-12 06:37:39 -07001034
Tyler Gunn5b452df2014-10-01 15:02:58 -07001035 /**
1036 * Determines if a dialed number is potentially an In-Call MMI code. In-Call MMI codes are
1037 * MMI codes which can be dialed when one or more calls are in progress.
1038 * <P>
1039 * Checks for numbers formatted similar to the MMI codes defined in:
1040 * {@link com.android.internal.telephony.gsm.GSMPhone#handleInCallMmiCommands(String)}
1041 * and
1042 * {@link com.android.internal.telephony.imsphone.ImsPhone#handleInCallMmiCommands(String)}
1043 *
1044 * @param handle The URI to call.
1045 * @return {@code True} if the URI represents a number which could be an in-call MMI code.
1046 */
1047 private boolean isPotentialInCallMMICode(Uri handle) {
1048 if (handle != null && handle.getSchemeSpecificPart() != null &&
1049 handle.getScheme().equals(PhoneAccount.SCHEME_TEL)) {
1050
1051 String dialedNumber = handle.getSchemeSpecificPart();
1052 return (dialedNumber.equals("0") ||
1053 (dialedNumber.startsWith("1") && dialedNumber.length() <= 2) ||
1054 (dialedNumber.startsWith("2") && dialedNumber.length() <= 2) ||
1055 dialedNumber.equals("3") ||
1056 dialedNumber.equals("4") ||
1057 dialedNumber.equals("5"));
1058 }
1059 return false;
1060 }
1061
Santos Cordonf193ba42014-09-12 06:37:39 -07001062 private int getNumCallsWithState(int... states) {
1063 int count = 0;
1064 for (int state : states) {
1065 for (Call call : mCalls) {
1066 if (call.getState() == state) {
1067 count++;
1068 }
1069 }
1070 }
1071 return count;
1072 }
1073
1074 private boolean hasMaximumLiveCalls() {
1075 return MAXIMUM_LIVE_CALLS <= getNumCallsWithState(LIVE_CALL_STATES);
1076 }
1077
1078 private boolean hasMaximumHoldingCalls() {
1079 return MAXIMUM_HOLD_CALLS <= getNumCallsWithState(CallState.ON_HOLD);
1080 }
1081
1082 private boolean hasMaximumRingingCalls() {
1083 return MAXIMUM_RINGING_CALLS <= getNumCallsWithState(CallState.RINGING);
1084 }
1085
1086 private boolean hasMaximumOutgoingCalls() {
1087 return MAXIMUM_OUTGOING_CALLS <= getNumCallsWithState(OUTGOING_CALL_STATES);
1088 }
1089
1090 private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) {
1091 if (hasMaximumLiveCalls()) {
1092 // NOTE: If the amount of live calls changes beyond 1, this logic will probably
1093 // have to change.
1094 Call liveCall = getFirstCallWithState(call, LIVE_CALL_STATES);
1095
Santos Cordond1766502014-09-26 15:45:39 -07001096 if (call == liveCall) {
1097 // If the call is already the foreground call, then we are golden.
1098 // This can happen after the user selects an account in the PRE_DIAL_WAIT
1099 // state since the call was already populated into the list.
1100 return true;
1101 }
1102
Andrew Leee6595182014-09-23 18:43:05 -07001103 if (hasMaximumOutgoingCalls()) {
1104 // Disconnect the current outgoing call if it's not an emergency call. If the user
1105 // tries to make two outgoing calls to different emergency call numbers, we will try
1106 // to connect the first outgoing call.
1107 if (isEmergency) {
1108 Call outgoingCall = getFirstCallWithState(OUTGOING_CALL_STATES);
1109 if (!outgoingCall.isEmergencyCall()) {
1110 outgoingCall.disconnect();
1111 return true;
1112 }
1113 }
1114 return false;
1115 }
1116
Santos Cordonf193ba42014-09-12 06:37:39 -07001117 if (hasMaximumHoldingCalls()) {
1118 // There is no more room for any more calls, unless it's an emergency.
1119 if (isEmergency) {
1120 // Kill the current active call, this is easier then trying to disconnect a
1121 // holding call and hold an active call.
1122 liveCall.disconnect();
1123 return true;
1124 }
1125 return false; // No more room!
1126 }
1127
1128 // We have room for at least one more holding call at this point.
1129
1130 // First thing, if we are trying to make a call with the same phone account as the live
1131 // call, then allow it so that the connection service can make its own decision about
1132 // how to handle the new call relative to the current one.
1133 if (Objects.equals(liveCall.getTargetPhoneAccount(), call.getTargetPhoneAccount())) {
1134 return true;
1135 } else if (call.getTargetPhoneAccount() == null) {
1136 // Without a phone account, we can't say reliably that the call will fail.
1137 // If the user chooses the same phone account as the live call, then it's
1138 // still possible that the call can be made (like with CDMA calls not supporting
1139 // hold but they still support adding a call by going immediately into conference
1140 // mode). Return true here and we'll run this code again after user chooses an
1141 // account.
1142 return true;
1143 }
1144
1145 // Try to hold the live call before attempting the new outgoing call.
1146 if (liveCall.can(PhoneCapabilities.HOLD)) {
1147 liveCall.hold();
1148 return true;
1149 }
1150
1151 // The live call cannot be held so we're out of luck here. There's no room.
1152 return false;
1153 }
1154 return true;
1155 }
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001156
1157 /**
1158 * Dumps the state of the {@link CallsManager}.
1159 *
1160 * @param pw The {@code IndentingPrintWriter} to write the state to.
1161 */
1162 public void dump(IndentingPrintWriter pw) {
1163 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
1164 pw.increaseIndent();
1165 if (mCalls != null) {
1166 pw.println("mCalls: ");
1167 pw.increaseIndent();
1168 for (Call call : mCalls) {
1169 pw.println(call);
1170 }
1171 pw.decreaseIndent();
1172 }
1173 pw.decreaseIndent();
1174 }
Ben Gilad9f2bed32013-12-12 17:43:26 -08001175}