From 01e0009b71b7185f4000e7b1aaab88814a952caf Mon Sep 17 00:00:00 2001 From: "sfufa@google.com" Date: Wed, 6 Oct 2021 14:27:09 -0700 Subject: [PATCH] [Work profile] Fix flickering work mode switch Since there is no system broadcast with Intent.ACTION_MANAGED_PROFILE_ADDED, UserCache's user list does not get updated when a new profile is installed until launcher is restarted. This change fixes that problem by getting the freshest list of users directly from UserManager. This change also applies the proper padding to work apps recycler-view after work mode switch is attached. Test: Manual Bug: 201191227 Change-Id: I0f570eba44ebb845d0d6f8c5f14a63f9a8c18539 --- .../android/launcher3/allapps/AllAppsContainerView.java | 1 + src/com/android/launcher3/allapps/WorkModeSwitch.java | 9 +++++---- src/com/android/launcher3/model/UserManagerState.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 3f1f915923..9bb4b25fdc 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -491,6 +491,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo mViewPager.initParentViews(this); mViewPager.getPageIndicator().setOnActivePageChangedListener(this); mWorkManager.attachWorkModeSwitch(); + mWorkManager.getWorkModeSwitch().post(() -> mAH[AdapterHolder.WORK].applyPadding()); } else { mWorkManager.detachWorkModeSwitch(); mViewPager = null; diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java index 5d640412be..be015817d0 100644 --- a/src/com/android/launcher3/allapps/WorkModeSwitch.java +++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java @@ -113,10 +113,12 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi /** * Sets the enabled or disabled state of the button */ - public void updateCurrentState(boolean active) { + public void updateCurrentState(boolean isEnabled) { removeFlag(FLAG_PROFILE_TOGGLE_ONGOING); - mWorkEnabled = active; - updateVisibility(); + if (mWorkEnabled != isEnabled) { + mWorkEnabled = isEnabled; + updateVisibility(); + } } @@ -125,7 +127,6 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi if (mWorkEnabled && mOnWorkTab) { setFlag(FLAG_FADE_ONGOING); setVisibility(VISIBLE); - setAlpha(0); animate().alpha(1).withEndAction(() -> removeFlag(FLAG_FADE_ONGOING)).start(); } else if (getVisibility() != GONE) { setFlag(FLAG_FADE_ONGOING); diff --git a/src/com/android/launcher3/model/UserManagerState.java b/src/com/android/launcher3/model/UserManagerState.java index 3a4206c144..97a5905f0a 100644 --- a/src/com/android/launcher3/model/UserManagerState.java +++ b/src/com/android/launcher3/model/UserManagerState.java @@ -36,7 +36,7 @@ public class UserManagerState { * Initialises the state values for all users */ public void init(UserCache userCache, UserManager userManager) { - for (UserHandle user : userCache.getUserProfiles()) { + for (UserHandle user : userManager.getUserProfiles()) { long serialNo = userCache.getSerialNumberForUser(user); boolean isUserQuiet = userManager.isQuietModeEnabled(user); allUsers.put(serialNo, user);