Merge "Fix race condition causing screenshot view to be added to window twice" into sc-qpr1-dev am: 4c76184ee1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15717016

Change-Id: I0b4d1d6e8dd62c83619af8f2096d228e9320ad57
This commit is contained in:
Govinda Wasserman
2021-09-01 19:36:49 +00:00
committed by Automerger Merge Worker

View File

@@ -33,6 +33,7 @@ import static java.util.Objects.requireNonNull;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.annotation.MainThread;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityOptions; import android.app.ActivityOptions;
@@ -261,6 +262,7 @@ public class ScreenshotController {
private Bitmap mScreenBitmap; private Bitmap mScreenBitmap;
private SaveImageInBackgroundTask mSaveInBgTask; private SaveImageInBackgroundTask mSaveInBgTask;
private boolean mScreenshotTakenInPortrait; private boolean mScreenshotTakenInPortrait;
private boolean mBlockAttach;
private Animator mScreenshotAnimation; private Animator mScreenshotAnimation;
private RequestCallback mCurrentRequestCallback; private RequestCallback mCurrentRequestCallback;
@@ -731,6 +733,7 @@ public class ScreenshotController {
new ViewTreeObserver.OnWindowAttachListener() { new ViewTreeObserver.OnWindowAttachListener() {
@Override @Override
public void onWindowAttached() { public void onWindowAttached() {
mBlockAttach = false;
decorView.getViewTreeObserver().removeOnWindowAttachListener(this); decorView.getViewTreeObserver().removeOnWindowAttachListener(this);
action.run(); action.run();
} }
@@ -747,14 +750,16 @@ public class ScreenshotController {
mWindow.setContentView(contentView); mWindow.setContentView(contentView);
} }
@MainThread
private void attachWindow() { private void attachWindow() {
View decorView = mWindow.getDecorView(); View decorView = mWindow.getDecorView();
if (decorView.isAttachedToWindow()) { if (decorView.isAttachedToWindow() || mBlockAttach) {
return; return;
} }
if (DEBUG_WINDOW) { if (DEBUG_WINDOW) {
Log.d(TAG, "attachWindow"); Log.d(TAG, "attachWindow");
} }
mBlockAttach = true;
mWindowManager.addView(decorView, mWindowLayoutParams); mWindowManager.addView(decorView, mWindowLayoutParams);
decorView.requestApplyInsets(); decorView.requestApplyInsets();
} }