From 5125501099a184b2a377ec7d60d0106f8e2251c7 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Fri, 24 Feb 2017 16:19:14 +0900 Subject: [PATCH] MediaSessionService: Synchronize isGlobalPriorityActive() Test: Manual test (Press the headset button while the phone is ringing) Change-Id: I682d4d07a1e238892afe8b03b2b824bb40345ab8 --- .../server/media/MediaSessionService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 36f328716306f..dfa2f863d0683 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -801,16 +801,17 @@ public class MediaSessionService extends SystemService implements Monitor { + "setup is in progress."); return; } - if (isGlobalPriorityActive() && uid != Process.SYSTEM_UID) { - // Prevent dispatching key event through reflection while the global priority - // session is active. - Slog.i(TAG, "Only the system can dispatch media key event " - + "to the global priority session."); - return; - } synchronized (mLock) { - if (!isGlobalPriorityActive() && isVoiceKey(keyEvent.getKeyCode())) { + boolean isGlobalPriorityActive = mPriorityStack.isGlobalPriorityActive(); + if (isGlobalPriorityActive && uid != Process.SYSTEM_UID) { + // Prevent dispatching key event through reflection while the global + // priority session is active. + Slog.i(TAG, "Only the system can dispatch media key event " + + "to the global priority session."); + return; + } + if (!isGlobalPriorityActive && isVoiceKey(keyEvent.getKeyCode())) { handleVoiceKeyEventLocked(keyEvent, needWakeLock); } else { dispatchMediaKeyEventLocked(keyEvent, needWakeLock, true); @@ -1080,7 +1081,9 @@ public class MediaSessionService extends SystemService implements Monitor { @Override public boolean isGlobalPriorityActive() { - return mPriorityStack.isGlobalPriorityActive(); + synchronized (mLock) { + return mPriorityStack.isGlobalPriorityActive(); + } } @Override