From 2cecad8e756810b9853056b1ce2d43b3c3da5600 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Mon, 17 May 2021 00:33:54 -0700 Subject: [PATCH] Catch NPE for AllAppsContainerView.dispatchRestoreInstanceState TL;DR;; Missing view id for work profile recycler view caused restore failure as there are different type of views that contains same id. However, even after that fix, lack of view id in slice views generated by other process causes failure when mFlags on these not restored slice views needs to be accessed. Bug: 186596139 Test: manual Change-Id: I8a97598c27acbc05ac8a39c50fe5862e541d62ad --- res/values/id.xml | 1 + .../launcher3/allapps/AllAppsContainerView.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/res/values/id.xml b/res/values/id.xml index 39c49bd5e1..1bd40cec4a 100644 --- a/res/values/id.xml +++ b/res/values/id.xml @@ -15,6 +15,7 @@ limitations under the License. --> + diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 7be1138b5f..6f26e3b93b 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -30,11 +30,13 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; +import android.os.Parcelable; import android.os.Process; import android.text.Selection; import android.text.SpannableStringBuilder; import android.util.AttributeSet; import android.util.Log; +import android.util.SparseArray; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -133,6 +135,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo private int mHeaderColor; + public AllAppsContainerView(Context context) { this(context, null); } @@ -171,6 +174,19 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo mAllAppsStore.addUpdateListener(this::onAppsUpdated); } + @Override + protected void dispatchRestoreInstanceState(SparseArray sparseArray) { + try { + // Many slice view id is not properly assigned, and hence throws null + // pointer exception in the underneath method. Catching the exception + // simply doesn't restore these slice views. This doesn't have any + // user visible effect because because we query them again. + super.dispatchRestoreInstanceState(sparseArray); + } catch (Exception e) { + Log.e("AllAppsContainerView", "restoreInstanceState viewId = 0", e); + } + } + /** * Sets the long click listener for icons */ @@ -438,6 +454,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo setupWorkToggle(); mAH[AdapterHolder.MAIN].setup(mViewPager.getChildAt(0), mPersonalMatcher); mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkMatcher); + mAH[AdapterHolder.WORK].recyclerView.setId(R.id.apps_list_view_work); mViewPager.getPageIndicator().setActiveMarker(AdapterHolder.MAIN); findViewById(R.id.tab_personal) .setOnClickListener((View view) -> {