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