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

Commit d570a556 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Remove manual freezing screen

Currently this is only used when switching to a new user. That was a
workaround of bug 279773661. In the case, the UserSwitchingDialog
looks flickering because the animation incorrectly put the top activity
(setupwizard) at a higher z-order than the overlay window, which causes
  dialog (cover on top) -> activity (animating wrong z-order)
     -> dialog (animation finished) -> activity (dialog dismissed)

The incorrect z-order was fixed by the change
If6c12d4c4ee3b19abbe1fe4307dd4acae35e5cf8 (wm.Transition)
Which makes the transition recognize that the top activity is
a dependent change which shouldn't be put at transition root.

So now UserSwitchingDialog can always stay on top during switching
user, then startFreezingScreen/stopFreezingScreen are no longer needed.

Bug: 389860816
Flag: EXEMPT bugfix
Test: Switch to a new user. The animation appearance is the same as
      before this change.
Change-Id: I73685cbfc1beb1fc4066daa870408a23c731f551
parent e4046a28
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -208,9 +208,6 @@ interface IWindowManager
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    void endProlongedAnimations();

    void startFreezingScreen(int exitAnim, int enterAnim);
    void stopFreezingScreen();

    // these require DISABLE_KEYGUARD permission
    /** @deprecated use Activity.setShowWhenLocked instead. */
    void disableKeyguard(IBinder token, String tag, int userId);
+1 −2
Original line number Diff line number Diff line
@@ -4060,8 +4060,7 @@ class UserController implements Handler.Callback {
            synchronized (mUserSwitchingDialogLock) {
                dismissUserSwitchingDialog(null);
                mUserSwitchingDialog = new UserSwitchingDialog(mService.mContext, fromUser, toUser,
                        switchingFromSystemUserMessage, switchingToSystemUserMessage,
                        getWindowManager());
                        switchingFromSystemUserMessage, switchingToSystemUserMessage);
                mUserSwitchingDialog.show(onShown);
            }
        }
+2 −44
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.util.Slog;
import android.util.TypedValue;
import android.view.View;
@@ -53,7 +52,6 @@ import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.util.ObjectUtils;
import com.android.internal.util.UserIcons;
import com.android.server.wm.WindowManagerService;

import java.util.concurrent.atomic.AtomicBoolean;

