summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/VideoView.java
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2015-03-11 09:59:49 -0700
committerMarco Nelissen <marcone@google.com>2015-03-11 10:00:28 -0700
commit926ebb860a8b5cbdec17f07404272be7c484fd79 (patch)
tree2167cd0e594f42fc5514d136fe2154b053066e2b /core/java/android/widget/VideoView.java
parent686947801e7c35eb60bf25385f46e45db66bee69 (diff)
downloadframeworks_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.java11
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);
}
}