Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 18 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 21 | import android.os.Bundle; |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 22 | import android.os.Handler; |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 23 | import android.os.Looper; |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 24 | import android.os.SystemProperties; |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 25 | import android.os.Trace; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 26 | import android.provider.CallLog.Calls; |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 27 | import android.telecom.CallAudioState; |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 28 | import android.telecom.Conference; |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 29 | import android.telecom.Connection; |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 30 | import android.telecom.DisconnectCause; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 31 | import android.telecom.GatewayInfo; |
| 32 | import android.telecom.ParcelableConference; |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 33 | import android.telecom.ParcelableConnection; |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 34 | import android.telecom.PhoneAccount; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 35 | import android.telecom.PhoneAccountHandle; |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 36 | import android.telecom.TelecomManager; |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 37 | import android.telecom.VideoProfile; |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 38 | import android.telephony.PhoneNumberUtils; |
Sailesh Nepal | 8aa6a00 | 2014-09-12 10:52:49 -0700 | [diff] [blame] | 39 | import android.telephony.TelephonyManager; |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 41 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 43 | import com.android.internal.telephony.PhoneConstants; |
| 44 | import com.android.internal.telephony.TelephonyProperties; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 45 | import com.android.internal.util.IndentingPrintWriter; |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 46 | |
Santos Cordon | 4bc0245 | 2014-11-19 15:51:12 -0800 | [diff] [blame] | 47 | import java.util.Collection; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 48 | import java.util.Collections; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 49 | import java.util.HashSet; |
Santos Cordon | 7cdb909 | 2014-07-24 21:33:33 -0700 | [diff] [blame] | 50 | import java.util.List; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 51 | import java.util.Objects; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 52 | import java.util.Set; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 53 | import java.util.concurrent.ConcurrentHashMap; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 54 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Singleton. |
| 57 | * |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 58 | * NOTE: by design most APIs are package private, use the relevant adapter/s to allow |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 59 | * access from other packages specifically refraining from passing the CallsManager instance |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 60 | * beyond the com.android.server.telecom package boundary. |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 61 | */ |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 62 | @VisibleForTesting |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 63 | public class CallsManager extends Call.ListenerBase implements VideoProviderProxy.Listener { |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 64 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 65 | // TODO: Consider renaming this CallsManagerPlugin. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 66 | interface CallsManagerListener { |
| 67 | void onCallAdded(Call call); |
| 68 | void onCallRemoved(Call call); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 69 | void onCallStateChanged(Call call, int oldState, int newState); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 70 | void onConnectionServiceChanged( |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 71 | Call call, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 72 | ConnectionServiceWrapper oldService, |
| 73 | ConnectionServiceWrapper newService); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 74 | void onIncomingCallAnswered(Call call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 75 | void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 76 | void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall); |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 77 | void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState); |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 78 | void onRingbackRequested(Call call, boolean ringback); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 79 | void onIsConferencedChanged(Call call); |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 80 | void onIsVoipAudioModeChanged(Call call); |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 81 | void onVideoStateChanged(Call call); |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 82 | void onCanAddCallChanged(boolean canAddCall); |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 83 | void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 86 | private static final String TAG = "CallsManager"; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 87 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 88 | private static final int MAXIMUM_LIVE_CALLS = 1; |
| 89 | private static final int MAXIMUM_HOLD_CALLS = 1; |
| 90 | private static final int MAXIMUM_RINGING_CALLS = 1; |
| 91 | private static final int MAXIMUM_OUTGOING_CALLS = 1; |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 92 | private static final int MAXIMUM_TOP_LEVEL_CALLS = 2; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 93 | |
| 94 | private static final int[] OUTGOING_CALL_STATES = |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 95 | {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING}; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 96 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 97 | private static final int[] LIVE_CALL_STATES = |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 98 | {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING, CallState.ACTIVE}; |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 99 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 100 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 101 | * The main call repository. Keeps an instance of all live calls. New incoming and outgoing |
| 102 | * calls are added to the map and removed when the calls move to the disconnected state. |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 103 | * |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 104 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 105 | * load factor before resizing, 1 means we only expect a single thread to |
| 106 | * access the map so make only a single shard |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 107 | */ |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 108 | private final Set<Call> mCalls = Collections.newSetFromMap( |
| 109 | new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1)); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 110 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 111 | private final ConnectionServiceRepository mConnectionServiceRepository; |
| 112 | private final DtmfLocalTonePlayer mDtmfLocalTonePlayer; |
| 113 | private final InCallController mInCallController; |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 114 | private final CallAudioManager mCallAudioManager; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 115 | private RespondViaSmsManager mRespondViaSmsManager; |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 116 | private final Ringer mRinger; |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 117 | private final InCallWakeLockController mInCallWakeLockController; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 118 | // For this set initial table size to 16 because we add 13 listeners in |
| 119 | // the CallsManager constructor. |
| 120 | private final Set<CallsManagerListener> mListeners = Collections.newSetFromMap( |
| 121 | new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1)); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 122 | private final HeadsetMediaButton mHeadsetMediaButton; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 123 | private final WiredHeadsetManager mWiredHeadsetManager; |
Santos Cordon | a04bdca | 2015-03-04 16:57:55 -0800 | [diff] [blame] | 124 | private final DockManager mDockManager; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 125 | private final TtyManager mTtyManager; |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 126 | private final ProximitySensorManager mProximitySensorManager; |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 127 | private final PhoneStateBroadcaster mPhoneStateBroadcaster; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 128 | private final CallLogManager mCallLogManager; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 129 | private final Context mContext; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 130 | private final TelecomSystem.SyncRoot mLock; |
| 131 | private final ContactsAsyncHelper mContactsAsyncHelper; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 132 | private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 133 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
| 134 | private final MissedCallNotifier mMissedCallNotifier; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 135 | private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>(); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 136 | private final Set<Call> mPendingCallsToDisconnect = new HashSet<>(); |
| 137 | /* Handler tied to thread in which CallManager was initialized. */ |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 138 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 139 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 140 | private boolean mCanAddCall = true; |
| 141 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 142 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 143 | * The call the user is currently interacting with. This is the call that should have audio |
| 144 | * focus and be visible in the in-call UI. |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 145 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 146 | private Call mForegroundCall; |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 147 | |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 148 | private Runnable mStopTone; |
| 149 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 150 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 151 | * Initializes the required Telecom components. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 152 | */ |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 153 | CallsManager( |
| 154 | Context context, |
| 155 | TelecomSystem.SyncRoot lock, |
| 156 | ContactsAsyncHelper contactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 157 | CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 158 | MissedCallNotifier missedCallNotifier, |
| 159 | PhoneAccountRegistrar phoneAccountRegistrar, |
| 160 | HeadsetMediaButtonFactory headsetMediaButtonFactory, |
| 161 | ProximitySensorManagerFactory proximitySensorManagerFactory, |
| 162 | InCallWakeLockControllerFactory inCallWakeLockControllerFactory) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 163 | mContext = context; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 164 | mLock = lock; |
| 165 | mContactsAsyncHelper = contactsAsyncHelper; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 166 | mCallerInfoAsyncQueryFactory = callerInfoAsyncQueryFactory; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 167 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
| 168 | mMissedCallNotifier = missedCallNotifier; |
| 169 | StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this); |
| 170 | mWiredHeadsetManager = new WiredHeadsetManager(context); |
Santos Cordon | a04bdca | 2015-03-04 16:57:55 -0800 | [diff] [blame] | 171 | mDockManager = new DockManager(context); |
| 172 | mCallAudioManager = new CallAudioManager( |
Ihab Awad | b60f006 | 2015-05-26 16:20:32 -0700 | [diff] [blame] | 173 | context, mLock, statusBarNotifier, mWiredHeadsetManager, mDockManager, this); |
Vinit Deshpande | 73ff372 | 2015-04-14 17:58:09 -0700 | [diff] [blame] | 174 | InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager, lock); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 175 | mRinger = new Ringer(mCallAudioManager, this, playerFactory, context); |
Ihab Awad | 731369c | 2015-05-19 09:23:21 -0700 | [diff] [blame] | 176 | mHeadsetMediaButton = headsetMediaButtonFactory.create(context, this, mLock); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 177 | mTtyManager = new TtyManager(context, mWiredHeadsetManager); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 178 | mProximitySensorManager = proximitySensorManagerFactory.create(context, this); |
| 179 | mPhoneStateBroadcaster = new PhoneStateBroadcaster(this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 180 | mCallLogManager = new CallLogManager(context); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 181 | mInCallController = new InCallController(context, mLock, this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 182 | mDtmfLocalTonePlayer = new DtmfLocalTonePlayer(context); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 183 | mConnectionServiceRepository = |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 184 | new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 185 | mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 186 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 187 | mListeners.add(statusBarNotifier); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 188 | mListeners.add(mCallLogManager); |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 189 | mListeners.add(mPhoneStateBroadcaster); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 190 | mListeners.add(mInCallController); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 191 | mListeners.add(mRinger); |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 192 | mListeners.add(new RingbackPlayer(this, playerFactory)); |
| 193 | mListeners.add(new InCallToneMonitor(playerFactory, this)); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 194 | mListeners.add(mCallAudioManager); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 195 | mListeners.add(missedCallNotifier); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 196 | mListeners.add(mDtmfLocalTonePlayer); |
Santos Cordon | 8128998 | 2014-06-03 16:03:08 -0700 | [diff] [blame] | 197 | mListeners.add(mHeadsetMediaButton); |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 198 | mListeners.add(mProximitySensorManager); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 199 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 200 | mMissedCallNotifier.updateOnStartup( |
| 201 | mLock, this, mContactsAsyncHelper, mCallerInfoAsyncQueryFactory); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 204 | public void setRespondViaSmsManager(RespondViaSmsManager respondViaSmsManager) { |
| 205 | if (mRespondViaSmsManager != null) { |
| 206 | mListeners.remove(mRespondViaSmsManager); |
| 207 | } |
| 208 | mRespondViaSmsManager = respondViaSmsManager; |
| 209 | mListeners.add(respondViaSmsManager); |
| 210 | } |
| 211 | |
| 212 | public RespondViaSmsManager getRespondViaSmsManager() { |
| 213 | return mRespondViaSmsManager; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 216 | @Override |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 217 | public void onSuccessfulOutgoingCall(Call call, int callState) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 218 | Log.v(this, "onSuccessfulOutgoingCall, %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 219 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 220 | setCallState(call, callState, "successful outgoing call"); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 221 | if (!mCalls.contains(call)) { |
| 222 | // Call was not added previously in startOutgoingCall due to it being a potential MMI |
| 223 | // code, so add it now. |
| 224 | addCall(call); |
| 225 | } |
| 226 | |
| 227 | // The call's ConnectionService has been updated. |
| 228 | for (CallsManagerListener listener : mListeners) { |
| 229 | listener.onConnectionServiceChanged(call, null, call.getConnectionService()); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 230 | } |
Santos Cordon | 6cb7ba9 | 2014-05-23 14:09:32 -0700 | [diff] [blame] | 231 | |
| 232 | markCallAsDialing(call); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 236 | public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) { |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 237 | Log.v(this, "onFailedOutgoingCall, call: %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 238 | |
Andrew Lee | e6288a7 | 2014-10-01 13:50:02 -0700 | [diff] [blame] | 239 | markCallAsRemoved(call); |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | @Override |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 243 | public void onSuccessfulIncomingCall(Call incomingCall) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 244 | Log.d(this, "onSuccessfulIncomingCall"); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 245 | setCallState(incomingCall, CallState.RINGING, "successful incoming call"); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 246 | |
| 247 | if (hasMaximumRingingCalls()) { |
| 248 | incomingCall.reject(false, null); |
| 249 | // since the call was not added to the list of calls, we have to call the missed |
| 250 | // call notifier and the call logger manually. |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 251 | mMissedCallNotifier.showMissedCallNotification(incomingCall); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 252 | mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE); |
| 253 | } else { |
| 254 | addCall(incomingCall); |
| 255 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void onFailedIncomingCall(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 260 | setCallState(call, CallState.DISCONNECTED, "failed incoming call"); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 261 | call.removeListener(this); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 264 | @Override |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 265 | public void onSuccessfulUnknownCall(Call call, int callState) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 266 | setCallState(call, callState, "successful unknown call"); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 267 | Log.i(this, "onSuccessfulUnknownCall for call %s", call); |
| 268 | addCall(call); |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public void onFailedUnknownCall(Call call) { |
| 273 | Log.i(this, "onFailedUnknownCall for call %s", call); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 274 | setCallState(call, CallState.DISCONNECTED, "failed unknown call"); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 275 | call.removeListener(this); |
| 276 | } |
| 277 | |
| 278 | @Override |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 279 | public void onRingbackRequested(Call call, boolean ringback) { |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 280 | for (CallsManagerListener listener : mListeners) { |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 281 | listener.onRingbackRequested(call, ringback); |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 285 | @Override |
| 286 | public void onPostDialWait(Call call, String remaining) { |
| 287 | mInCallController.onPostDialWait(call, remaining); |
| 288 | } |
| 289 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 290 | @Override |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 291 | public void onPostDialChar(final Call call, char nextChar) { |
| 292 | if (PhoneNumberUtils.is12Key(nextChar)) { |
| 293 | // Play tone if it is one of the dialpad digits, canceling out the previously queued |
| 294 | // up stopTone runnable since playing a new tone automatically stops the previous tone. |
| 295 | if (mStopTone != null) { |
| 296 | mHandler.removeCallbacks(mStopTone); |
| 297 | } |
| 298 | |
| 299 | mDtmfLocalTonePlayer.playTone(call, nextChar); |
| 300 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 301 | // TODO: Create a LockedRunnable class that does the synchronization automatically. |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 302 | mStopTone = new Runnable() { |
| 303 | @Override |
| 304 | public void run() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 305 | synchronized (mLock) { |
| 306 | // Set a timeout to stop the tone in case there isn't another tone to follow. |
| 307 | mDtmfLocalTonePlayer.stopTone(call); |
| 308 | } |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 309 | } |
| 310 | }; |
| 311 | mHandler.postDelayed( |
| 312 | mStopTone, |
| 313 | Timeouts.getDelayBetweenDtmfTonesMillis(mContext.getContentResolver())); |
| 314 | } else if (nextChar == 0 || nextChar == TelecomManager.DTMF_CHARACTER_WAIT || |
| 315 | nextChar == TelecomManager.DTMF_CHARACTER_PAUSE) { |
| 316 | // Stop the tone if a tone is playing, removing any other stopTone callbacks since |
| 317 | // the previous tone is being stopped anyway. |
| 318 | if (mStopTone != null) { |
| 319 | mHandler.removeCallbacks(mStopTone); |
| 320 | } |
| 321 | mDtmfLocalTonePlayer.stopTone(call); |
| 322 | } else { |
| 323 | Log.w(this, "onPostDialChar: invalid value %d", nextChar); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 328 | public void onParentChanged(Call call) { |
Santos Cordon | 66fe882 | 2014-10-10 16:10:58 -0700 | [diff] [blame] | 329 | // parent-child relationship affects which call should be foreground, so do an update. |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 330 | updateCallsManagerState(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 331 | for (CallsManagerListener listener : mListeners) { |
| 332 | listener.onIsConferencedChanged(call); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void onChildrenChanged(Call call) { |
Santos Cordon | 66fe882 | 2014-10-10 16:10:58 -0700 | [diff] [blame] | 338 | // parent-child relationship affects which call should be foreground, so do an update. |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 339 | updateCallsManagerState(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 340 | for (CallsManagerListener listener : mListeners) { |
| 341 | listener.onIsConferencedChanged(call); |
| 342 | } |
| 343 | } |
| 344 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 345 | @Override |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 346 | public void onIsVoipAudioModeChanged(Call call) { |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 347 | for (CallsManagerListener listener : mListeners) { |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 348 | listener.onIsVoipAudioModeChanged(call); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 352 | @Override |
| 353 | public void onVideoStateChanged(Call call) { |
| 354 | for (CallsManagerListener listener : mListeners) { |
| 355 | listener.onVideoStateChanged(call); |
| 356 | } |
| 357 | } |
| 358 | |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 359 | @Override |
| 360 | public boolean onCanceledViaNewOutgoingCallBroadcast(final Call call) { |
| 361 | mPendingCallsToDisconnect.add(call); |
| 362 | mHandler.postDelayed(new Runnable() { |
| 363 | @Override |
| 364 | public void run() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 365 | synchronized (mLock) { |
| 366 | if (mPendingCallsToDisconnect.remove(call)) { |
| 367 | Log.i(this, "Delayed disconnection of call: %s", call); |
| 368 | call.disconnect(); |
| 369 | } |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | }, Timeouts.getNewOutgoingCallCancelMillis(mContext.getContentResolver())); |
| 373 | |
| 374 | return true; |
| 375 | } |
| 376 | |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 377 | /** |
| 378 | * Handles changes to the {@link Connection.VideoProvider} for a call. Adds the |
| 379 | * {@link CallsManager} as a listener for the {@link VideoProviderProxy} which is created |
| 380 | * in {@link Call#setVideoProvider(IVideoProvider)}. This allows the {@link CallsManager} to |
| 381 | * respond to callbacks from the {@link VideoProviderProxy}. |
| 382 | * |
| 383 | * @param call The call. |
| 384 | */ |
| 385 | @Override |
| 386 | public void onVideoCallProviderChanged(Call call) { |
| 387 | VideoProviderProxy videoProviderProxy = call.getVideoProviderProxy(); |
| 388 | |
| 389 | if (videoProviderProxy == null) { |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | videoProviderProxy.addListener(this); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Handles session modification requests received via the {@link TelecomVideoCallCallback} for |
| 398 | * a call. Notifies listeners of the {@link CallsManager.CallsManagerListener} of the session |
| 399 | * modification request. |
| 400 | * |
| 401 | * @param call The call. |
| 402 | * @param videoProfile The {@link VideoProfile}. |
| 403 | */ |
| 404 | @Override |
| 405 | public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) { |
| 406 | int videoState = videoProfile != null ? videoProfile.getVideoState() : |
| 407 | VideoProfile.STATE_AUDIO_ONLY; |
| 408 | Log.v(TAG, "onSessionModifyRequestReceived : videoProfile = " + VideoProfile |
| 409 | .videoStateToString(videoState)); |
| 410 | |
| 411 | for (CallsManagerListener listener : mListeners) { |
| 412 | listener.onSessionModifyRequestReceived(call, videoProfile); |
| 413 | } |
| 414 | } |
| 415 | |
Santos Cordon | 4bc0245 | 2014-11-19 15:51:12 -0800 | [diff] [blame] | 416 | Collection<Call> getCalls() { |
| 417 | return Collections.unmodifiableCollection(mCalls); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | Call getForegroundCall() { |
| 421 | return mForegroundCall; |
| 422 | } |
| 423 | |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 424 | Ringer getRinger() { |
| 425 | return mRinger; |
| 426 | } |
| 427 | |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 428 | InCallController getInCallController() { |
| 429 | return mInCallController; |
| 430 | } |
| 431 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 432 | boolean hasEmergencyCall() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 433 | for (Call call : mCalls) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 434 | if (call.isEmergencyCall()) { |
| 435 | return true; |
| 436 | } |
| 437 | } |
| 438 | return false; |
| 439 | } |
| 440 | |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 441 | boolean hasVideoCall() { |
| 442 | for (Call call : mCalls) { |
Tyler Gunn | 467b64f | 2015-06-09 13:48:47 -0700 | [diff] [blame] | 443 | if (VideoProfile.isVideo(call.getVideoState())) { |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | } |
| 447 | return false; |
| 448 | } |
| 449 | |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 450 | CallAudioState getAudioState() { |
| 451 | return mCallAudioManager.getCallAudioState(); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 454 | boolean isTtySupported() { |
| 455 | return mTtyManager.isTtySupported(); |
| 456 | } |
| 457 | |
| 458 | int getCurrentTtyMode() { |
| 459 | return mTtyManager.getCurrentTtyMode(); |
| 460 | } |
| 461 | |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 462 | void addListener(CallsManagerListener listener) { |
| 463 | mListeners.add(listener); |
| 464 | } |
| 465 | |
| 466 | void removeListener(CallsManagerListener listener) { |
| 467 | mListeners.remove(listener); |
| 468 | } |
| 469 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 470 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 471 | * Starts the process to attach the call to a connection service. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 472 | * |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 473 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 474 | * connection service to use for this call. |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 475 | * @param extras The optional extras Bundle passed with the intent used for the incoming call. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 476 | */ |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 477 | void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 478 | Log.d(this, "processIncomingCallIntent"); |
Yorke Lee | 69fa897 | 2015-06-08 11:25:32 -0700 | [diff] [blame] | 479 | Uri handle = extras.getParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS); |
| 480 | if (handle == null) { |
| 481 | // Required for backwards compatibility |
| 482 | handle = extras.getParcelable(TelephonyManager.EXTRA_INCOMING_NUMBER); |
| 483 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 484 | Call call = new Call( |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 485 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 486 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 487 | mLock, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 488 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 489 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 490 | mCallerInfoAsyncQueryFactory, |
Sailesh Nepal | 8aa6a00 | 2014-09-12 10:52:49 -0700 | [diff] [blame] | 491 | handle, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 492 | null /* gatewayInfo */, |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 493 | null /* connectionManagerPhoneAccount */, |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 494 | phoneAccountHandle, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 495 | true /* isIncoming */, |
| 496 | false /* isConference */); |
| 497 | |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 498 | call.setIntentExtras(extras); |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 499 | // TODO: Move this to be a part of addCall() |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 500 | call.addListener(this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 501 | call.startCreateConnection(mPhoneAccountRegistrar); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 504 | void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
| 505 | Uri handle = extras.getParcelable(TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE); |
| 506 | Log.i(this, "addNewUnknownCall with handle: %s", Log.pii(handle)); |
| 507 | Call call = new Call( |
| 508 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 509 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 510 | mLock, |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 511 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 512 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 513 | mCallerInfoAsyncQueryFactory, |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 514 | handle, |
| 515 | null /* gatewayInfo */, |
| 516 | null /* connectionManagerPhoneAccount */, |
| 517 | phoneAccountHandle, |
| 518 | // Use onCreateIncomingConnection in TelephonyConnectionService, so that we attach |
| 519 | // to the existing connection instead of trying to create a new one. |
| 520 | true /* isIncoming */, |
| 521 | false /* isConference */); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 522 | call.setIsUnknown(true); |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 523 | call.setIntentExtras(extras); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 524 | call.addListener(this); |
| 525 | call.startCreateConnection(mPhoneAccountRegistrar); |
| 526 | } |
| 527 | |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 528 | private boolean areHandlesEqual(Uri handle1, Uri handle2) { |
| 529 | if (handle1 == null || handle2 == null) { |
| 530 | return handle1 == handle2; |
| 531 | } |
| 532 | |
| 533 | if (!TextUtils.equals(handle1.getScheme(), handle2.getScheme())) { |
| 534 | return false; |
| 535 | } |
| 536 | |
| 537 | final String number1 = PhoneNumberUtils.normalizeNumber(handle1.getSchemeSpecificPart()); |
| 538 | final String number2 = PhoneNumberUtils.normalizeNumber(handle2.getSchemeSpecificPart()); |
| 539 | return TextUtils.equals(number1, number2); |
| 540 | } |
| 541 | |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 542 | private Call getNewOutgoingCall(Uri handle) { |
| 543 | // First check to see if we can reuse any of the calls that are waiting to disconnect. |
| 544 | // See {@link Call#abort} and {@link #onCanceledViaNewOutgoingCall} for more information. |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 545 | Call reusedCall = null; |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 546 | for (Call pendingCall : mPendingCallsToDisconnect) { |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 547 | if (reusedCall == null && areHandlesEqual(pendingCall.getHandle(), handle)) { |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 548 | mPendingCallsToDisconnect.remove(pendingCall); |
| 549 | Log.i(this, "Reusing disconnected call %s", pendingCall); |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 550 | reusedCall = pendingCall; |
| 551 | } else { |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 552 | Log.i(this, "Not reusing disconnected call %s", pendingCall); |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 553 | pendingCall.disconnect(); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 554 | } |
| 555 | } |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 556 | if (reusedCall != null) { |
| 557 | return reusedCall; |
| 558 | } |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 559 | |
| 560 | // Create a call with original handle. The handle may be changed when the call is attached |
| 561 | // to a connection service, but in most cases will remain the same. |
| 562 | return new Call( |
| 563 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 564 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 565 | mLock, |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 566 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 567 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 568 | mCallerInfoAsyncQueryFactory, |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 569 | handle, |
| 570 | null /* gatewayInfo */, |
| 571 | null /* connectionManagerPhoneAccount */, |
| 572 | null /* phoneAccountHandle */, |
| 573 | false /* isIncoming */, |
| 574 | false /* isConference */); |
| 575 | } |
| 576 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 577 | /** |
| 578 | * Kicks off the first steps to creating an outgoing call so that InCallUI can launch. |
| 579 | * |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 580 | * @param handle Handle to connect the call with. |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 581 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 582 | * connection service to use for this call. |
| 583 | * @param extras The optional extras Bundle passed with the intent used for the incoming call. |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 584 | */ |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 585 | Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 586 | Call call = getNewOutgoingCall(handle); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 587 | |
| 588 | List<PhoneAccountHandle> accounts = |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 589 | mPhoneAccountRegistrar.getCallCapablePhoneAccounts(handle.getScheme(), false); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 590 | |
Ihab Awad | 7e2c7f3 | 2014-11-03 09:49:45 -0800 | [diff] [blame] | 591 | Log.v(this, "startOutgoingCall found accounts = " + accounts); |
| 592 | |
Nancy Chen | bc95db9 | 2014-11-24 13:19:18 -0800 | [diff] [blame] | 593 | if (mForegroundCall != null && mForegroundCall.getTargetPhoneAccount() != null) { |
| 594 | // If there is an ongoing call, use the same phone account to place this new call. |
| 595 | phoneAccountHandle = mForegroundCall.getTargetPhoneAccount(); |
| 596 | } |
| 597 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 598 | // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call |
| 599 | // as if a phoneAccount was not specified (does the default behavior instead). |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 600 | // Note: We will not attempt to dial with a requested phoneAccount if it is disabled. |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 601 | if (phoneAccountHandle != null) { |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 602 | if (!accounts.contains(phoneAccountHandle)) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 603 | phoneAccountHandle = null; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if (phoneAccountHandle == null) { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 608 | // No preset account, check if default exists that supports the URI scheme for the |
| 609 | // handle. |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 610 | phoneAccountHandle = |
| 611 | mPhoneAccountRegistrar.getOutgoingPhoneAccountForScheme(handle.getScheme()); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 614 | call.setTargetPhoneAccount(phoneAccountHandle); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 615 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 616 | boolean isEmergencyCall = TelephonyUtil.shouldProcessAsEmergency(mContext, |
| 617 | call.getHandle()); |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 618 | boolean isPotentialInCallMMICode = isPotentialInCallMMICode(handle); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 619 | |
| 620 | // Do not support any more live calls. Our options are to move a call to hold, disconnect |
| 621 | // a call, or cancel this call altogether. |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 622 | if (!isPotentialInCallMMICode && !makeRoomForOutgoingCall(call, isEmergencyCall)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 623 | // just cancel at this point. |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 624 | Log.i(this, "No remaining room for outgoing call: %s", call); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 625 | if (mCalls.contains(call)) { |
| 626 | // This call can already exist if it is a reused call, |
| 627 | // See {@link #getNewOutgoingCall}. |
| 628 | call.disconnect(); |
| 629 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 630 | return null; |
| 631 | } |
| 632 | |
Nancy Chen | 8d92f45 | 2014-10-20 21:43:44 -0700 | [diff] [blame] | 633 | boolean needsAccountSelection = phoneAccountHandle == null && accounts.size() > 1 && |
| 634 | !isEmergencyCall; |
| 635 | |
| 636 | if (needsAccountSelection) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 637 | // This is the state where the user is expected to select an account |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 638 | call.setState(CallState.SELECT_PHONE_ACCOUNT, "needs account selection"); |
Pawit Pornkitprasan | 1b2fd28 | 2015-03-15 08:33:32 +0700 | [diff] [blame] | 639 | // Create our own instance to modify (since extras may be Bundle.EMPTY) |
| 640 | extras = new Bundle(extras); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 641 | extras.putParcelableList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS, accounts); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 642 | } else { |
Roshan Pius | 781d025 | 2015-06-25 14:13:07 -0700 | [diff] [blame] | 643 | call.setState( |
| 644 | CallState.CONNECTING, |
| 645 | phoneAccountHandle == null ? "no-handle" : phoneAccountHandle.toString()); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 646 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 647 | |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 648 | call.setIntentExtras(extras); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 649 | |
Tyler Gunn | 504eb83 | 2014-10-13 14:15:27 -0700 | [diff] [blame] | 650 | // Do not add the call if it is a potential MMI code. |
Nancy Chen | 8d92f45 | 2014-10-20 21:43:44 -0700 | [diff] [blame] | 651 | if ((isPotentialMMICode(handle) || isPotentialInCallMMICode) && !needsAccountSelection) { |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 652 | call.addListener(this); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 653 | } else if (!mCalls.contains(call)) { |
| 654 | // We check if mCalls already contains the call because we could potentially be reusing |
| 655 | // a call which was previously added (See {@link #getNewOutgoingCall}). |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 656 | addCall(call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 657 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 658 | |
| 659 | return call; |
| 660 | } |
| 661 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 662 | /** |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 663 | * Attempts to issue/connect the specified call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 664 | * |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 665 | * @param handle Handle to connect the call with. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 666 | * @param gatewayInfo Optional gateway information that can be used to route the call to the |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 667 | * actual dialed handle via a gateway provider. May be null. |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 668 | * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects. |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 669 | * @param videoState The desired video state for the outgoing call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 670 | */ |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 671 | void placeOutgoingCall(Call call, Uri handle, GatewayInfo gatewayInfo, boolean speakerphoneOn, |
| 672 | int videoState) { |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 673 | if (call == null) { |
| 674 | // don't do anything if the call no longer exists |
| 675 | Log.i(this, "Canceling unknown call."); |
Santos Cordon | b7af09e | 2014-08-06 04:30:01 -0700 | [diff] [blame] | 676 | return; |
| 677 | } |
| 678 | |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 679 | final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayAddress(); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 680 | |
| 681 | if (gatewayInfo == null) { |
Santos Cordon | b58f453 | 2014-05-29 11:59:06 -0700 | [diff] [blame] | 682 | Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle)); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 683 | } else { |
| 684 | Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s", |
| 685 | Log.pii(uriHandle), Log.pii(handle)); |
| 686 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 687 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 688 | call.setHandle(uriHandle); |
| 689 | call.setGatewayInfo(gatewayInfo); |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 690 | call.setVideoState(videoState); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 691 | |
Santos Cordon | a04bdca | 2015-03-04 16:57:55 -0800 | [diff] [blame] | 692 | if (speakerphoneOn) { |
| 693 | Log.i(this, "%s Starting with speakerphone as requested", call); |
| 694 | } else { |
| 695 | Log.i(this, "%s Starting with speakerphone because car is docked.", call); |
| 696 | } |
| 697 | call.setStartWithSpeakerphoneOn(speakerphoneOn || mDockManager.isDocked()); |
| 698 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 699 | boolean isEmergencyCall = TelephonyUtil.shouldProcessAsEmergency(mContext, |
| 700 | call.getHandle()); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 701 | if (isEmergencyCall) { |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 702 | // Emergency -- CreateConnectionProcessor will choose accounts automatically |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 703 | call.setTargetPhoneAccount(null); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 704 | } |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 705 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 706 | if (call.getTargetPhoneAccount() != null || isEmergencyCall) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 707 | // If the account has been set, proceed to place the outgoing call. |
| 708 | // Otherwise the connection will be initiated when the account is set by the user. |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 709 | call.startCreateConnection(mPhoneAccountRegistrar); |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 710 | } |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 714 | * Attempts to start a conference call for the specified call. |
| 715 | * |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 716 | * @param call The call to conference. |
| 717 | * @param otherCall The other call to conference with. |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 718 | */ |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 719 | void conference(Call call, Call otherCall) { |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 720 | call.conferenceWith(otherCall); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 724 | * Instructs Telecom to answer the specified call. Intended to be invoked by the in-call |
| 725 | * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 726 | * the user opting to answer said call. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 727 | * |
| 728 | * @param call The call to answer. |
| 729 | * @param videoState The video state in which to answer the call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 730 | */ |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 731 | void answerCall(Call call, int videoState) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 732 | if (!mCalls.contains(call)) { |
| 733 | Log.i(this, "Request to answer a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 734 | } else { |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 735 | // If the foreground call is not the ringing call and it is currently isActive() or |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 736 | // STATE_DIALING, put it on hold before answering the call. |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 737 | if (mForegroundCall != null && mForegroundCall != call && |
| 738 | (mForegroundCall.isActive() || |
| 739 | mForegroundCall.getState() == CallState.DIALING)) { |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 740 | if (0 == (mForegroundCall.getConnectionCapabilities() |
| 741 | & Connection.CAPABILITY_HOLD)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 742 | // This call does not support hold. If it is from a different connection |
| 743 | // service, then disconnect it, otherwise allow the connection service to |
| 744 | // figure out the right states. |
| 745 | if (mForegroundCall.getConnectionService() != call.getConnectionService()) { |
| 746 | mForegroundCall.disconnect(); |
| 747 | } |
| 748 | } else { |
Andrew Lee | e94a8f1 | 2014-12-19 16:19:51 -0800 | [diff] [blame] | 749 | Call heldCall = getHeldCall(); |
| 750 | if (heldCall != null) { |
| 751 | Log.v(this, "Disconnecting held call %s before holding active call.", |
| 752 | heldCall); |
| 753 | heldCall.disconnect(); |
| 754 | } |
| 755 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 756 | Log.v(this, "Holding active/dialing call %s before answering incoming call %s.", |
| 757 | mForegroundCall, call); |
| 758 | mForegroundCall.hold(); |
| 759 | } |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 760 | // TODO: Wait until we get confirmation of the active call being |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 761 | // on-hold before answering the new call. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 762 | // TODO: Import logic from CallManager.acceptCall() |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 765 | for (CallsManagerListener listener : mListeners) { |
| 766 | listener.onIncomingCallAnswered(call); |
| 767 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 768 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 769 | // We do not update the UI until we get confirmation of the answer() through |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 770 | // {@link #markCallAsActive}. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 771 | call.answer(videoState); |
Tyler Gunn | 5b88249 | 2015-06-03 10:03:13 -0700 | [diff] [blame] | 772 | if (VideoProfile.isVideo(videoState) && |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 773 | !mWiredHeadsetManager.isPluggedIn() && |
| 774 | !mCallAudioManager.isBluetoothDeviceAvailable() && |
| 775 | isSpeakerEnabledForVideoCalls()) { |
| 776 | call.setStartWithSpeakerphoneOn(true); |
| 777 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 778 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 781 | private static boolean isSpeakerEnabledForVideoCalls() { |
| 782 | return (SystemProperties.getInt(TelephonyProperties.PROPERTY_VIDEOCALL_AUDIO_OUTPUT, |
| 783 | PhoneConstants.AUDIO_OUTPUT_DEFAULT) == |
| 784 | PhoneConstants.AUDIO_OUTPUT_ENABLE_SPEAKER); |
| 785 | } |
| 786 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 787 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 788 | * Instructs Telecom to reject the specified call. Intended to be invoked by the in-call |
| 789 | * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 790 | * the user opting to reject said call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 791 | */ |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 792 | void rejectCall(Call call, boolean rejectWithMessage, String textMessage) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 793 | if (!mCalls.contains(call)) { |
| 794 | Log.i(this, "Request to reject a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 795 | } else { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 796 | for (CallsManagerListener listener : mListeners) { |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 797 | listener.onIncomingCallRejected(call, rejectWithMessage, textMessage); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 798 | } |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 799 | call.reject(rejectWithMessage, textMessage); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 800 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 804 | * Instructs Telecom to play the specified DTMF tone within the specified call. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 805 | * |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 806 | * @param digit The DTMF digit to play. |
| 807 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 808 | void playDtmfTone(Call call, char digit) { |
| 809 | if (!mCalls.contains(call)) { |
| 810 | Log.i(this, "Request to play DTMF in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 811 | } else { |
| 812 | call.playDtmfTone(digit); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 813 | mDtmfLocalTonePlayer.playTone(call, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 818 | * Instructs Telecom to stop the currently playing DTMF tone, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 819 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 820 | void stopDtmfTone(Call call) { |
| 821 | if (!mCalls.contains(call)) { |
| 822 | Log.i(this, "Request to stop DTMF in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 823 | } else { |
| 824 | call.stopDtmfTone(); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 825 | mDtmfLocalTonePlayer.stopTone(call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 830 | * Instructs Telecom to continue (or not) the current post-dial DTMF string, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 831 | */ |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 832 | void postDialContinue(Call call, boolean proceed) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 833 | if (!mCalls.contains(call)) { |
| 834 | Log.i(this, "Request to continue post-dial string in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 835 | } else { |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 836 | call.postDialContinue(proceed); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
| 840 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 841 | * Instructs Telecom to disconnect the specified call. Intended to be invoked by the |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 842 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 843 | * the user hitting the end-call button. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 844 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 845 | void disconnectCall(Call call) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 846 | Log.v(this, "disconnectCall %s", call); |
| 847 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 848 | if (!mCalls.contains(call)) { |
| 849 | Log.w(this, "Unknown call (%s) asked to disconnect", call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 850 | } else { |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 851 | mLocallyDisconnectingCalls.add(call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 852 | call.disconnect(); |
| 853 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 854 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 855 | |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 856 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 857 | * Instructs Telecom to disconnect all calls. |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 858 | */ |
| 859 | void disconnectAllCalls() { |
| 860 | Log.v(this, "disconnectAllCalls"); |
| 861 | |
| 862 | for (Call call : mCalls) { |
| 863 | disconnectCall(call); |
| 864 | } |
| 865 | } |
| 866 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 867 | |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 868 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 869 | * Instructs Telecom to put the specified call on hold. Intended to be invoked by the |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 870 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 871 | * the user hitting the hold button during an active call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 872 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 873 | void holdCall(Call call) { |
| 874 | if (!mCalls.contains(call)) { |
| 875 | Log.w(this, "Unknown call (%s) asked to be put on hold", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 876 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 877 | Log.d(this, "Putting call on hold: (%s)", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 878 | call.hold(); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 883 | * Instructs Telecom to release the specified call from hold. Intended to be invoked by |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 884 | * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered |
| 885 | * by the user hitting the hold button during a held call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 886 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 887 | void unholdCall(Call call) { |
| 888 | if (!mCalls.contains(call)) { |
| 889 | Log.w(this, "Unknown call (%s) asked to be removed from hold", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 890 | } else { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 891 | Log.d(this, "unholding call: (%s)", call); |
Sai Cheemalapati | 45b3e3f | 2014-08-15 09:33:00 -0700 | [diff] [blame] | 892 | for (Call c : mCalls) { |
Tyler Gunn | e44adb4 | 2015-01-02 10:55:35 -0800 | [diff] [blame] | 893 | // Only attempt to hold parent calls and not the individual children. |
| 894 | if (c != null && c.isAlive() && c != call && c.getParentCall() == null) { |
Sai Cheemalapati | 45b3e3f | 2014-08-15 09:33:00 -0700 | [diff] [blame] | 895 | c.hold(); |
| 896 | } |
| 897 | } |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 898 | call.unhold(); |
| 899 | } |
| 900 | } |
| 901 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 902 | /** Called by the in-call UI to change the mute state. */ |
| 903 | void mute(boolean shouldMute) { |
| 904 | mCallAudioManager.mute(shouldMute); |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Called by the in-call UI to change the audio route, for example to change from earpiece to |
| 909 | * speaker phone. |
| 910 | */ |
| 911 | void setAudioRoute(int route) { |
| 912 | mCallAudioManager.setAudioRoute(route); |
| 913 | } |
| 914 | |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 915 | /** Called by the in-call UI to turn the proximity sensor on. */ |
| 916 | void turnOnProximitySensor() { |
| 917 | mProximitySensorManager.turnOn(); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * Called by the in-call UI to turn the proximity sensor off. |
| 922 | * @param screenOnImmediately If true, the screen will be turned on immediately. Otherwise, |
| 923 | * the screen will be kept off until the proximity sensor goes negative. |
| 924 | */ |
| 925 | void turnOffProximitySensor(boolean screenOnImmediately) { |
| 926 | mProximitySensorManager.turnOff(screenOnImmediately); |
| 927 | } |
| 928 | |
Nancy Chen | f5e5d3c | 2014-10-21 18:45:56 -0700 | [diff] [blame] | 929 | void phoneAccountSelected(Call call, PhoneAccountHandle account, boolean setDefault) { |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 930 | if (!mCalls.contains(call)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 931 | Log.i(this, "Attempted to add account to unknown call %s", call); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 932 | } else { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 933 | // TODO: There is an odd race condition here. Since NewOutgoingCallIntentBroadcaster and |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 934 | // the SELECT_PHONE_ACCOUNT sequence run in parallel, if the user selects an account before the |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 935 | // NEW_OUTGOING_CALL sequence finishes, we'll start the call immediately without |
| 936 | // respecting a rewritten number or a canceled number. This is unlikely since |
| 937 | // NEW_OUTGOING_CALL sequence, in practice, runs a lot faster than the user selecting |
| 938 | // a phone account from the in-call UI. |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 939 | call.setTargetPhoneAccount(account); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 940 | |
| 941 | // Note: emergency calls never go through account selection dialog so they never |
| 942 | // arrive here. |
| 943 | if (makeRoomForOutgoingCall(call, false /* isEmergencyCall */)) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 944 | call.startCreateConnection(mPhoneAccountRegistrar); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 945 | } else { |
| 946 | call.disconnect(); |
| 947 | } |
Nancy Chen | f5e5d3c | 2014-10-21 18:45:56 -0700 | [diff] [blame] | 948 | |
| 949 | if (setDefault) { |
| 950 | mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount(account); |
| 951 | } |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 955 | /** Called when the audio state changes. */ |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 956 | void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 957 | Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 958 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 959 | listener.onCallAudioStateChanged(oldAudioState, newAudioState); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 960 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 963 | void markCallAsRinging(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 964 | setCallState(call, CallState.RINGING, "ringing set explicitly"); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 965 | } |
| 966 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 967 | void markCallAsDialing(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 968 | setCallState(call, CallState.DIALING, "dialing set explicitly"); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 969 | maybeMoveToSpeakerPhone(call); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 970 | } |
| 971 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 972 | void markCallAsActive(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 973 | setCallState(call, CallState.ACTIVE, "active set explicitly"); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 974 | maybeMoveToSpeakerPhone(call); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 977 | void markCallAsOnHold(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 978 | setCallState(call, CallState.ON_HOLD, "on-hold set explicitly"); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 981 | /** |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 982 | * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the |
| 983 | * last live call, then also disconnect from the in-call controller. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 984 | * |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 985 | * @param disconnectCause The disconnect cause, see {@link android.telecom.DisconnectCause}. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 986 | */ |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 987 | void markCallAsDisconnected(Call call, DisconnectCause disconnectCause) { |
| 988 | call.setDisconnectCause(disconnectCause); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 989 | setCallState(call, CallState.DISCONNECTED, "disconnected set explicitly"); |
Sailesh Nepal | 6ab6fb7 | 2014-04-01 20:03:19 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 992 | /** |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 993 | * Removes an existing disconnected call, and notifies the in-call app. |
| 994 | */ |
| 995 | void markCallAsRemoved(Call call) { |
| 996 | removeCall(call); |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 997 | if (mLocallyDisconnectingCalls.contains(call)) { |
| 998 | mLocallyDisconnectingCalls.remove(call); |
| 999 | if (mForegroundCall != null && mForegroundCall.getState() == CallState.ON_HOLD) { |
| 1000 | mForegroundCall.unhold(); |
| 1001 | } |
| 1002 | } |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1006 | * Cleans up any calls currently associated with the specified connection service when the |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1007 | * service binder disconnects unexpectedly. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1008 | * |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1009 | * @param service The connection service that disconnected. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1010 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1011 | void handleConnectionServiceDeath(ConnectionServiceWrapper service) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1012 | if (service != null) { |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 1013 | for (Call call : mCalls) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1014 | if (call.getConnectionService() == service) { |
Yorke Lee | 2af16b6 | 2014-11-11 17:36:57 -0800 | [diff] [blame] | 1015 | if (call.getState() != CallState.DISCONNECTED) { |
| 1016 | markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR)); |
| 1017 | } |
| 1018 | markCallAsRemoved(call); |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1019 | } |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1024 | boolean hasAnyCalls() { |
| 1025 | return !mCalls.isEmpty(); |
| 1026 | } |
| 1027 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1028 | boolean hasActiveOrHoldingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1029 | return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | boolean hasRingingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1033 | return getFirstCallWithState(CallState.RINGING) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1036 | boolean onMediaButton(int type) { |
| 1037 | if (hasAnyCalls()) { |
| 1038 | if (HeadsetMediaButton.SHORT_PRESS == type) { |
| 1039 | Call ringingCall = getFirstCallWithState(CallState.RINGING); |
| 1040 | if (ringingCall == null) { |
| 1041 | mCallAudioManager.toggleMute(); |
| 1042 | return true; |
| 1043 | } else { |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 1044 | ringingCall.answer(ringingCall.getVideoState()); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1045 | return true; |
| 1046 | } |
| 1047 | } else if (HeadsetMediaButton.LONG_PRESS == type) { |
| 1048 | Log.d(this, "handleHeadsetHook: longpress -> hangup"); |
| 1049 | Call callToHangup = getFirstCallWithState( |
| 1050 | CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD); |
| 1051 | if (callToHangup != null) { |
| 1052 | callToHangup.disconnect(); |
| 1053 | return true; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | return false; |
| 1058 | } |
| 1059 | |
| 1060 | /** |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1061 | * Returns true if telecom supports adding another top-level call. |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1062 | */ |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1063 | boolean canAddCall() { |
Andrew Lee | 113ad62 | 2014-12-01 18:33:10 -0800 | [diff] [blame] | 1064 | if (getFirstCallWithState(OUTGOING_CALL_STATES) != null) { |
| 1065 | return false; |
| 1066 | } |
| 1067 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1068 | int count = 0; |
| 1069 | for (Call call : mCalls) { |
| 1070 | if (call.isEmergencyCall()) { |
| 1071 | // We never support add call if one of the calls is an emergency call. |
| 1072 | return false; |
| 1073 | } else if (call.getParentCall() == null) { |
| 1074 | count++; |
| 1075 | } |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1076 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1077 | // We do not check states for canAddCall. We treat disconnected calls the same |
| 1078 | // and wait until they are removed instead. If we didn't count disconnected calls, |
| 1079 | // we could put InCallServices into a state where they are showing two calls but |
| 1080 | // also support add-call. Technically it's right, but overall looks better (UI-wise) |
| 1081 | // and acts better if we wait until the call is removed. |
| 1082 | if (count >= MAXIMUM_TOP_LEVEL_CALLS) { |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1083 | return false; |
| 1084 | } |
| 1085 | } |
| 1086 | return true; |
| 1087 | } |
| 1088 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 1089 | @VisibleForTesting |
P.Y. Laligand | d35be75 | 2015-03-06 14:12:43 -0800 | [diff] [blame] | 1090 | public Call getRingingCall() { |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 1091 | return getFirstCallWithState(CallState.RINGING); |
| 1092 | } |
| 1093 | |
| 1094 | Call getActiveCall() { |
| 1095 | return getFirstCallWithState(CallState.ACTIVE); |
| 1096 | } |
| 1097 | |
Nancy Chen | 05a9e40 | 2014-09-26 14:14:32 -0700 | [diff] [blame] | 1098 | Call getDialingCall() { |
| 1099 | return getFirstCallWithState(CallState.DIALING); |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | Call getHeldCall() { |
| 1103 | return getFirstCallWithState(CallState.ON_HOLD); |
| 1104 | } |
| 1105 | |
Santos Cordon | c0ca76e | 2014-10-21 15:54:19 -0700 | [diff] [blame] | 1106 | int getNumHeldCalls() { |
| 1107 | int count = 0; |
| 1108 | for (Call call : mCalls) { |
| 1109 | if (call.getParentCall() == null && call.getState() == CallState.ON_HOLD) { |
| 1110 | count++; |
| 1111 | } |
| 1112 | } |
| 1113 | return count; |
| 1114 | } |
| 1115 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1116 | Call getFirstCallWithState(int... states) { |
| 1117 | return getFirstCallWithState(null, states); |
| 1118 | } |
| 1119 | |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1120 | /** |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1121 | * Returns the first call that it finds with the given states. The states are treated as having |
| 1122 | * priority order so that any call with the first state will be returned before any call with |
| 1123 | * states listed later in the parameter list. |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1124 | * |
| 1125 | * @param callToSkip Call that this method should skip while searching |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1126 | */ |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1127 | Call getFirstCallWithState(Call callToSkip, int... states) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1128 | for (int currentState : states) { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1129 | // check the foreground first |
| 1130 | if (mForegroundCall != null && mForegroundCall.getState() == currentState) { |
| 1131 | return mForegroundCall; |
| 1132 | } |
| 1133 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1134 | for (Call call : mCalls) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1135 | if (Objects.equals(callToSkip, call)) { |
| 1136 | continue; |
| 1137 | } |
| 1138 | |
| 1139 | // Only operate on top-level calls |
| 1140 | if (call.getParentCall() != null) { |
| 1141 | continue; |
| 1142 | } |
| 1143 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1144 | if (currentState == call.getState()) { |
| 1145 | return call; |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | return null; |
| 1150 | } |
| 1151 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1152 | Call createConferenceCall( |
| 1153 | PhoneAccountHandle phoneAccount, |
| 1154 | ParcelableConference parcelableConference) { |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 1155 | |
| 1156 | // If the parceled conference specifies a connect time, use it; otherwise default to 0, |
| 1157 | // which is the default value for new Calls. |
| 1158 | long connectTime = |
| 1159 | parcelableConference.getConnectTimeMillis() == |
| 1160 | Conference.CONNECT_TIME_NOT_SPECIFIED ? 0 : |
| 1161 | parcelableConference.getConnectTimeMillis(); |
| 1162 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1163 | Call call = new Call( |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1164 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1165 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 1166 | mLock, |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1167 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1168 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 1169 | mCallerInfoAsyncQueryFactory, |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1170 | null /* handle */, |
| 1171 | null /* gatewayInfo */, |
| 1172 | null /* connectionManagerPhoneAccount */, |
| 1173 | phoneAccount, |
| 1174 | false /* isIncoming */, |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 1175 | true /* isConference */, |
| 1176 | connectTime); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1177 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1178 | setCallState(call, Call.getStateFromConnectionState(parcelableConference.getState()), |
| 1179 | "new conference call"); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1180 | call.setConnectionCapabilities(parcelableConference.getConnectionCapabilities()); |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 1181 | call.setVideoState(parcelableConference.getVideoState()); |
| 1182 | call.setVideoProvider(parcelableConference.getVideoProvider()); |
Andrew Lee | 57412d3 | 2015-04-14 13:38:44 -0700 | [diff] [blame] | 1183 | call.setStatusHints(parcelableConference.getStatusHints()); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 1184 | call.setExtras(parcelableConference.getExtras()); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1185 | |
| 1186 | // TODO: Move this to be a part of addCall() |
| 1187 | call.addListener(this); |
| 1188 | addCall(call); |
| 1189 | return call; |
| 1190 | } |
| 1191 | |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 1192 | /** |
| 1193 | * @return the call state currently tracked by {@link PhoneStateBroadcaster} |
| 1194 | */ |
| 1195 | int getCallState() { |
| 1196 | return mPhoneStateBroadcaster.getCallState(); |
| 1197 | } |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 1198 | |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1199 | /** |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1200 | * Retrieves the {@link PhoneAccountRegistrar}. |
| 1201 | * |
| 1202 | * @return The {@link PhoneAccountRegistrar}. |
| 1203 | */ |
| 1204 | PhoneAccountRegistrar getPhoneAccountRegistrar() { |
| 1205 | return mPhoneAccountRegistrar; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * Retrieves the {@link MissedCallNotifier} |
| 1210 | * @return The {@link MissedCallNotifier}. |
| 1211 | */ |
| 1212 | MissedCallNotifier getMissedCallNotifier() { |
| 1213 | return mMissedCallNotifier; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1217 | * Adds the specified call to the main list of live calls. |
| 1218 | * |
| 1219 | * @param call The call to add. |
| 1220 | */ |
| 1221 | private void addCall(Call call) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1222 | Trace.beginSection("addCall"); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1223 | Log.v(this, "addCall(%s)", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1224 | call.addListener(this); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1225 | mCalls.add(call); |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1226 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1227 | // TODO: Update mForegroundCall prior to invoking |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1228 | // onCallAdded for calls which immediately take the foreground (like the first call). |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1229 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1230 | if (Log.SYSTRACE_DEBUG) { |
| 1231 | Trace.beginSection(listener.getClass().toString() + " addCall"); |
| 1232 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1233 | listener.onCallAdded(call); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1234 | if (Log.SYSTRACE_DEBUG) { |
| 1235 | Trace.endSection(); |
| 1236 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1237 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1238 | updateCallsManagerState(); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1239 | Trace.endSection(); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1242 | private void removeCall(Call call) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1243 | Trace.beginSection("removeCall"); |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 1244 | Log.v(this, "removeCall(%s)", call); |
Sailesh Nepal | 4857f47 | 2014-04-07 22:26:27 -0700 | [diff] [blame] | 1245 | |
Santos Cordon | 672321e | 2014-08-21 14:38:58 -0700 | [diff] [blame] | 1246 | call.setParentCall(null); // need to clean up parent relationship before destroying. |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 1247 | call.removeListener(this); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1248 | call.clearConnectionService(); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1249 | |
| 1250 | boolean shouldNotify = false; |
| 1251 | if (mCalls.contains(call)) { |
| 1252 | mCalls.remove(call); |
| 1253 | shouldNotify = true; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1254 | } |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1255 | |
Santos Cordon | 2685dab | 2015-04-17 17:12:09 -0700 | [diff] [blame] | 1256 | call.destroy(); |
| 1257 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1258 | // Only broadcast changes for calls that are being tracked. |
| 1259 | if (shouldNotify) { |
| 1260 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1261 | if (Log.SYSTRACE_DEBUG) { |
| 1262 | Trace.beginSection(listener.getClass().toString() + " onCallRemoved"); |
| 1263 | } |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1264 | listener.onCallRemoved(call); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1265 | if (Log.SYSTRACE_DEBUG) { |
| 1266 | Trace.endSection(); |
| 1267 | } |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1268 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1269 | updateCallsManagerState(); |
Yorke Lee | 604a90f | 2014-10-20 12:13:32 -0700 | [diff] [blame] | 1270 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1271 | Trace.endSection(); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1272 | } |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 1273 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1274 | /** |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 1275 | * Sets the specified state on the specified call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1276 | * |
| 1277 | * @param call The call. |
| 1278 | * @param newState The new state of the call. |
| 1279 | */ |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1280 | private void setCallState(Call call, int newState, String tag) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1281 | if (call == null) { |
| 1282 | return; |
| 1283 | } |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1284 | int oldState = call.getState(); |
Nancy Chen | 308ab8b | 2014-09-02 16:18:30 -0700 | [diff] [blame] | 1285 | Log.i(this, "setCallState %s -> %s, call: %s", CallState.toString(oldState), |
| 1286 | CallState.toString(newState), call); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1287 | if (newState != oldState) { |
| 1288 | // Unfortunately, in the telephony world the radio is king. So if the call notifies |
| 1289 | // us that the call is in a particular state, we allow it even if it doesn't make |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1290 | // sense (e.g., STATE_ACTIVE -> STATE_RINGING). |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1291 | // TODO: Consider putting a stop to the above and turning CallState |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1292 | // into a well-defined state machine. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1293 | // TODO: Define expected state transitions here, and log when an |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1294 | // unexpected transition occurs. |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1295 | call.setState(newState, tag); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1296 | |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1297 | Trace.beginSection("onCallStateChanged"); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1298 | // Only broadcast state change for calls that are being tracked. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1299 | if (mCalls.contains(call)) { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1300 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1301 | if (Log.SYSTRACE_DEBUG) { |
| 1302 | Trace.beginSection(listener.getClass().toString() + " onCallStateChanged"); |
| 1303 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1304 | listener.onCallStateChanged(call, oldState, newState); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1305 | if (Log.SYSTRACE_DEBUG) { |
| 1306 | Trace.endSection(); |
| 1307 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1308 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1309 | updateCallsManagerState(); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1310 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1311 | Trace.endSection(); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1316 | * Checks which call should be visible to the user and have audio focus. |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 1317 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1318 | private void updateForegroundCall() { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1319 | Trace.beginSection("updateForegroundCall"); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1320 | Call newForegroundCall = null; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1321 | for (Call call : mCalls) { |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1322 | // TODO: Foreground-ness needs to be explicitly set. No call, regardless |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1323 | // of its state will be foreground by default and instead the connection service should |
| 1324 | // be notified when its calls enter and exit foreground state. Foreground will mean that |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1325 | // the call should play audio and listen to microphone if it wants. |
| 1326 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1327 | // Only top-level calls can be in foreground |
| 1328 | if (call.getParentCall() != null) { |
| 1329 | continue; |
| 1330 | } |
| 1331 | |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1332 | // Active calls have priority. |
| 1333 | if (call.isActive()) { |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1334 | newForegroundCall = call; |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 1335 | break; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1336 | } |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1337 | |
| 1338 | if (call.isAlive() || call.getState() == CallState.RINGING) { |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1339 | newForegroundCall = call; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1340 | // Don't break in case there's an active call that has priority. |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1341 | } |
| 1342 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1343 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1344 | if (newForegroundCall != mForegroundCall) { |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1345 | Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1346 | Call oldForegroundCall = mForegroundCall; |
| 1347 | mForegroundCall = newForegroundCall; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 1348 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1349 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1350 | if (Log.SYSTRACE_DEBUG) { |
| 1351 | Trace.beginSection(listener.getClass().toString() + " updateForegroundCall"); |
| 1352 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1353 | listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1354 | if (Log.SYSTRACE_DEBUG) { |
| 1355 | Trace.endSection(); |
| 1356 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1357 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1358 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1359 | Trace.endSection(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1360 | } |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1361 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1362 | private void updateCanAddCall() { |
| 1363 | boolean newCanAddCall = canAddCall(); |
| 1364 | if (newCanAddCall != mCanAddCall) { |
| 1365 | mCanAddCall = newCanAddCall; |
| 1366 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1367 | if (Log.SYSTRACE_DEBUG) { |
| 1368 | Trace.beginSection(listener.getClass().toString() + " updateCanAddCall"); |
| 1369 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1370 | listener.onCanAddCallChanged(mCanAddCall); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1371 | if (Log.SYSTRACE_DEBUG) { |
| 1372 | Trace.endSection(); |
| 1373 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | private void updateCallsManagerState() { |
| 1379 | updateForegroundCall(); |
| 1380 | updateCanAddCall(); |
| 1381 | } |
| 1382 | |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1383 | private boolean isPotentialMMICode(Uri handle) { |
| 1384 | return (handle != null && handle.getSchemeSpecificPart() != null |
| 1385 | && handle.getSchemeSpecificPart().contains("#")); |
| 1386 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1387 | |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 1388 | /** |
| 1389 | * Determines if a dialed number is potentially an In-Call MMI code. In-Call MMI codes are |
| 1390 | * MMI codes which can be dialed when one or more calls are in progress. |
| 1391 | * <P> |
| 1392 | * Checks for numbers formatted similar to the MMI codes defined in: |
| 1393 | * {@link com.android.internal.telephony.gsm.GSMPhone#handleInCallMmiCommands(String)} |
| 1394 | * and |
| 1395 | * {@link com.android.internal.telephony.imsphone.ImsPhone#handleInCallMmiCommands(String)} |
| 1396 | * |
| 1397 | * @param handle The URI to call. |
| 1398 | * @return {@code True} if the URI represents a number which could be an in-call MMI code. |
| 1399 | */ |
| 1400 | private boolean isPotentialInCallMMICode(Uri handle) { |
| 1401 | if (handle != null && handle.getSchemeSpecificPart() != null && |
| 1402 | handle.getScheme().equals(PhoneAccount.SCHEME_TEL)) { |
| 1403 | |
| 1404 | String dialedNumber = handle.getSchemeSpecificPart(); |
| 1405 | return (dialedNumber.equals("0") || |
| 1406 | (dialedNumber.startsWith("1") && dialedNumber.length() <= 2) || |
| 1407 | (dialedNumber.startsWith("2") && dialedNumber.length() <= 2) || |
| 1408 | dialedNumber.equals("3") || |
| 1409 | dialedNumber.equals("4") || |
| 1410 | dialedNumber.equals("5")); |
| 1411 | } |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1415 | private int getNumCallsWithState(int... states) { |
| 1416 | int count = 0; |
| 1417 | for (int state : states) { |
| 1418 | for (Call call : mCalls) { |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1419 | if (call.getParentCall() == null && call.getState() == state) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1420 | count++; |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | return count; |
| 1425 | } |
| 1426 | |
| 1427 | private boolean hasMaximumLiveCalls() { |
| 1428 | return MAXIMUM_LIVE_CALLS <= getNumCallsWithState(LIVE_CALL_STATES); |
| 1429 | } |
| 1430 | |
| 1431 | private boolean hasMaximumHoldingCalls() { |
| 1432 | return MAXIMUM_HOLD_CALLS <= getNumCallsWithState(CallState.ON_HOLD); |
| 1433 | } |
| 1434 | |
| 1435 | private boolean hasMaximumRingingCalls() { |
| 1436 | return MAXIMUM_RINGING_CALLS <= getNumCallsWithState(CallState.RINGING); |
| 1437 | } |
| 1438 | |
| 1439 | private boolean hasMaximumOutgoingCalls() { |
| 1440 | return MAXIMUM_OUTGOING_CALLS <= getNumCallsWithState(OUTGOING_CALL_STATES); |
| 1441 | } |
| 1442 | |
| 1443 | private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) { |
| 1444 | if (hasMaximumLiveCalls()) { |
| 1445 | // NOTE: If the amount of live calls changes beyond 1, this logic will probably |
| 1446 | // have to change. |
| 1447 | Call liveCall = getFirstCallWithState(call, LIVE_CALL_STATES); |
Anju Mathapati | c88574c | 2014-12-16 14:46:19 +0530 | [diff] [blame] | 1448 | Log.i(this, "makeRoomForOutgoingCall call = " + call + " livecall = " + |
| 1449 | liveCall); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1450 | |
Santos Cordon | d176650 | 2014-09-26 15:45:39 -0700 | [diff] [blame] | 1451 | if (call == liveCall) { |
| 1452 | // If the call is already the foreground call, then we are golden. |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 1453 | // This can happen after the user selects an account in the SELECT_PHONE_ACCOUNT |
Santos Cordon | d176650 | 2014-09-26 15:45:39 -0700 | [diff] [blame] | 1454 | // state since the call was already populated into the list. |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
Andrew Lee | e659518 | 2014-09-23 18:43:05 -0700 | [diff] [blame] | 1458 | if (hasMaximumOutgoingCalls()) { |
Yorke Lee | 867907d | 2015-06-03 12:24:43 -0700 | [diff] [blame] | 1459 | Call outgoingCall = getFirstCallWithState(OUTGOING_CALL_STATES); |
| 1460 | if (isEmergency && !outgoingCall.isEmergencyCall()) { |
| 1461 | // Disconnect the current outgoing call if it's not an emergency call. If the |
| 1462 | // user tries to make two outgoing calls to different emergency call numbers, |
| 1463 | // we will try to connect the first outgoing call. |
| 1464 | outgoingCall.disconnect(); |
| 1465 | return true; |
| 1466 | } |
| 1467 | if (outgoingCall.getState() == CallState.SELECT_PHONE_ACCOUNT) { |
| 1468 | // If there is an orphaned call in the {@link CallState#SELECT_PHONE_ACCOUNT} |
| 1469 | // state, just disconnect it since the user has explicitly started a new call. |
| 1470 | outgoingCall.disconnect(); |
| 1471 | return true; |
Andrew Lee | e659518 | 2014-09-23 18:43:05 -0700 | [diff] [blame] | 1472 | } |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1476 | if (hasMaximumHoldingCalls()) { |
| 1477 | // There is no more room for any more calls, unless it's an emergency. |
| 1478 | if (isEmergency) { |
| 1479 | // Kill the current active call, this is easier then trying to disconnect a |
| 1480 | // holding call and hold an active call. |
| 1481 | liveCall.disconnect(); |
| 1482 | return true; |
| 1483 | } |
| 1484 | return false; // No more room! |
| 1485 | } |
| 1486 | |
| 1487 | // We have room for at least one more holding call at this point. |
| 1488 | |
| 1489 | // First thing, if we are trying to make a call with the same phone account as the live |
| 1490 | // call, then allow it so that the connection service can make its own decision about |
| 1491 | // how to handle the new call relative to the current one. |
| 1492 | if (Objects.equals(liveCall.getTargetPhoneAccount(), call.getTargetPhoneAccount())) { |
| 1493 | return true; |
| 1494 | } else if (call.getTargetPhoneAccount() == null) { |
| 1495 | // Without a phone account, we can't say reliably that the call will fail. |
| 1496 | // If the user chooses the same phone account as the live call, then it's |
| 1497 | // still possible that the call can be made (like with CDMA calls not supporting |
| 1498 | // hold but they still support adding a call by going immediately into conference |
| 1499 | // mode). Return true here and we'll run this code again after user chooses an |
| 1500 | // account. |
| 1501 | return true; |
| 1502 | } |
| 1503 | |
| 1504 | // Try to hold the live call before attempting the new outgoing call. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1505 | if (liveCall.can(Connection.CAPABILITY_HOLD)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1506 | liveCall.hold(); |
| 1507 | return true; |
| 1508 | } |
| 1509 | |
| 1510 | // The live call cannot be held so we're out of luck here. There's no room. |
| 1511 | return false; |
| 1512 | } |
| 1513 | return true; |
| 1514 | } |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1515 | |
| 1516 | /** |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1517 | * Checks to see if the call should be on speakerphone and if so, set it. |
| 1518 | */ |
| 1519 | private void maybeMoveToSpeakerPhone(Call call) { |
| 1520 | if (call.getStartWithSpeakerphoneOn()) { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1521 | setAudioRoute(CallAudioState.ROUTE_SPEAKER); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1522 | call.setStartWithSpeakerphoneOn(false); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | /** |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1527 | * Creates a new call for an existing connection. |
| 1528 | * |
| 1529 | * @param callId The id of the new call. |
| 1530 | * @param connection The connection information. |
| 1531 | * @return The new call. |
| 1532 | */ |
| 1533 | Call createCallForExistingConnection(String callId, ParcelableConnection connection) { |
| 1534 | Call call = new Call( |
| 1535 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1536 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 1537 | mLock, |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1538 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1539 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 1540 | mCallerInfoAsyncQueryFactory, |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1541 | connection.getHandle() /* handle */, |
| 1542 | null /* gatewayInfo */, |
| 1543 | null /* connectionManagerPhoneAccount */, |
| 1544 | connection.getPhoneAccount(), /* targetPhoneAccountHandle */ |
| 1545 | false /* isIncoming */, |
Roshan Pius | 084ab08 | 2015-07-15 12:17:04 -0700 | [diff] [blame] | 1546 | false /* isConference */, |
| 1547 | connection.getConnectTimeMillis() /* connectTimeMillis */); |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1548 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1549 | setCallState(call, Call.getStateFromConnectionState(connection.getState()), |
| 1550 | "existing connection"); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1551 | call.setConnectionCapabilities(connection.getConnectionCapabilities()); |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1552 | call.setCallerDisplayName(connection.getCallerDisplayName(), |
| 1553 | connection.getCallerDisplayNamePresentation()); |
| 1554 | |
| 1555 | call.addListener(this); |
| 1556 | addCall(call); |
| 1557 | |
| 1558 | return call; |
| 1559 | } |
| 1560 | |
| 1561 | /** |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1562 | * Dumps the state of the {@link CallsManager}. |
| 1563 | * |
| 1564 | * @param pw The {@code IndentingPrintWriter} to write the state to. |
| 1565 | */ |
| 1566 | public void dump(IndentingPrintWriter pw) { |
| 1567 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1568 | if (mCalls != null) { |
| 1569 | pw.println("mCalls: "); |
| 1570 | pw.increaseIndent(); |
| 1571 | for (Call call : mCalls) { |
| 1572 | pw.println(call); |
| 1573 | } |
| 1574 | pw.decreaseIndent(); |
| 1575 | } |
Tyler Gunn | 9787e0e | 2014-10-14 14:36:12 -0700 | [diff] [blame] | 1576 | pw.println("mForegroundCall: " + (mForegroundCall == null ? "none" : mForegroundCall)); |
| 1577 | |
| 1578 | if (mCallAudioManager != null) { |
| 1579 | pw.println("mCallAudioManager:"); |
| 1580 | pw.increaseIndent(); |
| 1581 | mCallAudioManager.dump(pw); |
| 1582 | pw.decreaseIndent(); |
| 1583 | } |
| 1584 | |
| 1585 | if (mTtyManager != null) { |
| 1586 | pw.println("mTtyManager:"); |
| 1587 | pw.increaseIndent(); |
| 1588 | mTtyManager.dump(pw); |
| 1589 | pw.decreaseIndent(); |
| 1590 | } |
| 1591 | |
| 1592 | if (mInCallController != null) { |
| 1593 | pw.println("mInCallController:"); |
| 1594 | pw.increaseIndent(); |
| 1595 | mInCallController.dump(pw); |
| 1596 | pw.decreaseIndent(); |
| 1597 | } |
| 1598 | |
| 1599 | if (mConnectionServiceRepository != null) { |
| 1600 | pw.println("mConnectionServiceRepository:"); |
| 1601 | pw.increaseIndent(); |
| 1602 | mConnectionServiceRepository.dump(pw); |
| 1603 | pw.decreaseIndent(); |
| 1604 | } |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1605 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 1606 | } |