Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9a0fc96 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "NotificationPlayer: fix focus not abandoned on playback error"

parents 66c261f6 d8cb4196
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -133,12 +133,19 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
                            + mNotificationRampTimeMs + "ms"); }
                    try {
                        Thread.sleep(mNotificationRampTimeMs);
                        player.start();
                    } catch (InterruptedException e) {
                        Log.e(mTag, "Exception while sleeping to sync notification playback"
                                + " with ducking", e);
                    }
                    try {
                        player.start();
                        if (DEBUG) { Log.d(mTag, "player.start"); }
                    } catch (Exception e) {
                        player.release();
                        player = null;
                        // playing the notification didn't work, revert the focus request
                        abandonAudioFocusAfterError();
                    }
                    if (mPlayer != null) {
                        if (DEBUG) { Log.d(mTag, "mPlayer.release"); }
                        mPlayer.release();
@@ -147,6 +154,8 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
                }
                catch (Exception e) {
                    Log.w(mTag, "error loading sound for " + mCmd.uri, e);
                    // playing the notification didn't work, revert the focus request
                    abandonAudioFocusAfterError();
                }
                this.notify();
            }
@@ -154,6 +163,16 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
        }
    };

    private void abandonAudioFocusAfterError() {
        synchronized (mQueueAudioFocusLock) {
            if (mAudioManagerWithAudioFocus != null) {
                if (DEBUG) Log.d(mTag, "abandoning focus after playback error");
                mAudioManagerWithAudioFocus.abandonAudioFocus(null);
                mAudioManagerWithAudioFocus = null;
            }
        }
    }

    private void startSound(Command cmd) {
        // Preparing can be slow, so if there is something else
        // is playing, let it continue until we're done, so there