Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 18 | |
| 19 | import android.media.AudioManager; |
| 20 | import android.media.ToneGenerator; |
| 21 | import android.os.Handler; |
| 22 | import android.os.Looper; |
Brad Ebinger | a3eccfe | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 23 | import android.telecom.Log; |
| 24 | import android.telecom.Logging.Runnable; |
| 25 | import android.telecom.Logging.Session; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 27 | import com.android.internal.annotations.VisibleForTesting; |
| 28 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Play a call-related tone (ringback, busy signal, etc.) through ToneGenerator. To use, create an |
| 31 | * instance using InCallTonePlayer.Factory (passing in the TONE_* constant for the tone you want) |
| 32 | * and start() it. Implemented on top of {@link Thread} so that the tone plays in its own thread. |
| 33 | */ |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 34 | public class InCallTonePlayer extends Thread { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Factory used to create InCallTonePlayers. Exists to aid with testing mocks. |
| 38 | */ |
| 39 | public static class Factory { |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 40 | private CallAudioManager mCallAudioManager; |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 41 | private final CallAudioRoutePeripheralAdapter mCallAudioRoutePeripheralAdapter; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 42 | private final TelecomSystem.SyncRoot mLock; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 43 | private final ToneGeneratorFactory mToneGeneratorFactory; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 44 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 45 | Factory(CallAudioRoutePeripheralAdapter callAudioRoutePeripheralAdapter, |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 46 | TelecomSystem.SyncRoot lock, ToneGeneratorFactory toneGeneratorFactory) { |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 47 | mCallAudioRoutePeripheralAdapter = callAudioRoutePeripheralAdapter; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 48 | mLock = lock; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 49 | mToneGeneratorFactory = toneGeneratorFactory; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 52 | public void setCallAudioManager(CallAudioManager callAudioManager) { |
| 53 | mCallAudioManager = callAudioManager; |
| 54 | } |
| 55 | |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 56 | public InCallTonePlayer createPlayer(int tone) { |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 57 | return new InCallTonePlayer(tone, mCallAudioManager, |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 58 | mCallAudioRoutePeripheralAdapter, mLock, mToneGeneratorFactory); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 62 | public interface ToneGeneratorFactory { |
| 63 | ToneGenerator get (int streamType, int volume); |
| 64 | } |
| 65 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 66 | // The possible tones that we can play. |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 67 | public static final int TONE_INVALID = 0; |
| 68 | public static final int TONE_BUSY = 1; |
| 69 | public static final int TONE_CALL_ENDED = 2; |
| 70 | public static final int TONE_OTA_CALL_ENDED = 3; |
| 71 | public static final int TONE_CALL_WAITING = 4; |
| 72 | public static final int TONE_CDMA_DROP = 5; |
| 73 | public static final int TONE_CONGESTION = 6; |
| 74 | public static final int TONE_INTERCEPT = 7; |
| 75 | public static final int TONE_OUT_OF_SERVICE = 8; |
| 76 | public static final int TONE_REDIAL = 9; |
| 77 | public static final int TONE_REORDER = 10; |
| 78 | public static final int TONE_RING_BACK = 11; |
| 79 | public static final int TONE_UNOBTAINABLE_NUMBER = 12; |
| 80 | public static final int TONE_VOICE_PRIVACY = 13; |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 81 | public static final int TONE_VIDEO_UPGRADE = 14; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 82 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 83 | private static final int RELATIVE_VOLUME_EMERGENCY = 100; |
| 84 | private static final int RELATIVE_VOLUME_HIPRI = 80; |
| 85 | private static final int RELATIVE_VOLUME_LOPRI = 50; |
| 86 | |
| 87 | // Buffer time (in msec) to add on to the tone timeout value. Needed mainly when the timeout |
| 88 | // value for a tone is exact duration of the tone itself. |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 89 | private static final int TIMEOUT_BUFFER_MILLIS = 20; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 90 | |
| 91 | // The tone state. |
| 92 | private static final int STATE_OFF = 0; |
| 93 | private static final int STATE_ON = 1; |
| 94 | private static final int STATE_STOPPED = 2; |
| 95 | |
| 96 | /** |
| 97 | * Keeps count of the number of actively playing tones so that we can notify CallAudioManager |
| 98 | * when we need focus and when it can be release. This should only be manipulated from the main |
| 99 | * thread. |
| 100 | */ |
| 101 | private static int sTonesPlaying = 0; |
| 102 | |
| 103 | private final CallAudioManager mCallAudioManager; |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 104 | private final CallAudioRoutePeripheralAdapter mCallAudioRoutePeripheralAdapter; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 105 | |
| 106 | private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper()); |
| 107 | |
| 108 | /** The ID of the tone to play. */ |
| 109 | private final int mToneId; |
| 110 | |
| 111 | /** Current state of the tone player. */ |
| 112 | private int mState; |
| 113 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 114 | /** Telecom lock object. */ |
| 115 | private final TelecomSystem.SyncRoot mLock; |
| 116 | |
Hall Liu | d8ca545 | 2016-03-10 14:53:15 -0800 | [diff] [blame] | 117 | private Session mSession; |
| 118 | private final Object mSessionLock = new Object(); |
| 119 | |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 120 | private final ToneGeneratorFactory mToneGenerator; |
| 121 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Initializes the tone player. Private; use the {@link Factory} to create tone players. |
| 124 | * |
| 125 | * @param toneId ID of the tone to play, see TONE_* constants. |
| 126 | */ |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 127 | private InCallTonePlayer( |
| 128 | int toneId, |
| 129 | CallAudioManager callAudioManager, |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 130 | CallAudioRoutePeripheralAdapter callAudioRoutePeripheralAdapter, |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 131 | TelecomSystem.SyncRoot lock, |
| 132 | ToneGeneratorFactory toneGeneratorFactory) { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 133 | mState = STATE_OFF; |
| 134 | mToneId = toneId; |
| 135 | mCallAudioManager = callAudioManager; |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 136 | mCallAudioRoutePeripheralAdapter = callAudioRoutePeripheralAdapter; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 137 | mLock = lock; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 138 | mToneGenerator = toneGeneratorFactory; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** {@inheritDoc} */ |
| 142 | @Override |
| 143 | public void run() { |
| 144 | ToneGenerator toneGenerator = null; |
| 145 | try { |
Hall Liu | d8ca545 | 2016-03-10 14:53:15 -0800 | [diff] [blame] | 146 | synchronized (mSessionLock) { |
| 147 | if (mSession != null) { |
| 148 | Log.continueSession(mSession, "ICTP.r"); |
| 149 | mSession = null; |
| 150 | } |
| 151 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 152 | Log.d(this, "run(toneId = %s)", mToneId); |
| 153 | |
| 154 | final int toneType; // Passed to ToneGenerator.startTone. |
| 155 | final int toneVolume; // Passed to the ToneGenerator constructor. |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 156 | final int toneLengthMillis; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 157 | |
| 158 | switch (mToneId) { |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 159 | case TONE_BUSY: |
| 160 | // TODO: CDMA-specific tones |
| 161 | toneType = ToneGenerator.TONE_SUP_BUSY; |
| 162 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 163 | toneLengthMillis = 4000; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 164 | break; |
| 165 | case TONE_CALL_ENDED: |
| 166 | toneType = ToneGenerator.TONE_PROP_PROMPT; |
| 167 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Yorke Lee | 7062bb9 | 2014-10-13 09:54:15 -0700 | [diff] [blame] | 168 | toneLengthMillis = 200; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 169 | break; |
| 170 | case TONE_OTA_CALL_ENDED: |
| 171 | // TODO: fill in |
| 172 | throw new IllegalStateException("OTA Call ended NYI."); |
| 173 | case TONE_CALL_WAITING: |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 174 | toneType = ToneGenerator.TONE_SUP_CALL_WAITING; |
| 175 | toneVolume = RELATIVE_VOLUME_HIPRI; |
| 176 | toneLengthMillis = Integer.MAX_VALUE - TIMEOUT_BUFFER_MILLIS; |
| 177 | break; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 178 | case TONE_CDMA_DROP: |
| 179 | toneType = ToneGenerator.TONE_CDMA_CALLDROP_LITE; |
| 180 | toneVolume = RELATIVE_VOLUME_LOPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 181 | toneLengthMillis = 375; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 182 | break; |
| 183 | case TONE_CONGESTION: |
| 184 | toneType = ToneGenerator.TONE_SUP_CONGESTION; |
| 185 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 186 | toneLengthMillis = 4000; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 187 | break; |
| 188 | case TONE_INTERCEPT: |
| 189 | toneType = ToneGenerator.TONE_CDMA_ABBR_INTERCEPT; |
| 190 | toneVolume = RELATIVE_VOLUME_LOPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 191 | toneLengthMillis = 500; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 192 | break; |
| 193 | case TONE_OUT_OF_SERVICE: |
| 194 | toneType = ToneGenerator.TONE_CDMA_CALLDROP_LITE; |
| 195 | toneVolume = RELATIVE_VOLUME_LOPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 196 | toneLengthMillis = 375; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 197 | break; |
| 198 | case TONE_REDIAL: |
| 199 | toneType = ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE; |
| 200 | toneVolume = RELATIVE_VOLUME_LOPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 201 | toneLengthMillis = 5000; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 202 | break; |
| 203 | case TONE_REORDER: |
| 204 | toneType = ToneGenerator.TONE_CDMA_REORDER; |
| 205 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Yorke Lee | 7062bb9 | 2014-10-13 09:54:15 -0700 | [diff] [blame] | 206 | toneLengthMillis = 4000; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 207 | break; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 208 | case TONE_RING_BACK: |
| 209 | toneType = ToneGenerator.TONE_SUP_RINGTONE; |
| 210 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 211 | toneLengthMillis = Integer.MAX_VALUE - TIMEOUT_BUFFER_MILLIS; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 212 | break; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 213 | case TONE_UNOBTAINABLE_NUMBER: |
| 214 | toneType = ToneGenerator.TONE_SUP_ERROR; |
| 215 | toneVolume = RELATIVE_VOLUME_HIPRI; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 216 | toneLengthMillis = 4000; |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 217 | break; |
| 218 | case TONE_VOICE_PRIVACY: |
| 219 | // TODO: fill in. |
| 220 | throw new IllegalStateException("Voice privacy tone NYI."); |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 221 | case TONE_VIDEO_UPGRADE: |
| 222 | // Similar to the call waiting tone, but does not repeat. |
| 223 | toneType = ToneGenerator.TONE_SUP_CALL_WAITING; |
| 224 | toneVolume = RELATIVE_VOLUME_HIPRI; |
| 225 | toneLengthMillis = 4000; |
| 226 | break; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 227 | default: |
| 228 | throw new IllegalStateException("Bad toneId: " + mToneId); |
| 229 | } |
| 230 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 231 | int stream = AudioManager.STREAM_VOICE_CALL; |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 232 | if (mCallAudioRoutePeripheralAdapter.isBluetoothAudioOn()) { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 233 | stream = AudioManager.STREAM_BLUETOOTH_SCO; |
| 234 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 235 | |
| 236 | // If the ToneGenerator creation fails, just continue without it. It is a local audio |
| 237 | // signal, and is not as important. |
| 238 | try { |
| 239 | Log.v(this, "Creating generator"); |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 240 | toneGenerator = mToneGenerator.get(stream, toneVolume); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 241 | } catch (RuntimeException e) { |
| 242 | Log.w(this, "Failed to create ToneGenerator.", e); |
| 243 | return; |
| 244 | } |
| 245 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 246 | // TODO: Certain CDMA tones need to check the ringer-volume state before |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 247 | // playing. See CallNotifier.InCallTonePlayer. |
| 248 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 249 | // TODO: Some tones play through the end of a call so we need to inform |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 250 | // CallAudioManager that we want focus the same way that Ringer does. |
| 251 | |
| 252 | synchronized (this) { |
| 253 | if (mState != STATE_STOPPED) { |
| 254 | mState = STATE_ON; |
| 255 | toneGenerator.startTone(toneType); |
| 256 | try { |
| 257 | Log.v(this, "Starting tone %d...waiting for %d ms.", mToneId, |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 258 | toneLengthMillis + TIMEOUT_BUFFER_MILLIS); |
| 259 | wait(toneLengthMillis + TIMEOUT_BUFFER_MILLIS); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 260 | } catch (InterruptedException e) { |
| 261 | Log.w(this, "wait interrupted", e); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | mState = STATE_OFF; |
| 266 | } finally { |
| 267 | if (toneGenerator != null) { |
| 268 | toneGenerator.release(); |
| 269 | } |
| 270 | cleanUpTonePlayer(); |
Brad Ebinger | efa8d2a | 2016-04-01 11:23:05 -0700 | [diff] [blame] | 271 | Log.endSession(); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 274 | |
| 275 | @VisibleForTesting |
| 276 | public void startTone() { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 277 | sTonesPlaying++; |
| 278 | if (sTonesPlaying == 1) { |
| 279 | mCallAudioManager.setIsTonePlaying(true); |
| 280 | } |
| 281 | |
Hall Liu | d8ca545 | 2016-03-10 14:53:15 -0800 | [diff] [blame] | 282 | synchronized (mSessionLock) { |
| 283 | if (mSession != null) { |
| 284 | Log.cancelSubsession(mSession); |
| 285 | } |
| 286 | mSession = Log.createSubsession(); |
| 287 | } |
| 288 | |
Hall Liu | b626c02 | 2016-06-23 13:16:51 -0700 | [diff] [blame] | 289 | super.start(); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void start() { |
| 294 | Log.w(this, "Do not call the start method directly; use startTone instead."); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Stops the tone. |
| 299 | */ |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 300 | @VisibleForTesting |
| 301 | public void stopTone() { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 302 | synchronized (this) { |
| 303 | if (mState == STATE_ON) { |
| 304 | Log.d(this, "Stopping the tone %d.", mToneId); |
| 305 | notify(); |
| 306 | } |
| 307 | mState = STATE_STOPPED; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | private void cleanUpTonePlayer() { |
| 312 | // Release focus on the main thread. |
Brad Ebinger | f5e0666 | 2016-08-25 16:16:27 -0700 | [diff] [blame] | 313 | mMainThreadHandler.post(new Runnable("ICTP.cUTP", mLock) { |
Brad Ebinger | e62e9e8 | 2016-02-01 18:26:40 -0800 | [diff] [blame] | 314 | @Override |
| 315 | public void loggedRun() { |
Brad Ebinger | f5e0666 | 2016-08-25 16:16:27 -0700 | [diff] [blame] | 316 | if (sTonesPlaying == 0) { |
| 317 | Log.wtf(this, "Over-releasing focus for tone player."); |
| 318 | } else if (--sTonesPlaying == 0) { |
| 319 | mCallAudioManager.setIsTonePlaying(false); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
Brad Ebinger | e62e9e8 | 2016-02-01 18:26:40 -0800 | [diff] [blame] | 322 | }.prepare()); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 323 | } |
| 324 | } |