From 6c137496fe6ffecf7d1f319f5de9fda50930085b Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Tue, 20 Sep 2022 09:19:56 -0400 Subject: [PATCH 1/2] Always reset screenshot preview to alpha=1 It's possible for the screenshot process to not get shut down as soon as the UI disappears. If this occurs after a shared transition (which sets the preview to alpha=0 to hide it as part of the transition), the preview gets stuck at alpha=0 and isn't visible. Always resetting the screenshot view and setting alpha=1 guarantees that regardless of the state of the screenshot process, we always start from a clean slate. Bug: 242862442 Test: forced the screenshot process to stay up by never running the finish callback in ScreenshotHelper, verified that we get the invisible-preview behavior and that it's fixed with this change Change-Id: I9b795928cba93f8cef19244105db2c7f31c0973b --- .../com/android/systemui/screenshot/ScreenshotController.java | 3 ++- .../src/com/android/systemui/screenshot/ScreenshotView.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 69ee8e8fb8dc0..3fee232b34658 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -555,6 +555,8 @@ public class ScreenshotController { mScreenshotView.announceForAccessibility( mContext.getResources().getString(R.string.screenshot_saving_title))); + mScreenshotView.reset(); + if (mScreenshotView.isAttachedToWindow()) { // if we didn't already dismiss for another reason if (!mScreenshotView.isDismissing()) { @@ -564,7 +566,6 @@ public class ScreenshotController { Log.d(TAG, "saveScreenshot: screenshotView is already attached, resetting. " + "(dismissing=" + mScreenshotView.isDismissing() + ")"); } - mScreenshotView.reset(); } mPackageName = topComponent == null ? "" : topComponent.getPackageName(); mScreenshotView.setPackageName(mPackageName); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java index 5e7fc6faef1fc..360fc879731c7 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java @@ -1006,6 +1006,7 @@ public class ScreenshotView extends FrameLayout implements // Clear any references to the bitmap mScreenshotPreview.setImageDrawable(null); mScreenshotPreview.setVisibility(View.INVISIBLE); + mScreenshotPreview.setAlpha(1f); mScreenshotPreviewBorder.setAlpha(0); mPendingSharedTransition = false; mActionsContainerBackground.setVisibility(View.GONE); From 9f8f1fd9a7f22db4c89fbdf0b03885eac70e327f Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Wed, 21 Sep 2022 11:49:47 -0400 Subject: [PATCH 2/2] 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));