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
This commit is contained in:
Shibin George
2016-06-14 20:42:13 +05:30
parent cf81fdb37b
commit 19e84047ab

View File

@@ -887,13 +887,24 @@ public class MediaSessionService extends SystemService implements Monitor {
}
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);