summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jean-Michel Trivi <jmtrivi@google.com> 2011-11-14 14:38:30 -0800
committer Android Git Automerger <android-git-automerger@android.com> 2011-11-14 14:38:30 -0800
commitf1ec32db686586eddd023583e1c5978005c06d58 (patch)
treee539f119e3f2031d42cecd584a1e591bf94d882b
parent28a5ec9613a824d2ec15ce5e5cec77a6fcf444d5 (diff)
parent9d36a99582518ed1a7fb005382e0128479b43e18 (diff)
am 9d36a995: am 258576a8: Merge "Fix 5607938 AudioFocusDeathHandler leaks GREF" into ics-mr1
* commit '9d36a99582518ed1a7fb005382e0128479b43e18': Fix 5607938 AudioFocusDeathHandler leaks GREF
-rw-r--r--media/java/android/media/AudioService.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index a06afc8391c9..54f72260fa2b 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -2687,11 +2687,22 @@ public class AudioService extends IAudioService.Stub {
mCallingUid = uid;
}
- public void unlinkToDeath() {
+ private void unlinkToDeath() {
if (mSourceRef != null && mHandler != null) {
mSourceRef.unlinkToDeath(mHandler, 0);
}
}
+
+ @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();
+ }
+ }
}
private Stack<FocusStackEntry> mFocusStack = new Stack<FocusStackEntry>();
@@ -2726,8 +2737,7 @@ public class AudioService extends IAudioService.Stub {
if (!mFocusStack.empty() && mFocusStack.peek().mClientId.equals(clientToRemove))
{
//Log.i(TAG, " removeFocusStackEntry() removing top of stack");
- FocusStackEntry fse = mFocusStack.pop();
- fse.unlinkToDeath();
+ mFocusStack.pop();
if (signal) {
// notify the new top of the stack it gained focus
notifyTopOfAudioFocusStack();
@@ -2746,7 +2756,6 @@ public class AudioService extends IAudioService.Stub {
Log.i(TAG, " AudioFocus abandonAudioFocus(): removing entry for "
+ fse.mClientId);
stackIterator.remove();
- fse.unlinkToDeath();
}
}
}
@@ -2852,6 +2861,9 @@ public class AudioService extends IAudioService.Stub {
// if focus is already owned by this client and the reason for acquiring the focus
// hasn't changed, don't do anything
if (mFocusStack.peek().mFocusChangeType == focusChangeHint) {
+ // unlink death handler so it can be gc'ed.
+ // linkToDeath() creates a JNI global reference preventing collection.
+ cb.unlinkToDeath(afdh, 0);
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
// the reason for the audio focus request has changed: remove the current top of