Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [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 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 17 | package com.android.server.audio; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 18 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 20 | import android.media.AudioAttributes; |
| 21 | import android.media.AudioFocusInfo; |
| 22 | import android.media.AudioManager; |
| 23 | import android.media.IAudioFocusDispatcher; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 24 | import android.os.IBinder; |
| 25 | import android.util.Log; |
| 26 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 27 | import com.android.server.audio.MediaFocusControl.AudioFocusDeathHandler; |
| 28 | |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 29 | import java.io.PrintWriter; |
| 30 | |
| 31 | /** |
| 32 | * @hide |
| 33 | * Class to handle all the information about a user of audio focus. The lifecycle of each |
| 34 | * instance is managed by android.media.MediaFocusControl, from its addition to the audio focus |
| 35 | * stack to its release. |
| 36 | */ |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 37 | public class FocusRequester { |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 38 | |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 39 | // on purpose not using this classe's name, as it will only be used from MediaFocusControl |
| 40 | private static final String TAG = "MediaFocusControl"; |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 41 | private static final boolean DEBUG = false; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 42 | |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 43 | private AudioFocusDeathHandler mDeathHandler; // may be null |
| 44 | private IAudioFocusDispatcher mFocusDispatcher; // may be null |
| 45 | private final IBinder mSourceRef; // may be null |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 46 | private final String mClientId; |
| 47 | private final String mPackageName; |
| 48 | private final int mCallingUid; |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 49 | private final MediaFocusControl mFocusController; // never null |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 50 | /** |
| 51 | * the audio focus gain request that caused the addition of this object in the focus stack. |
| 52 | */ |
| 53 | private final int mFocusGainRequest; |
| 54 | /** |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 55 | * the flags associated with the gain request that qualify the type of grant (e.g. accepting |
| 56 | * delay vs grant must be immediate) |
| 57 | */ |
| 58 | private final int mGrantFlags; |
| 59 | /** |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 60 | * the audio focus loss received my mFocusDispatcher, is AudioManager.AUDIOFOCUS_NONE if |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 61 | * it never lost focus. |
| 62 | */ |
| 63 | private int mFocusLossReceived; |
| 64 | /** |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 65 | * the audio attributes associated with the focus request |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 66 | */ |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 67 | private final AudioAttributes mAttributes; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 68 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 69 | /** |
| 70 | * Class constructor |
| 71 | * @param aa |
| 72 | * @param focusRequest |
| 73 | * @param grantFlags |
| 74 | * @param afl |
| 75 | * @param source |
| 76 | * @param id |
| 77 | * @param hdlr |
| 78 | * @param pn |
| 79 | * @param uid |
| 80 | * @param ctlr cannot be null |
| 81 | */ |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 82 | FocusRequester(AudioAttributes aa, int focusRequest, int grantFlags, |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 83 | IAudioFocusDispatcher afl, IBinder source, String id, AudioFocusDeathHandler hdlr, |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 84 | String pn, int uid, @NonNull MediaFocusControl ctlr) { |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 85 | mAttributes = aa; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 86 | mFocusDispatcher = afl; |
| 87 | mSourceRef = source; |
| 88 | mClientId = id; |
| 89 | mDeathHandler = hdlr; |
| 90 | mPackageName = pn; |
| 91 | mCallingUid = uid; |
| 92 | mFocusGainRequest = focusRequest; |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 93 | mGrantFlags = grantFlags; |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 94 | mFocusLossReceived = AudioManager.AUDIOFOCUS_NONE; |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 95 | mFocusController = ctlr; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 99 | boolean hasSameClient(String otherClient) { |
| 100 | try { |
| 101 | return mClientId.compareTo(otherClient) == 0; |
| 102 | } catch (NullPointerException e) { |
| 103 | return false; |
| 104 | } |
| 105 | } |
| 106 | |
Jean-Michel Trivi | 958876f | 2014-11-16 15:40:22 -0800 | [diff] [blame] | 107 | boolean isLockedFocusOwner() { |
| 108 | return ((mGrantFlags & AudioManager.AUDIOFOCUS_FLAG_LOCK) != 0); |
| 109 | } |
| 110 | |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 111 | boolean hasSameBinder(IBinder ib) { |
| 112 | return (mSourceRef != null) && mSourceRef.equals(ib); |
| 113 | } |
| 114 | |
| 115 | boolean hasSamePackage(String pack) { |
| 116 | try { |
| 117 | return mPackageName.compareTo(pack) == 0; |
| 118 | } catch (NullPointerException e) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | boolean hasSameUid(int uid) { |
| 124 | return mCallingUid == uid; |
| 125 | } |
| 126 | |
Jean-Michel Trivi | 958876f | 2014-11-16 15:40:22 -0800 | [diff] [blame] | 127 | String getClientId() { |
| 128 | return mClientId; |
| 129 | } |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 130 | |
| 131 | int getGainRequest() { |
| 132 | return mFocusGainRequest; |
| 133 | } |
| 134 | |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 135 | int getGrantFlags() { |
| 136 | return mGrantFlags; |
| 137 | } |
| 138 | |
| 139 | AudioAttributes getAudioAttributes() { |
| 140 | return mAttributes; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | private static String focusChangeToString(int focus) { |
| 145 | switch(focus) { |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 146 | case AudioManager.AUDIOFOCUS_NONE: |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 147 | return "none"; |
| 148 | case AudioManager.AUDIOFOCUS_GAIN: |
| 149 | return "GAIN"; |
| 150 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: |
| 151 | return "GAIN_TRANSIENT"; |
| 152 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK: |
| 153 | return "GAIN_TRANSIENT_MAY_DUCK"; |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 154 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE: |
| 155 | return "GAIN_TRANSIENT_EXCLUSIVE"; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 156 | case AudioManager.AUDIOFOCUS_LOSS: |
| 157 | return "LOSS"; |
| 158 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: |
| 159 | return "LOSS_TRANSIENT"; |
| 160 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: |
| 161 | return "LOSS_TRANSIENT_CAN_DUCK"; |
| 162 | default: |
| 163 | return "[invalid focus change" + focus + "]"; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | private String focusGainToString() { |
| 168 | return focusChangeToString(mFocusGainRequest); |
| 169 | } |
| 170 | |
| 171 | private String focusLossToString() { |
| 172 | return focusChangeToString(mFocusLossReceived); |
| 173 | } |
| 174 | |
Jean-Michel Trivi | 958876f | 2014-11-16 15:40:22 -0800 | [diff] [blame] | 175 | private static String flagsToString(int flags) { |
| 176 | String msg = new String(); |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 177 | if ((flags & AudioManager.AUDIOFOCUS_FLAG_DELAY_OK) != 0) { |
| 178 | msg += "DELAY_OK"; |
| 179 | } |
| 180 | if ((flags & AudioManager.AUDIOFOCUS_FLAG_LOCK) != 0) { |
| 181 | if (!msg.isEmpty()) { msg += "|"; } |
| 182 | msg += "LOCK"; |
| 183 | } |
| 184 | if ((flags & AudioManager.AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS) != 0) { |
| 185 | if (!msg.isEmpty()) { msg += "|"; } |
| 186 | msg += "PAUSES_ON_DUCKABLE_LOSS"; |
| 187 | } |
Jean-Michel Trivi | 958876f | 2014-11-16 15:40:22 -0800 | [diff] [blame] | 188 | return msg; |
| 189 | } |
| 190 | |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 191 | void dump(PrintWriter pw) { |
| 192 | pw.println(" source:" + mSourceRef |
| 193 | + " -- pack: " + mPackageName |
| 194 | + " -- client: " + mClientId |
| 195 | + " -- gain: " + focusGainToString() |
Jean-Michel Trivi | 958876f | 2014-11-16 15:40:22 -0800 | [diff] [blame] | 196 | + " -- flags: " + flagsToString(mGrantFlags) |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 197 | + " -- loss: " + focusLossToString() |
| 198 | + " -- uid: " + mCallingUid |
Jean-Michel Trivi | fd6ad74 | 2014-11-10 14:38:30 -0800 | [diff] [blame] | 199 | + " -- attr: " + mAttributes); |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | |
| 203 | void release() { |
| 204 | try { |
| 205 | if (mSourceRef != null && mDeathHandler != null) { |
| 206 | mSourceRef.unlinkToDeath(mDeathHandler, 0); |
| 207 | mDeathHandler = null; |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 208 | mFocusDispatcher = null; |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 209 | } |
| 210 | } catch (java.util.NoSuchElementException e) { |
| 211 | Log.e(TAG, "FocusRequester.release() hit ", e); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | protected void finalize() throws Throwable { |
| 217 | release(); |
| 218 | super.finalize(); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * For a given audio focus gain request, return the audio focus loss type that will result |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 223 | * from it, taking into account any previous focus loss. |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 224 | * @param gainRequest |
| 225 | * @return the audio focus loss type that matches the gain request |
| 226 | */ |
| 227 | private int focusLossForGainRequest(int gainRequest) { |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 228 | switch(gainRequest) { |
| 229 | case AudioManager.AUDIOFOCUS_GAIN: |
| 230 | switch(mFocusLossReceived) { |
| 231 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: |
| 232 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: |
| 233 | case AudioManager.AUDIOFOCUS_LOSS: |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 234 | case AudioManager.AUDIOFOCUS_NONE: |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 235 | return AudioManager.AUDIOFOCUS_LOSS; |
| 236 | } |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 237 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE: |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 238 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: |
| 239 | switch(mFocusLossReceived) { |
| 240 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: |
| 241 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 242 | case AudioManager.AUDIOFOCUS_NONE: |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 243 | return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT; |
| 244 | case AudioManager.AUDIOFOCUS_LOSS: |
| 245 | return AudioManager.AUDIOFOCUS_LOSS; |
| 246 | } |
| 247 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK: |
| 248 | switch(mFocusLossReceived) { |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 249 | case AudioManager.AUDIOFOCUS_NONE: |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 250 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 251 | return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK; |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 252 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: |
| 253 | return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT; |
| 254 | case AudioManager.AUDIOFOCUS_LOSS: |
| 255 | return AudioManager.AUDIOFOCUS_LOSS; |
| 256 | } |
| 257 | default: |
| 258 | Log.e(TAG, "focusLossForGainRequest() for invalid focus request "+ gainRequest); |
Jean-Michel Trivi | 2380566 | 2013-07-31 14:19:18 -0700 | [diff] [blame] | 259 | return AudioManager.AUDIOFOCUS_NONE; |
Jean-Michel Trivi | 53e6e28 | 2013-07-30 14:21:34 -0700 | [diff] [blame] | 260 | } |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Called synchronized on MediaFocusControl.mAudioFocusLock |
| 265 | */ |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 266 | void handleExternalFocusGain(int focusGain) { |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 267 | int focusLoss = focusLossForGainRequest(focusGain); |
| 268 | handleFocusLoss(focusLoss); |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 271 | /** |
| 272 | * Called synchronized on MediaFocusControl.mAudioFocusLock |
| 273 | */ |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 274 | void handleFocusGain(int focusGain) { |
| 275 | try { |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 276 | mFocusLossReceived = AudioManager.AUDIOFOCUS_NONE; |
| 277 | mFocusController.notifyExtPolicyFocusGrant_syncAf(toAudioFocusInfo(), |
| 278 | AudioManager.AUDIOFOCUS_REQUEST_GRANTED); |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 279 | final IAudioFocusDispatcher fd = mFocusDispatcher; |
| 280 | if (fd != null) { |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 281 | if (DEBUG) { |
| 282 | Log.v(TAG, "dispatching " + focusChangeToString(focusGain) + " to " |
| 283 | + mClientId); |
| 284 | } |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 285 | fd.dispatchAudioFocusChange(focusGain, mClientId); |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 286 | } |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 287 | } catch (android.os.RemoteException e) { |
| 288 | Log.e(TAG, "Failure to signal gain of audio focus due to: ", e); |
| 289 | } |
| 290 | } |
| 291 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Called synchronized on MediaFocusControl.mAudioFocusLock |
| 294 | */ |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 295 | void handleFocusLoss(int focusLoss) { |
| 296 | try { |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 297 | if (focusLoss != mFocusLossReceived) { |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 298 | mFocusLossReceived = focusLoss; |
| 299 | // before dispatching a focus loss, check if the following conditions are met: |
| 300 | // 1/ the framework is not supposed to notify the focus loser on a DUCK loss |
| 301 | // 2/ it is a DUCK loss |
| 302 | // 3/ the focus loser isn't flagged as pausing in a DUCK loss |
| 303 | // if they are, do not notify the focus loser |
| 304 | if (!mFocusController.mustNotifyFocusOwnerOnDuck() |
| 305 | && mFocusLossReceived == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK |
| 306 | && (mGrantFlags |
| 307 | & AudioManager.AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS) == 0) { |
| 308 | if (DEBUG) { |
| 309 | Log.v(TAG, "NOT dispatching " + focusChangeToString(mFocusLossReceived) |
| 310 | + " to " + mClientId + ", to be handled externally"); |
| 311 | } |
| 312 | mFocusController.notifyExtPolicyFocusLoss_syncAf( |
| 313 | toAudioFocusInfo(), false /* wasDispatched */); |
| 314 | return; |
| 315 | } |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 316 | final IAudioFocusDispatcher fd = mFocusDispatcher; |
| 317 | if (fd != null) { |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 318 | if (DEBUG) { |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 319 | Log.v(TAG, "dispatching " + focusChangeToString(mFocusLossReceived) + " to " |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 320 | + mClientId); |
| 321 | } |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 322 | mFocusController.notifyExtPolicyFocusLoss_syncAf( |
| 323 | toAudioFocusInfo(), true /* wasDispatched */); |
Jean-Michel Trivi | e898772 | 2016-07-07 15:38:32 -0700 | [diff] [blame] | 324 | fd.dispatchAudioFocusChange(mFocusLossReceived, mClientId); |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 325 | } |
Jean-Michel Trivi | cbb212f | 2013-07-30 15:09:33 -0700 | [diff] [blame] | 326 | } |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 327 | } catch (android.os.RemoteException e) { |
| 328 | Log.e(TAG, "Failure to signal loss of audio focus due to:", e); |
| 329 | } |
| 330 | } |
| 331 | |
Jean-Michel Trivi | 0212be5 | 2014-11-24 14:43:10 -0800 | [diff] [blame] | 332 | AudioFocusInfo toAudioFocusInfo() { |
| 333 | return new AudioFocusInfo(mAttributes, mClientId, mPackageName, |
| 334 | mFocusGainRequest, mFocusLossReceived, mGrantFlags); |
| 335 | } |
Jean-Michel Trivi | 83283f2 | 2013-07-29 18:09:41 -0700 | [diff] [blame] | 336 | } |