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

Commit 9d588a70 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

DO NOT MERGE: Don't let keyguard to influence orientation when dismissing

When keyguard is being dismissed it still was overriding orientation
for the display, which caused report of wrong configuration to
activity that was becoming visible.

Bug: 66979760
Bug: 36897968
Bug: 62796190
Bug: 62904487
Bug: 38494778
Test: Launch Unity 4 based game, lock and unlock screen, check UI
Test: com.android.server.wm.DisplayContentTests#testOrientationDefinedByKeyguard
Change-Id: I0a180b8e941a85ba4174a40cdec2ff0b8f3e00eb
parent e68565b6
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -225,9 +225,6 @@ public abstract class WindowManagerInternal {
     */
     */
    public abstract boolean isKeyguardLocked();
    public abstract boolean isKeyguardLocked();


    /** @return {@code true} if the keyguard is going away. */
    public abstract boolean isKeyguardGoingAway();

    /**
    /**
    * @return Whether the keyguard is showing and not occluded.
    * @return Whether the keyguard is showing and not occluded.
    */
    */
+0 −20
Original line number Original line Diff line number Diff line
@@ -2249,26 +2249,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        mTmpConfig.unset();
        mTmpConfig.unset();
        computeBounds(mTmpBounds);
        computeBounds(mTmpBounds);
        if (mTmpBounds.equals(mBounds)) {
        if (mTmpBounds.equals(mBounds)) {
            final ActivityStack stack = getStack();
            if (!mBounds.isEmpty() || task == null || stack == null || !task.mFullscreen) {
                // We don't want to influence the override configuration here if our task is in
                // multi-window mode or there is a bounds specified to calculate the override
                // config. In both of this cases the app should be compatible with whatever the
                // current configuration is or will be.
                return;
            }

            // Currently limited to the top activity for now to avoid situations where non-top
            // visible activity and top might have conflicting requests putting the non-top activity
            // windows in an odd state.
            final ActivityRecord top = mStackSupervisor.topRunningActivityLocked();
            final Configuration parentConfig = getParent().getConfiguration();
            if (top != this || isConfigurationCompatible(parentConfig)) {
                onOverrideConfigurationChanged(mTmpConfig);
            } else if (isConfigurationCompatible(
                    mLastReportedConfiguration.getMergedConfiguration())) {
                onOverrideConfigurationChanged(mLastReportedConfiguration.getMergedConfiguration());
            }
            return;
            return;
        }
        }


+2 −4
Original line number Original line Diff line number Diff line
@@ -1152,14 +1152,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
                + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
                + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
                + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
                + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
                + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
        final boolean keyguardGoingAway = mWindowManagerInternal.isKeyguardGoingAway();


        boolean disable = true;
        boolean disable = true;
        // Note: We postpone the rotating of the screen until the keyguard as well as the
        // Note: We postpone the rotating of the screen until the keyguard as well as the
        // window manager have reported a draw complete or the keyguard is going away in dismiss
        // window manager have reported a draw complete or the keyguard is going away in dismiss
        // mode.
        // mode.
        if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete)
        if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete))) {
                || keyguardGoingAway)) {
            if (needSensorRunningLp()) {
            if (needSensorRunningLp()) {
                disable = false;
                disable = false;
                //enable listener if not already enabled
                //enable listener if not already enabled
@@ -1170,7 +1168,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    // the sensor reading was cleared which can cause it to relaunch the app that
                    // the sensor reading was cleared which can cause it to relaunch the app that
                    // will show in the wrong orientation first before correcting leading to app
                    // will show in the wrong orientation first before correcting leading to app
                    // launch delays.
                    // launch delays.
                    mOrientationListener.enable(!keyguardGoingAway /* clearCurrentRotation */);
                    mOrientationListener.enable(true /* clearCurrentRotation */);
                    if(localLOGV) Slog.v(TAG, "Enabling listeners");
                    if(localLOGV) Slog.v(TAG, "Enabling listeners");
                    mOrientationSensorEnabled = true;
                    mOrientationSensorEnabled = true;
                }
                }
+3 −9
Original line number Original line Diff line number Diff line
@@ -2994,10 +2994,9 @@ public class WindowManagerService extends IWindowManager.Stub
    }
    }


    public void setKeyguardGoingAway(boolean keyguardGoingAway) {
    public void setKeyguardGoingAway(boolean keyguardGoingAway) {
// TODO: Use of this can be removed. Revert ag/I8369723d6a77f2c602f1ef080371fa7cd9ee094e
        synchronized (mWindowMap) {
//        synchronized (mWindowMap) {
            mKeyguardGoingAway = keyguardGoingAway;
//            mKeyguardGoingAway = keyguardGoingAway;
        }
//        }
    }
    }


    // -------------------------------------------------------------
    // -------------------------------------------------------------
@@ -7435,11 +7434,6 @@ public class WindowManagerService extends IWindowManager.Stub
            return WindowManagerService.this.isKeyguardLocked();
            return WindowManagerService.this.isKeyguardLocked();
        }
        }


        @Override
        public boolean isKeyguardGoingAway() {
            return WindowManagerService.this.mKeyguardGoingAway;
        }

        @Override
        @Override
        public boolean isKeyguardShowingAndNotOccluded() {
        public boolean isKeyguardShowingAndNotOccluded() {
            return WindowManagerService.this.isKeyguardShowingAndNotOccluded();
            return WindowManagerService.this.isKeyguardShowingAndNotOccluded();
+31 −0
Original line number Original line Diff line number Diff line
@@ -17,11 +17,16 @@
package com.android.server.wm;
package com.android.server.wm;


import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;

import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
@@ -30,6 +35,7 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;


import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.os.SystemClock;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
@@ -378,6 +384,31 @@ public class DisplayContentTests extends WindowTestsBase {
        assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId()));
        assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId()));
    }
    }


    @Test
    @SuppressLint("InlinedApi")
    public void testOrientationDefinedByKeyguard() {
        final DisplayContent dc = createNewDisplay();
        // Create a window that requests landscape orientation. It will define device orientation
        // by default.
        final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
        window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);

        final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard");
        keyguard.mHasSurface = true;
        keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

        assertEquals("Screen orientation must be defined by the app window by default",
                SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());

        keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
        assertEquals("Visible keyguard must influence device orientation",
                SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation());

        sWm.setKeyguardGoingAway(true);
        assertEquals("Keyguard that is going away must not influence device orientation",
                SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
    }

    private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
    private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
                             int expectedBaseHeight, int expectedBaseDensity) {
                             int expectedBaseHeight, int expectedBaseDensity) {
        assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);
        assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);
Loading