From 7d0769249f7d88c03c984b37849cea8bbdddff54 Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 31 May 2018 11:04:00 -0700 Subject: [PATCH] Avoid possibility of leaking an activity/service context The bug here was that we'd create a VideoFrameReleaseTimeHelper using whatever context DefaultRenderersFactory has, and it would then hold a reference to that context via DisplayManager. A leak could then occur if the player outlived the life of the context used to create it (which would be strange/unusual, but not impossible). Issue: #4249 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198747599 --- .../android/exoplayer2/video/MediaCodecVideoRenderer.java | 2 +- .../exoplayer2/video/VideoFrameReleaseTimeHelper.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index 579f7c45f48..d166297054e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -205,7 +205,7 @@ public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSel this.allowedJoiningTimeMs = allowedJoiningTimeMs; this.maxDroppedFramesToNotify = maxDroppedFramesToNotify; this.context = context.getApplicationContext(); - frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(context); + frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context); eventDispatcher = new EventDispatcher(eventHandler, eventListener); deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround(); pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT]; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java index 9036b19a754..b4835186ff2 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java @@ -72,8 +72,12 @@ public VideoFrameReleaseTimeHelper() { * @param context A context from which information about the default display can be retrieved. */ public VideoFrameReleaseTimeHelper(@Nullable Context context) { - windowManager = context == null ? null - : (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + if (context != null) { + context = context.getApplicationContext(); + windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + } else { + windowManager = null; + } if (windowManager != null) { displayListener = Util.SDK_INT >= 17 ? maybeBuildDefaultDisplayListenerV17(context) : null; vsyncSampler = VSyncSampler.getInstance();