From 47d72ffccb759bb4d6b2aec9a706ff8517ded50f Mon Sep 17 00:00:00 2001 From: Fengjiang Li Date: Mon, 15 May 2023 21:51:10 -0700 Subject: [PATCH] Fix NPE of FolderPagedView#setFocusOnFirstChild Test: open and close folder with swipe back quickly Fix: 282814528 Change-Id: I163c2f9d54b48684738f8104be8c085f26b52ceb --- .../android/launcher3/folder/FolderPagedView.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index 6ff8ece5d7..26a1886695 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -46,7 +46,6 @@ import com.android.launcher3.keyboard.ViewGroupFocusHelper; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.pageindicators.PageIndicatorDots; -import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.ViewCache; @@ -421,10 +420,15 @@ public class FolderPagedView extends PagedView implements Cli * Sets the focus on the first visible child. */ public void setFocusOnFirstChild() { - View firstChild = getCurrentCellLayout().getChildAt(0, 0); - if (firstChild != null) { - firstChild.requestFocus(); + CellLayout currentCellLayout = getCurrentCellLayout(); + if (currentCellLayout == null) { + return; } + View firstChild = currentCellLayout.getChildAt(0, 0); + if (firstChild == null) { + return; + } + firstChild.requestFocus(); } @Override