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

Commit 644b41a9 authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Update the current user again after registering UserChangeListener

Active user change event may not be caught by DesktopTasksController if
it happens between init and onInit() call.

Bug: 391666399
Test: manual - the correct Home activity is launched after minimizing
      the last task
Flag: EXEMPT - bug fix
Change-Id: I142ae3fc41dcb2021108748cc650a2016be510cb
parent b8a11f73
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -306,6 +306,8 @@ class DesktopTasksController(
            this,
        )
        shellController.addUserChangeListener(this)
        // Update the current user id again because it might be updated between init and onInit().
        updateCurrentUser(ActivityManager.getCurrentUser())
        transitions.addHandler(this)
        dragToDesktopTransitionHandler.dragToDesktopStateListener = dragToDesktopStateListener
        recentsTransitionHandler.addTransitionStateListener(
@@ -3544,10 +3546,16 @@ class DesktopTasksController(
    // TODO(b/366397912): Support full multi-user mode in Windowing.
    override fun onUserChanged(newUserId: Int, userContext: Context) {
        logV("onUserChanged previousUserId=%d, newUserId=%d", userId, newUserId)
        updateCurrentUser(newUserId)
    }

    private fun updateCurrentUser(newUserId: Int) {
        userId = newUserId
        taskRepository = userRepositories.getProfile(userId)
        if (this::snapEventHandler.isInitialized) {
            snapEventHandler.onUserChange()
        }
    }

    /** Called when a task's info changes. */
    fun onTaskInfoChanged(taskInfo: RunningTaskInfo) {