@@ -80,14 +78,11 @@ class UserSwitchingDialog extends Dialog {
    protected final UserInfo mNewUser;
    private final String mSwitchingFromSystemUserMessage;
    private final String mSwitchingToSystemUserMessage;
    private final WindowManagerService mWindowManager;
    protected final Context mContext;
    private final int mTraceCookie;
    private final boolean mNeedToFreezeScreen;

    UserSwitchingDialog(Context context, UserInfo oldUser, UserInfo newUser,
            String switchingFromSystemUserMessage, String switchingToSystemUserMessage,
            WindowManagerService windowManager) {
            String switchingFromSystemUserMessage, String switchingToSystemUserMessage) {
        super(context, R.style.Theme_Material_NoActionBar_Fullscreen);

        mContext = context;
@@ -97,8 +92,6 @@ class UserSwitchingDialog extends Dialog {
        mSwitchingToSystemUserMessage = switchingToSystemUserMessage;
        mDisableAnimations = SystemProperties.getBoolean(
                "debug.usercontroller.disable_user_switching_dialog_animations", false);
        mWindowManager = windowManager;
        mNeedToFreezeScreen = !mDisableAnimations && !isUserSetupComplete(newUser);
        mTraceCookie = UserHandle.MAX_SECONDARY_USER_ID * oldUser.id + newUser.id;

        inflateContent();
@@ -183,11 +176,6 @@ class UserSwitchingDialog extends Dialog {
                : res.getString(R.string.user_switching_message, mNewUser.name);
    }

    private boolean isUserSetupComplete(UserInfo user) {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.USER_SETUP_COMPLETE, /* default= */ 0, user.id) == 1;
    }

    @Override
    public void show() {
        asyncTraceBegin("dialog", 0);
@@ -197,7 +185,6 @@ class UserSwitchingDialog extends Dialog {
    @Override
    public void dismiss() {
        super.dismiss();
        stopFreezingScreen();
        asyncTraceEnd("dialog", 0);
    }

@@ -205,7 +192,6 @@ class UserSwitchingDialog extends Dialog {
        if (DEBUG) Slog.d(TAG, "show called");
        show();
        startShowAnimation(() -> {
            startFreezingScreen();
            onShown.run();
        });
    }
@@ -223,24 +209,6 @@ class UserSwitchingDialog extends Dialog {
        }
    }

    private void startFreezingScreen() {
        if (!mNeedToFreezeScreen) {
            return;
        }
        traceBegin("startFreezingScreen");
        mWindowManager.startFreezingScreen(0, 0);
        traceEnd("startFreezingScreen");
    }

    private void stopFreezingScreen() {
        if (!mNeedToFreezeScreen) {
            return;
        }
        traceBegin("stopFreezingScreen");
        mWindowManager.stopFreezingScreen();
        traceEnd("stopFreezingScreen");
    }

    private void startShowAnimation(Runnable onAnimationEnd) {
        if (mDisableAnimations) {
            onAnimationEnd.run();
@@ -260,7 +228,7 @@ class UserSwitchingDialog extends Dialog {
    }

    private void startDismissAnimation(Runnable onAnimationEnd) {
        if (mDisableAnimations || mNeedToFreezeScreen) {
        if (mDisableAnimations) {
            // animations are disabled or screen is frozen, no need to play an animation
            onAnimationEnd.run();
            return;
@@ -352,14 +320,4 @@ class UserSwitchingDialog extends Dialog {
        Trace.asyncTraceEnd(TRACE_TAG, TAG + subTag, mTraceCookie + subCookie);
        if (DEBUG) Slog.d(TAG, "asyncTraceEnd-" + subTag);
    }

    private void traceBegin(String msg) {
        if (DEBUG) Slog.d(TAG, "traceBegin-" + msg);
        Trace.traceBegin(TRACE_TAG, msg);
    }

    private void traceEnd(String msg) {
        Trace.traceEnd(TRACE_TAG);
        if (DEBUG) Slog.d(TAG, "traceEnd-" + msg);
    }
}
+3 −73
Original line number Diff line number Diff line
@@ -751,8 +751,6 @@ public class WindowManagerService extends IWindowManager.Stub
    final static int WINDOWS_FREEZING_SCREENS_TIMEOUT = 2;
    int mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;

    /** Indicates that the system server is actively demanding the screen be frozen. */
    boolean mClientFreezingScreen = false;
    int mAppsFreezingScreen = 0;

    @VisibleForTesting
@@ -3356,60 +3354,6 @@ public class WindowManagerService extends IWindowManager.Stub
        return getDefaultDisplayContentLocked().mAppTransition.isIdle();
    }


    // -------------------------------------------------------------
    // Misc IWindowSession methods
    // -------------------------------------------------------------

    /** Freeze the screen during a user-switch event. Called by UserController. */
    @Override
    public void startFreezingScreen(int exitAnim, int enterAnim) {
        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
                "startFreezingScreen()")) {
            throw new SecurityException("Requires FREEZE_SCREEN permission");
        }

        synchronized (mGlobalLock) {
            if (!mClientFreezingScreen) {
                mClientFreezingScreen = true;
                final long origId = Binder.clearCallingIdentity();
                try {
                    startFreezingDisplay(exitAnim, enterAnim);
                    mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
                    mH.sendEmptyMessageDelayed(H.CLIENT_FREEZE_TIMEOUT, 5000);
                } finally {
                    Binder.restoreCallingIdentity(origId);
                }
            }
        }
    }

    /**
     * No longer actively demand that the screen remain frozen.
     * Called by UserController after a user-switch.
     * This doesn't necessarily immediately unlock the screen; it just allows it if we're ready.
     */
    @Override
    public void stopFreezingScreen() {
        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
                "stopFreezingScreen()")) {
            throw new SecurityException("Requires FREEZE_SCREEN permission");
        }

        synchronized (mGlobalLock) {
            if (mClientFreezingScreen) {
                mClientFreezingScreen = false;
                mLastFinishedFreezeSource = "client";
                final long origId = Binder.clearCallingIdentity();
                try {
                    stopFreezingDisplayLocked();
                } finally {
                    Binder.restoreCallingIdentity(origId);
                }
            }
        }
    }

    @Override
    public void disableKeyguard(IBinder token, String tag, int userId) {
        userId = mAmInternal.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
@@ -5671,7 +5615,6 @@ public class WindowManagerService extends IWindowManager.Stub
        public static final int WAITING_FOR_DRAWN_TIMEOUT = 24;
        public static final int SHOW_STRICT_MODE_VIOLATION = 25;

        public static final int CLIENT_FREEZE_TIMEOUT = 30;
        public static final int NOTIFY_ACTIVITY_DRAWN = 32;

        public static final int NEW_ANIMATOR_SCALE = 34;
@@ -5761,17 +5704,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    break;
                }

                case CLIENT_FREEZE_TIMEOUT: {
                    synchronized (mGlobalLock) {
                        if (mClientFreezingScreen) {
                            mClientFreezingScreen = false;
                            mLastFinishedFreezeSource = "client-timeout";
                            stopFreezingDisplayLocked();
                        }
                    }
                    break;
                }

                case REPORT_WINDOWS_CHANGE: {
                    if (mWindowsChanged) {
                        synchronized (mGlobalLock) {
@@ -6509,14 +6441,14 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        if (waitingForConfig || waitingForRemoteDisplayChange || mAppsFreezingScreen > 0
                || mWindowsFreezingScreen == WINDOWS_FREEZING_SCREENS_ACTIVE
                || mClientFreezingScreen || numOpeningApps > 0) {
                || numOpeningApps > 0) {
            ProtoLog.d(WM_DEBUG_ORIENTATION, "stopFreezingDisplayLocked: Returning "
                    + "waitingForConfig=%b, waitingForRemoteDisplayChange=%b, "
                    + "mAppsFreezingScreen=%d, mWindowsFreezingScreen=%d, "
                    + "mClientFreezingScreen=%b, mOpeningApps.size()=%d",
                    + "mOpeningApps.size()=%d",
                    waitingForConfig, waitingForRemoteDisplayChange,
                    mAppsFreezingScreen, mWindowsFreezingScreen,
                    mClientFreezingScreen, numOpeningApps);
                    numOpeningApps);
            return;
        }

@@ -6546,7 +6478,6 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        ProtoLog.i(WM_ERROR, "%s", sb.toString());
        mH.removeMessages(H.APP_FREEZE_TIMEOUT);
        mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
        if (PROFILE_ORIENTATION) {
            Debug.stopMethodTracing();
        }
@@ -7053,7 +6984,6 @@ public class WindowManagerService extends IWindowManager.Stub
            pw.print("  mTransactionSequence="); pw.println(mTransactionSequence);
            pw.print("  mDisplayFrozen="); pw.print(mDisplayFrozen);
                    pw.print(" windows="); pw.print(mWindowsFreezingScreen);
                    pw.print(" client="); pw.print(mClientFreezingScreen);
                    pw.print(" apps="); pw.println(mAppsFreezingScreen);
            final DisplayContent defaultDisplayContent = getDefaultDisplayContentLocked();
            pw.print("  mRotation="); pw.println(defaultDisplayContent.getRotation());