Add kill switch for ViewPool.initPool.

This fixes an issue where, in fast E2E tests, the test can complete before initPool is completed. This results in the ViewPool continuing to create TaskViews and therefore TaskThumbnailViews after RecentsDeps is destroyed. Doing this causes a crash.

Stopping the ViewPool.initPool thread before destroying RecentsDeps fixes this.

Bug: 390156722
Flag: com.android.launcher3.enable_refactor_task_thumbnail
Test: fast E2E tests in presubmit e.g. AllAppsImageTest
Change-Id: I0f8801ca75cda383df8ed96077cf1b7178771cb6
This commit is contained in:
Uwais Ashraf
2025-01-20 23:57:21 +00:00
parent e545182223
commit 6322c00b70
2 changed files with 20 additions and 2 deletions
+13 -2
View File
@@ -44,6 +44,9 @@ public class ViewPool<T extends View & Reusable> {
private int mCurrentSize = 0;
@Nullable
private Thread mViewPoolInitThread;
public ViewPool(Context context, @Nullable ViewGroup parent,
int layoutId, int maxSize, int initialSize) {
this(LayoutInflater.from(context).cloneInContext(context),
@@ -74,13 +77,15 @@ public class ViewPool<T extends View & Reusable> {
// Inflate views on a non looper thread. This allows us to catch errors like calling
// "new Handler()" in constructor easily.
new Thread(() -> {
mViewPoolInitThread = new Thread(() -> {
for (int i = 0; i < initialSize; i++) {
T view = inflateNewView(inflater);
handler.post(() -> addToPool(view));
}
Log.d(TAG, "initPool complete");
}, "ViewPool-init").start();
mViewPoolInitThread = null;
}, "ViewPool-init");
mViewPoolInitThread.start();
}
@UiThread
@@ -117,6 +122,12 @@ public class ViewPool<T extends View & Reusable> {
return (T) inflater.inflate(mLayoutId, mParent, false);
}
public void killOngoingInitializations() throws InterruptedException {
if (mViewPoolInitThread != null) {
mViewPoolInitThread.join();
}
}
/**
* Interface to indicate that a view is reusable
*/