Skip to content

Commit e981647

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Fix deadlock in AudioService"
2 parents 9a10bf0 + 3094d95 commit e981647

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

media/java/android/media/AudioService.java

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@ private boolean isCurrentRcController(ComponentName eventReceiver) {
30723072
/**
30733073
* Update the remote control displays with the new "focused" client generation
30743074
*/
3075-
private void setNewRcClientOnDisplays_syncRcStack(int newClientGeneration,
3075+
private void setNewRcClientOnDisplays_syncAfRcsCurrc(int newClientGeneration,
30763076
ComponentName newClientEventReceiver, boolean clearing) {
30773077
// NOTE: Only one IRemoteControlDisplay supported in this implementation
30783078
if (mRcDisplay != null) {
@@ -3091,7 +3091,7 @@ private void setNewRcClientOnDisplays_syncRcStack(int newClientGeneration,
30913091
/**
30923092
* Update the remote control clients with the new "focused" client generation
30933093
*/
3094-
private void setNewRcClientGenerationOnClients_syncRcStack(int newClientGeneration) {
3094+
private void setNewRcClientGenerationOnClients_syncAfRcsCurrc(int newClientGeneration) {
30953095
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
30963096
while(stackIterator.hasNext()) {
30973097
RemoteControlStackEntry se = stackIterator.next();
@@ -3115,15 +3115,13 @@ private void setNewRcClientGenerationOnClients_syncRcStack(int newClientGenerati
31153115
* @param clearing true if the new client generation value maps to a remote control update
31163116
* where the display should be cleared.
31173117
*/
3118-
private void setNewRcClient(int newClientGeneration, ComponentName newClientEventReceiver,
3119-
boolean clearing) {
3120-
synchronized(mRCStack) {
3121-
// send the new valid client generation ID to all displays
3122-
setNewRcClientOnDisplays_syncRcStack(newClientGeneration, newClientEventReceiver,
3123-
clearing);
3124-
// send the new valid client generation ID to all clients
3125-
setNewRcClientGenerationOnClients_syncRcStack(newClientGeneration);
3126-
}
3118+
private void setNewRcClient_syncAfRcsCurrc(int newClientGeneration,
3119+
ComponentName newClientEventReceiver, boolean clearing) {
3120+
// send the new valid client generation ID to all displays
3121+
setNewRcClientOnDisplays_syncAfRcsCurrc(newClientGeneration, newClientEventReceiver,
3122+
clearing);
3123+
// send the new valid client generation ID to all clients
3124+
setNewRcClientGenerationOnClients_syncAfRcsCurrc(newClientGeneration);
31273125
}
31283126

31293127
/**
@@ -3133,42 +3131,46 @@ private void onRcDisplayClear() {
31333131
// TODO remove log before release
31343132
Log.i(TAG, "Clear remote control display");
31353133

3136-
synchronized(mCurrentRcLock) {
3137-
mCurrentRcClientGen++;
3138-
3139-
// synchronously update the displays and clients with the new client generation
3140-
setNewRcClient(mCurrentRcClientGen, null /*event receiver*/, true /*clearing*/);
3134+
synchronized(mRCStack) {
3135+
synchronized(mCurrentRcLock) {
3136+
mCurrentRcClientGen++;
3137+
// synchronously update the displays and clients with the new client generation
3138+
setNewRcClient_syncAfRcsCurrc(mCurrentRcClientGen,
3139+
null /*event receiver*/, true /*clearing*/);
3140+
}
31413141
}
31423142
}
31433143

31443144
/**
31453145
* Called when processing MSG_RCDISPLAY_UPDATE event
31463146
*/
31473147
private void onRcDisplayUpdate(RemoteControlStackEntry rcse, int flags /* USED ?*/) {
3148-
synchronized(mCurrentRcLock) {
3149-
if ((mCurrentRcClient != null) && (mCurrentRcClient.equals(rcse.mRcClient))) {
3150-
// TODO remove log before release
3151-
Log.i(TAG, "Display/update remote control ");
3152-
3153-
mCurrentRcClientGen++;
3154-
3155-
// synchronously update the displays and clients with the new client generation
3156-
setNewRcClient(mCurrentRcClientGen,
3157-
rcse.mReceiverComponent /*event receiver*/,
3158-
false /*clearing*/);
3159-
3160-
// ask the current client that it needs to send info
3161-
try {
3162-
mCurrentRcClient.onInformationRequested(mCurrentRcClientGen,
3163-
flags, mArtworkExpectedWidth, mArtworkExpectedHeight);
3164-
} catch (RemoteException e) {
3165-
Log.e(TAG, "Current valid remote client is dead: "+e);
3166-
mCurrentRcClient = null;
3148+
synchronized(mRCStack) {
3149+
synchronized(mCurrentRcLock) {
3150+
if ((mCurrentRcClient != null) && (mCurrentRcClient.equals(rcse.mRcClient))) {
3151+
// TODO remove log before release
3152+
Log.i(TAG, "Display/update remote control ");
3153+
3154+
mCurrentRcClientGen++;
3155+
// synchronously update the displays and clients with
3156+
// the new client generation
3157+
setNewRcClient_syncAfRcsCurrc(mCurrentRcClientGen,
3158+
rcse.mReceiverComponent /*event receiver*/,
3159+
false /*clearing*/);
3160+
3161+
// ask the current client that it needs to send info
3162+
try {
3163+
mCurrentRcClient.onInformationRequested(mCurrentRcClientGen,
3164+
flags, mArtworkExpectedWidth, mArtworkExpectedHeight);
3165+
} catch (RemoteException e) {
3166+
Log.e(TAG, "Current valid remote client is dead: "+e);
3167+
mCurrentRcClient = null;
3168+
}
3169+
} else {
3170+
// the remote control display owner has changed between the
3171+
// the message to update the display was sent, and the time it
3172+
// gets to be processed (now)
31673173
}
3168-
} else {
3169-
// the remote control display owner has changed between the
3170-
// the message to update the display was sent, and the time it
3171-
// gets to be processed (now)
31723174
}
31733175
}
31743176
}

0 commit comments

Comments
 (0)