diff options
| author | Marco Nelissen <marcone@google.com> | 2015-03-11 09:59:49 -0700 |
|---|---|---|
| committer | Marco Nelissen <marcone@google.com> | 2015-03-11 10:00:28 -0700 |
| commit | 926ebb860a8b5cbdec17f07404272be7c484fd79 (patch) | |
| tree | 2167cd0e594f42fc5514d136fe2154b053066e2b /core/java/android/widget/VideoView.java | |
| parent | 686947801e7c35eb60bf25385f46e45db66bee69 (diff) | |
| download | frameworks_base-926ebb860a8b5cbdec17f07404272be7c484fd79.zip frameworks_base-926ebb860a8b5cbdec17f07404272be7c484fd79.tar.gz frameworks_base-926ebb860a8b5cbdec17f07404272be7c484fd79.tar.bz2 | |
Fix context leak
Using an activity context with AudioManager could cause that context
to be held on to longer than desired, for example if the caller
acquired audio focus but never abandoned it. Fix acquire/abandon in
VideoView, and use the application context in AudioManager to mitigate
the issue for other misbehaving code.
Bug: https://code.google.com/p/android/issues/detail?id=152173
Change-Id: I0fb8390207422c784800dda25b1f2c03d4574bcd
Diffstat (limited to 'core/java/android/widget/VideoView.java')
| -rw-r--r-- | core/java/android/widget/VideoView.java | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java index 572cca2..47644f9 100644 --- a/core/java/android/widget/VideoView.java +++ b/core/java/android/widget/VideoView.java @@ -311,6 +311,8 @@ public class VideoView extends SurfaceView mMediaPlayer = null; mCurrentState = STATE_IDLE; mTargetState = STATE_IDLE; + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.abandonAudioFocus(null); } } @@ -319,12 +321,13 @@ public class VideoView extends SurfaceView // not ready for playback just yet, will try again later return; } - AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); - am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); - // we shouldn't clear the target state, because somebody might have // called start() previously release(false); + + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); + try { mMediaPlayer = new MediaPlayer(); // TODO: create SubtitleController in MediaPlayer, but we need @@ -650,6 +653,8 @@ public class VideoView extends SurfaceView if (cleartargetstate) { mTargetState = STATE_IDLE; } + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + am.abandonAudioFocus(null); } } |
