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