From 9f8f1fd9a7f22db4c89fbdf0b03885eac70e327f Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Wed, 21 Sep 2022 11:49:47 -0400 Subject: [PATCH] Clean up leaked screenshot connections If a subsequent screenshot is taken after we bind to the screenshot service, but before we get the onServiceConnected callback, we leak the connection to the service, preventing it from ever getting shut down. Fix this by unbinding the old connection before connecting with the new one. Bug: 242862442 Fix: 242862442 Test: forced DisplayPolicy to take two consecutive screenshots Change-Id: Iffb62170266a2c1bb332bfb416f0f5e19c5236fb --- core/java/com/android/internal/util/ScreenshotHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index 9474f6fc3252f..79c519645a24d 100644 --- a/core/java/com/android/internal/util/ScreenshotHelper.java +++ b/core/java/com/android/internal/util/ScreenshotHelper.java @@ -377,6 +377,9 @@ public class ScreenshotHelper { msg.replyTo = new Messenger(h); if (mScreenshotConnection == null || mScreenshotService == null) { + if (mScreenshotConnection != null) { + resetConnection(); + } final ComponentName serviceComponent = ComponentName.unflattenFromString( mContext.getResources().getString( com.android.internal.R.string.config_screenshotServiceComponent));