blob: d6cb19b87a6db466c9f38638a4d544d6bd8bc2b6 [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
Santos Cordonf0f99f32016-02-18 16:13:57 -080019import android.app.ActivityManager;
Tyler Gunn91d43cf2014-09-17 12:19:39 -070020import android.content.Context;
Tony Maka9930942016-01-15 10:57:14 +000021import android.content.pm.UserInfo;
Xueren Zhangc0e8e9d2015-03-06 14:16:55 +010022import android.content.Intent;
Hall Liufbed0162016-01-14 18:06:29 -080023import android.media.AudioManager;
Sailesh Nepalce704b92014-03-17 18:31:43 -070024import android.net.Uri;
Evan Charltona05805b2014-03-05 08:21:46 -080025import android.os.Bundle;
Santos Cordoncf5b2912014-11-05 21:57:54 -080026import android.os.Handler;
Ihab Awade6dbc9d2015-03-26 10:33:44 -070027import android.os.Looper;
Tony Maka9930942016-01-15 10:57:14 +000028import android.os.Process;
Sailesh Nepal703a1af2016-04-14 20:10:12 -070029import android.os.SystemClock;
Rekha Kumard240fe82015-04-01 21:45:57 -070030import android.os.SystemProperties;
Brad Ebingerd931a012015-10-21 12:54:08 -070031import android.os.SystemVibrator;
Yorke Leee4a9c412014-11-14 16:59:42 -080032import android.os.Trace;
Tony Mak578a4e62015-11-23 11:18:51 +000033import android.os.UserHandle;
Tony Maka9930942016-01-15 10:57:14 +000034import android.os.UserManager;
Santos Cordonf193ba42014-09-12 06:37:39 -070035import android.provider.CallLog.Calls;
Hall Liuf1422e72016-01-27 11:07:07 -080036import android.provider.Settings;
Yorke Lee2a66f7b2015-05-13 14:21:19 -070037import android.telecom.CallAudioState;
Tyler Gunnd92e7372015-01-09 15:59:45 -080038import android.telecom.Conference;
Ihab Awad07bc5ee2014-11-12 13:42:52 -080039import android.telecom.Connection;
Andrew Lee701dc002014-09-11 21:29:12 -070040import android.telecom.DisconnectCause;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070041import android.telecom.GatewayInfo;
42import android.telecom.ParcelableConference;
Tyler Gunn6e2b94e2014-10-30 11:05:22 -070043import android.telecom.ParcelableConnection;
Tyler Gunn5b452df2014-10-01 15:02:58 -070044import android.telecom.PhoneAccount;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070045import android.telecom.PhoneAccountHandle;
Tyler Gunn5b452df2014-10-01 15:02:58 -070046import android.telecom.TelecomManager;
Andrew Lee45506232014-10-22 17:54:33 -070047import android.telecom.VideoProfile;
Nancy Chena469f762014-12-09 18:29:20 -080048import android.telephony.PhoneNumberUtils;
Sailesh Nepal8aa6a002014-09-12 10:52:49 -070049import android.telephony.TelephonyManager;
Yorke Lee8d3f2692015-05-08 11:44:39 -070050import android.text.TextUtils;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080051
Ihab Awada3653902015-01-23 13:44:46 -080052import com.android.internal.annotations.VisibleForTesting;
Abhijith Shastrycf27f682016-03-01 18:28:44 -080053import com.android.internal.telephony.AsyncEmergencyContactNotifier;
Rekha Kumard240fe82015-04-01 21:45:57 -070054import com.android.internal.telephony.PhoneConstants;
55import com.android.internal.telephony.TelephonyProperties;
Tyler Gunn91d43cf2014-09-17 12:19:39 -070056import com.android.internal.util.IndentingPrintWriter;
Santos Cordon501b9b32016-03-07 14:40:07 -080057import com.android.server.telecom.TelecomServiceImpl.DefaultDialerManagerAdapter;
Hall Liu6d4b66d2016-04-01 16:31:13 -070058import com.android.server.telecom.callfiltering.AsyncBlockCheckFilter;
59import com.android.server.telecom.callfiltering.BlockCheckerAdapter;
60import com.android.server.telecom.callfiltering.CallFilterResultCallback;
61import com.android.server.telecom.callfiltering.CallFilteringResult;
62import com.android.server.telecom.callfiltering.CallScreeningServiceFilter;
63import com.android.server.telecom.callfiltering.DirectToVoicemailCallFilter;
64import com.android.server.telecom.callfiltering.IncomingCallFilter;
Xueren Zhangc0e8e9d2015-03-06 14:16:55 +010065import com.android.server.telecom.components.ErrorDialogActivity;
Yorke Leee4a9c412014-11-14 16:59:42 -080066
Hall Liu6d4b66d2016-04-01 16:31:13 -070067import java.util.ArrayList;
Santos Cordon4bc02452014-11-19 15:51:12 -080068import java.util.Collection;
Jay Shraunera82c8f72014-08-14 15:49:16 -070069import java.util.Collections;
Hall Liu32587202015-11-18 11:10:08 -080070import java.util.HashMap;
Ihab Awad5b281322014-09-25 18:25:29 -070071import java.util.HashSet;
Santos Cordon7cdb9092014-07-24 21:33:33 -070072import java.util.List;
Hall Liu32587202015-11-18 11:10:08 -080073import java.util.Map;
Santos Cordonf193ba42014-09-12 06:37:39 -070074import java.util.Objects;
Santos Cordona56f2762014-03-24 15:55:53 -070075import java.util.Set;
Jay Shraunera82c8f72014-08-14 15:49:16 -070076import java.util.concurrent.ConcurrentHashMap;
Ben Gilad9f2bed32013-12-12 17:43:26 -080077
Ben Giladdd8c6082013-12-30 14:44:08 -080078/**
79 * Singleton.
80 *
Jay Shrauneracb91eb2014-08-08 16:04:53 -070081 * NOTE: by design most APIs are package private, use the relevant adapter/s to allow
Ben Giladdd8c6082013-12-30 14:44:08 -080082 * access from other packages specifically refraining from passing the CallsManager instance
Tyler Gunn7cc70b42014-09-12 22:17:27 -070083 * beyond the com.android.server.telecom package boundary.
Ben Giladdd8c6082013-12-30 14:44:08 -080084 */
Ihab Awadaa383cc2015-03-22 22:12:28 -070085@VisibleForTesting
Sailesh Nepalae925952016-01-24 18:56:58 -080086public class CallsManager extends Call.ListenerBase
Hall Liu6d4b66d2016-04-01 16:31:13 -070087 implements VideoProviderProxy.Listener, CallFilterResultCallback {
Ben Gilada0d9f752014-02-26 11:49:03 -080088
Santos Cordondf399862014-08-06 04:39:15 -070089 // TODO: Consider renaming this CallsManagerPlugin.
Brad Ebinger53855132015-10-30 10:58:19 -070090 @VisibleForTesting
91 public interface CallsManagerListener {
Sailesh Nepal810735e2014-03-18 18:15:46 -070092 void onCallAdded(Call call);
93 void onCallRemoved(Call call);
Ihab Awad6fb37c82014-08-07 19:48:57 -070094 void onCallStateChanged(Call call, int oldState, int newState);
Sailesh Nepalc92c4362014-07-04 18:33:21 -070095 void onConnectionServiceChanged(
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070096 Call call,
Sailesh Nepalc92c4362014-07-04 18:33:21 -070097 ConnectionServiceWrapper oldService,
98 ConnectionServiceWrapper newService);
Sailesh Nepal810735e2014-03-18 18:15:46 -070099 void onIncomingCallAnswered(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -0700100 void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage);
Yorke Lee2a66f7b2015-05-13 14:21:19 -0700101 void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState);
Andrew Lee5be64bc2014-09-08 18:35:15 -0700102 void onRingbackRequested(Call call, boolean ringback);
Santos Cordona1610702014-06-04 20:22:56 -0700103 void onIsConferencedChanged(Call call);
Andrew Lee5be64bc2014-09-08 18:35:15 -0700104 void onIsVoipAudioModeChanged(Call call);
Hall Liu9696c212016-06-24 16:09:02 -0700105 void onVideoStateChanged(Call call, int previousVideoState, int newVideoState);
Santos Cordon91bd74c2014-11-07 16:10:22 -0800106 void onCanAddCallChanged(boolean canAddCall);
Tyler Gunn86014fc2015-06-12 14:31:25 -0700107 void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
Tyler Gunndb821912016-02-16 14:35:25 -0800108 void onHoldToneRequested(Call call);
Tyler Gunn1a40c4f2016-04-14 14:29:45 -0700109 void onExternalCallChanged(Call call, boolean isExternalCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700110 }
111
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700112 private static final String TAG = "CallsManager";
Ben Gilad9f2bed32013-12-12 17:43:26 -0800113
Santos Cordonf193ba42014-09-12 06:37:39 -0700114 private static final int MAXIMUM_LIVE_CALLS = 1;
115 private static final int MAXIMUM_HOLD_CALLS = 1;
116 private static final int MAXIMUM_RINGING_CALLS = 1;
Roshan Pius4de4a892015-08-24 11:06:58 -0700117 private static final int MAXIMUM_DIALING_CALLS = 1;
Santos Cordonf193ba42014-09-12 06:37:39 -0700118 private static final int MAXIMUM_OUTGOING_CALLS = 1;
Santos Cordon91bd74c2014-11-07 16:10:22 -0800119 private static final int MAXIMUM_TOP_LEVEL_CALLS = 2;
Santos Cordonf193ba42014-09-12 06:37:39 -0700120
121 private static final int[] OUTGOING_CALL_STATES =
Tyler Gunn1e37be52016-07-11 08:54:23 -0700122 {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING,
123 CallState.PULLING};
Santos Cordonf193ba42014-09-12 06:37:39 -0700124
Santos Cordon91bd74c2014-11-07 16:10:22 -0800125 private static final int[] LIVE_CALL_STATES =
Santos Cordonf0f99f32016-02-18 16:13:57 -0800126 {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING,
Tyler Gunn1e37be52016-07-11 08:54:23 -0700127 CallState.PULLING, CallState.ACTIVE};
128
Tyler Gunn8452be02015-09-17 09:57:02 -0700129 public static final String TELECOM_CALL_ID_PREFIX = "TC@";
Santos Cordon91bd74c2014-11-07 16:10:22 -0800130
Hall Liu32587202015-11-18 11:10:08 -0800131 // Maps call technologies in PhoneConstants to those in Analytics.
132 private static final Map<Integer, Integer> sAnalyticsTechnologyMap;
133 static {
134 sAnalyticsTechnologyMap = new HashMap<>(5);
135 sAnalyticsTechnologyMap.put(PhoneConstants.PHONE_TYPE_CDMA, Analytics.CDMA_PHONE);
136 sAnalyticsTechnologyMap.put(PhoneConstants.PHONE_TYPE_GSM, Analytics.GSM_PHONE);
137 sAnalyticsTechnologyMap.put(PhoneConstants.PHONE_TYPE_IMS, Analytics.IMS_PHONE);
138 sAnalyticsTechnologyMap.put(PhoneConstants.PHONE_TYPE_SIP, Analytics.SIP_PHONE);
139 sAnalyticsTechnologyMap.put(PhoneConstants.PHONE_TYPE_THIRD_PARTY,
140 Analytics.THIRD_PARTY_PHONE);
141 }
142
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800143 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -0700144 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
145 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordoncf5b2912014-11-05 21:57:54 -0800146 *
Jay Shraunera82c8f72014-08-14 15:49:16 -0700147 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
148 * load factor before resizing, 1 means we only expect a single thread to
149 * access the map so make only a single shard
Santos Cordon681663d2014-01-30 04:32:15 -0800150 */
Jay Shraunera82c8f72014-08-14 15:49:16 -0700151 private final Set<Call> mCalls = Collections.newSetFromMap(
152 new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1));
Santos Cordon681663d2014-01-30 04:32:15 -0800153
Tyler Gunn8452be02015-09-17 09:57:02 -0700154 /**
155 * The current telecom call ID. Used when creating new instances of {@link Call}. Should
156 * only be accessed using the {@link #getNextCallId()} method which synchronizes on the
157 * {@link #mLock} sync root.
158 */
159 private int mCallId = 0;
160
Santos Cordonf0f99f32016-02-18 16:13:57 -0800161 /**
162 * Stores the current foreground user.
163 */
164 private UserHandle mCurrentUserHandle = UserHandle.of(ActivityManager.getCurrentUser());
165
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700166 private final ConnectionServiceRepository mConnectionServiceRepository;
167 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer;
168 private final InCallController mInCallController;
Santos Cordonf3671a62014-05-29 21:51:53 -0700169 private final CallAudioManager mCallAudioManager;
Ihab Awad8de76912015-02-17 12:25:52 -0800170 private RespondViaSmsManager mRespondViaSmsManager;
Santos Cordonf3671a62014-05-29 21:51:53 -0700171 private final Ringer mRinger;
Santos Cordon61e6f352014-12-03 02:53:34 -0800172 private final InCallWakeLockController mInCallWakeLockController;
Jay Shraunera82c8f72014-08-14 15:49:16 -0700173 // For this set initial table size to 16 because we add 13 listeners in
174 // the CallsManager constructor.
175 private final Set<CallsManagerListener> mListeners = Collections.newSetFromMap(
176 new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1));
Santos Cordondeb8c892014-05-30 01:38:03 -0700177 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepalb88795a2014-07-15 14:53:27 -0700178 private final WiredHeadsetManager mWiredHeadsetManager;
Hall Liuf62630a2015-10-27 14:53:39 -0700179 private final BluetoothManager mBluetoothManager;
Santos Cordona04bdca2015-03-04 16:57:55 -0800180 private final DockManager mDockManager;
Sailesh Nepalb88795a2014-07-15 14:53:27 -0700181 private final TtyManager mTtyManager;
Yorke Leed1346872014-07-28 14:38:45 -0700182 private final ProximitySensorManager mProximitySensorManager;
Yorke Leef86db2e2014-09-12 17:56:48 -0700183 private final PhoneStateBroadcaster mPhoneStateBroadcaster;
Santos Cordonf193ba42014-09-12 06:37:39 -0700184 private final CallLogManager mCallLogManager;
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700185 private final Context mContext;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700186 private final TelecomSystem.SyncRoot mLock;
187 private final ContactsAsyncHelper mContactsAsyncHelper;
Ihab Awadabcbce42015-04-07 14:04:01 -0700188 private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory;
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700189 private final PhoneAccountRegistrar mPhoneAccountRegistrar;
190 private final MissedCallNotifier mMissedCallNotifier;
Hall Liu5b70c1c2016-03-03 18:42:57 -0800191 private final CallerInfoLookupHelper mCallerInfoLookupHelper;
Hall Liu6d4b66d2016-04-01 16:31:13 -0700192 private final DefaultDialerManagerAdapter mDefaultDialerManagerAdapter;
193 private final Timeouts.Adapter mTimeoutsAdapter;
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700194 private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;
Ihab Awad5b281322014-09-25 18:25:29 -0700195 private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>();
Santos Cordoncf5b2912014-11-05 21:57:54 -0800196 private final Set<Call> mPendingCallsToDisconnect = new HashSet<>();
197 /* Handler tied to thread in which CallManager was initialized. */
Ihab Awade6dbc9d2015-03-26 10:33:44 -0700198 private final Handler mHandler = new Handler(Looper.getMainLooper());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700199
Santos Cordon91bd74c2014-11-07 16:10:22 -0800200 private boolean mCanAddCall = true;
201
Brad Ebinger3da57642016-04-04 17:32:19 -0700202 private TelephonyManager.MultiSimVariants mRadioSimVariants = null;
203
Nancy Chena469f762014-12-09 18:29:20 -0800204 private Runnable mStopTone;
205
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700206 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700207 * Initializes the required Telecom components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800208 */
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700209 CallsManager(
210 Context context,
211 TelecomSystem.SyncRoot lock,
212 ContactsAsyncHelper contactsAsyncHelper,
Ihab Awadabcbce42015-04-07 14:04:01 -0700213 CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700214 MissedCallNotifier missedCallNotifier,
215 PhoneAccountRegistrar phoneAccountRegistrar,
216 HeadsetMediaButtonFactory headsetMediaButtonFactory,
217 ProximitySensorManagerFactory proximitySensorManagerFactory,
Hall Liu8fb1fb72015-10-22 15:24:40 -0700218 InCallWakeLockControllerFactory inCallWakeLockControllerFactory,
Hall Liuf62630a2015-10-27 14:53:39 -0700219 CallAudioManager.AudioServiceFactory audioServiceFactory,
220 BluetoothManager bluetoothManager,
Santos Cordonf78a72f2016-01-21 22:10:32 +0000221 WiredHeadsetManager wiredHeadsetManager,
Santos Cordon501b9b32016-03-07 14:40:07 -0800222 SystemStateProvider systemStateProvider,
Brad Ebinger7ade5e22016-04-05 18:43:50 -0700223 DefaultDialerManagerAdapter defaultDialerAdapter,
Hall Liu6d4b66d2016-04-01 16:31:13 -0700224 Timeouts.Adapter timeoutsAdapter,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700225 AsyncRingtonePlayer asyncRingtonePlayer,
226 PhoneNumberUtilsAdapter phoneNumberUtilsAdapter) {
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700227 mContext = context;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700228 mLock = lock;
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700229 mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700230 mContactsAsyncHelper = contactsAsyncHelper;
Ihab Awadabcbce42015-04-07 14:04:01 -0700231 mCallerInfoAsyncQueryFactory = callerInfoAsyncQueryFactory;
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700232 mPhoneAccountRegistrar = phoneAccountRegistrar;
233 mMissedCallNotifier = missedCallNotifier;
234 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this);
Hall Liuf62630a2015-10-27 14:53:39 -0700235 mWiredHeadsetManager = wiredHeadsetManager;
236 mBluetoothManager = bluetoothManager;
Hall Liu6d4b66d2016-04-01 16:31:13 -0700237 mDefaultDialerManagerAdapter = defaultDialerAdapter;
Santos Cordona04bdca2015-03-04 16:57:55 -0800238 mDockManager = new DockManager(context);
Hall Liu6d4b66d2016-04-01 16:31:13 -0700239 mTimeoutsAdapter = timeoutsAdapter;
Hall Liu5b70c1c2016-03-03 18:42:57 -0800240 mCallerInfoLookupHelper = new CallerInfoLookupHelper(context, mCallerInfoAsyncQueryFactory,
Hall Liu46598272016-04-05 12:58:51 -0700241 mContactsAsyncHelper, mLock);
Hall Liue091ab92015-12-18 17:05:30 -0800242
243 mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
Hall Liuf62630a2015-10-27 14:53:39 -0700244 CallAudioRouteStateMachine callAudioRouteStateMachine = new CallAudioRouteStateMachine(
245 context,
246 this,
247 bluetoothManager,
248 wiredHeadsetManager,
249 statusBarNotifier,
Hall Liua3e9dda2015-12-15 17:52:50 -0800250 audioServiceFactory,
251 CallAudioRouteStateMachine.doesDeviceSupportEarpieceRoute()
Hall Liuf62630a2015-10-27 14:53:39 -0700252 );
Hall Liu29855702015-12-11 17:42:03 -0800253 callAudioRouteStateMachine.initialize();
254
Hall Liuf62630a2015-10-27 14:53:39 -0700255 CallAudioRoutePeripheralAdapter callAudioRoutePeripheralAdapter =
256 new CallAudioRoutePeripheralAdapter(
257 callAudioRouteStateMachine,
258 bluetoothManager,
259 wiredHeadsetManager,
260 mDockManager);
261
Hall Liue091ab92015-12-18 17:05:30 -0800262 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(
Hall Liuf62630a2015-10-27 14:53:39 -0700263 callAudioRoutePeripheralAdapter, lock);
264
Hall Liue091ab92015-12-18 17:05:30 -0800265 SystemSettingsUtil systemSettingsUtil = new SystemSettingsUtil();
Brad Ebingerc9286f42016-03-10 16:02:54 -0800266 RingtoneFactory ringtoneFactory = new RingtoneFactory(this, context);
Brad Ebingerd931a012015-10-21 12:54:08 -0700267 SystemVibrator systemVibrator = new SystemVibrator(context);
Santos Cordon501b9b32016-03-07 14:40:07 -0800268 mInCallController = new InCallController(
269 context, mLock, this, systemStateProvider, defaultDialerAdapter);
Hall Liue091ab92015-12-18 17:05:30 -0800270 mRinger = new Ringer(playerFactory, context, systemSettingsUtil, asyncRingtonePlayer,
Santos Cordonf0f99f32016-02-18 16:13:57 -0800271 ringtoneFactory, systemVibrator, mInCallController);
Hall Liue091ab92015-12-18 17:05:30 -0800272
273 mCallAudioManager = new CallAudioManager(callAudioRouteStateMachine,
Hall Liufbed0162016-01-14 18:06:29 -0800274 this,new CallAudioModeStateMachine((AudioManager)
275 mContext.getSystemService(Context.AUDIO_SERVICE)),
276 playerFactory, mRinger, new RingbackPlayer(playerFactory), mDtmfLocalTonePlayer);
Hall Liue091ab92015-12-18 17:05:30 -0800277
Hall Liuf62630a2015-10-27 14:53:39 -0700278 mHeadsetMediaButton = headsetMediaButtonFactory.create(context, this, mLock);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700279 mTtyManager = new TtyManager(context, mWiredHeadsetManager);
Ihab Awad8de76912015-02-17 12:25:52 -0800280 mProximitySensorManager = proximitySensorManagerFactory.create(context, this);
281 mPhoneStateBroadcaster = new PhoneStateBroadcaster(this);
Ta-wei Yen982c0bd2016-04-14 13:59:54 -0700282 mCallLogManager = new CallLogManager(context, phoneAccountRegistrar, mMissedCallNotifier);
Ihab Awad8de76912015-02-17 12:25:52 -0800283 mConnectionServiceRepository =
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700284 new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this);
Ihab Awad8de76912015-02-17 12:25:52 -0800285 mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this);
Santos Cordonae193062014-05-21 21:21:49 -0700286
Tyler Gunnae694b12015-11-11 17:46:03 -0800287 mListeners.add(mInCallWakeLockController);
Santos Cordondeb8c892014-05-30 01:38:03 -0700288 mListeners.add(statusBarNotifier);
Santos Cordonf193ba42014-09-12 06:37:39 -0700289 mListeners.add(mCallLogManager);
Yorke Leef86db2e2014-09-12 17:56:48 -0700290 mListeners.add(mPhoneStateBroadcaster);
Santos Cordonf3671a62014-05-29 21:51:53 -0700291 mListeners.add(mInCallController);
Santos Cordona56f2762014-03-24 15:55:53 -0700292 mListeners.add(mCallAudioManager);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700293 mListeners.add(missedCallNotifier);
Santos Cordon81289982014-06-03 16:03:08 -0700294 mListeners.add(mHeadsetMediaButton);
Yorke Leed1346872014-07-28 14:38:45 -0700295 mListeners.add(mProximitySensorManager);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700296
Tony Maka9930942016-01-15 10:57:14 +0000297 // There is no USER_SWITCHED broadcast for user 0, handle it here explicitly.
298 final UserManager userManager = UserManager.get(mContext);
299 // Don't load missed call if it is run in split user model.
300 if (userManager.isPrimaryUser()) {
301 onUserSwitch(Process.myUserHandle());
302 }
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800303 }
304
Ihab Awad8de76912015-02-17 12:25:52 -0800305 public void setRespondViaSmsManager(RespondViaSmsManager respondViaSmsManager) {
306 if (mRespondViaSmsManager != null) {
307 mListeners.remove(mRespondViaSmsManager);
308 }
309 mRespondViaSmsManager = respondViaSmsManager;
310 mListeners.add(respondViaSmsManager);
311 }
312
313 public RespondViaSmsManager getRespondViaSmsManager() {
314 return mRespondViaSmsManager;
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800315 }
316
Hall Liu5b70c1c2016-03-03 18:42:57 -0800317 public CallerInfoLookupHelper getCallerInfoLookupHelper() {
318 return mCallerInfoLookupHelper;
319 }
320
Santos Cordon766d04f2014-05-06 10:28:25 -0700321 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700322 public void onSuccessfulOutgoingCall(Call call, int callState) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700323 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700324
Santos Cordon5fa4e4f2015-06-10 14:56:01 -0700325 setCallState(call, callState, "successful outgoing call");
Yorke Leeb701f6d2014-08-12 14:04:19 -0700326 if (!mCalls.contains(call)) {
327 // Call was not added previously in startOutgoingCall due to it being a potential MMI
328 // code, so add it now.
329 addCall(call);
330 }
331
332 // The call's ConnectionService has been updated.
333 for (CallsManagerListener listener : mListeners) {
334 listener.onConnectionServiceChanged(call, null, call.getConnectionService());
Santos Cordon766d04f2014-05-06 10:28:25 -0700335 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700336
337 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700338 }
339
340 @Override
Andrew Lee701dc002014-09-11 21:29:12 -0700341 public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) {
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700342 Log.v(this, "onFailedOutgoingCall, call: %s", call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700343
Andrew Leee6288a72014-10-01 13:50:02 -0700344 markCallAsRemoved(call);
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700345 }
346
347 @Override
Hall Liu6d4b66d2016-04-01 16:31:13 -0700348 public void onSuccessfulIncomingCall(Call incomingCall) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700349 Log.d(this, "onSuccessfulIncomingCall");
Hall Liuddf3f9c2016-08-30 13:38:52 -0700350 if (incomingCall.hasProperty(Connection.PROPERTY_EMERGENCY_CALLBACK_MODE)) {
351 Log.i(this, "Skipping call filtering due to ECBM");
352 onCallFilteringComplete(incomingCall, new CallFilteringResult(true, false, true, true));
353 return;
354 }
355
Hall Liu6d4b66d2016-04-01 16:31:13 -0700356 List<IncomingCallFilter.CallFilter> filters = new ArrayList<>();
357 filters.add(new DirectToVoicemailCallFilter(mCallerInfoLookupHelper));
358 filters.add(new AsyncBlockCheckFilter(mContext, new BlockCheckerAdapter()));
359 filters.add(new CallScreeningServiceFilter(mContext, this, mPhoneAccountRegistrar,
360 mDefaultDialerManagerAdapter,
361 new ParcelableCallUtils.Converter(), mLock));
362 new IncomingCallFilter(mContext, this, incomingCall, mLock,
363 mTimeoutsAdapter, filters).performFiltering();
Sailesh Nepalae925952016-01-24 18:56:58 -0800364 }
365
366 @Override
Hall Liu6d4b66d2016-04-01 16:31:13 -0700367 public void onCallFilteringComplete(Call incomingCall, CallFilteringResult result) {
Hall Liue091ab92015-12-18 17:05:30 -0800368 // Only set the incoming call as ringing if it isn't already disconnected. It is possible
Tyler Gunne6276e12015-10-22 20:48:50 -0700369 // that the connection service disconnected the call before it was even added to Telecom, in
370 // which case it makes no sense to set it back to a ringing state.
371 if (incomingCall.getState() != CallState.DISCONNECTED &&
372 incomingCall.getState() != CallState.DISCONNECTING) {
373 setCallState(incomingCall, CallState.RINGING,
Hall Liu6d4b66d2016-04-01 16:31:13 -0700374 result.shouldAllowCall ? "successful incoming call" : "blocking call");
Tyler Gunne6276e12015-10-22 20:48:50 -0700375 } else {
Hall Liu6d4b66d2016-04-01 16:31:13 -0700376 Log.i(this, "onCallFilteringCompleted: call already disconnected.");
Tyler Gunne6276e12015-10-22 20:48:50 -0700377 }
Santos Cordonf193ba42014-09-12 06:37:39 -0700378
Hall Liu6d4b66d2016-04-01 16:31:13 -0700379 if (result.shouldAllowCall) {
Sailesh Nepalae925952016-01-24 18:56:58 -0800380 if (hasMaximumRingingCalls()) {
Hall Liu6d4b66d2016-04-01 16:31:13 -0700381 Log.i(this, "onCallFilteringCompleted: Call rejected! Exceeds maximum number of " +
Sailesh Nepalae925952016-01-24 18:56:58 -0800382 "ringing calls.");
383 rejectCallAndLog(incomingCall);
384 } else if (hasMaximumDialingCalls()) {
Hall Liu6d4b66d2016-04-01 16:31:13 -0700385 Log.i(this, "onCallFilteringCompleted: Call rejected! Exceeds maximum number of " +
Sailesh Nepalae925952016-01-24 18:56:58 -0800386 "dialing calls.");
387 rejectCallAndLog(incomingCall);
388 } else {
389 addCall(incomingCall);
390 }
Santos Cordonf193ba42014-09-12 06:37:39 -0700391 } else {
Hall Liu6d4b66d2016-04-01 16:31:13 -0700392 if (result.shouldReject) {
393 Log.i(this, "onCallFilteringCompleted: blocked call, rejecting.");
Sailesh Nepalae925952016-01-24 18:56:58 -0800394 incomingCall.reject(false, null);
395 }
Hall Liu6d4b66d2016-04-01 16:31:13 -0700396 if (result.shouldAddToCallLog) {
Sailesh Nepalae925952016-01-24 18:56:58 -0800397 Log.i(this, "onCallScreeningCompleted: blocked call, adding to call log.");
Hall Liu6d4b66d2016-04-01 16:31:13 -0700398 if (result.shouldShowNotification) {
Ta-wei Yen982c0bd2016-04-14 13:59:54 -0700399 Log.w(this, "onCallScreeningCompleted: blocked call, showing notification.");
400 }
Hall Liu6d4b66d2016-04-01 16:31:13 -0700401 mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE,
402 result.shouldShowNotification);
403 } else if (result.shouldShowNotification) {
Sailesh Nepalae925952016-01-24 18:56:58 -0800404 Log.i(this, "onCallScreeningCompleted: blocked call, showing notification.");
405 mMissedCallNotifier.showMissedCallNotification(incomingCall);
406 }
Santos Cordonf193ba42014-09-12 06:37:39 -0700407 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700408 }
409
410 @Override
411 public void onFailedIncomingCall(Call call) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -0700412 setCallState(call, CallState.DISCONNECTED, "failed incoming call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700413 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800414 }
415
Ihab Awadcb387ac2014-05-28 16:49:38 -0700416 @Override
Yorke Lee9250e5f2014-10-01 13:39:09 -0700417 public void onSuccessfulUnknownCall(Call call, int callState) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -0700418 setCallState(call, callState, "successful unknown call");
Yorke Lee9250e5f2014-10-01 13:39:09 -0700419 Log.i(this, "onSuccessfulUnknownCall for call %s", call);
420 addCall(call);
421 }
422
423 @Override
424 public void onFailedUnknownCall(Call call) {
425 Log.i(this, "onFailedUnknownCall for call %s", call);
Santos Cordon5fa4e4f2015-06-10 14:56:01 -0700426 setCallState(call, CallState.DISCONNECTED, "failed unknown call");
Yorke Lee9250e5f2014-10-01 13:39:09 -0700427 call.removeListener(this);
428 }
429
430 @Override
Andrew Lee5be64bc2014-09-08 18:35:15 -0700431 public void onRingbackRequested(Call call, boolean ringback) {
Ihab Awadcb387ac2014-05-28 16:49:38 -0700432 for (CallsManagerListener listener : mListeners) {
Andrew Lee5be64bc2014-09-08 18:35:15 -0700433 listener.onRingbackRequested(call, ringback);
Ihab Awadcb387ac2014-05-28 16:49:38 -0700434 }
435 }
436
Evan Charlton352105c2014-06-03 14:10:54 -0700437 @Override
438 public void onPostDialWait(Call call, String remaining) {
439 mInCallController.onPostDialWait(call, remaining);
440 }
441
Santos Cordona1610702014-06-04 20:22:56 -0700442 @Override
Nancy Chena469f762014-12-09 18:29:20 -0800443 public void onPostDialChar(final Call call, char nextChar) {
444 if (PhoneNumberUtils.is12Key(nextChar)) {
445 // Play tone if it is one of the dialpad digits, canceling out the previously queued
446 // up stopTone runnable since playing a new tone automatically stops the previous tone.
447 if (mStopTone != null) {
Brad Ebingere62e9e82016-02-01 18:26:40 -0800448 mHandler.removeCallbacks(mStopTone.getRunnableToCancel());
449 mStopTone.cancel();
Nancy Chena469f762014-12-09 18:29:20 -0800450 }
451
452 mDtmfLocalTonePlayer.playTone(call, nextChar);
453
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700454 // TODO: Create a LockedRunnable class that does the synchronization automatically.
Brad Ebingere62e9e82016-02-01 18:26:40 -0800455 mStopTone = new Runnable("CM.oPDC") {
Nancy Chena469f762014-12-09 18:29:20 -0800456 @Override
Brad Ebingere62e9e82016-02-01 18:26:40 -0800457 public void loggedRun() {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700458 synchronized (mLock) {
Brad Ebingerd931a012015-10-21 12:54:08 -0700459 // Set a timeout to stop the tone in case there isn't another tone to
460 // follow.
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700461 mDtmfLocalTonePlayer.stopTone(call);
462 }
Nancy Chena469f762014-12-09 18:29:20 -0800463 }
464 };
Brad Ebingere62e9e82016-02-01 18:26:40 -0800465 mHandler.postDelayed(mStopTone.prepare(),
Nancy Chena469f762014-12-09 18:29:20 -0800466 Timeouts.getDelayBetweenDtmfTonesMillis(mContext.getContentResolver()));
467 } else if (nextChar == 0 || nextChar == TelecomManager.DTMF_CHARACTER_WAIT ||
468 nextChar == TelecomManager.DTMF_CHARACTER_PAUSE) {
469 // Stop the tone if a tone is playing, removing any other stopTone callbacks since
470 // the previous tone is being stopped anyway.
471 if (mStopTone != null) {
Brad Ebingere62e9e82016-02-01 18:26:40 -0800472 mHandler.removeCallbacks(mStopTone.getRunnableToCancel());
473 mStopTone.cancel();
Nancy Chena469f762014-12-09 18:29:20 -0800474 }
475 mDtmfLocalTonePlayer.stopTone(call);
476 } else {
477 Log.w(this, "onPostDialChar: invalid value %d", nextChar);
478 }
479 }
480
481 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700482 public void onParentChanged(Call call) {
Santos Cordon66fe8822014-10-10 16:10:58 -0700483 // parent-child relationship affects which call should be foreground, so do an update.
Hall Liufc130b22016-06-15 17:54:48 -0700484 updateCanAddCall();
Santos Cordona1610702014-06-04 20:22:56 -0700485 for (CallsManagerListener listener : mListeners) {
486 listener.onIsConferencedChanged(call);
487 }
488 }
489
490 @Override
491 public void onChildrenChanged(Call call) {
Santos Cordon66fe8822014-10-10 16:10:58 -0700492 // parent-child relationship affects which call should be foreground, so do an update.
Hall Liufc130b22016-06-15 17:54:48 -0700493 updateCanAddCall();
Santos Cordona1610702014-06-04 20:22:56 -0700494 for (CallsManagerListener listener : mListeners) {
495 listener.onIsConferencedChanged(call);
496 }
497 }
498
Ihab Awadff7493a2014-06-10 13:47:44 -0700499 @Override
Andrew Lee5be64bc2014-09-08 18:35:15 -0700500 public void onIsVoipAudioModeChanged(Call call) {
Sailesh Nepal7e669572014-07-08 21:29:12 -0700501 for (CallsManagerListener listener : mListeners) {
Andrew Lee5be64bc2014-09-08 18:35:15 -0700502 listener.onIsVoipAudioModeChanged(call);
Sailesh Nepal7e669572014-07-08 21:29:12 -0700503 }
504 }
505
Andrew Lee4a796602014-07-11 17:23:03 -0700506 @Override
Hall Liu9696c212016-06-24 16:09:02 -0700507 public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
Andrew Lee4a796602014-07-11 17:23:03 -0700508 for (CallsManagerListener listener : mListeners) {
Hall Liu9696c212016-06-24 16:09:02 -0700509 listener.onVideoStateChanged(call, previousVideoState, newVideoState);
Andrew Lee4a796602014-07-11 17:23:03 -0700510 }
511 }
512
Santos Cordoncf5b2912014-11-05 21:57:54 -0800513 @Override
514 public boolean onCanceledViaNewOutgoingCallBroadcast(final Call call) {
515 mPendingCallsToDisconnect.add(call);
Brad Ebingere62e9e82016-02-01 18:26:40 -0800516 mHandler.postDelayed(new Runnable("CM.oCVNOCB") {
Santos Cordoncf5b2912014-11-05 21:57:54 -0800517 @Override
Brad Ebingere62e9e82016-02-01 18:26:40 -0800518 public void loggedRun() {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700519 synchronized (mLock) {
520 if (mPendingCallsToDisconnect.remove(call)) {
521 Log.i(this, "Delayed disconnection of call: %s", call);
522 call.disconnect();
523 }
Santos Cordoncf5b2912014-11-05 21:57:54 -0800524 }
525 }
Brad Ebingere62e9e82016-02-01 18:26:40 -0800526 }.prepare(), Timeouts.getNewOutgoingCallCancelMillis(mContext.getContentResolver()));
Santos Cordoncf5b2912014-11-05 21:57:54 -0800527
528 return true;
529 }
530
Tyler Gunn86014fc2015-06-12 14:31:25 -0700531 /**
532 * Handles changes to the {@link Connection.VideoProvider} for a call. Adds the
533 * {@link CallsManager} as a listener for the {@link VideoProviderProxy} which is created
534 * in {@link Call#setVideoProvider(IVideoProvider)}. This allows the {@link CallsManager} to
535 * respond to callbacks from the {@link VideoProviderProxy}.
536 *
537 * @param call The call.
538 */
539 @Override
540 public void onVideoCallProviderChanged(Call call) {
541 VideoProviderProxy videoProviderProxy = call.getVideoProviderProxy();
542
543 if (videoProviderProxy == null) {
544 return;
545 }
546
547 videoProviderProxy.addListener(this);
548 }
549
550 /**
551 * Handles session modification requests received via the {@link TelecomVideoCallCallback} for
552 * a call. Notifies listeners of the {@link CallsManager.CallsManagerListener} of the session
553 * modification request.
554 *
555 * @param call The call.
556 * @param videoProfile The {@link VideoProfile}.
557 */
558 @Override
559 public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) {
560 int videoState = videoProfile != null ? videoProfile.getVideoState() :
561 VideoProfile.STATE_AUDIO_ONLY;
562 Log.v(TAG, "onSessionModifyRequestReceived : videoProfile = " + VideoProfile
563 .videoStateToString(videoState));
564
565 for (CallsManagerListener listener : mListeners) {
566 listener.onSessionModifyRequestReceived(call, videoProfile);
567 }
568 }
569
Brad Ebinger53855132015-10-30 10:58:19 -0700570 public Collection<Call> getCalls() {
Santos Cordon4bc02452014-11-19 15:51:12 -0800571 return Collections.unmodifiableCollection(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700572 }
573
Tyler Gunndb821912016-02-16 14:35:25 -0800574 /**
575 * Play or stop a call hold tone for a call. Triggered via
576 * {@link Connection#sendConnectionEvent(String)} when the
577 * {@link Connection#EVENT_ON_HOLD_TONE_START} event or
578 * {@link Connection#EVENT_ON_HOLD_TONE_STOP} event is passed through to the
579 *
580 * @param call The call which requested the hold tone.
581 */
582 @Override
583 public void onHoldToneRequested(Call call) {
584 for (CallsManagerListener listener : mListeners) {
585 listener.onHoldToneRequested(call);
586 }
587 }
588
Brad Ebingerd931a012015-10-21 12:54:08 -0700589 @VisibleForTesting
590 public Call getForegroundCall() {
Hall Liue091ab92015-12-18 17:05:30 -0800591 if (mCallAudioManager == null) {
592 // Happens when getForegroundCall is called before full initialization.
593 return null;
594 }
595 return mCallAudioManager.getForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700596 }
597
Santos Cordonf0f99f32016-02-18 16:13:57 -0800598 public UserHandle getCurrentUserHandle() {
599 return mCurrentUserHandle;
600 }
601
Hall Liu9ecbb1c2016-04-14 14:35:48 -0700602 public CallAudioManager getCallAudioManager() {
Hall Liue091ab92015-12-18 17:05:30 -0800603 return mCallAudioManager;
Santos Cordonae193062014-05-21 21:21:49 -0700604 }
605
Santos Cordonf3671a62014-05-29 21:51:53 -0700606 InCallController getInCallController() {
607 return mInCallController;
608 }
609
Santos Cordonf0f99f32016-02-18 16:13:57 -0800610 @VisibleForTesting
611 public boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700612 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700613 if (call.isEmergencyCall()) {
614 return true;
615 }
616 }
617 return false;
618 }
619
Roshan Pius669f90b2015-09-02 16:21:39 -0700620 boolean hasOnlyDisconnectedCalls() {
621 for (Call call : mCalls) {
622 if (!call.isDisconnected()) {
623 return false;
624 }
625 }
626 return true;
627 }
628
Andrew Lee45506232014-10-22 17:54:33 -0700629 boolean hasVideoCall() {
630 for (Call call : mCalls) {
Tyler Gunn467b64f2015-06-09 13:48:47 -0700631 if (VideoProfile.isVideo(call.getVideoState())) {
Andrew Lee45506232014-10-22 17:54:33 -0700632 return true;
633 }
634 }
635 return false;
636 }
637
Yorke Lee2a66f7b2015-05-13 14:21:19 -0700638 CallAudioState getAudioState() {
639 return mCallAudioManager.getCallAudioState();
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700640 }
641
Sailesh Nepalb88795a2014-07-15 14:53:27 -0700642 boolean isTtySupported() {
643 return mTtyManager.isTtySupported();
644 }
645
646 int getCurrentTtyMode() {
647 return mTtyManager.getCurrentTtyMode();
648 }
649
Brad Ebinger53855132015-10-30 10:58:19 -0700650 @VisibleForTesting
651 public void addListener(CallsManagerListener listener) {
Santos Cordon68d1a6b2014-09-19 12:25:58 -0700652 mListeners.add(listener);
653 }
654
655 void removeListener(CallsManagerListener listener) {
656 mListeners.remove(listener);
657 }
658
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800659 /**
Sailesh Nepal664837f2014-07-14 16:31:51 -0700660 * Starts the process to attach the call to a connection service.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800661 *
Nancy Chenbc9ef172014-08-15 17:11:57 -0700662 * @param phoneAccountHandle The phone account which contains the component name of the
663 * connection service to use for this call.
Evan Charltona05805b2014-03-05 08:21:46 -0800664 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800665 */
Evan Charlton89176372014-07-19 18:23:09 -0700666 void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800667 Log.d(this, "processIncomingCallIntent");
Yorke Lee69fa8972015-06-08 11:25:32 -0700668 Uri handle = extras.getParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS);
669 if (handle == null) {
670 // Required for backwards compatibility
671 handle = extras.getParcelable(TelephonyManager.EXTRA_INCOMING_NUMBER);
672 }
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700673 Call call = new Call(
Tyler Gunn8452be02015-09-17 09:57:02 -0700674 getNextCallId(),
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700675 mContext,
Ihab Awad78a5e6b2015-02-06 10:13:05 -0800676 this,
Ihab Awade6dbc9d2015-03-26 10:33:44 -0700677 mLock,
Sailesh Nepal664837f2014-07-14 16:31:51 -0700678 mConnectionServiceRepository,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700679 mContactsAsyncHelper,
Ihab Awadabcbce42015-04-07 14:04:01 -0700680 mCallerInfoAsyncQueryFactory,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700681 mPhoneNumberUtilsAdapter,
Sailesh Nepal8aa6a002014-09-12 10:52:49 -0700682 handle,
Sailesh Nepal664837f2014-07-14 16:31:51 -0700683 null /* gatewayInfo */,
Ihab Awadb78b2762014-07-25 15:16:23 -0700684 null /* connectionManagerPhoneAccount */,
Evan Charlton89176372014-07-19 18:23:09 -0700685 phoneAccountHandle,
Hall Liu32587202015-11-18 11:10:08 -0800686 Call.CALL_DIRECTION_INCOMING /* callDirection */,
687 false /* forceAttachToExistingConnection */,
Tony Mak578a4e62015-11-23 11:18:51 +0000688 false /* isConference */
689 );
Hall Liu32587202015-11-18 11:10:08 -0800690
691 call.initAnalytics();
Hall Liue091ab92015-12-18 17:05:30 -0800692 if (getForegroundCall() != null) {
693 getForegroundCall().getAnalytics().setCallIsInterrupted(true);
Hall Liu32587202015-11-18 11:10:08 -0800694 call.getAnalytics().setCallIsAdditional(true);
695 }
696
Sailesh Nepal703a1af2016-04-14 20:10:12 -0700697 setIntentExtrasAndStartTime(call, extras);
Santos Cordondf399862014-08-06 04:39:15 -0700698 // TODO: Move this to be a part of addCall()
Santos Cordon766d04f2014-05-06 10:28:25 -0700699 call.addListener(this);
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700700 call.startCreateConnection(mPhoneAccountRegistrar);
Ben Gilada0d9f752014-02-26 11:49:03 -0800701 }
702
Yorke Lee9250e5f2014-10-01 13:39:09 -0700703 void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
704 Uri handle = extras.getParcelable(TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE);
705 Log.i(this, "addNewUnknownCall with handle: %s", Log.pii(handle));
706 Call call = new Call(
Tyler Gunn8452be02015-09-17 09:57:02 -0700707 getNextCallId(),
Yorke Lee9250e5f2014-10-01 13:39:09 -0700708 mContext,
Ihab Awad78a5e6b2015-02-06 10:13:05 -0800709 this,
Ihab Awade6dbc9d2015-03-26 10:33:44 -0700710 mLock,
Yorke Lee9250e5f2014-10-01 13:39:09 -0700711 mConnectionServiceRepository,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700712 mContactsAsyncHelper,
Ihab Awadabcbce42015-04-07 14:04:01 -0700713 mCallerInfoAsyncQueryFactory,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700714 mPhoneNumberUtilsAdapter,
Yorke Lee9250e5f2014-10-01 13:39:09 -0700715 handle,
716 null /* gatewayInfo */,
717 null /* connectionManagerPhoneAccount */,
718 phoneAccountHandle,
Hall Liu32587202015-11-18 11:10:08 -0800719 Call.CALL_DIRECTION_UNKNOWN /* callDirection */,
Yorke Lee9250e5f2014-10-01 13:39:09 -0700720 // Use onCreateIncomingConnection in TelephonyConnectionService, so that we attach
721 // to the existing connection instead of trying to create a new one.
Hall Liu32587202015-11-18 11:10:08 -0800722 true /* forceAttachToExistingConnection */,
Tony Mak578a4e62015-11-23 11:18:51 +0000723 false /* isConference */
724 );
Hall Liu32587202015-11-18 11:10:08 -0800725 call.initAnalytics();
726
Sailesh Nepal703a1af2016-04-14 20:10:12 -0700727 setIntentExtrasAndStartTime(call, extras);
Yorke Lee9250e5f2014-10-01 13:39:09 -0700728 call.addListener(this);
729 call.startCreateConnection(mPhoneAccountRegistrar);
730 }
731
Yorke Lee8d3f2692015-05-08 11:44:39 -0700732 private boolean areHandlesEqual(Uri handle1, Uri handle2) {
733 if (handle1 == null || handle2 == null) {
734 return handle1 == handle2;
735 }
736
737 if (!TextUtils.equals(handle1.getScheme(), handle2.getScheme())) {
738 return false;
739 }
740
741 final String number1 = PhoneNumberUtils.normalizeNumber(handle1.getSchemeSpecificPart());
742 final String number2 = PhoneNumberUtils.normalizeNumber(handle2.getSchemeSpecificPart());
743 return TextUtils.equals(number1, number2);
744 }
745
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800746 private Call reuseOutgoingCall(Uri handle) {
747 // Check to see if we can reuse any of the calls that are waiting to disconnect.
Santos Cordoncf5b2912014-11-05 21:57:54 -0800748 // See {@link Call#abort} and {@link #onCanceledViaNewOutgoingCall} for more information.
Yorke Lee59979512014-12-02 01:03:40 -0800749 Call reusedCall = null;
Santos Cordoncf5b2912014-11-05 21:57:54 -0800750 for (Call pendingCall : mPendingCallsToDisconnect) {
Yorke Lee8d3f2692015-05-08 11:44:39 -0700751 if (reusedCall == null && areHandlesEqual(pendingCall.getHandle(), handle)) {
Santos Cordoncf5b2912014-11-05 21:57:54 -0800752 mPendingCallsToDisconnect.remove(pendingCall);
753 Log.i(this, "Reusing disconnected call %s", pendingCall);
Yorke Lee59979512014-12-02 01:03:40 -0800754 reusedCall = pendingCall;
755 } else {
Yorke Lee8d3f2692015-05-08 11:44:39 -0700756 Log.i(this, "Not reusing disconnected call %s", pendingCall);
Yorke Lee59979512014-12-02 01:03:40 -0800757 pendingCall.disconnect();
Santos Cordoncf5b2912014-11-05 21:57:54 -0800758 }
759 }
760
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800761 return reusedCall;
Santos Cordoncf5b2912014-11-05 21:57:54 -0800762 }
763
Nancy Chen0d3076c2014-07-30 14:45:44 -0700764 /**
765 * Kicks off the first steps to creating an outgoing call so that InCallUI can launch.
766 *
Nancy Chena9d91da2014-08-12 14:31:06 -0700767 * @param handle Handle to connect the call with.
Nancy Chenbc9ef172014-08-15 17:11:57 -0700768 * @param phoneAccountHandle The phone account which contains the component name of the
769 * connection service to use for this call.
770 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Tony Mak578a4e62015-11-23 11:18:51 +0000771 * @param initiatingUser {@link UserHandle} of user that place the outgoing call.
Nancy Chen0d3076c2014-07-30 14:45:44 -0700772 */
Tony Mak578a4e62015-11-23 11:18:51 +0000773 Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras,
774 UserHandle initiatingUser) {
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800775 boolean isReusedCall = true;
776 Call call = reuseOutgoingCall(handle);
777
778 // Create a call with original handle. The handle may be changed when the call is attached
779 // to a connection service, but in most cases will remain the same.
780 if (call == null) {
781 call = new Call(getNextCallId(), mContext,
782 this,
783 mLock,
784 mConnectionServiceRepository,
785 mContactsAsyncHelper,
786 mCallerInfoAsyncQueryFactory,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700787 mPhoneNumberUtilsAdapter,
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800788 handle,
789 null /* gatewayInfo */,
790 null /* connectionManagerPhoneAccount */,
791 null /* phoneAccountHandle */,
Hall Liu32587202015-11-18 11:10:08 -0800792 Call.CALL_DIRECTION_OUTGOING /* callDirection */,
793 false /* forceAttachToExistingConnection */,
Tony Mak578a4e62015-11-23 11:18:51 +0000794 false /* isConference */
795 );
Hall Liu32587202015-11-18 11:10:08 -0800796 call.initAnalytics();
797
Hall Liu874c0f82016-04-29 18:13:18 -0700798 call.setInitiatingUser(initiatingUser);
799
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800800 isReusedCall = false;
801 }
Nancy Chen1c5926f2014-09-17 14:44:14 -0700802
Tyler Gunn228f95e2016-03-03 16:24:45 -0800803 // Set the video state on the call early so that when it is added to the InCall UI the UI
804 // knows to configure itself as a video call immediately.
805 if (extras != null) {
Tyler Gunnf8156382016-03-30 08:35:29 -0700806 int videoState = extras.getInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
807 VideoProfile.STATE_AUDIO_ONLY);
808
809 // If this is an emergency video call, we need to check if the phone account supports
810 // emergency video calling.
Tyler Gunn10274f72016-07-26 15:38:16 -0700811 // Also, ensure we don't try to place an outgoing call with video if video is not
812 // supported.
813 if (VideoProfile.isVideo(videoState)) {
Tyler Gunnf8156382016-03-30 08:35:29 -0700814 PhoneAccount account =
815 mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle, initiatingUser);
816
Tyler Gunn10274f72016-07-26 15:38:16 -0700817 if (call.isEmergencyCall() && account != null &&
Tyler Gunnf8156382016-03-30 08:35:29 -0700818 !account.hasCapabilities(PhoneAccount.CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
819 // Phone account doesn't support emergency video calling, so fallback to
820 // audio-only now to prevent the InCall UI from setting up video surfaces
821 // needlessly.
822 Log.i(this, "startOutgoingCall - emergency video calls not supported; " +
823 "falling back to audio-only");
824 videoState = VideoProfile.STATE_AUDIO_ONLY;
Tyler Gunn10274f72016-07-26 15:38:16 -0700825 } else if (account != null &&
826 !account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
827 // Phone account doesn't support video calling, so fallback to audio-only.
828 Log.i(this, "startOutgoingCall - video calls not supported; fallback to " +
829 "audio-only.");
830 videoState = VideoProfile.STATE_AUDIO_ONLY;
Tyler Gunnf8156382016-03-30 08:35:29 -0700831 }
832 }
833
834 call.setVideoState(videoState);
Omkar Kolangade005612a2015-08-25 11:08:18 -0700835 }
836
Brad Ebinger3da57642016-04-04 17:32:19 -0700837 List<PhoneAccountHandle> accounts = constructPossiblePhoneAccounts(handle, initiatingUser);
Ihab Awad7e2c7f32014-11-03 09:49:45 -0800838 Log.v(this, "startOutgoingCall found accounts = " + accounts);
839
Nancy Chenbc9ef172014-08-15 17:11:57 -0700840 // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call
841 // as if a phoneAccount was not specified (does the default behavior instead).
Tyler Gunn8e0fef42014-09-08 18:34:44 -0700842 // Note: We will not attempt to dial with a requested phoneAccount if it is disabled.
Nancy Chenbc9ef172014-08-15 17:11:57 -0700843 if (phoneAccountHandle != null) {
Nancy Chen309198e2014-09-15 18:02:49 -0700844 if (!accounts.contains(phoneAccountHandle)) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700845 phoneAccountHandle = null;
846 }
847 }
848
Brad Ebingere6c481a2016-05-12 14:13:26 -0700849 if (phoneAccountHandle == null && accounts.size() > 0) {
Tyler Gunn84253572014-09-02 14:50:05 -0700850 // No preset account, check if default exists that supports the URI scheme for the
Brad Ebinger3da57642016-04-04 17:32:19 -0700851 // handle and verify it can be used.
852 if(accounts.size() > 1) {
853 PhoneAccountHandle defaultPhoneAccountHandle =
854 mPhoneAccountRegistrar.getOutgoingPhoneAccountForScheme(handle.getScheme(),
855 initiatingUser);
856 if (defaultPhoneAccountHandle != null &&
857 accounts.contains(defaultPhoneAccountHandle)) {
858 phoneAccountHandle = defaultPhoneAccountHandle;
859 }
860 } else {
861 // Use the only PhoneAccount that is available
862 phoneAccountHandle = accounts.get(0);
863 }
864
Nancy Chenbc9ef172014-08-15 17:11:57 -0700865 }
866
Nancy Chen1c5926f2014-09-17 14:44:14 -0700867 call.setTargetPhoneAccount(phoneAccountHandle);
Nancy Chenbc9ef172014-08-15 17:11:57 -0700868
Tyler Gunn5b452df2014-10-01 15:02:58 -0700869 boolean isPotentialInCallMMICode = isPotentialInCallMMICode(handle);
Santos Cordonf193ba42014-09-12 06:37:39 -0700870
871 // Do not support any more live calls. Our options are to move a call to hold, disconnect
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800872 // a call, or cancel this call altogether. If a call is being reused, then it has already
873 // passed the makeRoomForOutgoingCall check once and will fail the second time due to the
874 // call transitioning into the CONNECTING state.
875 if (!isPotentialInCallMMICode && (!isReusedCall &&
876 !makeRoomForOutgoingCall(call, call.isEmergencyCall()))) {
Santos Cordonf193ba42014-09-12 06:37:39 -0700877 // just cancel at this point.
Yorke Lee59979512014-12-02 01:03:40 -0800878 Log.i(this, "No remaining room for outgoing call: %s", call);
Santos Cordoncf5b2912014-11-05 21:57:54 -0800879 if (mCalls.contains(call)) {
880 // This call can already exist if it is a reused call,
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800881 // See {@link #reuseOutgoingCall}.
Santos Cordoncf5b2912014-11-05 21:57:54 -0800882 call.disconnect();
883 }
Santos Cordonf193ba42014-09-12 06:37:39 -0700884 return null;
885 }
886
Nancy Chen8d92f452014-10-20 21:43:44 -0700887 boolean needsAccountSelection = phoneAccountHandle == null && accounts.size() > 1 &&
Tyler Gunn6ffe5312015-08-12 08:19:20 -0700888 !call.isEmergencyCall();
Nancy Chen8d92f452014-10-20 21:43:44 -0700889
890 if (needsAccountSelection) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700891 // This is the state where the user is expected to select an account
Santos Cordon5fa4e4f2015-06-10 14:56:01 -0700892 call.setState(CallState.SELECT_PHONE_ACCOUNT, "needs account selection");
Pawit Pornkitprasan1b2fd282015-03-15 08:33:32 +0700893 // Create our own instance to modify (since extras may be Bundle.EMPTY)
894 extras = new Bundle(extras);
Nancy Chen1c5926f2014-09-17 14:44:14 -0700895 extras.putParcelableList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS, accounts);
Nancy Chenbc9ef172014-08-15 17:11:57 -0700896 } else {
Roshan Pius781d0252015-06-25 14:13:07 -0700897 call.setState(
898 CallState.CONNECTING,
899 phoneAccountHandle == null ? "no-handle" : phoneAccountHandle.toString());
Nancy Chenbc9ef172014-08-15 17:11:57 -0700900 }
Nancy Chen0d3076c2014-07-30 14:45:44 -0700901
Sailesh Nepal703a1af2016-04-14 20:10:12 -0700902 setIntentExtrasAndStartTime(call, extras);
Nancy Chen1c5926f2014-09-17 14:44:14 -0700903
Tyler Gunn504eb832014-10-13 14:15:27 -0700904 // Do not add the call if it is a potential MMI code.
Nancy Chen8d92f452014-10-20 21:43:44 -0700905 if ((isPotentialMMICode(handle) || isPotentialInCallMMICode) && !needsAccountSelection) {
Yorke Leeb701f6d2014-08-12 14:04:19 -0700906 call.addListener(this);
Santos Cordoncf5b2912014-11-05 21:57:54 -0800907 } else if (!mCalls.contains(call)) {
908 // We check if mCalls already contains the call because we could potentially be reusing
Brad Ebingerb1e3d752015-11-09 17:54:17 -0800909 // a call which was previously added (See {@link #reuseOutgoingCall}).
Tyler Gunn5b452df2014-10-01 15:02:58 -0700910 addCall(call);
Yorke Leeb701f6d2014-08-12 14:04:19 -0700911 }
Nancy Chen0d3076c2014-07-30 14:45:44 -0700912
913 return call;
914 }
915
Ben Gilada0d9f752014-02-26 11:49:03 -0800916 /**
Yorke Lee33501632014-03-17 19:24:12 -0700917 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800918 *
Yorke Lee33501632014-03-17 19:24:12 -0700919 * @param handle Handle to connect the call with.
Yorke Lee33501632014-03-17 19:24:12 -0700920 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Nancy Chen53ceedc2014-07-08 18:56:51 -0700921 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700922 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Tyler Gunnc4abd912014-07-08 14:22:10 -0700923 * @param videoState The desired video state for the outgoing call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800924 */
Hall Liu220b4192015-12-11 11:33:08 -0800925 @VisibleForTesting
926 public void placeOutgoingCall(Call call, Uri handle, GatewayInfo gatewayInfo,
927 boolean speakerphoneOn, int videoState) {
Nancy Chen0d3076c2014-07-30 14:45:44 -0700928 if (call == null) {
929 // don't do anything if the call no longer exists
930 Log.i(this, "Canceling unknown call.");
Santos Cordonb7af09e2014-08-06 04:30:01 -0700931 return;
932 }
933
Nancy Chen201b4372014-09-08 14:18:24 -0700934 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayAddress();
Yorke Lee33501632014-03-17 19:24:12 -0700935
936 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700937 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700938 } else {
939 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
940 Log.pii(uriHandle), Log.pii(handle));
941 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700942
Nancy Chen0d3076c2014-07-30 14:45:44 -0700943 call.setHandle(uriHandle);
944 call.setGatewayInfo(gatewayInfo);
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800945
946 final boolean useSpeakerWhenDocked = mContext.getResources().getBoolean(
947 R.bool.use_speaker_when_docked);
John Eckerdal63486002015-11-20 13:17:29 +0100948 final boolean useSpeakerForDock = isSpeakerphoneEnabledForDock();
Hall Liu9696c212016-06-24 16:09:02 -0700949 final boolean useSpeakerForVideoCall = isSpeakerphoneAutoEnabledForVideoCalls(videoState);
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800950
951 // Auto-enable speakerphone if the originating intent specified to do so, if the call
952 // is a video call, of if using speaker when docked
953 call.setStartWithSpeakerphoneOn(speakerphoneOn || useSpeakerForVideoCall
John Eckerdal63486002015-11-20 13:17:29 +0100954 || (useSpeakerWhenDocked && useSpeakerForDock));
Tyler Gunnc4abd912014-07-08 14:22:10 -0700955 call.setVideoState(videoState);
Santos Cordon766d04f2014-05-06 10:28:25 -0700956
Santos Cordona04bdca2015-03-04 16:57:55 -0800957 if (speakerphoneOn) {
958 Log.i(this, "%s Starting with speakerphone as requested", call);
John Eckerdal63486002015-11-20 13:17:29 +0100959 } else if (useSpeakerWhenDocked && useSpeakerForDock) {
Santos Cordona04bdca2015-03-04 16:57:55 -0800960 Log.i(this, "%s Starting with speakerphone because car is docked.", call);
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800961 } else if (useSpeakerForVideoCall) {
962 Log.i(this, "%s Starting with speakerphone because its a video call.", call);
Santos Cordona04bdca2015-03-04 16:57:55 -0800963 }
Bryce Lee88f900a2015-11-06 08:51:22 -0800964
Tyler Gunn6ffe5312015-08-12 08:19:20 -0700965 if (call.isEmergencyCall()) {
Abhijith Shastrycf27f682016-03-01 18:28:44 -0800966 new AsyncEmergencyContactNotifier(mContext).execute();
Nancy Chen53ceedc2014-07-08 18:56:51 -0700967 }
Nancy Chend9de92c2014-07-21 16:09:13 -0700968
Bryce Lee6afefa42015-10-25 22:25:53 -0700969 final boolean requireCallCapableAccountByHandle = mContext.getResources().getBoolean(
970 com.android.internal.R.bool.config_requireCallCapableAccountForHandle);
971
Tyler Gunn6ffe5312015-08-12 08:19:20 -0700972 if (call.getTargetPhoneAccount() != null || call.isEmergencyCall()) {
Nancy Chenbc9ef172014-08-15 17:11:57 -0700973 // If the account has been set, proceed to place the outgoing call.
974 // Otherwise the connection will be initiated when the account is set by the user.
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700975 call.startCreateConnection(mPhoneAccountRegistrar);
Bryce Lee6afefa42015-10-25 22:25:53 -0700976 } else if (mPhoneAccountRegistrar.getCallCapablePhoneAccounts(
Tony Mak240656f2015-12-04 11:36:22 +0000977 requireCallCapableAccountByHandle ? call.getHandle().getScheme() : null, false,
978 call.getInitiatingUser()).isEmpty()) {
Bryce Leede0ac372015-10-23 16:06:00 -0700979 // If there are no call capable accounts, disconnect the call.
980 markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.CANCELED,
981 "No registered PhoneAccounts"));
982 markCallAsRemoved(call);
Nancy Chend9de92c2014-07-21 16:09:13 -0700983 }
Yorke Leef98fb572014-03-05 10:56:55 -0800984 }
985
986 /**
Santos Cordona1610702014-06-04 20:22:56 -0700987 * Attempts to start a conference call for the specified call.
988 *
Santos Cordon12d61822014-07-29 16:02:20 -0700989 * @param call The call to conference.
990 * @param otherCall The other call to conference with.
Santos Cordona1610702014-06-04 20:22:56 -0700991 */
Brad Ebinger53855132015-10-30 10:58:19 -0700992 @VisibleForTesting
993 public void conference(Call call, Call otherCall) {
Santos Cordon0fbe6322014-08-14 04:04:25 -0700994 call.conferenceWith(otherCall);
Santos Cordona1610702014-06-04 20:22:56 -0700995 }
996
997 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -0700998 * Instructs Telecom to answer the specified call. Intended to be invoked by the in-call
999 * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by
Santos Cordone3d76ab2014-01-28 17:25:20 -08001000 * the user opting to answer said call.
Andrew Lee38931d02014-07-16 10:17:36 -07001001 *
1002 * @param call The call to answer.
1003 * @param videoState The video state in which to answer the call.
Santos Cordone3d76ab2014-01-28 17:25:20 -08001004 */
Brad Ebinger53855132015-10-30 10:58:19 -07001005 @VisibleForTesting
1006 public void answerCall(Call call, int videoState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001007 if (!mCalls.contains(call)) {
1008 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -08001009 } else {
Hall Liue091ab92015-12-18 17:05:30 -08001010 Call foregroundCall = getForegroundCall();
Santos Cordon40f78c22014-04-07 02:11:42 -07001011 // If the foreground call is not the ringing call and it is currently isActive() or
Ihab Awad6fb37c82014-08-07 19:48:57 -07001012 // STATE_DIALING, put it on hold before answering the call.
Hall Liue091ab92015-12-18 17:05:30 -08001013 if (foregroundCall != null && foregroundCall != call &&
1014 (foregroundCall.isActive() ||
Tyler Gunn1e37be52016-07-11 08:54:23 -07001015 foregroundCall.getState() == CallState.DIALING ||
1016 foregroundCall.getState() == CallState.PULLING)) {
Hall Liue091ab92015-12-18 17:05:30 -08001017 if (0 == (foregroundCall.getConnectionCapabilities()
Ihab Awad07bc5ee2014-11-12 13:42:52 -08001018 & Connection.CAPABILITY_HOLD)) {
Santos Cordonf193ba42014-09-12 06:37:39 -07001019 // This call does not support hold. If it is from a different connection
1020 // service, then disconnect it, otherwise allow the connection service to
1021 // figure out the right states.
Hall Liue091ab92015-12-18 17:05:30 -08001022 if (foregroundCall.getConnectionService() != call.getConnectionService()) {
1023 foregroundCall.disconnect();
Santos Cordonf193ba42014-09-12 06:37:39 -07001024 }
1025 } else {
Andrew Leee94a8f12014-12-19 16:19:51 -08001026 Call heldCall = getHeldCall();
1027 if (heldCall != null) {
1028 Log.v(this, "Disconnecting held call %s before holding active call.",
1029 heldCall);
1030 heldCall.disconnect();
1031 }
1032
Santos Cordonf193ba42014-09-12 06:37:39 -07001033 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
Hall Liue091ab92015-12-18 17:05:30 -08001034 foregroundCall, call);
1035 foregroundCall.hold();
Santos Cordonf193ba42014-09-12 06:37:39 -07001036 }
Santos Cordondf399862014-08-06 04:39:15 -07001037 // TODO: Wait until we get confirmation of the active call being
Santos Cordon40f78c22014-04-07 02:11:42 -07001038 // on-hold before answering the new call.
Santos Cordondf399862014-08-06 04:39:15 -07001039 // TODO: Import logic from CallManager.acceptCall()
Santos Cordon40f78c22014-04-07 02:11:42 -07001040 }
1041
Santos Cordona56f2762014-03-24 15:55:53 -07001042 for (CallsManagerListener listener : mListeners) {
1043 listener.onIncomingCallAnswered(call);
1044 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -08001045
Santos Cordon61d0f702014-02-19 02:52:23 -08001046 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -07001047 // {@link #markCallAsActive}.
Andrew Lee38931d02014-07-16 10:17:36 -07001048 call.answer(videoState);
Hall Liu9696c212016-06-24 16:09:02 -07001049 if (isSpeakerphoneAutoEnabledForVideoCalls(videoState)) {
Rekha Kumard240fe82015-04-01 21:45:57 -07001050 call.setStartWithSpeakerphoneOn(true);
1051 }
Santos Cordon61d0f702014-02-19 02:52:23 -08001052 }
Santos Cordone3d76ab2014-01-28 17:25:20 -08001053 }
1054
Tyler Gunnb360f0d2015-12-01 14:34:03 -08001055 /**
1056 * Determines if the speakerphone should be automatically enabled for the call. Speakerphone
1057 * should be enabled if the call is a video call and bluetooth or the wired headset are not in
1058 * use.
1059 *
1060 * @param videoState The video state of the call.
1061 * @return {@code true} if the speakerphone should be enabled.
1062 */
Hall Liu9696c212016-06-24 16:09:02 -07001063 public boolean isSpeakerphoneAutoEnabledForVideoCalls(int videoState) {
Tyler Gunnb360f0d2015-12-01 14:34:03 -08001064 return VideoProfile.isVideo(videoState) &&
1065 !mWiredHeadsetManager.isPluggedIn() &&
1066 !mBluetoothManager.isBluetoothAvailable() &&
1067 isSpeakerEnabledForVideoCalls();
1068 }
1069
1070 /**
John Eckerdal63486002015-11-20 13:17:29 +01001071 * Determines if the speakerphone should be enabled for when docked. Speakerphone
1072 * should be enabled if the device is docked and bluetooth or the wired headset are
1073 * not in use.
1074 *
1075 * @return {@code true} if the speakerphone should be enabled for the dock.
1076 */
1077 private boolean isSpeakerphoneEnabledForDock() {
1078 return mDockManager.isDocked() &&
1079 !mWiredHeadsetManager.isPluggedIn() &&
1080 !mBluetoothManager.isBluetoothAvailable();
1081 }
1082
1083 /**
Tyler Gunnb360f0d2015-12-01 14:34:03 -08001084 * Determines if the speakerphone should be automatically enabled for video calls.
1085 *
1086 * @return {@code true} if the speakerphone should automatically be enabled.
1087 */
Rekha Kumard240fe82015-04-01 21:45:57 -07001088 private static boolean isSpeakerEnabledForVideoCalls() {
1089 return (SystemProperties.getInt(TelephonyProperties.PROPERTY_VIDEOCALL_AUDIO_OUTPUT,
1090 PhoneConstants.AUDIO_OUTPUT_DEFAULT) ==
1091 PhoneConstants.AUDIO_OUTPUT_ENABLE_SPEAKER);
1092 }
1093
Santos Cordone3d76ab2014-01-28 17:25:20 -08001094 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001095 * Instructs Telecom to reject the specified call. Intended to be invoked by the in-call
1096 * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by
Santos Cordone3d76ab2014-01-28 17:25:20 -08001097 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -08001098 */
Brad Ebinger53855132015-10-30 10:58:19 -07001099 @VisibleForTesting
1100 public void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001101 if (!mCalls.contains(call)) {
1102 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -08001103 } else {
Santos Cordona56f2762014-03-24 15:55:53 -07001104 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -07001105 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -07001106 }
Ihab Awadff7493a2014-06-10 13:47:44 -07001107 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -08001108 }
Santos Cordone3d76ab2014-01-28 17:25:20 -08001109 }
1110
1111 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001112 * Instructs Telecom to play the specified DTMF tone within the specified call.
Ihab Awad74549ec2014-03-10 15:33:25 -07001113 *
Ihab Awad74549ec2014-03-10 15:33:25 -07001114 * @param digit The DTMF digit to play.
1115 */
Brad Ebinger53855132015-10-30 10:58:19 -07001116 @VisibleForTesting
1117 public void playDtmfTone(Call call, char digit) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001118 if (!mCalls.contains(call)) {
1119 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -07001120 } else {
1121 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -07001122 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -07001123 }
1124 }
1125
1126 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001127 * Instructs Telecom to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -07001128 */
Brad Ebinger53855132015-10-30 10:58:19 -07001129 @VisibleForTesting
1130 public void stopDtmfTone(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001131 if (!mCalls.contains(call)) {
1132 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -07001133 } else {
1134 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -07001135 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -07001136 }
1137 }
1138
1139 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001140 * Instructs Telecom to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -07001141 */
Evan Charlton352105c2014-06-03 14:10:54 -07001142 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001143 if (!mCalls.contains(call)) {
1144 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -07001145 } else {
Evan Charlton352105c2014-06-03 14:10:54 -07001146 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -07001147 }
1148 }
1149
1150 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001151 * Instructs Telecom to disconnect the specified call. Intended to be invoked by the
Santos Cordone3d76ab2014-01-28 17:25:20 -08001152 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
1153 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -08001154 */
Brad Ebinger53855132015-10-30 10:58:19 -07001155 @VisibleForTesting
1156 public void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -07001157 Log.v(this, "disconnectCall %s", call);
1158
Sailesh Nepale59bb192014-04-01 18:33:59 -07001159 if (!mCalls.contains(call)) {
1160 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -08001161 } else {
Ihab Awad5b281322014-09-25 18:25:29 -07001162 mLocallyDisconnectingCalls.add(call);
Santos Cordon049b7b62014-01-30 05:34:26 -08001163 call.disconnect();
1164 }
Santos Cordone3d76ab2014-01-28 17:25:20 -08001165 }
Santos Cordon681663d2014-01-30 04:32:15 -08001166
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001167 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001168 * Instructs Telecom to disconnect all calls.
Tyler Gunn61b92102014-08-19 07:42:20 -07001169 */
1170 void disconnectAllCalls() {
1171 Log.v(this, "disconnectAllCalls");
1172
1173 for (Call call : mCalls) {
1174 disconnectCall(call);
1175 }
1176 }
1177
Nancy Chenbc9ef172014-08-15 17:11:57 -07001178
Tyler Gunn61b92102014-08-19 07:42:20 -07001179 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001180 * Instructs Telecom to put the specified call on hold. Intended to be invoked by the
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001181 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
1182 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001183 */
Brad Ebinger53855132015-10-30 10:58:19 -07001184 @VisibleForTesting
1185 public void holdCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001186 if (!mCalls.contains(call)) {
1187 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001188 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001189 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001190 call.hold();
1191 }
1192 }
1193
1194 /**
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001195 * Instructs Telecom to release the specified call from hold. Intended to be invoked by
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001196 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
1197 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001198 */
Brad Ebinger53855132015-10-30 10:58:19 -07001199 @VisibleForTesting
1200 public void unholdCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -07001201 if (!mCalls.contains(call)) {
1202 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001203 } else {
Hall Liu874c0f82016-04-29 18:13:18 -07001204 boolean otherCallHeld = false;
Santos Cordonc7e85d42014-05-22 02:51:48 -07001205 Log.d(this, "unholding call: (%s)", call);
Sai Cheemalapati45b3e3f2014-08-15 09:33:00 -07001206 for (Call c : mCalls) {
Tyler Gunne44adb42015-01-02 10:55:35 -08001207 // Only attempt to hold parent calls and not the individual children.
1208 if (c != null && c.isAlive() && c != call && c.getParentCall() == null) {
Hall Liu874c0f82016-04-29 18:13:18 -07001209 otherCallHeld = true;
1210 Log.event(c, Log.Events.SWAP);
Sai Cheemalapati45b3e3f2014-08-15 09:33:00 -07001211 c.hold();
1212 }
1213 }
Hall Liu874c0f82016-04-29 18:13:18 -07001214 if (otherCallHeld) {
1215 Log.event(call, Log.Events.SWAP);
1216 }
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001217 call.unhold();
1218 }
1219 }
1220
Hall Liu32587202015-11-18 11:10:08 -08001221 @Override
Tyler Gunn961694a2016-03-21 16:01:40 -07001222 public void onExtrasChanged(Call c, int source, Bundle extras) {
1223 if (source != Call.SOURCE_CONNECTION_SERVICE) {
1224 return;
1225 }
1226 handleCallTechnologyChange(c);
Brad Ebingerbaf52ba2016-03-21 16:38:32 -07001227 handleChildAddressChange(c);
Hall Liufc130b22016-06-15 17:54:48 -07001228 updateCanAddCall();
Tyler Gunn961694a2016-03-21 16:01:40 -07001229 }
1230
Brad Ebinger3da57642016-04-04 17:32:19 -07001231 // Construct the list of possible PhoneAccounts that the outgoing call can use based on the
1232 // active calls in CallsManager. If any of the active calls are on a SIM based PhoneAccount,
1233 // then include only that SIM based PhoneAccount and any non-SIM PhoneAccounts, such as SIP.
1234 private List<PhoneAccountHandle> constructPossiblePhoneAccounts(Uri handle, UserHandle user) {
1235 if (handle == null) {
1236 return Collections.emptyList();
1237 }
1238 List<PhoneAccountHandle> allAccounts =
1239 mPhoneAccountRegistrar.getCallCapablePhoneAccounts(handle.getScheme(), false, user);
1240 // First check the Radio SIM Technology
1241 if(mRadioSimVariants == null) {
1242 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
1243 Context.TELEPHONY_SERVICE);
1244 // Cache Sim Variants
1245 mRadioSimVariants = tm.getMultiSimConfiguration();
1246 }
1247 // Only one SIM PhoneAccount can be active at one time for DSDS. Only that SIM PhoneAccount
1248 // Should be available if a call is already active on the SIM account.
1249 if(mRadioSimVariants != TelephonyManager.MultiSimVariants.DSDA) {
1250 List<PhoneAccountHandle> simAccounts =
1251 mPhoneAccountRegistrar.getSimPhoneAccountsOfCurrentUser();
1252 PhoneAccountHandle ongoingCallAccount = null;
1253 for (Call c : mCalls) {
1254 if (!c.isDisconnected() && !c.isNew() && simAccounts.contains(
1255 c.getTargetPhoneAccount())) {
1256 ongoingCallAccount = c.getTargetPhoneAccount();
1257 break;
1258 }
1259 }
1260 if (ongoingCallAccount != null) {
1261 // Remove all SIM accounts that are not the active SIM from the list.
1262 simAccounts.remove(ongoingCallAccount);
1263 allAccounts.removeAll(simAccounts);
1264 }
1265 }
1266 return allAccounts;
1267 }
1268
Tyler Gunn1a40c4f2016-04-14 14:29:45 -07001269 /**
1270 * Informs listeners (notably {@link CallAudioManager} of a change to the call's external
1271 * property.
1272 * .
1273 * @param call The call whose external property changed.
1274 * @param isExternalCall {@code True} if the call is now external, {@code false} otherwise.
1275 */
1276 @Override
1277 public void onExternalCallChanged(Call call, boolean isExternalCall) {
1278 Log.v(this, "onConnectionPropertiesChanged: %b", isExternalCall);
1279 for (CallsManagerListener listener : mListeners) {
1280 listener.onExternalCallChanged(call, isExternalCall);
1281 }
1282 }
1283
Tyler Gunn961694a2016-03-21 16:01:40 -07001284 private void handleCallTechnologyChange(Call call) {
Hall Liu32587202015-11-18 11:10:08 -08001285 if (call.getExtras() != null
1286 && call.getExtras().containsKey(TelecomManager.EXTRA_CALL_TECHNOLOGY_TYPE)) {
1287
1288 Integer analyticsCallTechnology = sAnalyticsTechnologyMap.get(
1289 call.getExtras().getInt(TelecomManager.EXTRA_CALL_TECHNOLOGY_TYPE));
1290 if (analyticsCallTechnology == null) {
1291 analyticsCallTechnology = Analytics.THIRD_PARTY_PHONE;
1292 }
1293 call.getAnalytics().addCallTechnology(analyticsCallTechnology);
1294 }
1295 }
1296
Brad Ebingerbaf52ba2016-03-21 16:38:32 -07001297 public void handleChildAddressChange(Call call) {
1298 if (call.getExtras() != null
1299 && call.getExtras().containsKey(Connection.EXTRA_CHILD_ADDRESS)) {
1300
1301 String viaNumber = call.getExtras().getString(Connection.EXTRA_CHILD_ADDRESS);
1302 call.setViaNumber(viaNumber);
1303 }
1304 }
1305
Sailesh Nepal6aca10a2014-03-24 16:11:02 -07001306 /** Called by the in-call UI to change the mute state. */
1307 void mute(boolean shouldMute) {
1308 mCallAudioManager.mute(shouldMute);
1309 }
1310
1311 /**
1312 * Called by the in-call UI to change the audio route, for example to change from earpiece to
1313 * speaker phone.
1314 */
1315 void setAudioRoute(int route) {
1316 mCallAudioManager.setAudioRoute(route);
1317 }
1318
Yorke Leed1346872014-07-28 14:38:45 -07001319 /** Called by the in-call UI to turn the proximity sensor on. */
1320 void turnOnProximitySensor() {
1321 mProximitySensorManager.turnOn();
1322 }
1323
1324 /**
1325 * Called by the in-call UI to turn the proximity sensor off.
1326 * @param screenOnImmediately If true, the screen will be turned on immediately. Otherwise,
1327 * the screen will be kept off until the proximity sensor goes negative.
1328 */
1329 void turnOffProximitySensor(boolean screenOnImmediately) {
1330 mProximitySensorManager.turnOff(screenOnImmediately);
1331 }
1332
Nancy Chenf5e5d3c2014-10-21 18:45:56 -07001333 void phoneAccountSelected(Call call, PhoneAccountHandle account, boolean setDefault) {
Nancy Chen53ceedc2014-07-08 18:56:51 -07001334 if (!mCalls.contains(call)) {
Santos Cordonf193ba42014-09-12 06:37:39 -07001335 Log.i(this, "Attempted to add account to unknown call %s", call);
Nancy Chen53ceedc2014-07-08 18:56:51 -07001336 } else {
Ihab Awadb78b2762014-07-25 15:16:23 -07001337 call.setTargetPhoneAccount(account);
Santos Cordonf193ba42014-09-12 06:37:39 -07001338
Hall Liu4b1759d2016-02-02 18:17:40 -08001339 if (!call.isNewOutgoingCallIntentBroadcastDone()) {
1340 return;
1341 }
1342
Santos Cordonf193ba42014-09-12 06:37:39 -07001343 // Note: emergency calls never go through account selection dialog so they never
1344 // arrive here.
1345 if (makeRoomForOutgoingCall(call, false /* isEmergencyCall */)) {
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001346 call.startCreateConnection(mPhoneAccountRegistrar);
Santos Cordonf193ba42014-09-12 06:37:39 -07001347 } else {
1348 call.disconnect();
1349 }
Nancy Chenf5e5d3c2014-10-21 18:45:56 -07001350
1351 if (setDefault) {
Tony Mak4a3e2fd2015-12-04 11:58:38 +00001352 mPhoneAccountRegistrar
1353 .setUserSelectedOutgoingPhoneAccount(account, call.getInitiatingUser());
Nancy Chenf5e5d3c2014-10-21 18:45:56 -07001354 }
Nancy Chen53ceedc2014-07-08 18:56:51 -07001355 }
1356 }
1357
Sailesh Nepal6aca10a2014-03-24 16:11:02 -07001358 /** Called when the audio state changes. */
Hall Liuf62630a2015-10-27 14:53:39 -07001359 @VisibleForTesting
1360 public void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState
1361 newAudioState) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -07001362 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -07001363 for (CallsManagerListener listener : mListeners) {
Yorke Lee2a66f7b2015-05-13 14:21:19 -07001364 listener.onCallAudioStateChanged(oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -07001365 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -07001366 }
1367
Sailesh Nepale59bb192014-04-01 18:33:59 -07001368 void markCallAsRinging(Call call) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001369 setCallState(call, CallState.RINGING, "ringing set explicitly");
Santos Cordon681663d2014-01-30 04:32:15 -08001370 }
1371
Sailesh Nepale59bb192014-04-01 18:33:59 -07001372 void markCallAsDialing(Call call) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001373 setCallState(call, CallState.DIALING, "dialing set explicitly");
Santos Cordond6782cd2015-04-16 09:57:50 -07001374 maybeMoveToSpeakerPhone(call);
Santos Cordon681663d2014-01-30 04:32:15 -08001375 }
1376
Tyler Gunn1e37be52016-07-11 08:54:23 -07001377 void markCallAsPulling(Call call) {
1378 setCallState(call, CallState.PULLING, "pulling set explicitly");
1379 maybeMoveToSpeakerPhone(call);
1380 }
1381
Sailesh Nepale59bb192014-04-01 18:33:59 -07001382 void markCallAsActive(Call call) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001383 setCallState(call, CallState.ACTIVE, "active set explicitly");
Santos Cordond6782cd2015-04-16 09:57:50 -07001384 maybeMoveToSpeakerPhone(call);
Santos Cordon681663d2014-01-30 04:32:15 -08001385 }
1386
Sailesh Nepale59bb192014-04-01 18:33:59 -07001387 void markCallAsOnHold(Call call) {
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001388 setCallState(call, CallState.ON_HOLD, "on-hold set explicitly");
Yorke Leecdf3ebd2014-03-12 18:31:41 -07001389 }
1390
Santos Cordon049b7b62014-01-30 05:34:26 -08001391 /**
Santos Cordonf193ba42014-09-12 06:37:39 -07001392 * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the
1393 * last live call, then also disconnect from the in-call controller.
Santos Cordon049b7b62014-01-30 05:34:26 -08001394 *
Ihab Awad78a5e6b2015-02-06 10:13:05 -08001395 * @param disconnectCause The disconnect cause, see {@link android.telecom.DisconnectCause}.
Santos Cordon049b7b62014-01-30 05:34:26 -08001396 */
Andrew Lee701dc002014-09-11 21:29:12 -07001397 void markCallAsDisconnected(Call call, DisconnectCause disconnectCause) {
1398 call.setDisconnectCause(disconnectCause);
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001399 setCallState(call, CallState.DISCONNECTED, "disconnected set explicitly");
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -07001400 }
1401
Ben Gilada0d9f752014-02-26 11:49:03 -08001402 /**
Ihab Awada02bef52014-08-13 18:18:42 -07001403 * Removes an existing disconnected call, and notifies the in-call app.
1404 */
1405 void markCallAsRemoved(Call call) {
1406 removeCall(call);
Tyler Gunn7d58ba52016-07-25 15:05:48 -07001407 Call foregroundCall = mCallAudioManager.getPossiblyHeldForegroundCall();
Ihab Awad5b281322014-09-25 18:25:29 -07001408 if (mLocallyDisconnectingCalls.contains(call)) {
1409 mLocallyDisconnectingCalls.remove(call);
Hall Liue091ab92015-12-18 17:05:30 -08001410 if (foregroundCall != null && foregroundCall.getState() == CallState.ON_HOLD) {
1411 foregroundCall.unhold();
Ihab Awad5b281322014-09-25 18:25:29 -07001412 }
Tyler Gunn7d58ba52016-07-25 15:05:48 -07001413 } else if (foregroundCall != null &&
1414 !foregroundCall.can(Connection.CAPABILITY_SUPPORT_HOLD) &&
1415 foregroundCall.getState() == CallState.ON_HOLD) {
1416
1417 // The new foreground call is on hold, however the carrier does not display the hold
1418 // button in the UI. Therefore, we need to auto unhold the held call since the user has
1419 // no means of unholding it themselves.
1420 Log.i(this, "Auto-unholding held foreground call (call doesn't support hold)");
1421 foregroundCall.unhold();
Ihab Awad5b281322014-09-25 18:25:29 -07001422 }
Ihab Awada02bef52014-08-13 18:18:42 -07001423 }
1424
1425 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001426 * Cleans up any calls currently associated with the specified connection service when the
Sailesh Nepal905dfba2014-07-14 08:20:41 -07001427 * service binder disconnects unexpectedly.
Santos Cordon4b2c1192014-03-19 18:15:38 -07001428 *
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001429 * @param service The connection service that disconnected.
Santos Cordon4b2c1192014-03-19 18:15:38 -07001430 */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001431 void handleConnectionServiceDeath(ConnectionServiceWrapper service) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -07001432 if (service != null) {
Jay Shraunera82c8f72014-08-14 15:49:16 -07001433 for (Call call : mCalls) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -07001434 if (call.getConnectionService() == service) {
Yorke Lee2af16b62014-11-11 17:36:57 -08001435 if (call.getState() != CallState.DISCONNECTED) {
1436 markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR));
1437 }
1438 markCallAsRemoved(call);
Jay Shrauneracb91eb2014-08-08 16:04:53 -07001439 }
Santos Cordon4b2c1192014-03-19 18:15:38 -07001440 }
1441 }
1442 }
1443
Tyler Gunn1a40c4f2016-04-14 14:29:45 -07001444 /**
1445 * Determines if the {@link CallsManager} has any non-external calls.
1446 *
1447 * @return {@code True} if there are any non-external calls, {@code false} otherwise.
1448 */
Santos Cordondeb8c892014-05-30 01:38:03 -07001449 boolean hasAnyCalls() {
Tyler Gunn1a40c4f2016-04-14 14:29:45 -07001450 if (mCalls.isEmpty()) {
1451 return false;
1452 }
1453
1454 for (Call call : mCalls) {
1455 if (!call.isExternalCall()) {
1456 return true;
1457 }
1458 }
1459 return false;
Santos Cordondeb8c892014-05-30 01:38:03 -07001460 }
1461
Santos Cordonc7e85d42014-05-22 02:51:48 -07001462 boolean hasActiveOrHoldingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -07001463 return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -07001464 }
1465
1466 boolean hasRingingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -07001467 return getFirstCallWithState(CallState.RINGING) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -07001468 }
1469
Santos Cordondeb8c892014-05-30 01:38:03 -07001470 boolean onMediaButton(int type) {
1471 if (hasAnyCalls()) {
1472 if (HeadsetMediaButton.SHORT_PRESS == type) {
1473 Call ringingCall = getFirstCallWithState(CallState.RINGING);
1474 if (ringingCall == null) {
1475 mCallAudioManager.toggleMute();
1476 return true;
1477 } else {
Hall Liu3777a7e2016-07-25 14:46:48 -07001478 ringingCall.answer(VideoProfile.STATE_AUDIO_ONLY);
Santos Cordondeb8c892014-05-30 01:38:03 -07001479 return true;
1480 }
1481 } else if (HeadsetMediaButton.LONG_PRESS == type) {
1482 Log.d(this, "handleHeadsetHook: longpress -> hangup");
1483 Call callToHangup = getFirstCallWithState(
Tyler Gunn1e37be52016-07-11 08:54:23 -07001484 CallState.RINGING, CallState.DIALING, CallState.PULLING, CallState.ACTIVE,
1485 CallState.ON_HOLD);
Santos Cordondeb8c892014-05-30 01:38:03 -07001486 if (callToHangup != null) {
1487 callToHangup.disconnect();
1488 return true;
1489 }
1490 }
1491 }
1492 return false;
1493 }
1494
1495 /**
Santos Cordon91bd74c2014-11-07 16:10:22 -08001496 * Returns true if telecom supports adding another top-level call.
Santos Cordon10838c22014-06-11 17:36:04 -07001497 */
Santos Cordon91bd74c2014-11-07 16:10:22 -08001498 boolean canAddCall() {
Hall Liuf1422e72016-01-27 11:07:07 -08001499 boolean isDeviceProvisioned = Settings.Global.getInt(mContext.getContentResolver(),
1500 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
1501 if (!isDeviceProvisioned) {
1502 Log.d(TAG, "Device not provisioned, canAddCall is false.");
1503 return false;
1504 }
1505
Andrew Lee113ad622014-12-01 18:33:10 -08001506 if (getFirstCallWithState(OUTGOING_CALL_STATES) != null) {
1507 return false;
1508 }
1509
Santos Cordon91bd74c2014-11-07 16:10:22 -08001510 int count = 0;
1511 for (Call call : mCalls) {
1512 if (call.isEmergencyCall()) {
1513 // We never support add call if one of the calls is an emergency call.
1514 return false;
Tyler Gunn1e37be52016-07-11 08:54:23 -07001515 } else if (call.isExternalCall()) {
1516 // External calls don't count.
1517 continue;
Santos Cordon91bd74c2014-11-07 16:10:22 -08001518 } else if (call.getParentCall() == null) {
1519 count++;
1520 }
Hall Liufc130b22016-06-15 17:54:48 -07001521 Bundle extras = call.getExtras();
1522 if (extras != null) {
Hall Liu140c8402016-07-06 16:30:46 -07001523 if (extras.getBoolean(Connection.EXTRA_DISABLE_ADD_CALL, false)) {
1524 return false;
1525 }
Hall Liufc130b22016-06-15 17:54:48 -07001526 }
Santos Cordon10838c22014-06-11 17:36:04 -07001527
Santos Cordon91bd74c2014-11-07 16:10:22 -08001528 // We do not check states for canAddCall. We treat disconnected calls the same
1529 // and wait until they are removed instead. If we didn't count disconnected calls,
1530 // we could put InCallServices into a state where they are showing two calls but
1531 // also support add-call. Technically it's right, but overall looks better (UI-wise)
1532 // and acts better if we wait until the call is removed.
1533 if (count >= MAXIMUM_TOP_LEVEL_CALLS) {
Santos Cordon10838c22014-06-11 17:36:04 -07001534 return false;
1535 }
1536 }
Hall Liufc130b22016-06-15 17:54:48 -07001537
Santos Cordon10838c22014-06-11 17:36:04 -07001538 return true;
1539 }
1540
Ihab Awada3653902015-01-23 13:44:46 -08001541 @VisibleForTesting
P.Y. Laligandd35be752015-03-06 14:12:43 -08001542 public Call getRingingCall() {
Santos Cordon68d1a6b2014-09-19 12:25:58 -07001543 return getFirstCallWithState(CallState.RINGING);
1544 }
1545
Brad Ebinger53855132015-10-30 10:58:19 -07001546 @VisibleForTesting
1547 public Call getActiveCall() {
Santos Cordon68d1a6b2014-09-19 12:25:58 -07001548 return getFirstCallWithState(CallState.ACTIVE);
1549 }
1550
Nancy Chen05a9e402014-09-26 14:14:32 -07001551 Call getDialingCall() {
1552 return getFirstCallWithState(CallState.DIALING);
Santos Cordon68d1a6b2014-09-19 12:25:58 -07001553 }
1554
Brad Ebinger53855132015-10-30 10:58:19 -07001555 @VisibleForTesting
1556 public Call getHeldCall() {
Santos Cordon68d1a6b2014-09-19 12:25:58 -07001557 return getFirstCallWithState(CallState.ON_HOLD);
1558 }
1559
Brad Ebinger53855132015-10-30 10:58:19 -07001560 @VisibleForTesting
1561 public int getNumHeldCalls() {
Santos Cordonc0ca76e2014-10-21 15:54:19 -07001562 int count = 0;
1563 for (Call call : mCalls) {
1564 if (call.getParentCall() == null && call.getState() == CallState.ON_HOLD) {
1565 count++;
1566 }
1567 }
1568 return count;
1569 }
1570
Brad Ebinger53855132015-10-30 10:58:19 -07001571 @VisibleForTesting
1572 public Call getOutgoingCall() {
Roshan Pius7d7cf272015-08-28 11:10:56 -07001573 return getFirstCallWithState(OUTGOING_CALL_STATES);
1574 }
1575
Hall Liu0a6dd302015-12-16 15:06:49 -08001576 @VisibleForTesting
1577 public Call getFirstCallWithState(int... states) {
Santos Cordonf193ba42014-09-12 06:37:39 -07001578 return getFirstCallWithState(null, states);
1579 }
1580
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07001581 @VisibleForTesting
1582 public PhoneNumberUtilsAdapter getPhoneNumberUtilsAdapter() {
1583 return mPhoneNumberUtilsAdapter;
1584 }
1585
Santos Cordon10838c22014-06-11 17:36:04 -07001586 /**
Santos Cordondeb8c892014-05-30 01:38:03 -07001587 * Returns the first call that it finds with the given states. The states are treated as having
1588 * priority order so that any call with the first state will be returned before any call with
1589 * states listed later in the parameter list.
Santos Cordonf193ba42014-09-12 06:37:39 -07001590 *
1591 * @param callToSkip Call that this method should skip while searching
Santos Cordondeb8c892014-05-30 01:38:03 -07001592 */
Santos Cordonf193ba42014-09-12 06:37:39 -07001593 Call getFirstCallWithState(Call callToSkip, int... states) {
Ihab Awad6fb37c82014-08-07 19:48:57 -07001594 for (int currentState : states) {
Santos Cordon23baed32014-06-27 14:45:39 -07001595 // check the foreground first
Hall Liue091ab92015-12-18 17:05:30 -08001596 Call foregroundCall = getForegroundCall();
1597 if (foregroundCall != null && foregroundCall.getState() == currentState) {
1598 return foregroundCall;
Santos Cordon23baed32014-06-27 14:45:39 -07001599 }
1600
Santos Cordondeb8c892014-05-30 01:38:03 -07001601 for (Call call : mCalls) {
Santos Cordonf193ba42014-09-12 06:37:39 -07001602 if (Objects.equals(callToSkip, call)) {
1603 continue;
1604 }
1605
1606 // Only operate on top-level calls
1607 if (call.getParentCall() != null) {
1608 continue;
1609 }
1610
Tyler Gunnf15dc332016-06-07 16:01:41 -07001611 if (call.isExternalCall()) {
1612 continue;
1613 }
1614
Santos Cordondeb8c892014-05-30 01:38:03 -07001615 if (currentState == call.getState()) {
1616 return call;
1617 }
1618 }
1619 }
1620 return null;
1621 }
1622
Santos Cordon0fbe6322014-08-14 04:04:25 -07001623 Call createConferenceCall(
Tyler Gunn8452be02015-09-17 09:57:02 -07001624 String callId,
Santos Cordon0fbe6322014-08-14 04:04:25 -07001625 PhoneAccountHandle phoneAccount,
1626 ParcelableConference parcelableConference) {
Tyler Gunnd92e7372015-01-09 15:59:45 -08001627
1628 // If the parceled conference specifies a connect time, use it; otherwise default to 0,
1629 // which is the default value for new Calls.
1630 long connectTime =
1631 parcelableConference.getConnectTimeMillis() ==
1632 Conference.CONNECT_TIME_NOT_SPECIFIED ? 0 :
1633 parcelableConference.getConnectTimeMillis();
1634
Santos Cordon0fbe6322014-08-14 04:04:25 -07001635 Call call = new Call(
Tyler Gunn8452be02015-09-17 09:57:02 -07001636 callId,
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001637 mContext,
Ihab Awad78a5e6b2015-02-06 10:13:05 -08001638 this,
Ihab Awade6dbc9d2015-03-26 10:33:44 -07001639 mLock,
Santos Cordon0fbe6322014-08-14 04:04:25 -07001640 mConnectionServiceRepository,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001641 mContactsAsyncHelper,
Ihab Awadabcbce42015-04-07 14:04:01 -07001642 mCallerInfoAsyncQueryFactory,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07001643 mPhoneNumberUtilsAdapter,
Santos Cordon0fbe6322014-08-14 04:04:25 -07001644 null /* handle */,
1645 null /* gatewayInfo */,
1646 null /* connectionManagerPhoneAccount */,
1647 phoneAccount,
Hall Liu32587202015-11-18 11:10:08 -08001648 Call.CALL_DIRECTION_UNDEFINED /* callDirection */,
1649 false /* forceAttachToExistingConnection */,
Tyler Gunnd92e7372015-01-09 15:59:45 -08001650 true /* isConference */,
1651 connectTime);
Santos Cordon0fbe6322014-08-14 04:04:25 -07001652
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001653 setCallState(call, Call.getStateFromConnectionState(parcelableConference.getState()),
1654 "new conference call");
Ihab Awad07bc5ee2014-11-12 13:42:52 -08001655 call.setConnectionCapabilities(parcelableConference.getConnectionCapabilities());
Tyler Gunn571d5e62016-03-15 15:55:18 -07001656 call.setConnectionProperties(parcelableConference.getConnectionProperties());
Tyler Gunn13e8a692016-08-03 18:38:00 -07001657 call.setVideoState(parcelableConference.getVideoState());
Rekha Kumard240fe82015-04-01 21:45:57 -07001658 call.setVideoProvider(parcelableConference.getVideoProvider());
Andrew Lee57412d32015-04-14 13:38:44 -07001659 call.setStatusHints(parcelableConference.getStatusHints());
Tyler Gunn961694a2016-03-21 16:01:40 -07001660 call.putExtras(Call.SOURCE_CONNECTION_SERVICE, parcelableConference.getExtras());
Santos Cordon0fbe6322014-08-14 04:04:25 -07001661
1662 // TODO: Move this to be a part of addCall()
1663 call.addListener(this);
1664 addCall(call);
1665 return call;
1666 }
1667
Yorke Leef86db2e2014-09-12 17:56:48 -07001668 /**
1669 * @return the call state currently tracked by {@link PhoneStateBroadcaster}
1670 */
1671 int getCallState() {
1672 return mPhoneStateBroadcaster.getCallState();
1673 }
Nancy Chenbc9ef172014-08-15 17:11:57 -07001674
Santos Cordon4b2c1192014-03-19 18:15:38 -07001675 /**
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001676 * Retrieves the {@link PhoneAccountRegistrar}.
1677 *
1678 * @return The {@link PhoneAccountRegistrar}.
1679 */
1680 PhoneAccountRegistrar getPhoneAccountRegistrar() {
1681 return mPhoneAccountRegistrar;
1682 }
1683
1684 /**
1685 * Retrieves the {@link MissedCallNotifier}
1686 * @return The {@link MissedCallNotifier}.
1687 */
1688 MissedCallNotifier getMissedCallNotifier() {
1689 return mMissedCallNotifier;
1690 }
1691
1692 /**
Brad Ebinger3165d502015-12-15 17:22:29 -08001693 * Reject an incoming call and manually add it to the Call Log.
1694 * @param incomingCall Incoming call that has been rejected
1695 */
1696 private void rejectCallAndLog(Call incomingCall) {
1697 incomingCall.reject(false, null);
1698 // Since the call was not added to the list of calls, we have to call the missed
1699 // call notifier and the call logger manually.
1700 // Do we need missed call notification for direct to Voicemail calls?
Ta-wei Yen982c0bd2016-04-14 13:59:54 -07001701 mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE,
1702 true /*showNotificationForMissedCall*/);
Brad Ebinger3165d502015-12-15 17:22:29 -08001703 }
1704
1705 /**
Ben Gilada0d9f752014-02-26 11:49:03 -08001706 * Adds the specified call to the main list of live calls.
1707 *
1708 * @param call The call to add.
1709 */
1710 private void addCall(Call call) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001711 Trace.beginSection("addCall");
Yorke Leeb701f6d2014-08-12 14:04:19 -07001712 Log.v(this, "addCall(%s)", call);
Yorke Leeb701f6d2014-08-12 14:04:19 -07001713 call.addListener(this);
Sailesh Nepale59bb192014-04-01 18:33:59 -07001714 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -07001715
Sailesh Nepal703a1af2016-04-14 20:10:12 -07001716 // Specifies the time telecom finished routing the call. This is used by the dialer for
1717 // analytics.
1718 Bundle extras = call.getIntentExtras();
1719 extras.putLong(TelecomManager.EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS,
1720 SystemClock.elapsedRealtime());
1721
Hall Liufc130b22016-06-15 17:54:48 -07001722 updateCanAddCall();
Santos Cordon40f78c22014-04-07 02:11:42 -07001723 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -07001724 for (CallsManagerListener listener : mListeners) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001725 if (Log.SYSTRACE_DEBUG) {
1726 Trace.beginSection(listener.getClass().toString() + " addCall");
1727 }
Santos Cordona56f2762014-03-24 15:55:53 -07001728 listener.onCallAdded(call);
Yorke Leee4a9c412014-11-14 16:59:42 -08001729 if (Log.SYSTRACE_DEBUG) {
1730 Trace.endSection();
1731 }
Santos Cordona56f2762014-03-24 15:55:53 -07001732 }
Yorke Leee4a9c412014-11-14 16:59:42 -08001733 Trace.endSection();
Ben Gilada0d9f752014-02-26 11:49:03 -08001734 }
1735
Sailesh Nepal810735e2014-03-18 18:15:46 -07001736 private void removeCall(Call call) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001737 Trace.beginSection("removeCall");
Santos Cordonc499c1c2014-04-14 17:13:14 -07001738 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -07001739
Santos Cordon672321e2014-08-21 14:38:58 -07001740 call.setParentCall(null); // need to clean up parent relationship before destroying.
Santos Cordon766d04f2014-05-06 10:28:25 -07001741 call.removeListener(this);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001742 call.clearConnectionService();
Sailesh Nepale59bb192014-04-01 18:33:59 -07001743
1744 boolean shouldNotify = false;
1745 if (mCalls.contains(call)) {
1746 mCalls.remove(call);
1747 shouldNotify = true;
Santos Cordona56f2762014-03-24 15:55:53 -07001748 }
Ben Gilada0d9f752014-02-26 11:49:03 -08001749
Santos Cordon2685dab2015-04-17 17:12:09 -07001750 call.destroy();
1751
Sailesh Nepale59bb192014-04-01 18:33:59 -07001752 // Only broadcast changes for calls that are being tracked.
1753 if (shouldNotify) {
Hall Liufc130b22016-06-15 17:54:48 -07001754 updateCanAddCall();
Sailesh Nepale59bb192014-04-01 18:33:59 -07001755 for (CallsManagerListener listener : mListeners) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001756 if (Log.SYSTRACE_DEBUG) {
1757 Trace.beginSection(listener.getClass().toString() + " onCallRemoved");
1758 }
Sailesh Nepale59bb192014-04-01 18:33:59 -07001759 listener.onCallRemoved(call);
Yorke Leee4a9c412014-11-14 16:59:42 -08001760 if (Log.SYSTRACE_DEBUG) {
1761 Trace.endSection();
1762 }
Sailesh Nepale59bb192014-04-01 18:33:59 -07001763 }
Yorke Lee604a90f2014-10-20 12:13:32 -07001764 }
Yorke Leee4a9c412014-11-14 16:59:42 -08001765 Trace.endSection();
Sailesh Nepal810735e2014-03-18 18:15:46 -07001766 }
Evan Charlton5c670a92014-03-06 14:58:20 -08001767
Sailesh Nepal810735e2014-03-18 18:15:46 -07001768 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -07001769 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -07001770 *
1771 * @param call The call.
1772 * @param newState The new state of the call.
1773 */
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001774 private void setCallState(Call call, int newState, String tag) {
Jay Shrauneracb91eb2014-08-08 16:04:53 -07001775 if (call == null) {
1776 return;
1777 }
Ihab Awad6fb37c82014-08-07 19:48:57 -07001778 int oldState = call.getState();
Nancy Chen308ab8b2014-09-02 16:18:30 -07001779 Log.i(this, "setCallState %s -> %s, call: %s", CallState.toString(oldState),
1780 CallState.toString(newState), call);
Sailesh Nepal810735e2014-03-18 18:15:46 -07001781 if (newState != oldState) {
1782 // Unfortunately, in the telephony world the radio is king. So if the call notifies
1783 // 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 -07001784 // sense (e.g., STATE_ACTIVE -> STATE_RINGING).
Santos Cordondf399862014-08-06 04:39:15 -07001785 // TODO: Consider putting a stop to the above and turning CallState
Sailesh Nepal810735e2014-03-18 18:15:46 -07001786 // into a well-defined state machine.
Santos Cordondf399862014-08-06 04:39:15 -07001787 // TODO: Define expected state transitions here, and log when an
Sailesh Nepal810735e2014-03-18 18:15:46 -07001788 // unexpected transition occurs.
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07001789 call.setState(newState, tag);
Xueren Zhangc0e8e9d2015-03-06 14:16:55 +01001790 maybeShowErrorDialogOnDisconnect(call);
Sailesh Nepal810735e2014-03-18 18:15:46 -07001791
Yorke Leee4a9c412014-11-14 16:59:42 -08001792 Trace.beginSection("onCallStateChanged");
Sailesh Nepal810735e2014-03-18 18:15:46 -07001793 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -07001794 if (mCalls.contains(call)) {
Hall Liufc130b22016-06-15 17:54:48 -07001795 updateCanAddCall();
Santos Cordona56f2762014-03-24 15:55:53 -07001796 for (CallsManagerListener listener : mListeners) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001797 if (Log.SYSTRACE_DEBUG) {
1798 Trace.beginSection(listener.getClass().toString() + " onCallStateChanged");
1799 }
Santos Cordona56f2762014-03-24 15:55:53 -07001800 listener.onCallStateChanged(call, oldState, newState);
Yorke Leee4a9c412014-11-14 16:59:42 -08001801 if (Log.SYSTRACE_DEBUG) {
1802 Trace.endSection();
1803 }
Santos Cordona56f2762014-03-24 15:55:53 -07001804 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -08001805 }
Yorke Leee4a9c412014-11-14 16:59:42 -08001806 Trace.endSection();
Santos Cordon4e9fffe2014-03-04 18:13:41 -08001807 }
1808 }
1809
Santos Cordon91bd74c2014-11-07 16:10:22 -08001810 private void updateCanAddCall() {
1811 boolean newCanAddCall = canAddCall();
1812 if (newCanAddCall != mCanAddCall) {
1813 mCanAddCall = newCanAddCall;
1814 for (CallsManagerListener listener : mListeners) {
Yorke Leee4a9c412014-11-14 16:59:42 -08001815 if (Log.SYSTRACE_DEBUG) {
1816 Trace.beginSection(listener.getClass().toString() + " updateCanAddCall");
1817 }
Santos Cordon91bd74c2014-11-07 16:10:22 -08001818 listener.onCanAddCallChanged(mCanAddCall);
Yorke Leee4a9c412014-11-14 16:59:42 -08001819 if (Log.SYSTRACE_DEBUG) {
1820 Trace.endSection();
1821 }
Santos Cordon91bd74c2014-11-07 16:10:22 -08001822 }
1823 }
1824 }
1825
Yorke Leeb701f6d2014-08-12 14:04:19 -07001826 private boolean isPotentialMMICode(Uri handle) {
1827 return (handle != null && handle.getSchemeSpecificPart() != null
1828 && handle.getSchemeSpecificPart().contains("#"));
1829 }
Santos Cordonf193ba42014-09-12 06:37:39 -07001830
Tyler Gunn5b452df2014-10-01 15:02:58 -07001831 /**
1832 * Determines if a dialed number is potentially an In-Call MMI code. In-Call MMI codes are
1833 * MMI codes which can be dialed when one or more calls are in progress.
1834 * <P>
1835 * Checks for numbers formatted similar to the MMI codes defined in:
Amit Mahajan8c4e22a2015-12-14 13:24:15 -08001836 * {@link com.android.internal.telephony.Phone#handleInCallMmiCommands(String)}
Tyler Gunn5b452df2014-10-01 15:02:58 -07001837 *
1838 * @param handle The URI to call.
1839 * @return {@code True} if the URI represents a number which could be an in-call MMI code.
1840 */
1841 private boolean isPotentialInCallMMICode(Uri handle) {
1842 if (handle != null && handle.getSchemeSpecificPart() != null &&
Xueren Zhangc0e8e9d2015-03-06 14:16:55 +01001843 handle.getScheme() != null &&
Tyler Gunn5b452df2014-10-01 15:02:58 -07001844 handle.getScheme().equals(PhoneAccount.SCHEME_TEL)) {
1845
1846 String dialedNumber = handle.getSchemeSpecificPart();
1847 return (dialedNumber.equals("0") ||
1848 (dialedNumber.startsWith("1") && dialedNumber.length() <= 2) ||
1849 (dialedNumber.startsWith("2") && dialedNumber.length() <= 2) ||
1850 dialedNumber.equals("3") ||
1851 dialedNumber.equals("4") ||
1852 dialedNumber.equals("5"));
1853 }
1854 return false;
1855 }
1856
Santos Cordonf193ba42014-09-12 06:37:39 -07001857 private int getNumCallsWithState(int... states) {
1858 int count = 0;
1859 for (int state : states) {
1860 for (Call call : mCalls) {
Tyler Gunnf15dc332016-06-07 16:01:41 -07001861 if (call.getParentCall() == null && call.getState() == state &&
1862 !call.isExternalCall()) {
1863
Santos Cordonf193ba42014-09-12 06:37:39 -07001864 count++;
1865 }
1866 }
1867 }
1868 return count;
1869 }
1870
1871 private boolean hasMaximumLiveCalls() {
1872 return MAXIMUM_LIVE_CALLS <= getNumCallsWithState(LIVE_CALL_STATES);
1873 }
1874
1875 private boolean hasMaximumHoldingCalls() {
1876 return MAXIMUM_HOLD_CALLS <= getNumCallsWithState(CallState.ON_HOLD);
1877 }
1878
1879 private boolean hasMaximumRingingCalls() {
1880 return MAXIMUM_RINGING_CALLS <= getNumCallsWithState(CallState.RINGING);
1881 }
1882
1883 private boolean hasMaximumOutgoingCalls() {
1884 return MAXIMUM_OUTGOING_CALLS <= getNumCallsWithState(OUTGOING_CALL_STATES);
1885 }
1886
Roshan Pius4de4a892015-08-24 11:06:58 -07001887 private boolean hasMaximumDialingCalls() {
Tyler Gunn1e37be52016-07-11 08:54:23 -07001888 return MAXIMUM_DIALING_CALLS <= getNumCallsWithState(CallState.DIALING, CallState.PULLING);
Roshan Pius4de4a892015-08-24 11:06:58 -07001889 }
1890
Santos Cordonf193ba42014-09-12 06:37:39 -07001891 private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) {
1892 if (hasMaximumLiveCalls()) {
1893 // NOTE: If the amount of live calls changes beyond 1, this logic will probably
1894 // have to change.
Tony Makf5a32e42016-02-02 12:10:26 +00001895 Call liveCall = getFirstCallWithState(LIVE_CALL_STATES);
Anju Mathapatic88574c2014-12-16 14:46:19 +05301896 Log.i(this, "makeRoomForOutgoingCall call = " + call + " livecall = " +
1897 liveCall);
Santos Cordonf193ba42014-09-12 06:37:39 -07001898
Santos Cordond1766502014-09-26 15:45:39 -07001899 if (call == liveCall) {
1900 // If the call is already the foreground call, then we are golden.
Santos Cordon92694512015-04-23 14:47:28 -07001901 // This can happen after the user selects an account in the SELECT_PHONE_ACCOUNT
Santos Cordond1766502014-09-26 15:45:39 -07001902 // state since the call was already populated into the list.
1903 return true;
1904 }
1905
Andrew Leee6595182014-09-23 18:43:05 -07001906 if (hasMaximumOutgoingCalls()) {
Yorke Lee867907d2015-06-03 12:24:43 -07001907 Call outgoingCall = getFirstCallWithState(OUTGOING_CALL_STATES);
1908 if (isEmergency && !outgoingCall.isEmergencyCall()) {
1909 // Disconnect the current outgoing call if it's not an emergency call. If the
1910 // user tries to make two outgoing calls to different emergency call numbers,
1911 // we will try to connect the first outgoing call.
Hall Liu32587202015-11-18 11:10:08 -08001912 call.getAnalytics().setCallIsAdditional(true);
1913 outgoingCall.getAnalytics().setCallIsInterrupted(true);
Yorke Lee867907d2015-06-03 12:24:43 -07001914 outgoingCall.disconnect();
1915 return true;
1916 }
1917 if (outgoingCall.getState() == CallState.SELECT_PHONE_ACCOUNT) {
1918 // If there is an orphaned call in the {@link CallState#SELECT_PHONE_ACCOUNT}
1919 // state, just disconnect it since the user has explicitly started a new call.
Hall Liu32587202015-11-18 11:10:08 -08001920 call.getAnalytics().setCallIsAdditional(true);
1921 outgoingCall.getAnalytics().setCallIsInterrupted(true);
Yorke Lee867907d2015-06-03 12:24:43 -07001922 outgoingCall.disconnect();
1923 return true;
Andrew Leee6595182014-09-23 18:43:05 -07001924 }
1925 return false;
1926 }
1927
Santos Cordonf193ba42014-09-12 06:37:39 -07001928 if (hasMaximumHoldingCalls()) {
1929 // There is no more room for any more calls, unless it's an emergency.
1930 if (isEmergency) {
1931 // Kill the current active call, this is easier then trying to disconnect a
1932 // holding call and hold an active call.
Hall Liu32587202015-11-18 11:10:08 -08001933 call.getAnalytics().setCallIsAdditional(true);
1934 liveCall.getAnalytics().setCallIsInterrupted(true);
Santos Cordonf193ba42014-09-12 06:37:39 -07001935 liveCall.disconnect();
1936 return true;
1937 }
1938 return false; // No more room!
1939 }
1940
1941 // We have room for at least one more holding call at this point.
1942
Tyler Gunne4cd9162015-08-11 15:36:04 -07001943 // TODO: Remove once b/23035408 has been corrected.
1944 // If the live call is a conference, it will not have a target phone account set. This
1945 // means the check to see if the live call has the same target phone account as the new
1946 // call will not cause us to bail early. As a result, we'll end up holding the
1947 // ongoing conference call. However, the ConnectionService is already doing that. This
1948 // has caused problems with some carriers. As a workaround until b/23035408 is
1949 // corrected, we will try and get the target phone account for one of the conference's
1950 // children and use that instead.
1951 PhoneAccountHandle liveCallPhoneAccount = liveCall.getTargetPhoneAccount();
1952 if (liveCallPhoneAccount == null && liveCall.isConference() &&
1953 !liveCall.getChildCalls().isEmpty()) {
1954 liveCallPhoneAccount = getFirstChildPhoneAccount(liveCall);
1955 Log.i(this, "makeRoomForOutgoingCall: using child call PhoneAccount = " +
1956 liveCallPhoneAccount);
1957 }
1958
Santos Cordonf193ba42014-09-12 06:37:39 -07001959 // First thing, if we are trying to make a call with the same phone account as the live
1960 // call, then allow it so that the connection service can make its own decision about
1961 // how to handle the new call relative to the current one.
Tyler Gunne4cd9162015-08-11 15:36:04 -07001962 if (Objects.equals(liveCallPhoneAccount, call.getTargetPhoneAccount())) {
1963 Log.i(this, "makeRoomForOutgoingCall: phoneAccount matches.");
Hall Liu32587202015-11-18 11:10:08 -08001964 call.getAnalytics().setCallIsAdditional(true);
1965 liveCall.getAnalytics().setCallIsInterrupted(true);
Santos Cordonf193ba42014-09-12 06:37:39 -07001966 return true;
1967 } else if (call.getTargetPhoneAccount() == null) {
1968 // Without a phone account, we can't say reliably that the call will fail.
1969 // If the user chooses the same phone account as the live call, then it's
1970 // still possible that the call can be made (like with CDMA calls not supporting
1971 // hold but they still support adding a call by going immediately into conference
1972 // mode). Return true here and we'll run this code again after user chooses an
1973 // account.
1974 return true;
1975 }
1976
1977 // Try to hold the live call before attempting the new outgoing call.
Ihab Awad07bc5ee2014-11-12 13:42:52 -08001978 if (liveCall.can(Connection.CAPABILITY_HOLD)) {
Tyler Gunne4cd9162015-08-11 15:36:04 -07001979 Log.i(this, "makeRoomForOutgoingCall: holding live call.");
Hall Liu32587202015-11-18 11:10:08 -08001980 call.getAnalytics().setCallIsAdditional(true);
1981 liveCall.getAnalytics().setCallIsInterrupted(true);
Santos Cordonf193ba42014-09-12 06:37:39 -07001982 liveCall.hold();
1983 return true;
1984 }
1985
1986 // The live call cannot be held so we're out of luck here. There's no room.
1987 return false;
1988 }
1989 return true;
1990 }
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001991
1992 /**
Tyler Gunne4cd9162015-08-11 15:36:04 -07001993 * Given a call, find the first non-null phone account handle of its children.
1994 *
1995 * @param parentCall The parent call.
1996 * @return The first non-null phone account handle of the children, or {@code null} if none.
1997 */
1998 private PhoneAccountHandle getFirstChildPhoneAccount(Call parentCall) {
1999 for (Call childCall : parentCall.getChildCalls()) {
2000 PhoneAccountHandle childPhoneAccount = childCall.getTargetPhoneAccount();
2001 if (childPhoneAccount != null) {
2002 return childPhoneAccount;
2003 }
2004 }
2005 return null;
2006 }
2007
2008 /**
Santos Cordond6782cd2015-04-16 09:57:50 -07002009 * Checks to see if the call should be on speakerphone and if so, set it.
2010 */
2011 private void maybeMoveToSpeakerPhone(Call call) {
2012 if (call.getStartWithSpeakerphoneOn()) {
Yorke Lee2a66f7b2015-05-13 14:21:19 -07002013 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
Santos Cordond6782cd2015-04-16 09:57:50 -07002014 call.setStartWithSpeakerphoneOn(false);
2015 }
2016 }
2017
2018 /**
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002019 * Creates a new call for an existing connection.
2020 *
2021 * @param callId The id of the new call.
2022 * @param connection The connection information.
2023 * @return The new call.
2024 */
2025 Call createCallForExistingConnection(String callId, ParcelableConnection connection) {
Hall Liu4b9e5562016-07-14 15:34:56 -07002026 boolean isDowngradedConference = (connection.getConnectionProperties()
2027 & Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE) != 0;
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002028 Call call = new Call(
Tyler Gunn234d5422015-12-08 14:27:49 -08002029 callId,
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002030 mContext,
Ihab Awad78a5e6b2015-02-06 10:13:05 -08002031 this,
Ihab Awade6dbc9d2015-03-26 10:33:44 -07002032 mLock,
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002033 mConnectionServiceRepository,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07002034 mContactsAsyncHelper,
Ihab Awadabcbce42015-04-07 14:04:01 -07002035 mCallerInfoAsyncQueryFactory,
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07002036 mPhoneNumberUtilsAdapter,
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002037 connection.getHandle() /* handle */,
2038 null /* gatewayInfo */,
2039 null /* connectionManagerPhoneAccount */,
2040 connection.getPhoneAccount(), /* targetPhoneAccountHandle */
Hall Liu32587202015-11-18 11:10:08 -08002041 Call.CALL_DIRECTION_UNDEFINED /* callDirection */,
2042 false /* forceAttachToExistingConnection */,
Hall Liu4b9e5562016-07-14 15:34:56 -07002043 isDowngradedConference /* isConference */,
Roshan Pius084ab082015-07-15 12:17:04 -07002044 connection.getConnectTimeMillis() /* connectTimeMillis */);
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002045
Hall Liu32587202015-11-18 11:10:08 -08002046 call.initAnalytics();
2047 call.getAnalytics().setCreatedFromExistingConnection(true);
2048
Santos Cordon5fa4e4f2015-06-10 14:56:01 -07002049 setCallState(call, Call.getStateFromConnectionState(connection.getState()),
2050 "existing connection");
Ihab Awad07bc5ee2014-11-12 13:42:52 -08002051 call.setConnectionCapabilities(connection.getConnectionCapabilities());
Tyler Gunn571d5e62016-03-15 15:55:18 -07002052 call.setConnectionProperties(connection.getConnectionProperties());
Tyler Gunn6e2b94e2014-10-30 11:05:22 -07002053 call.setCallerDisplayName(connection.getCallerDisplayName(),
2054 connection.getCallerDisplayNamePresentation());
2055
2056 call.addListener(this);
2057 addCall(call);
2058
2059 return call;
2060 }
2061
2062 /**
Tyler Gunn8452be02015-09-17 09:57:02 -07002063 * @return A new unique telecom call Id.
2064 */
2065 private String getNextCallId() {
2066 synchronized(mLock) {
2067 return TELECOM_CALL_ID_PREFIX + (++mCallId);
2068 }
2069 }
2070
2071 /**
Tony Maka9930942016-01-15 10:57:14 +00002072 * Callback when foreground user is switched. We will reload missed call in all profiles
2073 * including the user itself. There may be chances that profiles are not started yet.
2074 */
2075 void onUserSwitch(UserHandle userHandle) {
Santos Cordonf0f99f32016-02-18 16:13:57 -08002076 mCurrentUserHandle = userHandle;
Tony Maka9930942016-01-15 10:57:14 +00002077 mMissedCallNotifier.setCurrentUserHandle(userHandle);
2078 final UserManager userManager = UserManager.get(mContext);
2079 List<UserInfo> profiles = userManager.getEnabledProfiles(userHandle.getIdentifier());
2080 for (UserInfo profile : profiles) {
2081 reloadMissedCallsOfUser(profile.getUserHandle());
2082 }
2083 }
2084
2085 /**
2086 * Because there may be chances that profiles are not started yet though its parent user is
2087 * switched, we reload missed calls of profile that are just started here.
2088 */
2089 void onUserStarting(UserHandle userHandle) {
2090 if (UserUtil.isProfile(mContext, userHandle)) {
2091 reloadMissedCallsOfUser(userHandle);
2092 }
2093 }
2094
Hall Liuc9cf5442016-06-29 10:08:10 -07002095 public TelecomSystem.SyncRoot getLock() {
2096 return mLock;
2097 }
2098
Tony Maka9930942016-01-15 10:57:14 +00002099 private void reloadMissedCallsOfUser(UserHandle userHandle) {
2100 mMissedCallNotifier.reloadFromDatabase(
2101 mLock, this, mContactsAsyncHelper, mCallerInfoAsyncQueryFactory, userHandle);
2102 }
2103
2104 /**
Tyler Gunn91d43cf2014-09-17 12:19:39 -07002105 * Dumps the state of the {@link CallsManager}.
2106 *
2107 * @param pw The {@code IndentingPrintWriter} to write the state to.
2108 */
2109 public void dump(IndentingPrintWriter pw) {
2110 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
Tyler Gunn91d43cf2014-09-17 12:19:39 -07002111 if (mCalls != null) {
2112 pw.println("mCalls: ");
2113 pw.increaseIndent();
2114 for (Call call : mCalls) {
2115 pw.println(call);
2116 }
2117 pw.decreaseIndent();
2118 }
Tyler Gunn9787e0e2014-10-14 14:36:12 -07002119
2120 if (mCallAudioManager != null) {
2121 pw.println("mCallAudioManager:");
2122 pw.increaseIndent();
2123 mCallAudioManager.dump(pw);
2124 pw.decreaseIndent();
2125 }
2126
2127 if (mTtyManager != null) {
2128 pw.println("mTtyManager:");
2129 pw.increaseIndent();
2130 mTtyManager.dump(pw);
2131 pw.decreaseIndent();
2132 }
2133
2134 if (mInCallController != null) {
2135 pw.println("mInCallController:");
2136 pw.increaseIndent();
2137 mInCallController.dump(pw);
2138 pw.decreaseIndent();
2139 }
2140
2141 if (mConnectionServiceRepository != null) {
2142 pw.println("mConnectionServiceRepository:");
2143 pw.increaseIndent();
2144 mConnectionServiceRepository.dump(pw);
2145 pw.decreaseIndent();
2146 }
Tyler Gunn91d43cf2014-09-17 12:19:39 -07002147 }
Xueren Zhangc0e8e9d2015-03-06 14:16:55 +01002148
2149 /**
2150 * For some disconnected causes, we show a dialog when it's a mmi code or potential mmi code.
2151 *
2152 * @param call The call.
2153 */
2154 private void maybeShowErrorDialogOnDisconnect(Call call) {
2155 if (call.getState() == CallState.DISCONNECTED && (isPotentialMMICode(call.getHandle())
2156 || isPotentialInCallMMICode(call.getHandle()))) {
2157 DisconnectCause disconnectCause = call.getDisconnectCause();
2158 if (!TextUtils.isEmpty(disconnectCause.getDescription()) && (disconnectCause.getCode()
2159 == DisconnectCause.ERROR)) {
2160 Intent errorIntent = new Intent(mContext, ErrorDialogActivity.class);
2161 errorIntent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_STRING_EXTRA,
2162 disconnectCause.getDescription());
2163 errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2164 mContext.startActivityAsUser(errorIntent, UserHandle.CURRENT);
2165 }
2166 }
2167 }
Sailesh Nepal703a1af2016-04-14 20:10:12 -07002168
2169 private void setIntentExtrasAndStartTime(Call call, Bundle extras) {
2170 // Create our own instance to modify (since extras may be Bundle.EMPTY)
2171 extras = new Bundle(extras);
2172
2173 // Specifies the time telecom began routing the call. This is used by the dialer for
2174 // analytics.
2175 extras.putLong(TelecomManager.EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS,
2176 SystemClock.elapsedRealtime());
2177
2178 call.setIntentExtras(extras);
2179 }
Ben Gilad9f2bed32013-12-12 17:43:26 -08002180}