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