am 0ddb0143: Merge "Fix 5623252 unlink to death of audio focus client early" into ics-mr1

* commit '0ddb0143895b816d4ff5c174b346390e07f26556':
  Fix 5623252 unlink to death of audio focus client early
This commit is contained in:
Jean-Michel Trivi
2011-11-15 18:21:44 -08:00
committed by Android Git Automerger

View File

@@ -2693,21 +2693,21 @@ public class AudioService extends IAudioService.Stub {
mCallingUid = uid;
}
private void unlinkToDeath() {
if (mSourceRef != null && mHandler != null) {
mSourceRef.unlinkToDeath(mHandler, 0);
public void unlinkToDeath() {
try {
if (mSourceRef != null && mHandler != null) {
mSourceRef.unlinkToDeath(mHandler, 0);
mHandler = null;
}
} catch (java.util.NoSuchElementException e) {
Log.e(TAG, "Encountered " + e + " in FocusStackEntry.unlinkToDeath()");
}
}
@Override
protected void finalize() throws Throwable {
try {
unlinkToDeath();
} catch (java.util.NoSuchElementException e) {
Log.w(TAG, e + " thrown by unlinkToDeath() during finalize, ignoring");
} finally {
super.finalize();
}
unlinkToDeath(); // unlink exception handled inside method
super.finalize();
}
}
@@ -2739,11 +2739,12 @@ public class AudioService extends IAudioService.Stub {
* focus, notify the next item in the stack it gained focus.
*/
private void removeFocusStackEntry(String clientToRemove, boolean signal) {
// is the current top of the focus stack abandoning focus? (because of death or request)
// is the current top of the focus stack abandoning focus? (because of request, not death)
if (!mFocusStack.empty() && mFocusStack.peek().mClientId.equals(clientToRemove))
{
//Log.i(TAG, " removeFocusStackEntry() removing top of stack");
mFocusStack.pop();
FocusStackEntry fse = mFocusStack.pop();
fse.unlinkToDeath();
if (signal) {
// notify the new top of the stack it gained focus
notifyTopOfAudioFocusStack();
@@ -2762,6 +2763,7 @@ public class AudioService extends IAudioService.Stub {
Log.i(TAG, " AudioFocus abandonAudioFocus(): removing entry for "
+ fse.mClientId);
stackIterator.remove();
fse.unlinkToDeath();
}
}
}
@@ -2770,7 +2772,7 @@ public class AudioService extends IAudioService.Stub {
/**
* Helper function:
* Called synchronized on mAudioFocusLock
* Remove focus listeners from the focus stack for a particular client.
* Remove focus listeners from the focus stack for a particular client when it has died.
*/
private void removeFocusStackEntryForClient(IBinder cb) {
// is the owner of the audio focus part of the client to remove?
@@ -2783,6 +2785,7 @@ public class AudioService extends IAudioService.Stub {
Log.i(TAG, " AudioFocus abandonAudioFocus(): removing entry for "
+ fse.mClientId);
stackIterator.remove();
// the client just died, no need to unlink to its death
}
}
if (isTopOfStackForClientToRemove) {
@@ -2874,7 +2877,8 @@ public class AudioService extends IAudioService.Stub {
}
// the reason for the audio focus request has changed: remove the current top of
// stack and respond as if we had a new focus owner
mFocusStack.pop();
FocusStackEntry fse = mFocusStack.pop();
fse.unlinkToDeath();
}
// notify current top of stack it is losing focus