From b6ebbb019cbe85f7c37a5d9453e0db659307e0b3 Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Wed, 29 Nov 2023 14:08:43 +0000 Subject: [PATCH] Fixing dangling PS container on profile addition. When Work profile state is changed, the all apps container is redrawn Eventually `PrivateProfileManager.reset()` is also called but PS decorator is not added as there is no change in PS state. https://photos.app.goo.gl/V2bmZWfzBzcRP97C8 To fix this, we allow decorator addition on reset, but only apply the same when its not already present in the recycler view. Flag: ACONFIG com.android.launcher3.Flags.enable_private_space DEVELOPMENT Bug: 313498792 Test: PrivateProfileManagerTest Change-Id: I4c9a89d84e670ed45bf53a2d2e2c4922b165463e --- .../allapps/PrivateProfileManager.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index d8f6689fe1..77eb07e2d3 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -92,9 +92,6 @@ public class PrivateProfileManager extends UserProfileManager { boolean isEnabled = !mAllApps.getAppsStore() .hasModelFlag(FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED); int updatedState = isEnabled ? STATE_ENABLED : STATE_DISABLED; - if (getCurrentState() == updatedState) { - return; - } setCurrentState(updatedState); resetPrivateSpaceDecorator(updatedState); } @@ -126,19 +123,27 @@ public class PrivateProfileManager extends UserProfileManager { @VisibleForTesting void resetPrivateSpaceDecorator(int updatedState) { + ActivityAllAppsContainerView.AdapterHolder mainAdapterHolder = mAllApps.mAH.get(MAIN); if (updatedState == STATE_ENABLED) { - // Add Private Space Decorator to the Recycler view. + // Create a new decorator instance if not already available. if (mPrivateAppsSectionDecorator == null) { mPrivateAppsSectionDecorator = new PrivateAppsSectionDecorator( mAllApps.mActivityContext, - mAllApps.mAH.get(MAIN).mAppsList); + mainAdapterHolder.mAppsList); } - mAllApps.mAH.get(MAIN).mRecyclerView.addItemDecoration(mPrivateAppsSectionDecorator); + for (int i = 0; i < mainAdapterHolder.mRecyclerView.getItemDecorationCount(); i++) { + if (mainAdapterHolder.mRecyclerView.getItemDecorationAt(i) + .equals(mPrivateAppsSectionDecorator)) { + // No need to add another decorator if one is already present in recycler view. + return; + } + } + // Add Private Space Decorator to the Recycler view. + mainAdapterHolder.mRecyclerView.addItemDecoration(mPrivateAppsSectionDecorator); } else { // Remove Private Space Decorator from the Recycler view. if (mPrivateAppsSectionDecorator != null) { - mAllApps.mAH.get(MAIN).mRecyclerView - .removeItemDecoration(mPrivateAppsSectionDecorator); + mainAdapterHolder.mRecyclerView.removeItemDecoration(mPrivateAppsSectionDecorator); } } }