diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java b/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java
index 20f8451037233..e8493f257029b 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java
@@ -21,6 +21,7 @@ import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.RenderNode;
import android.graphics.drawable.Drawable;
+import android.os.Handler;
import androidx.annotation.UiThread;
@@ -32,11 +33,14 @@ import java.util.List;
*
* To display on-screen, use {@link #getDrawable()}.
*/
-@UiThread
class ImageTileSet {
private static final String TAG = "ImageTileSet";
+ ImageTileSet(@UiThread Handler handler) {
+ mHandler = handler;
+ }
+
interface OnBoundsChangedListener {
/**
* Reports an update to the bounding box that contains all active tiles. These are virtual
@@ -54,6 +58,7 @@ class ImageTileSet {
private final List mTiles = new ArrayList<>();
private final Rect mBounds = new Rect();
+ private final Handler mHandler;
private OnContentChangedListener mOnContentChangedListener;
private OnBoundsChangedListener mOnBoundsChangedListener;
@@ -73,13 +78,32 @@ class ImageTileSet {
newBounds.union(newRect);
if (!newBounds.equals(mBounds)) {
mBounds.set(newBounds);
- if (mOnBoundsChangedListener != null) {
- mOnBoundsChangedListener.onBoundsChanged(
- newBounds.left, newBounds.top, newBounds.right, newBounds.bottom);
- }
+ notifyBoundsChanged(mBounds);
}
- if (mOnContentChangedListener != null) {
+ notifyContentChanged();
+ }
+
+ void notifyContentChanged() {
+ if (mOnContentChangedListener == null) {
+ return;
+ }
+ if (mHandler.getLooper().isCurrentThread()) {
mOnContentChangedListener.onContentChanged();
+ } else {
+ mHandler.post(() -> mOnContentChangedListener.onContentChanged());
+ }
+ }
+
+ void notifyBoundsChanged(Rect bounds) {
+ if (mOnBoundsChangedListener == null) {
+ return;
+ }
+ if (mHandler.getLooper().isCurrentThread()) {
+ mOnBoundsChangedListener.onBoundsChanged(
+ bounds.left, bounds.top, bounds.right, bounds.bottom);
+ } else {
+ mHandler.post(() -> mOnBoundsChangedListener.onBoundsChanged(
+ bounds.left, bounds.top, bounds.right, bounds.bottom));
}
}
@@ -162,14 +186,13 @@ class ImageTileSet {
}
void clear() {
- mBounds.set(0, 0, 0, 0);
+ if (mBounds.isEmpty()) {
+ return;
+ }
+ mBounds.setEmpty();
mTiles.forEach(ImageTile::close);
mTiles.clear();
- if (mOnBoundsChangedListener != null) {
- mOnBoundsChangedListener.onBoundsChanged(0, 0, 0, 0);
- }
- if (mOnContentChangedListener != null) {
- mOnContentChangedListener.onContentChanged();
- }
+ notifyBoundsChanged(mBounds);
+ notifyContentChanged();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
index 25438a6f57bae..ee9dc0e9f72d1 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
@@ -91,7 +91,7 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
mBgExecutor = bgExecutor;
mImageExporter = exporter;
mUiEventLogger = uiEventLogger;
- mImageTileSet = new ImageTileSet();
+ mImageTileSet = new ImageTileSet(context.getMainThreadHandler());
}
/**