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