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

Commit 9dc52bc4 authored by Craig Mautner's avatar Craig Mautner
Browse files

Hide non user app windows from other users.

When transitioning between old user and new user application windows
from the old user may not be shown because only one user's windows
can be shown at a time.

Change-Id: I4e17b36c9100c9457cc6eb3cb3b77f3a94fa2b41
parent 82d53ce2
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -318,15 +318,25 @@ public class WindowManagerService extends IWindowManager.Stub
    final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
                mPolicy.enableKeyguard(true);
                synchronized(mKeyguardTokenWatcher) {
                    // lazily evaluate this next time we're asked to disable keyguard
                    mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
                    mKeyguardDisabled = false;
                }
            } else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                final int newUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
                Slog.v(TAG, "Switching user from " + mCurrentUserId + " to " + newUserId);
                mCurrentUserId = newUserId;
            }
        }
    };

    // Current user when multi-user is enabled. Don't show windows of non-current user.
    int mCurrentUserId;

    final Context mContext;

    final boolean mHaveInputMethods;
@@ -908,6 +918,8 @@ public class WindowManagerService extends IWindowManager.Stub
        // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
        IntentFilter filter = new IntentFilter();
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        // Track user switching.
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        mContext.registerReceiver(mBroadcastReceiver, filter);

        mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
+23 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;

import com.android.server.input.InputWindowHandle;

@@ -34,6 +37,7 @@ import android.graphics.RectF;
import android.graphics.Region;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Slog;
import android.view.DisplayInfo;
import android.view.Gravity;
@@ -257,6 +261,9 @@ final class WindowState implements WindowManagerPolicy.WindowState {

    DisplayContent  mDisplayContent;

    // UserId of the owner. Don't display windows of non-current user.
    final int mOwnerUserId;

    WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
           WindowState attachedWindow, int seq, WindowManager.LayoutParams a,
           int viewVisibility, final DisplayContent displayContent) {
@@ -264,6 +271,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        mSession = s;
        mClient = c;
        mToken = token;
        mOwnerUserId = UserHandle.getUserId(s.mUid);
        mAttrs.copyFrom(a);
        mViewVisibility = viewVisibility;
        mDisplayContent = displayContent;
@@ -894,6 +902,11 @@ final class WindowState implements WindowManagerPolicy.WindowState {
    }

    boolean showLw(boolean doAnimation, boolean requestAnim) {
        if (isOtherUsersAppWindow()) {
            Slog.w(TAG, "Current user " + mService.mCurrentUserId + " trying to display "
                    + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUserId);
            return false;
        }
        if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
            // Already showing.
            return false;
@@ -970,6 +983,16 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        return mClient.asBinder().isBinderAlive();
    }

    boolean isOtherUsersAppWindow() {
        final int type = mAttrs.type;
        if ((mOwnerUserId != mService.mCurrentUserId)
                && (type >= TYPE_BASE_APPLICATION) && (type <= LAST_APPLICATION_WINDOW)
                && (type !=  TYPE_APPLICATION_STARTING)) {
            return true;
        }
        return false;
    }

    private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
        outRegion.set(
                frame.left + inset.left, frame.top + inset.top,
+5 −0
Original line number Diff line number Diff line
@@ -1300,6 +1300,11 @@ class WindowStateAnimator {

    // This must be called while inside a transaction.
    boolean performShowLocked() {
        if (mWin.isOtherUsersAppWindow()) {
            Slog.w(TAG, "Current user " + mService.mCurrentUserId + " trying to display "
                    + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUserId);
            return false;
        }
        if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
            RuntimeException e = null;