Fix deadlock b/w ActivityManagerService and MediaSessionService
While handling adjustVolume and finishReceiver at the same time,
system_server gets into deadlock situation where
ActivityManagerService lock and MediaSessionService lock are
getting acquired in reverse order. To fix this,
adjustSuggestedStreamVolume() is shifted to MediaSessionService's
Handler thread.
https://code.google.com/p/android/issues/detail?id=213014
Change-Id: I3125c890546c8ab7c4df530bb68ba87cd688f8ce
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 7028fa6..1a320d2 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -887,13 +887,24 @@
}
return;
}
- try {
- String packageName = getContext().getOpPackageName();
- mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
- flags, packageName, TAG);
- } catch (RemoteException e) {
- Log.e(TAG, "Error adjusting default volume.", e);
- }
+
+ // Execute mAudioService.adjustSuggestedStreamVolume() on
+ // handler thread of MediaSessionService.
+ // This will release the MediaSessionService.mLock sooner and avoid
+ // a potential deadlock between MediaSessionService.mLock and
+ // ActivityManagerService lock.
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ String packageName = getContext().getOpPackageName();
+ mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
+ flags, packageName, TAG);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error adjusting default volume.", e);
+ }
+ }
+ });
} else {
session.adjustVolume(direction, flags, getContext().getPackageName(),
UserHandle.myUserId(), true);