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

Commit 61ce1941 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Communal profile window persists on user switch

The window of a communal profile appears over other users, since it can
be used by any user. It should even remain on top after switching users,
so that, for example, a communal music playing app stays shown.

Bug: 274838657
Test: launch app in communal profile, switch users, ensure it's still
shown; do so with a non-communal app and ensure it isn't

Change-Id: Ic906351975ce7778a0d23911246c71206baa8516
parent ab75d2ce
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.UserProperties;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
@@ -148,6 +149,7 @@ import com.android.server.LocalServices;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.UserState;
import com.android.server.pm.UserManagerInternal;
import com.android.server.policy.PermissionPolicyInternal;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.utils.Slogf;
@@ -1856,6 +1858,14 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            rootTask.switchUser(userId);
        });


        if (topFocusedRootTask != null && isAlwaysVisibleUser(topFocusedRootTask.mUserId)) {
            Slog.i(TAG, "Persisting top task because it belongs to an always-visible user");
            // For a normal user-switch, we will restore the new user's task. But if the pre-switch
            // top task is an always-visible (Communal) one, keep it even after the switch.
            mUserRootTaskInFront.put(mCurrentUser, focusRootTaskId);
        }

        final int restoreRootTaskId = mUserRootTaskInFront.get(userId);
        Task rootTask = getRootTask(restoreRootTaskId);
        if (rootTask == null) {
@@ -1871,6 +1881,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        return homeInFront;
    }

    /** Returns whether the given user is to be always-visible (e.g. a communal profile). */
    private boolean isAlwaysVisibleUser(@UserIdInt int userId) {
        final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
        final UserProperties properties = umi.getUserProperties(userId);
        return properties != null && properties.getAlwaysVisible();
    }

    void removeUser(int userId) {
        mUserRootTaskInFront.delete(userId);
    }