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

Commit 5136249a authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Support for specifying orientation in WindowContainer

Also,
- Fixed failing tests when they are ran as a package vs.
individual classes due to multiple window manager instance.
- Correct some isVisible logic to so a window container that
is invisible is not said to be visible, because one of its
children is visible.

Bug: 30060889
Change-Id: I1bb8730361be2a9f5ce88cd59b7d57d5a459bde6
parent 182f9abd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -716,6 +716,11 @@ public class ActivityManager {
        public static boolean hasMovementAnimations(int stackId) {
            return stackId != PINNED_STACK_ID;
        }

        /** Returns true if the input stack and its content can affect the device orientation. */
        public static boolean canSpecifyOrientation(int stackId) {
            return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID;
        }
    }

    /**
+10 −0
Original line number Diff line number Diff line
@@ -377,6 +377,7 @@ public class ActivityInfo extends ComponentInfo

    /** @hide */
    @IntDef({
            SCREEN_ORIENTATION_UNSET,
            SCREEN_ORIENTATION_UNSPECIFIED,
            SCREEN_ORIENTATION_LANDSCAPE,
            SCREEN_ORIENTATION_PORTRAIT,
@@ -397,6 +398,15 @@ public class ActivityInfo extends ComponentInfo
    @Retention(RetentionPolicy.SOURCE)
    public @interface ScreenOrientation {}

    /**
     * Internal constant used to indicate that the app didn't set a specific orientation value.
     * Different from {@link #SCREEN_ORIENTATION_UNSPECIFIED} below as the app can set its
     * orientation to {@link #SCREEN_ORIENTATION_UNSPECIFIED} while this means that the app didn't
     * set anything. The system will mostly treat this similar to
     * {@link #SCREEN_ORIENTATION_UNSPECIFIED}.
     * @hide
     */
    public static final int SCREEN_ORIENTATION_UNSET = -2;
    /**
     * Constant corresponding to <code>unspecified</code> in
     * the {@link android.R.attr#screenOrientation} attribute.
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ public class AppWindowAnimator {

        this.mSkipFirstFrame = skipFirstFrame;

        if (!mAppToken.appFullscreen) {
        if (!mAppToken.fillsParent()) {
            anim.setBackgroundColor(0);
        }
        if (mClearProlongedAnimation) {
+26 −6
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

import static android.app.ActivityManager.StackId;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
@@ -40,7 +41,6 @@ import com.android.server.input.InputApplicationHandle;
import com.android.server.wm.WindowManagerService.H;

import android.annotation.NonNull;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Binder;
@@ -75,9 +75,8 @@ class AppWindowToken extends WindowToken {
    final boolean voiceInteraction;

    Task mTask;
    // TODO: Have a fillParent variable in WindowContainer to this?
    boolean appFullscreen;
    int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    /** @see WindowContainer#fillsParent() */
    private boolean mFillsParent;
    boolean layoutConfigChanges;
    boolean showForAllUsers;
    int targetSdk;
@@ -985,12 +984,33 @@ class AppWindowToken extends WindowToken {
        }
    }

    /**
     * We override because this class doesn't want its children affecting its reported orientation
     * in anyway.
     */
    @Override
    int getOrientation() {
        if (hidden || hiddenRequested) {
            return SCREEN_ORIENTATION_UNSET;
        }
        return mOrientation;
    }

    @Override
    AppWindowToken asAppWindowToken() {
        // I am an app window token!
        return this;
    }

    @Override
    boolean fillsParent() {
        return mFillsParent;
    }

    void setFillsParent(boolean fillsParent) {
        mFillsParent = fillsParent;
    }

    @Override
    void dump(PrintWriter pw, String prefix) {
        super.dump(pw, prefix);
@@ -998,8 +1018,8 @@ class AppWindowToken extends WindowToken {
            pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
        }
        pw.print(prefix); pw.print("task="); pw.println(mTask);
        pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
                pw.print(" requestedOrientation="); pw.println(requestedOrientation);
        pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
                pw.print(" mOrientation="); pw.println(mOrientation);
        pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
                pw.print(" clientHidden="); pw.print(clientHidden);
                pw.print(" reportedDrawn="); pw.print(reportedDrawn);
+49 −0
Original line number Diff line number Diff line
@@ -17,13 +17,18 @@
package com.android.server.wm;

import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.HOME_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;

@@ -201,6 +206,50 @@ class DisplayContent {
        return null;
    }

    int getOrientation() {
        // TODO: Most of the logic here can be removed once this class is converted to use
        // WindowContainer which has an abstract implementation of getOrientation that
        // should cover this.
        if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
                || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
            // Apps and their containers are not allowed to specify an orientation while the docked
            // or freeform stack is visible...except for the home stack/task if the docked stack is
            // minimized and it actually set something.
            if (mHomeStack.isVisible() && mDividerControllerLocked.isMinimizedDock()) {
                final int orientation = mHomeStack.getOrientation();
                if (orientation != SCREEN_ORIENTATION_UNSET) {
                    return orientation;
                }
            }
            return SCREEN_ORIENTATION_UNSPECIFIED;
        }

        for (int i = mStacks.size() - 1; i >= 0; --i) {
            final TaskStack stack = mStacks.get(i);
            if (!stack.isVisible()) {
                continue;
            }

            final int orientation = stack.getOrientation();

            if (orientation == SCREEN_ORIENTATION_BEHIND) {
                continue;
            }

            if (orientation != SCREEN_ORIENTATION_UNSET) {
                if (stack.fillsParent() || orientation != SCREEN_ORIENTATION_UNSPECIFIED) {
                    return orientation;
                }
            }
        }

        if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
                "No app is requesting an orientation, return " + mService.mLastOrientation);
        // The next app has not been requested to be visible, so we keep the current orientation
        // to prevent freezing/unfreezing the display too early.
        return mService.mLastOrientation;
    }

    void updateDisplayInfo() {
        mDisplay.getDisplayInfo(mDisplayInfo);
        mDisplay.getMetrics(mDisplayMetrics);
Loading