From 750c5af2da66f073dd3881664f63e97bc8702032 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 26 Jul 2023 10:16:04 -0700 Subject: [PATCH] Fix flaky RuntimeException in CellLayout. Changing the grid while a previous loader is running (more likely to happen in test) can cause a saved item info to have a cell position outside the bounds of the new grid. This should just be handled the same way as other item infos being loaded in an occupied space. Flag: not needed Fixes: 233989158 Test: changed grid sizes multiple times Change-Id: Ibba337c224e7a08533331a87b1369ebf96e3c9a3 --- src/com/android/launcher3/CellLayout.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 64ac84166f..4674401b2b 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -2735,11 +2735,13 @@ public class CellLayout extends ViewGroup { } public boolean isOccupied(int x, int y) { - if (x < mCountX && y < mCountY) { + if (x >= 0 && x < mCountX && y >= 0 && y < mCountY) { return mOccupied.cells[x][y]; - } else { + } + if (BuildConfig.IS_STUDIO_BUILD) { throw new RuntimeException("Position exceeds the bound of this CellLayout"); } + return true; } @Override