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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 20 | import android.os.Bundle; |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 21 | import android.telecomm.AudioState; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 22 | import android.telecomm.CallState; |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 23 | import android.telecomm.GatewayInfo; |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 24 | import android.telecomm.ParcelableConference; |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 25 | import android.telecomm.PhoneAccountHandle; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 26 | import android.telephony.DisconnectCause; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 27 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 28 | import com.google.common.collect.ImmutableCollection; |
| 29 | import com.google.common.collect.ImmutableList; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 30 | |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
Santos Cordon | 7cdb909 | 2014-07-24 21:33:33 -0700 | [diff] [blame] | 32 | import java.util.List; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 33 | import java.util.Set; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 34 | import java.util.concurrent.ConcurrentHashMap; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 35 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Singleton. |
| 38 | * |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 39 | * 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] | 40 | * access from other packages specifically refraining from passing the CallsManager instance |
| 41 | * beyond the com.android.telecomm package boundary. |
| 42 | */ |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 43 | public final class CallsManager extends Call.ListenerBase { |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 44 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 45 | // TODO: Consider renaming this CallsManagerPlugin. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 46 | interface CallsManagerListener { |
| 47 | void onCallAdded(Call call); |
| 48 | void onCallRemoved(Call call); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 49 | void onCallStateChanged(Call call, int oldState, int newState); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 50 | void onConnectionServiceChanged( |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 51 | Call call, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 52 | ConnectionServiceWrapper oldService, |
| 53 | ConnectionServiceWrapper newService); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 54 | void onIncomingCallAnswered(Call call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 55 | void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 56 | void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 57 | void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState); |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 58 | void onRequestingRingback(Call call, boolean ringback); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 59 | void onIsConferencedChanged(Call call); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 60 | void onAudioModeIsVoipChanged(Call call); |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 61 | void onVideoStateChanged(Call call); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 64 | private static final CallsManager INSTANCE = new CallsManager(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 65 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 66 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 67 | * The main call repository. Keeps an instance of all live calls. New incoming and outgoing |
| 68 | * 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] | 69 | * |
| 70 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 71 | * load factor before resizing, 1 means we only expect a single thread to |
| 72 | * access the map so make only a single shard |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 73 | */ |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 74 | private final Set<Call> mCalls = Collections.newSetFromMap( |
| 75 | new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1)); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 76 | |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 77 | private final ConnectionServiceRepository mConnectionServiceRepository = |
| 78 | new ConnectionServiceRepository(); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 79 | private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer(); |
| 80 | private final InCallController mInCallController = new InCallController(); |
| 81 | private final CallAudioManager mCallAudioManager; |
| 82 | private final Ringer mRinger; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 83 | // For this set initial table size to 16 because we add 13 listeners in |
| 84 | // the CallsManager constructor. |
| 85 | private final Set<CallsManagerListener> mListeners = Collections.newSetFromMap( |
| 86 | new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1)); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 87 | private final HeadsetMediaButton mHeadsetMediaButton; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 88 | private final WiredHeadsetManager mWiredHeadsetManager; |
| 89 | private final TtyManager mTtyManager; |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 90 | private final ProximitySensorManager mProximitySensorManager; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 93 | * The call the user is currently interacting with. This is the call that should have audio |
| 94 | * focus and be visible in the in-call UI. |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 95 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 96 | private Call mForegroundCall; |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 97 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 98 | /** Singleton accessor. */ |
| 99 | static CallsManager getInstance() { |
| 100 | return INSTANCE; |
| 101 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 102 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 103 | /** |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 104 | * Initializes the required Telecomm components. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 105 | */ |
| 106 | private CallsManager() { |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 107 | TelecommApp app = TelecommApp.getInstance(); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 108 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 109 | StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this); |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 110 | mWiredHeadsetManager = new WiredHeadsetManager(app); |
| 111 | mCallAudioManager = new CallAudioManager(app, statusBarNotifier, mWiredHeadsetManager); |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 112 | InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 113 | mRinger = new Ringer(mCallAudioManager, this, playerFactory, app); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 114 | mHeadsetMediaButton = new HeadsetMediaButton(app, this); |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 115 | mTtyManager = new TtyManager(app, mWiredHeadsetManager); |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 116 | mProximitySensorManager = new ProximitySensorManager(app); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 117 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 118 | mListeners.add(statusBarNotifier); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 119 | mListeners.add(new CallLogManager(app)); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 120 | mListeners.add(new PhoneStateBroadcaster()); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 121 | mListeners.add(mInCallController); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 122 | mListeners.add(mRinger); |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 123 | mListeners.add(new RingbackPlayer(this, playerFactory)); |
| 124 | mListeners.add(new InCallToneMonitor(playerFactory, this)); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 125 | mListeners.add(mCallAudioManager); |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 126 | mListeners.add(app.getMissedCallNotifier()); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 127 | mListeners.add(mDtmfLocalTonePlayer); |
Santos Cordon | 8128998 | 2014-06-03 16:03:08 -0700 | [diff] [blame] | 128 | mListeners.add(mHeadsetMediaButton); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 129 | mListeners.add(RespondViaSmsManager.getInstance()); |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 130 | mListeners.add(mProximitySensorManager); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 133 | @Override |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 134 | public void onSuccessfulOutgoingCall(Call call, int callState) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 135 | Log.v(this, "onSuccessfulOutgoingCall, %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 136 | |
Tyler Gunn | cde2e50 | 2014-08-12 14:35:58 -0700 | [diff] [blame] | 137 | setCallState(call, callState); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 138 | if (!mCalls.contains(call)) { |
| 139 | // Call was not added previously in startOutgoingCall due to it being a potential MMI |
| 140 | // code, so add it now. |
| 141 | addCall(call); |
| 142 | } |
| 143 | |
| 144 | // The call's ConnectionService has been updated. |
| 145 | for (CallsManagerListener listener : mListeners) { |
| 146 | listener.onConnectionServiceChanged(call, null, call.getConnectionService()); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 147 | } |
Santos Cordon | 6cb7ba9 | 2014-05-23 14:09:32 -0700 | [diff] [blame] | 148 | |
| 149 | markCallAsDialing(call); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | @Override |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 153 | public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) { |
| 154 | Log.v(this, "onFailedOutgoingCall, call: %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 155 | |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 156 | // TODO: Replace disconnect cause with more specific disconnect causes. |
| 157 | markCallAsDisconnected(call, errorCode, errorMsg); |
| 158 | } |
| 159 | |
| 160 | @Override |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 161 | public void onSuccessfulIncomingCall(Call call) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 162 | Log.d(this, "onSuccessfulIncomingCall"); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 163 | setCallState(call, CallState.RINGING); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 164 | addCall(call); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public void onFailedIncomingCall(Call call) { |
Tyler Gunn | cde2e50 | 2014-08-12 14:35:58 -0700 | [diff] [blame] | 169 | setCallState(call, CallState.DISCONNECTED); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 170 | call.removeListener(this); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 173 | @Override |
| 174 | public void onRequestingRingback(Call call, boolean ringback) { |
| 175 | for (CallsManagerListener listener : mListeners) { |
| 176 | listener.onRequestingRingback(call, ringback); |
| 177 | } |
| 178 | } |
| 179 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 180 | @Override |
| 181 | public void onPostDialWait(Call call, String remaining) { |
| 182 | mInCallController.onPostDialWait(call, remaining); |
| 183 | } |
| 184 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 185 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 186 | public void onParentChanged(Call call) { |
| 187 | for (CallsManagerListener listener : mListeners) { |
| 188 | listener.onIsConferencedChanged(call); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void onChildrenChanged(Call call) { |
| 194 | for (CallsManagerListener listener : mListeners) { |
| 195 | listener.onIsConferencedChanged(call); |
| 196 | } |
| 197 | } |
| 198 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 199 | @Override |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 200 | public void onAudioModeIsVoipChanged(Call call) { |
| 201 | for (CallsManagerListener listener : mListeners) { |
| 202 | listener.onAudioModeIsVoipChanged(call); |
| 203 | } |
| 204 | } |
| 205 | |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 206 | @Override |
| 207 | public void onVideoStateChanged(Call call) { |
| 208 | for (CallsManagerListener listener : mListeners) { |
| 209 | listener.onVideoStateChanged(call); |
| 210 | } |
| 211 | } |
| 212 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 213 | ImmutableCollection<Call> getCalls() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 214 | return ImmutableList.copyOf(mCalls); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | Call getForegroundCall() { |
| 218 | return mForegroundCall; |
| 219 | } |
| 220 | |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 221 | Ringer getRinger() { |
| 222 | return mRinger; |
| 223 | } |
| 224 | |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 225 | InCallController getInCallController() { |
| 226 | return mInCallController; |
| 227 | } |
| 228 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 229 | boolean hasEmergencyCall() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 230 | for (Call call : mCalls) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 231 | if (call.isEmergencyCall()) { |
| 232 | return true; |
| 233 | } |
| 234 | } |
| 235 | return false; |
| 236 | } |
| 237 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 238 | AudioState getAudioState() { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 239 | return mCallAudioManager.getAudioState(); |
| 240 | } |
| 241 | |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 242 | boolean isTtySupported() { |
| 243 | return mTtyManager.isTtySupported(); |
| 244 | } |
| 245 | |
| 246 | int getCurrentTtyMode() { |
| 247 | return mTtyManager.getCurrentTtyMode(); |
| 248 | } |
| 249 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 250 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 251 | * Starts the process to attach the call to a connection service. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 252 | * |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 253 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 254 | * connection service to use for this call. |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 255 | * @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] | 256 | */ |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 257 | void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 258 | Log.d(this, "processIncomingCallIntent"); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 259 | // Create a call with no handle. The handle is eventually set when the call is attached |
| 260 | // to a connection service. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 261 | Call call = new Call( |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 262 | mConnectionServiceRepository, |
| 263 | null /* handle */, |
| 264 | null /* gatewayInfo */, |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 265 | null /* connectionManagerPhoneAccount */, |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 266 | phoneAccountHandle, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 267 | true /* isIncoming */, |
| 268 | false /* isConference */); |
| 269 | |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 270 | call.setExtras(extras); |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 271 | // TODO: Move this to be a part of addCall() |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 272 | call.addListener(this); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 273 | call.startCreateConnection(); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 276 | /** |
| 277 | * Kicks off the first steps to creating an outgoing call so that InCallUI can launch. |
| 278 | * |
| 279 | * NOTE: emergency calls will never pass through this because they call |
| 280 | * placeOutgoingCall directly. |
| 281 | * |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 282 | * @param handle Handle to connect the call with. |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 283 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 284 | * connection service to use for this call. |
| 285 | * @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] | 286 | */ |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 287 | Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 288 | // We only allow a single outgoing call at any given time. Before placing a call, make sure |
| 289 | // there doesn't already exist another outgoing call. |
| 290 | Call call = getFirstCallWithState(CallState.NEW, CallState.DIALING); |
| 291 | |
| 292 | if (call != null) { |
| 293 | Log.i(this, "Canceling simultaneous outgoing call."); |
| 294 | return null; |
| 295 | } |
| 296 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 297 | TelecommApp app = TelecommApp.getInstance(); |
| 298 | |
| 299 | // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call |
| 300 | // as if a phoneAccount was not specified (does the default behavior instead). |
| 301 | if (phoneAccountHandle != null) { |
| 302 | List<PhoneAccountHandle> enabledAccounts = |
| 303 | app.getPhoneAccountRegistrar().getOutgoingPhoneAccounts(); |
| 304 | if (!enabledAccounts.contains(phoneAccountHandle)) { |
| 305 | phoneAccountHandle = null; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (phoneAccountHandle == null) { |
| 310 | // No preset account, check if default exists |
| 311 | PhoneAccountHandle defaultAccountHandle = |
| 312 | app.getPhoneAccountRegistrar().getDefaultOutgoingPhoneAccount(); |
| 313 | if (defaultAccountHandle != null) { |
| 314 | phoneAccountHandle = defaultAccountHandle; |
| 315 | } |
| 316 | } |
| 317 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 318 | // Create a call with original handle. The handle may be changed when the call is attached |
| 319 | // to a connection service, but in most cases will remain the same. |
| 320 | call = new Call( |
| 321 | mConnectionServiceRepository, |
| 322 | handle, |
| 323 | null /* gatewayInfo */, |
| 324 | null /* connectionManagerPhoneAccount */, |
| 325 | phoneAccountHandle, |
| 326 | false /* isIncoming */, |
| 327 | false /* isConference */); |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 328 | call.setExtras(extras); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 329 | |
| 330 | final boolean emergencyCall = TelephonyUtil.shouldProcessAsEmergency(app, call.getHandle()); |
| 331 | if (phoneAccountHandle == null && !emergencyCall) { |
| 332 | // This is the state where the user is expected to select an account |
| 333 | call.setState(CallState.PRE_DIAL_WAIT); |
| 334 | } else { |
| 335 | call.setState(CallState.CONNECTING); |
| 336 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 337 | |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 338 | if (!isPotentialMMICode(handle)) { |
| 339 | addCall(call); |
| 340 | } else { |
| 341 | call.addListener(this); |
| 342 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 343 | |
| 344 | return call; |
| 345 | } |
| 346 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 347 | /** |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 348 | * Attempts to issue/connect the specified call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 349 | * |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 350 | * @param handle Handle to connect the call with. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 351 | * @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] | 352 | * actual dialed handle via a gateway provider. May be null. |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 353 | * @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] | 354 | * @param videoState The desired video state for the outgoing call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 355 | */ |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 356 | void placeOutgoingCall(Call call, Uri handle, GatewayInfo gatewayInfo, boolean speakerphoneOn, |
| 357 | int videoState) { |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 358 | if (call == null) { |
| 359 | // don't do anything if the call no longer exists |
| 360 | Log.i(this, "Canceling unknown call."); |
Santos Cordon | b7af09e | 2014-08-06 04:30:01 -0700 | [diff] [blame] | 361 | return; |
| 362 | } |
| 363 | |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 364 | final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle(); |
| 365 | |
| 366 | if (gatewayInfo == null) { |
Santos Cordon | b58f453 | 2014-05-29 11:59:06 -0700 | [diff] [blame] | 367 | 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] | 368 | } else { |
| 369 | Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s", |
| 370 | Log.pii(uriHandle), Log.pii(handle)); |
| 371 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 372 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 373 | call.setHandle(uriHandle); |
| 374 | call.setGatewayInfo(gatewayInfo); |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 375 | call.setStartWithSpeakerphoneOn(speakerphoneOn); |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 376 | call.setVideoState(videoState); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 377 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 378 | TelecommApp app = TelecommApp.getInstance(); |
Santos Cordon | 7cdb909 | 2014-07-24 21:33:33 -0700 | [diff] [blame] | 379 | final boolean emergencyCall = TelephonyUtil.shouldProcessAsEmergency(app, call.getHandle()); |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 380 | if (emergencyCall) { |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 381 | // Emergency -- CreateConnectionProcessor will choose accounts automatically |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 382 | call.setTargetPhoneAccount(null); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 383 | } |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 384 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 385 | if (call.getTargetPhoneAccount() != null || emergencyCall) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 386 | // If the account has been set, proceed to place the outgoing call. |
| 387 | // Otherwise the connection will be initiated when the account is set by the user. |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 388 | call.startCreateConnection(); |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 389 | } |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /** |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 393 | * Attempts to start a conference call for the specified call. |
| 394 | * |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 395 | * @param call The call to conference. |
| 396 | * @param otherCall The other call to conference with. |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 397 | */ |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 398 | void conference(Call call, Call otherCall) { |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 399 | call.conferenceWith(otherCall); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 403 | * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call |
| 404 | * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by |
| 405 | * the user opting to answer said call. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 406 | * |
| 407 | * @param call The call to answer. |
| 408 | * @param videoState The video state in which to answer the call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 409 | */ |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 410 | void answerCall(Call call, int videoState) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 411 | if (!mCalls.contains(call)) { |
| 412 | Log.i(this, "Request to answer a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 413 | } else { |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 414 | // 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] | 415 | // STATE_DIALING, put it on hold before answering the call. |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 416 | if (mForegroundCall != null && mForegroundCall != call && |
| 417 | (mForegroundCall.isActive() || |
| 418 | mForegroundCall.getState() == CallState.DIALING)) { |
| 419 | Log.v(this, "Holding active/dialing call %s before answering incoming call %s.", |
| 420 | mForegroundCall, call); |
| 421 | mForegroundCall.hold(); |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 422 | // TODO: Wait until we get confirmation of the active call being |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 423 | // on-hold before answering the new call. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 424 | // TODO: Import logic from CallManager.acceptCall() |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 427 | for (CallsManagerListener listener : mListeners) { |
| 428 | listener.onIncomingCallAnswered(call); |
| 429 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 430 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 431 | // 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] | 432 | // {@link #markCallAsActive}. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 433 | call.answer(videoState); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 434 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call |
| 439 | * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by |
| 440 | * the user opting to reject said call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 441 | */ |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 442 | void rejectCall(Call call, boolean rejectWithMessage, String textMessage) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 443 | if (!mCalls.contains(call)) { |
| 444 | Log.i(this, "Request to reject a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 445 | } else { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 446 | for (CallsManagerListener listener : mListeners) { |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 447 | listener.onIncomingCallRejected(call, rejectWithMessage, textMessage); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 448 | } |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 449 | call.reject(rejectWithMessage, textMessage); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 450 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 454 | * Instructs Telecomm to play the specified DTMF tone within the specified call. |
| 455 | * |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 456 | * @param digit The DTMF digit to play. |
| 457 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 458 | void playDtmfTone(Call call, char digit) { |
| 459 | if (!mCalls.contains(call)) { |
| 460 | 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] | 461 | } else { |
| 462 | call.playDtmfTone(digit); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 463 | mDtmfLocalTonePlayer.playTone(call, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Instructs Telecomm to stop the currently playing DTMF tone, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 469 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 470 | void stopDtmfTone(Call call) { |
| 471 | if (!mCalls.contains(call)) { |
| 472 | 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] | 473 | } else { |
| 474 | call.stopDtmfTone(); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 475 | mDtmfLocalTonePlayer.stopTone(call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
| 479 | /** |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 480 | * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 481 | */ |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 482 | void postDialContinue(Call call, boolean proceed) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 483 | if (!mCalls.contains(call)) { |
| 484 | 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] | 485 | } else { |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 486 | call.postDialContinue(proceed); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 491 | * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the |
| 492 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 493 | * the user hitting the end-call button. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 494 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 495 | void disconnectCall(Call call) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 496 | Log.v(this, "disconnectCall %s", call); |
| 497 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 498 | if (!mCalls.contains(call)) { |
| 499 | Log.w(this, "Unknown call (%s) asked to disconnect", call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 500 | } else { |
| 501 | call.disconnect(); |
| 502 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 503 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 504 | |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 505 | /** |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 506 | * Instructs Telecomm to disconnect all calls. |
| 507 | */ |
| 508 | void disconnectAllCalls() { |
| 509 | Log.v(this, "disconnectAllCalls"); |
| 510 | |
| 511 | for (Call call : mCalls) { |
| 512 | disconnectCall(call); |
| 513 | } |
| 514 | } |
| 515 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 516 | |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 517 | /** |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 518 | * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the |
| 519 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 520 | * the user hitting the hold button during an active call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 521 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 522 | void holdCall(Call call) { |
| 523 | if (!mCalls.contains(call)) { |
| 524 | 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] | 525 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 526 | Log.d(this, "Putting call on hold: (%s)", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 527 | call.hold(); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Instructs Telecomm to release the specified call from hold. Intended to be invoked by |
| 533 | * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered |
| 534 | * by the user hitting the hold button during a held call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 535 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 536 | void unholdCall(Call call) { |
| 537 | if (!mCalls.contains(call)) { |
| 538 | 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] | 539 | } else { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 540 | Log.d(this, "unholding call: (%s)", call); |
Sai Cheemalapati | 45b3e3f | 2014-08-15 09:33:00 -0700 | [diff] [blame] | 541 | for (Call c : mCalls) { |
| 542 | if (c != null && c.isAlive() && c != call) { |
| 543 | c.hold(); |
| 544 | } |
| 545 | } |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 546 | call.unhold(); |
| 547 | } |
| 548 | } |
| 549 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 550 | /** Called by the in-call UI to change the mute state. */ |
| 551 | void mute(boolean shouldMute) { |
| 552 | mCallAudioManager.mute(shouldMute); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Called by the in-call UI to change the audio route, for example to change from earpiece to |
| 557 | * speaker phone. |
| 558 | */ |
| 559 | void setAudioRoute(int route) { |
| 560 | mCallAudioManager.setAudioRoute(route); |
| 561 | } |
| 562 | |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 563 | /** Called by the in-call UI to turn the proximity sensor on. */ |
| 564 | void turnOnProximitySensor() { |
| 565 | mProximitySensorManager.turnOn(); |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Called by the in-call UI to turn the proximity sensor off. |
| 570 | * @param screenOnImmediately If true, the screen will be turned on immediately. Otherwise, |
| 571 | * the screen will be kept off until the proximity sensor goes negative. |
| 572 | */ |
| 573 | void turnOffProximitySensor(boolean screenOnImmediately) { |
| 574 | mProximitySensorManager.turnOff(screenOnImmediately); |
| 575 | } |
| 576 | |
Sailesh Nepal | 77da19e | 2014-07-02 21:31:16 -0700 | [diff] [blame] | 577 | void phoneAccountClicked(Call call) { |
| 578 | if (!mCalls.contains(call)) { |
| 579 | Log.i(this, "phoneAccountClicked in a non-existent call %s", call); |
| 580 | } else { |
| 581 | call.phoneAccountClicked(); |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 582 | } |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 585 | void phoneAccountSelected(Call call, PhoneAccountHandle account) { |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 586 | if (!mCalls.contains(call)) { |
| 587 | Log.i(this, "Attemped to add account to unknown call %s", call); |
| 588 | } else { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 589 | call.setTargetPhoneAccount(account); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 590 | call.startCreateConnection(); |
| 591 | } |
| 592 | } |
| 593 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 594 | /** Called when the audio state changes. */ |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 595 | void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 596 | Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 597 | for (CallsManagerListener listener : mListeners) { |
| 598 | listener.onAudioStateChanged(oldAudioState, newAudioState); |
| 599 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 602 | void markCallAsRinging(Call call) { |
| 603 | setCallState(call, CallState.RINGING); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 606 | void markCallAsDialing(Call call) { |
| 607 | setCallState(call, CallState.DIALING); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 610 | void markCallAsActive(Call call) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 611 | if (call.getConnectTimeMillis() == 0) { |
| 612 | call.setConnectTimeMillis(System.currentTimeMillis()); |
| 613 | } |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 614 | setCallState(call, CallState.ACTIVE); |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 615 | |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 616 | if (call.getStartWithSpeakerphoneOn()) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 617 | setAudioRoute(AudioState.ROUTE_SPEAKER); |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 618 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 621 | void markCallAsOnHold(Call call) { |
| 622 | setCallState(call, CallState.ON_HOLD); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 625 | /** |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 626 | * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the last |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 627 | * live call, then also disconnect from the in-call controller. |
| 628 | * |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 629 | * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 630 | * @param disconnectMessage Optional message about the disconnect. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 631 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 632 | void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) { |
| 633 | call.setDisconnectCause(disconnectCause, disconnectMessage); |
| 634 | setCallState(call, CallState.DISCONNECTED); |
Sailesh Nepal | 77da19e | 2014-07-02 21:31:16 -0700 | [diff] [blame] | 635 | removeCall(call); |
Sailesh Nepal | 6ab6fb7 | 2014-04-01 20:03:19 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 638 | /** |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 639 | * Removes an existing disconnected call, and notifies the in-call app. |
| 640 | */ |
| 641 | void markCallAsRemoved(Call call) { |
| 642 | removeCall(call); |
| 643 | } |
| 644 | |
| 645 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 646 | * 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] | 647 | * service binder disconnects unexpectedly. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 648 | * |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 649 | * @param service The connection service that disconnected. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 650 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 651 | void handleConnectionServiceDeath(ConnectionServiceWrapper service) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 652 | if (service != null) { |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 653 | for (Call call : mCalls) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 654 | if (call.getConnectionService() == service) { |
| 655 | markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null); |
| 656 | } |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 661 | boolean hasAnyCalls() { |
| 662 | return !mCalls.isEmpty(); |
| 663 | } |
| 664 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 665 | boolean hasActiveOrHoldingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 666 | return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | boolean hasRingingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 670 | return getFirstCallWithState(CallState.RINGING) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 673 | boolean onMediaButton(int type) { |
| 674 | if (hasAnyCalls()) { |
| 675 | if (HeadsetMediaButton.SHORT_PRESS == type) { |
| 676 | Call ringingCall = getFirstCallWithState(CallState.RINGING); |
| 677 | if (ringingCall == null) { |
| 678 | mCallAudioManager.toggleMute(); |
| 679 | return true; |
| 680 | } else { |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 681 | ringingCall.answer(ringingCall.getVideoState()); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 682 | return true; |
| 683 | } |
| 684 | } else if (HeadsetMediaButton.LONG_PRESS == type) { |
| 685 | Log.d(this, "handleHeadsetHook: longpress -> hangup"); |
| 686 | Call callToHangup = getFirstCallWithState( |
| 687 | CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD); |
| 688 | if (callToHangup != null) { |
| 689 | callToHangup.disconnect(); |
| 690 | return true; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | /** |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 698 | * Checks to see if the specified call is the only high-level call and if so, enable the |
| 699 | * "Add-call" button. We allow you to add a second call but not a third or beyond. |
| 700 | * |
| 701 | * @param call The call to test for add-call. |
| 702 | * @return Whether the add-call feature should be enabled for the call. |
| 703 | */ |
| 704 | protected boolean isAddCallCapable(Call call) { |
| 705 | if (call.getParentCall() != null) { |
| 706 | // Never true for child calls. |
| 707 | return false; |
| 708 | } |
| 709 | |
| 710 | // Loop through all the other calls and there exists a top level (has no parent) call |
| 711 | // that is not the specified call, return false. |
| 712 | for (Call otherCall : mCalls) { |
| 713 | if (call != otherCall && otherCall.getParentCall() == null) { |
| 714 | return false; |
| 715 | } |
| 716 | } |
| 717 | return true; |
| 718 | } |
| 719 | |
| 720 | /** |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 721 | * Returns the first call that it finds with the given states. The states are treated as having |
| 722 | * priority order so that any call with the first state will be returned before any call with |
| 723 | * states listed later in the parameter list. |
| 724 | */ |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 725 | Call getFirstCallWithState(int... states) { |
| 726 | for (int currentState : states) { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 727 | // check the foreground first |
| 728 | if (mForegroundCall != null && mForegroundCall.getState() == currentState) { |
| 729 | return mForegroundCall; |
| 730 | } |
| 731 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 732 | for (Call call : mCalls) { |
| 733 | if (currentState == call.getState()) { |
| 734 | return call; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | return null; |
| 739 | } |
| 740 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 741 | Call createConferenceCall( |
| 742 | PhoneAccountHandle phoneAccount, |
| 743 | ParcelableConference parcelableConference) { |
| 744 | Call call = new Call( |
| 745 | mConnectionServiceRepository, |
| 746 | null /* handle */, |
| 747 | null /* gatewayInfo */, |
| 748 | null /* connectionManagerPhoneAccount */, |
| 749 | phoneAccount, |
| 750 | false /* isIncoming */, |
| 751 | true /* isConference */); |
| 752 | |
| 753 | setCallState(call, Call.getStateFromConnectionState(parcelableConference.getState())); |
| 754 | call.setCallCapabilities(parcelableConference.getCapabilities()); |
| 755 | |
| 756 | // TODO: Move this to be a part of addCall() |
| 757 | call.addListener(this); |
| 758 | addCall(call); |
| 759 | return call; |
| 760 | } |
| 761 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 762 | |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 763 | /** |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 764 | * Adds the specified call to the main list of live calls. |
| 765 | * |
| 766 | * @param call The call to add. |
| 767 | */ |
| 768 | private void addCall(Call call) { |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 769 | Log.v(this, "addCall(%s)", call); |
| 770 | |
| 771 | call.addListener(this); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 772 | mCalls.add(call); |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 773 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 774 | // TODO: Update mForegroundCall prior to invoking |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 775 | // onCallAdded for calls which immediately take the foreground (like the first call). |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 776 | for (CallsManagerListener listener : mListeners) { |
| 777 | listener.onCallAdded(call); |
| 778 | } |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 779 | updateForegroundCall(); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 782 | private void removeCall(Call call) { |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 783 | Log.v(this, "removeCall(%s)", call); |
Sailesh Nepal | 4857f47 | 2014-04-07 22:26:27 -0700 | [diff] [blame] | 784 | |
Santos Cordon | 672321e | 2014-08-21 14:38:58 -0700 | [diff] [blame] | 785 | call.setParentCall(null); // need to clean up parent relationship before destroying. |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 786 | call.removeListener(this); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 787 | call.clearConnectionService(); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 788 | |
| 789 | boolean shouldNotify = false; |
| 790 | if (mCalls.contains(call)) { |
| 791 | mCalls.remove(call); |
| 792 | shouldNotify = true; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 793 | } |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 794 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 795 | // Only broadcast changes for calls that are being tracked. |
| 796 | if (shouldNotify) { |
| 797 | for (CallsManagerListener listener : mListeners) { |
| 798 | listener.onCallRemoved(call); |
| 799 | } |
| 800 | updateForegroundCall(); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 801 | } |
| 802 | } |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 803 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 804 | /** |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 805 | * Sets the specified state on the specified call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 806 | * |
| 807 | * @param call The call. |
| 808 | * @param newState The new state of the call. |
| 809 | */ |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 810 | private void setCallState(Call call, int newState) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 811 | if (call == null) { |
| 812 | return; |
| 813 | } |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 814 | int oldState = call.getState(); |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 815 | Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 816 | if (newState != oldState) { |
| 817 | // Unfortunately, in the telephony world the radio is king. So if the call notifies |
| 818 | // 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] | 819 | // sense (e.g., STATE_ACTIVE -> STATE_RINGING). |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 820 | // TODO: Consider putting a stop to the above and turning CallState |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 821 | // into a well-defined state machine. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 822 | // TODO: Define expected state transitions here, and log when an |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 823 | // unexpected transition occurs. |
| 824 | call.setState(newState); |
| 825 | |
| 826 | // Only broadcast state change for calls that are being tracked. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 827 | if (mCalls.contains(call)) { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 828 | for (CallsManagerListener listener : mListeners) { |
| 829 | listener.onCallStateChanged(call, oldState, newState); |
| 830 | } |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 831 | updateForegroundCall(); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 837 | * 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] | 838 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 839 | private void updateForegroundCall() { |
| 840 | Call newForegroundCall = null; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 841 | for (Call call : mCalls) { |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 842 | // TODO: Foreground-ness needs to be explicitly set. No call, regardless |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 843 | // of its state will be foreground by default and instead the connection service should |
| 844 | // 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] | 845 | // the call should play audio and listen to microphone if it wants. |
| 846 | |
| 847 | // Active calls have priority. |
| 848 | if (call.isActive()) { |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 849 | newForegroundCall = call; |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 850 | break; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 851 | } |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 852 | |
| 853 | if (call.isAlive() || call.getState() == CallState.RINGING) { |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 854 | newForegroundCall = call; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 855 | // 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] | 856 | } |
| 857 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 858 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 859 | if (newForegroundCall != mForegroundCall) { |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 860 | Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 861 | Call oldForegroundCall = mForegroundCall; |
| 862 | mForegroundCall = newForegroundCall; |
| 863 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 864 | for (CallsManagerListener listener : mListeners) { |
| 865 | listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall); |
| 866 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 867 | } |
| 868 | } |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 869 | |
| 870 | private boolean isPotentialMMICode(Uri handle) { |
| 871 | return (handle != null && handle.getSchemeSpecificPart() != null |
| 872 | && handle.getSchemeSpecificPart().contains("#")); |
| 873 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 874 | } |