Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
| 20 | import android.media.AudioManager; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 21 | import android.telecom.AudioState; |
| 22 | import android.telecom.CallState; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 23 | |
Tyler Gunn | 9787e0e | 2014-10-14 14:36:12 -0700 | [diff] [blame] | 24 | import com.android.internal.util.IndentingPrintWriter; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 25 | import com.android.internal.util.Preconditions; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 26 | |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 27 | import java.util.Objects; |
| 28 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 29 | /** |
| 30 | * This class manages audio modes, streams and other properties. |
| 31 | */ |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 32 | final class CallAudioManager extends CallsManagerListenerBase |
| 33 | implements WiredHeadsetManager.Listener { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 34 | private static final int STREAM_NONE = -1; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 35 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 36 | private final StatusBarNotifier mStatusBarNotifier; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 37 | private final AudioManager mAudioManager; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 38 | private final BluetoothManager mBluetoothManager; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 39 | private final WiredHeadsetManager mWiredHeadsetManager; |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 40 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 41 | private AudioState mAudioState; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 42 | private int mAudioFocusStreamType; |
| 43 | private boolean mIsRinging; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 44 | private boolean mIsTonePlaying; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 45 | private boolean mWasSpeakerOn; |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 46 | private int mMostRecentlyUsedMode = AudioManager.MODE_IN_CALL; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 47 | |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 48 | CallAudioManager(Context context, StatusBarNotifier statusBarNotifier, |
| 49 | WiredHeadsetManager wiredHeadsetManager) { |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 50 | mStatusBarNotifier = statusBarNotifier; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 51 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 52 | mBluetoothManager = new BluetoothManager(context, this); |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 53 | mWiredHeadsetManager = wiredHeadsetManager; |
Sailesh Nepal | d0a76aa | 2014-07-16 22:12:23 -0700 | [diff] [blame] | 54 | mWiredHeadsetManager.addListener(this); |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 55 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 56 | saveAudioState(getInitialAudioState(null)); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 57 | mAudioFocusStreamType = STREAM_NONE; |
| 58 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 59 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 60 | AudioState getAudioState() { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 61 | return mAudioState; |
| 62 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 63 | |
| 64 | @Override |
| 65 | public void onCallAdded(Call call) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 66 | onCallUpdated(call); |
| 67 | |
| 68 | if (hasFocus() && getForegroundCall() == call) { |
| 69 | if (!call.isIncoming()) { |
| 70 | // Unmute new outgoing call. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 71 | setSystemAudioState(false, mAudioState.getRoute(), |
| 72 | mAudioState.getSupportedRouteMask()); |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 73 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 74 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void onCallRemoved(Call call) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 79 | // If we didn't already have focus, there's nothing to do. |
| 80 | if (hasFocus()) { |
| 81 | if (CallsManager.getInstance().getCalls().isEmpty()) { |
| 82 | Log.v(this, "all calls removed, reseting system audio to default state"); |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 83 | setInitialAudioState(null, false /* force */); |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 84 | mWasSpeakerOn = false; |
| 85 | } |
| 86 | updateAudioStreamAndMode(); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 87 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 90 | @Override |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 91 | public void onCallStateChanged(Call call, int oldState, int newState) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 92 | onCallUpdated(call); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void onIncomingCallAnswered(Call call) { |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 97 | int route = mAudioState.getRoute(); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 98 | |
| 99 | // We do two things: |
| 100 | // (1) If this is the first call, then we can to turn on bluetooth if available. |
| 101 | // (2) Unmute the audio for the new incoming call. |
| 102 | boolean isOnlyCall = CallsManager.getInstance().getCalls().size() == 1; |
| 103 | if (isOnlyCall && mBluetoothManager.isBluetoothAvailable()) { |
| 104 | mBluetoothManager.connectBluetoothAudio(); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 105 | route = AudioState.ROUTE_BLUETOOTH; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 108 | setSystemAudioState(false /* isMute */, route, mAudioState.getSupportedRouteMask()); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 112 | public void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 113 | onCallUpdated(newForegroundCall); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 114 | // Ensure that the foreground call knows about the latest audio state. |
| 115 | updateAudioForForegroundCall(); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 118 | @Override |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 119 | public void onIsVoipAudioModeChanged(Call call) { |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 120 | updateAudioStreamAndMode(); |
| 121 | } |
| 122 | |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 123 | /** |
| 124 | * Updates the audio route when the headset plugged in state changes. For example, if audio is |
| 125 | * being routed over speakerphone and a headset is plugged in then switch to wired headset. |
| 126 | */ |
| 127 | @Override |
| 128 | public void onWiredHeadsetPluggedInChanged(boolean oldIsPluggedIn, boolean newIsPluggedIn) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 129 | // This can happen even when there are no calls and we don't have focus. |
| 130 | if (!hasFocus()) { |
| 131 | return; |
| 132 | } |
| 133 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 134 | int newRoute = AudioState.ROUTE_EARPIECE; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 135 | if (newIsPluggedIn) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 136 | newRoute = AudioState.ROUTE_WIRED_HEADSET; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 137 | } else if (mWasSpeakerOn) { |
| 138 | Call call = getForegroundCall(); |
| 139 | if (call != null && call.isAlive()) { |
| 140 | // Restore the speaker state. |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 141 | newRoute = AudioState.ROUTE_SPEAKER; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 144 | setSystemAudioState(mAudioState.isMuted(), newRoute, calculateSupportedRoutes()); |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 147 | void toggleMute() { |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 148 | mute(!mAudioState.isMuted()); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 151 | void mute(boolean shouldMute) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 152 | if (!hasFocus()) { |
| 153 | return; |
| 154 | } |
| 155 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 156 | Log.v(this, "mute, shouldMute: %b", shouldMute); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 157 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 158 | // Don't mute if there are any emergency calls. |
| 159 | if (CallsManager.getInstance().hasEmergencyCall()) { |
| 160 | shouldMute = false; |
| 161 | Log.v(this, "ignoring mute for emergency call"); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 164 | if (mAudioState.isMuted() != shouldMute) { |
| 165 | setSystemAudioState(shouldMute, mAudioState.getRoute(), |
| 166 | mAudioState.getSupportedRouteMask()); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 170 | /** |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 171 | * Changed the audio route, for example from earpiece to speaker phone. |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 172 | * |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 173 | * @param route The new audio route to use. See {@link AudioState}. |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 174 | */ |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 175 | void setAudioRoute(int route) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 176 | // This can happen even when there are no calls and we don't have focus. |
| 177 | if (!hasFocus()) { |
| 178 | return; |
| 179 | } |
| 180 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 181 | Log.v(this, "setAudioRoute, route: %s", AudioState.audioRouteToString(route)); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 182 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 183 | // Change ROUTE_WIRED_OR_EARPIECE to a single entry. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 184 | int newRoute = selectWiredOrEarpiece(route, mAudioState.getSupportedRouteMask()); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 185 | |
| 186 | // If route is unsupported, do nothing. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 187 | if ((mAudioState.getSupportedRouteMask() | newRoute) == 0) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 188 | Log.wtf(this, "Asking to set to a route that is unsupported: %d", newRoute); |
| 189 | return; |
| 190 | } |
| 191 | |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 192 | if (mAudioState.getRoute() != newRoute) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 193 | // Remember the new speaker state so it can be restored when the user plugs and unplugs |
| 194 | // a headset. |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 195 | mWasSpeakerOn = newRoute == AudioState.ROUTE_SPEAKER; |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 196 | setSystemAudioState(mAudioState.isMuted(), newRoute, |
| 197 | mAudioState.getSupportedRouteMask()); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | void setIsRinging(boolean isRinging) { |
| 202 | if (mIsRinging != isRinging) { |
| 203 | Log.v(this, "setIsRinging %b -> %b", mIsRinging, isRinging); |
| 204 | mIsRinging = isRinging; |
| 205 | updateAudioStreamAndMode(); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 206 | } |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 209 | /** |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 210 | * Sets the tone playing status. Some tones can play even when there are no live calls and this |
| 211 | * status indicates that we should keep audio focus even for tones that play beyond the life of |
| 212 | * calls. |
| 213 | * |
| 214 | * @param isPlayingNew The status to set. |
| 215 | */ |
| 216 | void setIsTonePlaying(boolean isPlayingNew) { |
| 217 | ThreadUtil.checkOnMainThread(); |
| 218 | |
| 219 | if (mIsTonePlaying != isPlayingNew) { |
| 220 | Log.v(this, "mIsTonePlaying %b -> %b.", mIsTonePlaying, isPlayingNew); |
| 221 | mIsTonePlaying = isPlayingNew; |
| 222 | updateAudioStreamAndMode(); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 227 | * Updates the audio routing according to the bluetooth state. |
| 228 | */ |
| 229 | void onBluetoothStateChange(BluetoothManager bluetoothManager) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 230 | // This can happen even when there are no calls and we don't have focus. |
| 231 | if (!hasFocus()) { |
| 232 | return; |
| 233 | } |
| 234 | |
Santos Cordon | 3195364 | 2014-09-12 03:23:59 -0700 | [diff] [blame] | 235 | int supportedRoutes = calculateSupportedRoutes(); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 236 | int newRoute = mAudioState.getRoute(); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 237 | if (bluetoothManager.isBluetoothAudioConnectedOrPending()) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 238 | newRoute = AudioState.ROUTE_BLUETOOTH; |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 239 | } else if (mAudioState.getRoute() == AudioState.ROUTE_BLUETOOTH) { |
Santos Cordon | 3195364 | 2014-09-12 03:23:59 -0700 | [diff] [blame] | 240 | newRoute = selectWiredOrEarpiece(AudioState.ROUTE_WIRED_OR_EARPIECE, supportedRoutes); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 241 | // Do not switch to speaker when bluetooth disconnects. |
| 242 | mWasSpeakerOn = false; |
| 243 | } |
| 244 | |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 245 | setSystemAudioState(mAudioState.isMuted(), newRoute, supportedRoutes); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | boolean isBluetoothAudioOn() { |
| 249 | return mBluetoothManager.isBluetoothAudioConnected(); |
| 250 | } |
| 251 | |
| 252 | boolean isBluetoothDeviceAvailable() { |
| 253 | return mBluetoothManager.isBluetoothAvailable(); |
| 254 | } |
| 255 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 256 | private void saveAudioState(AudioState audioState) { |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 257 | mAudioState = audioState; |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 258 | mStatusBarNotifier.notifyMute(mAudioState.isMuted()); |
| 259 | mStatusBarNotifier.notifySpeakerphone(mAudioState.getRoute() == AudioState.ROUTE_SPEAKER); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 262 | private void onCallUpdated(Call call) { |
| 263 | boolean wasNotVoiceCall = mAudioFocusStreamType != AudioManager.STREAM_VOICE_CALL; |
| 264 | updateAudioStreamAndMode(); |
| 265 | |
| 266 | // If we transition from not voice call to voice call, we need to set an initial state. |
| 267 | if (wasNotVoiceCall && mAudioFocusStreamType == AudioManager.STREAM_VOICE_CALL) { |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 268 | setInitialAudioState(call, true /* force */); |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 272 | private void setSystemAudioState(boolean isMuted, int route, int supportedRouteMask) { |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 273 | setSystemAudioState(false /* force */, isMuted, route, supportedRouteMask); |
| 274 | } |
| 275 | |
| 276 | private void setSystemAudioState( |
| 277 | boolean force, boolean isMuted, int route, int supportedRouteMask) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 278 | if (!hasFocus()) { |
| 279 | return; |
| 280 | } |
| 281 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 282 | AudioState oldAudioState = mAudioState; |
| 283 | saveAudioState(new AudioState(isMuted, route, supportedRouteMask)); |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 284 | if (!force && Objects.equals(oldAudioState, mAudioState)) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 285 | return; |
| 286 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 287 | Log.i(this, "changing audio state from %s to %s", oldAudioState, mAudioState); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 288 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 289 | // Mute. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 290 | if (mAudioState.isMuted() != mAudioManager.isMicrophoneMute()) { |
| 291 | Log.i(this, "changing microphone mute state to: %b", mAudioState.isMuted()); |
| 292 | mAudioManager.setMicrophoneMute(mAudioState.isMuted()); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 295 | // Audio route. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 296 | if (mAudioState.getRoute() == AudioState.ROUTE_BLUETOOTH) { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 297 | turnOnSpeaker(false); |
| 298 | turnOnBluetooth(true); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 299 | } else if (mAudioState.getRoute() == AudioState.ROUTE_SPEAKER) { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 300 | turnOnBluetooth(false); |
| 301 | turnOnSpeaker(true); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 302 | } else if (mAudioState.getRoute() == AudioState.ROUTE_EARPIECE || |
| 303 | mAudioState.getRoute() == AudioState.ROUTE_WIRED_HEADSET) { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 304 | turnOnBluetooth(false); |
| 305 | turnOnSpeaker(false); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | if (!oldAudioState.equals(mAudioState)) { |
| 309 | CallsManager.getInstance().onAudioStateChanged(oldAudioState, mAudioState); |
| 310 | updateAudioForForegroundCall(); |
| 311 | } |
| 312 | } |
| 313 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 314 | private void turnOnSpeaker(boolean on) { |
| 315 | // Wired headset and earpiece work the same way |
| 316 | if (mAudioManager.isSpeakerphoneOn() != on) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 317 | Log.i(this, "turning speaker phone %s", on); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 318 | mAudioManager.setSpeakerphoneOn(on); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | private void turnOnBluetooth(boolean on) { |
| 323 | if (mBluetoothManager.isBluetoothAvailable()) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 324 | boolean isAlreadyOn = mBluetoothManager.isBluetoothAudioConnectedOrPending(); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 325 | if (on != isAlreadyOn) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 326 | Log.i(this, "connecting bluetooth %s", on); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 327 | if (on) { |
| 328 | mBluetoothManager.connectBluetoothAudio(); |
| 329 | } else { |
| 330 | mBluetoothManager.disconnectBluetoothAudio(); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 336 | private void updateAudioStreamAndMode() { |
Yorke Lee | e5a7c92 | 2014-10-16 16:50:51 -0700 | [diff] [blame] | 337 | Log.i(this, "updateAudioStreamAndMode, mIsRinging: %b, mIsTonePlaying: %b", mIsRinging, |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 338 | mIsTonePlaying); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 339 | if (mIsRinging) { |
| 340 | requestAudioFocusAndSetMode(AudioManager.STREAM_RING, AudioManager.MODE_RINGTONE); |
| 341 | } else { |
Nancy Chen | dda6919 | 2014-12-02 15:56:55 -0800 | [diff] [blame] | 342 | Call foregroundCall = getForegroundCall(); |
| 343 | Call waitingForAccountSelectionCall = |
| 344 | CallsManager.getInstance().getFirstCallWithState(CallState.PRE_DIAL_WAIT); |
| 345 | if (foregroundCall != null && waitingForAccountSelectionCall == null) { |
| 346 | // In the case where there is a call that is waiting for account selection, |
| 347 | // this will fall back to abandonAudioFocus() below, which temporarily exits |
| 348 | // the in-call audio mode. This is to allow TalkBack to speak the "Call with" |
| 349 | // dialog information at media volume as opposed to through the earpiece. |
| 350 | // Once exiting the "Call with" dialog, the audio focus will return to an in-call |
| 351 | // audio mode when this method (updateAudioStreamAndMode) is called again. |
| 352 | int mode = foregroundCall.getIsVoipAudioMode() ? |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 353 | AudioManager.MODE_IN_COMMUNICATION : AudioManager.MODE_IN_CALL; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 354 | requestAudioFocusAndSetMode(AudioManager.STREAM_VOICE_CALL, mode); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 355 | } else if (mIsTonePlaying) { |
| 356 | // There is no call, however, we are still playing a tone, so keep focus. |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 357 | // Since there is no call from which to determine the mode, use the most |
| 358 | // recently used mode instead. |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 359 | requestAudioFocusAndSetMode( |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 360 | AudioManager.STREAM_VOICE_CALL, mMostRecentlyUsedMode); |
Yorke Lee | 42afb97 | 2014-09-08 09:47:21 -0700 | [diff] [blame] | 361 | } else if (!hasRingingForegroundCall()) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 362 | abandonAudioFocus(); |
Yorke Lee | 42afb97 | 2014-09-08 09:47:21 -0700 | [diff] [blame] | 363 | } else { |
| 364 | // mIsRinging is false, but there is a foreground ringing call present. Don't |
| 365 | // abandon audio focus immediately to prevent audio focus from getting lost between |
| 366 | // the time it takes for the foreground call to transition from RINGING to ACTIVE/ |
| 367 | // DISCONNECTED. When the call eventually transitions to the next state, audio |
| 368 | // focus will be correctly abandoned by the if clause above. |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | private void requestAudioFocusAndSetMode(int stream, int mode) { |
Nancy Chen | dda6919 | 2014-12-02 15:56:55 -0800 | [diff] [blame] | 374 | Log.i(this, "requestAudioFocusAndSetMode, stream: %d -> %d, mode: %d", |
| 375 | mAudioFocusStreamType, stream, mode); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 376 | Preconditions.checkState(stream != STREAM_NONE); |
| 377 | |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 378 | // Even if we already have focus, if the stream is different we update audio manager to give |
| 379 | // it a hint about the purpose of our focus. |
| 380 | if (mAudioFocusStreamType != stream) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 381 | Log.v(this, "requesting audio focus for stream: %d", stream); |
| 382 | mAudioManager.requestAudioFocusForCall(stream, |
| 383 | AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); |
| 384 | } |
| 385 | mAudioFocusStreamType = stream; |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 386 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 387 | setMode(mode); |
| 388 | } |
| 389 | |
| 390 | private void abandonAudioFocus() { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 391 | if (hasFocus()) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 392 | setMode(AudioManager.MODE_NORMAL); |
| 393 | Log.v(this, "abandoning audio focus"); |
| 394 | mAudioManager.abandonAudioFocusForCall(); |
| 395 | mAudioFocusStreamType = STREAM_NONE; |
| 396 | } |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Sets the audio mode. |
| 401 | * |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 402 | * @param newMode Mode constant from AudioManager.MODE_*. |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 403 | */ |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 404 | private void setMode(int newMode) { |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 405 | Preconditions.checkState(hasFocus()); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 406 | int oldMode = mAudioManager.getMode(); |
| 407 | Log.v(this, "Request to change audio mode from %d to %d", oldMode, newMode); |
Yorke Lee | 60b6e28 | 2014-10-20 18:43:31 -0700 | [diff] [blame] | 408 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 409 | if (oldMode != newMode) { |
Yorke Lee | 60b6e28 | 2014-10-20 18:43:31 -0700 | [diff] [blame] | 410 | if (oldMode == AudioManager.MODE_IN_CALL && newMode == AudioManager.MODE_RINGTONE) { |
| 411 | Log.i(this, "Transition from IN_CALL -> RINGTONE. Resetting to NORMAL first."); |
| 412 | mAudioManager.setMode(AudioManager.MODE_NORMAL); |
| 413 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 414 | mAudioManager.setMode(newMode); |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 415 | mMostRecentlyUsedMode = newMode; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | private int selectWiredOrEarpiece(int route, int supportedRouteMask) { |
| 420 | // Since they are mutually exclusive and one is ALWAYS valid, we allow a special input of |
| 421 | // ROUTE_WIRED_OR_EARPIECE so that callers dont have to make a call to check which is |
| 422 | // supported before calling setAudioRoute. |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 423 | if (route == AudioState.ROUTE_WIRED_OR_EARPIECE) { |
| 424 | route = AudioState.ROUTE_WIRED_OR_EARPIECE & supportedRouteMask; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 425 | if (route == 0) { |
| 426 | Log.wtf(this, "One of wired headset or earpiece should always be valid."); |
| 427 | // assume earpiece in this case. |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 428 | route = AudioState.ROUTE_EARPIECE; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 429 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 430 | } |
| 431 | return route; |
| 432 | } |
| 433 | |
| 434 | private int calculateSupportedRoutes() { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 435 | int routeMask = AudioState.ROUTE_SPEAKER; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 436 | |
| 437 | if (mWiredHeadsetManager.isPluggedIn()) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 438 | routeMask |= AudioState.ROUTE_WIRED_HEADSET; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 439 | } else { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 440 | routeMask |= AudioState.ROUTE_EARPIECE; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 441 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 442 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 443 | if (mBluetoothManager.isBluetoothAvailable()) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 444 | routeMask |= AudioState.ROUTE_BLUETOOTH; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 447 | return routeMask; |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 450 | private AudioState getInitialAudioState(Call call) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 451 | int supportedRouteMask = calculateSupportedRoutes(); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 452 | int route = selectWiredOrEarpiece( |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 453 | AudioState.ROUTE_WIRED_OR_EARPIECE, supportedRouteMask); |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 454 | |
| 455 | // We want the UI to indicate that "bluetooth is in use" in two slightly different cases: |
| 456 | // (a) The obvious case: if a bluetooth headset is currently in use for an ongoing call. |
| 457 | // (b) The not-so-obvious case: if an incoming call is ringing, and we expect that audio |
| 458 | // *will* be routed to a bluetooth headset once the call is answered. In this case, just |
| 459 | // check if the headset is available. Note this only applies when we are dealing with |
| 460 | // the first call. |
| 461 | if (call != null && mBluetoothManager.isBluetoothAvailable()) { |
| 462 | switch(call.getState()) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 463 | case CallState.ACTIVE: |
| 464 | case CallState.ON_HOLD: |
| 465 | case CallState.DIALING: |
Santos Cordon | 5753f30 | 2014-09-26 13:56:16 -0700 | [diff] [blame] | 466 | case CallState.CONNECTING: |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 467 | case CallState.RINGING: |
| 468 | route = AudioState.ROUTE_BLUETOOTH; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 469 | break; |
| 470 | default: |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 475 | return new AudioState(false, route, supportedRouteMask); |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 478 | private void setInitialAudioState(Call call, boolean force) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 479 | AudioState audioState = getInitialAudioState(call); |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 480 | Log.v(this, "setInitialAudioState %s, %s", audioState, call); |
Santos Cordon | 7c6a5ec | 2014-09-11 19:47:23 -0700 | [diff] [blame] | 481 | setSystemAudioState( |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 482 | force, audioState.isMuted(), audioState.getRoute(), |
| 483 | audioState.getSupportedRouteMask()); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | private void updateAudioForForegroundCall() { |
| 487 | Call call = CallsManager.getInstance().getForegroundCall(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 488 | if (call != null && call.getConnectionService() != null) { |
| 489 | call.getConnectionService().onAudioStateChanged(call, mAudioState); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 490 | } |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 491 | } |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 492 | |
| 493 | /** |
| 494 | * Returns the current foreground call in order to properly set the audio mode. |
| 495 | */ |
| 496 | private Call getForegroundCall() { |
| 497 | Call call = CallsManager.getInstance().getForegroundCall(); |
| 498 | |
| 499 | // We ignore any foreground call that is in the ringing state because we deal with ringing |
| 500 | // calls exclusively through the mIsRinging variable set by {@link Ringer}. |
| 501 | if (call != null && call.getState() == CallState.RINGING) { |
Nancy Chen | dda6919 | 2014-12-02 15:56:55 -0800 | [diff] [blame] | 502 | return null; |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 503 | } |
Nancy Chen | dda6919 | 2014-12-02 15:56:55 -0800 | [diff] [blame] | 504 | |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 505 | return call; |
| 506 | } |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 507 | |
Yorke Lee | 42afb97 | 2014-09-08 09:47:21 -0700 | [diff] [blame] | 508 | private boolean hasRingingForegroundCall() { |
| 509 | Call call = CallsManager.getInstance().getForegroundCall(); |
| 510 | return call != null && call.getState() == CallState.RINGING; |
| 511 | } |
| 512 | |
Santos Cordon | 14ff838 | 2014-08-05 20:44:27 -0700 | [diff] [blame] | 513 | private boolean hasFocus() { |
| 514 | return mAudioFocusStreamType != STREAM_NONE; |
| 515 | } |
Tyler Gunn | 9787e0e | 2014-10-14 14:36:12 -0700 | [diff] [blame] | 516 | |
| 517 | /** |
| 518 | * Dumps the state of the {@link CallAudioManager}. |
| 519 | * |
| 520 | * @param pw The {@code IndentingPrintWriter} to write the state to. |
| 521 | */ |
| 522 | public void dump(IndentingPrintWriter pw) { |
| 523 | pw.println("mAudioState: " + mAudioState); |
| 524 | pw.println("mBluetoothManager:"); |
| 525 | pw.increaseIndent(); |
| 526 | mBluetoothManager.dump(pw); |
| 527 | pw.decreaseIndent(); |
| 528 | if (mWiredHeadsetManager != null) { |
| 529 | pw.println("mWiredHeadsetManager:"); |
| 530 | pw.increaseIndent(); |
| 531 | mWiredHeadsetManager.dump(pw); |
| 532 | pw.decreaseIndent(); |
| 533 | } else { |
| 534 | pw.println("mWiredHeadsetManager: null"); |
| 535 | } |
| 536 | pw.println("mAudioFocusStreamType: " + mAudioFocusStreamType); |
| 537 | pw.println("mIsRinging: " + mIsRinging); |
| 538 | pw.println("mIsTonePlaying: " + mIsTonePlaying); |
| 539 | pw.println("mWasSpeakerOn: " + mWasSpeakerOn); |
| 540 | pw.println("mMostRecentlyUsedMode: " + mMostRecentlyUsedMode); |
| 541 | } |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 542 | } |