Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01e0009b authored by sfufa@google.com's avatar sfufa@google.com
Browse files

[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
parent 516584e6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
+5 −4
Original line number Diff line number Diff line
@@ -113,11 +113,13 @@ 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;
        if (mWorkEnabled != isEnabled) {
            mWorkEnabled = isEnabled;
            updateVisibility();
        }
    }


    private void 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);
+1 −1
Original line number Diff line number Diff line
@@ -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);