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