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