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

Commit c4440898 authored by Jorge Gil's avatar Jorge Gil
Browse files

Apply user-switch restoration logic in WMS#setCurrentUser

Otherwise it may be applied after the transition request is sent to
shell overwriting any of its custom restoration logic.

Flag: com.android.window.flags.apply_desk_activation_on_user_switch
Bug: 430988310
Test: switch users while desktops are active for both, check tasks are
restored correctly

Change-Id: Ib42d707d0f5c279042080c004044667a11c74f0c
parent 3dc0feb2
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
import android.window.DesktopExperienceFlags;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -2252,7 +2253,7 @@ class UserController implements Handler.Callback {
            // it should be moved outside, but for now it's not as there are many calls to
            // external components here afterwards
            updateProfileRelatedCaches();
            mInjector.getWindowManager().setCurrentUser(userId);
            mInjector.getWindowManager().setCurrentUser(userId, uss);
            mInjector.reportCurWakefulnessUsageEvent();
            // Once the internal notion of the active user has switched, we lock the device
            // with the option to show the user switcher on the keyguard.
@@ -3056,12 +3057,16 @@ class UserController implements Handler.Callback {
    }

    private void moveUserToForeground(UserState uss, int newUserId) {
        if (DesktopExperienceFlags.ENABLE_APPLY_DESK_ACTIVATION_ON_USER_SWITCH.isTrue()) {
            mInjector.taskSupervisorResumeFocusedStackTopActivity();
        } else {
            boolean homeInFront = mInjector.taskSupervisorSwitchUser(newUserId, uss);
            if (homeInFront) {
                mInjector.startHomeActivity(newUserId, "moveUserToForeground");
            } else {
                mInjector.taskSupervisorResumeFocusedStackTopActivity();
            }
        }
        EventLogTags.writeAmSwitchUser(newUserId);
    }

+7 −1
Original line number Diff line number Diff line
@@ -358,6 +358,7 @@ import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.UiThread;
import com.android.server.Watchdog;
import com.android.server.am.UserState;
import com.android.server.input.InputManagerService;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.pm.UserManagerInternal;
@@ -3903,7 +3904,8 @@ public class WindowManagerService extends IWindowManager.Stub
                confirm);
    }

    public void setCurrentUser(@UserIdInt int newUserId) {
    /** Update the current user. */
    public void setCurrentUser(@UserIdInt int newUserId, UserState uss) {
        synchronized (mGlobalLock) {
            final TransitionController controller = mAtmService.getTransitionController();
            final Transition transition = new Transition(TRANSIT_OPEN, 0 /* flags */, controller,
@@ -3923,6 +3925,10 @@ public class WindowManagerService extends IWindowManager.Stub

                // Hide windows that should not be seen by the new user.
                mRoot.switchUser(newUserId);
                if (DesktopExperienceFlags.ENABLE_APPLY_DESK_ACTIVATION_ON_USER_SWITCH.isTrue()) {
                    // Restore the new user's previous windows or home.
                    mRoot.switchUser(newUserId, uss);
                }
                mWindowPlacerLocked.performSurfacePlacement();

                // Notify whether the root docked task exists for the current user
+4 −2
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import android.os.Build;
import android.os.IBinder;
import android.os.InputConfig;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
@@ -127,6 +128,7 @@ import androidx.test.filters.SmallTest;

import com.android.compatibility.common.util.SystemUtil;
import com.android.internal.R;
import com.android.server.am.UserState;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.testutils.StubTransaction;
import com.android.server.wm.SensitiveContentPackages.PackageInfo;
@@ -932,7 +934,7 @@ public class WindowStateTests extends WindowTestsBase {
        Settings.Secure.putIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MAGNIFY_NAV_AND_IME, 0, 1);

        mWm.setCurrentUser(1);
        mWm.setCurrentUser(1, new UserState(UserHandle.of(1)));

        assertFalse(mWm.isMagnifyImeEnabled());
    }
@@ -945,7 +947,7 @@ public class WindowStateTests extends WindowTestsBase {
        Settings.Secure.putIntForUser(cr,
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MAGNIFY_NAV_AND_IME, 1, 2);

        mWm.setCurrentUser(2);
        mWm.setCurrentUser(2, new UserState(UserHandle.of(2)));

        assertTrue(mWm.isMagnifyImeEnabled());
    }