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

Commit 3fad2a3b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Log if orientation is ignored by universal resizable

This logs for two cases for ignored fixed orientation:
1. The activity is first launched with declared
   android:screenOrientation in the manifest.
2. The activity calls Activity#setRequestedOrientation at runtime.

This makes it easier to see which activity's requested orientation
is ignored.

Bug: 377771481
Flag: com.android.window.flags.universal_resizable_by_default
Test: atest SizeCompatTests#testUniversalResizeable

Change-Id: I850b4b9143fc645ee410f52026047b9294aa77e0
parent 247a20f2
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -1622,6 +1622,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                newParent.setResumedActivity(this, "onParentChanged");
            }
            mAppCompatController.getTransparentPolicy().start();
            if (mState == INITIALIZING && isRestrictedFixedOrientation(info.screenOrientation)) {
                Slog.i(TAG, "Ignoring manifest-declared fixed orientation "
                        + ActivityInfo.screenOrientationToString(info.screenOrientation)
                        + " of " + this + " since target sdk 36");
            }
        }

        if (rootTask != null && rootTask.topRunningActivity() == this) {
@@ -3177,6 +3182,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return getWindowConfiguration().canReceiveKeys() && !mWaitForEnteringPinnedMode;
    }

    /**
     * Returns {@code true} if the orientation will be ignored for {@link #isUniversalResizeable()}.
     */
    private boolean isRestrictedFixedOrientation(
            @ActivityInfo.ScreenOrientation int orientation) {
        // Exclude "locked" because it is not explicit portrait or landscape.
        return orientation != ActivityInfo.SCREEN_ORIENTATION_LOCKED
                && ActivityInfo.isFixedOrientation(orientation)
                && isUniversalResizeable();
    }

    /**
     * Returns {@code true} if the fixed orientation, aspect ratio, resizability of this activity
     * will be ignored.
@@ -8107,7 +8123,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        ProtoLog.v(WM_DEBUG_ORIENTATION,
                "Setting requested orientation %s for %s",
                ActivityInfo.screenOrientationToString(requestedOrientation), this);
        setOrientation(requestedOrientation, this);
        final int resolvedOrientation = setOrientation(requestedOrientation, this);
        if (resolvedOrientation != requestedOrientation
                && isRestrictedFixedOrientation(requestedOrientation)) {
            Slog.i(TAG, "Ignoring requested fixed orientation "
                    + ActivityInfo.screenOrientationToString(requestedOrientation)
                    + " of " + this + " since target sdk 36");
        }

        // Push the new configuration to the requested app in case where it's not pushed, e.g. when
        // the request is handled at task level with letterbox.
@@ -8198,9 +8220,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    @ActivityInfo.ScreenOrientation
    protected int getOverrideOrientation() {
        int candidateOrientation = super.getOverrideOrientation();
        if (candidateOrientation != ActivityInfo.SCREEN_ORIENTATION_LOCKED
                && ActivityInfo.isFixedOrientation(candidateOrientation)
                && isUniversalResizeable()) {
        if (isRestrictedFixedOrientation(candidateOrientation)) {
            candidateOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
        }
        return mAppCompatController.getOrientationPolicy()
+0 −2
Original line number Diff line number Diff line
@@ -101,8 +101,6 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {

    DisplayArea(WindowManagerService wms, Type type, String name, int featureId) {
        super(wms);
        // TODO(display-area): move this up to ConfigurationContainer
        setOverrideOrientation(SCREEN_ORIENTATION_UNSET);
        mType = type;
        mName = name;
        mFeatureId = featureId;
+22 −16
Original line number Diff line number Diff line
@@ -1676,17 +1676,23 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     * @param orientation the specified orientation. Needs to be one of {@link ScreenOrientation}.
     * @param requestingContainer the container which orientation request has changed. Mostly used
     *                            to ensure it gets correct configuration.
     * @return the resolved override orientation of this window container.
     */
    void setOrientation(@ScreenOrientation int orientation,
    @ScreenOrientation
    int setOrientation(@ScreenOrientation int orientation,
            @Nullable WindowContainer requestingContainer) {
        if (getOverrideOrientation() == orientation) {
            return;
            return orientation;
        }

        setOverrideOrientation(orientation);
        final WindowContainer parent = getParent();
        if (parent != null) {
            if (getConfiguration().orientation != getRequestedConfigurationOrientation()
        if (parent == null) {
            return orientation;
        }
        // The derived class can return a result that is different from the given orientation.
        final int resolvedOrientation = getOverrideOrientation();
        if (getConfiguration().orientation != getRequestedConfigurationOrientation(
                false /* forDisplay */, resolvedOrientation)
                // Update configuration directly only if the change won't be dispatched from
                // ancestor. This prevents from computing intermediate configuration when the
                // parent also needs to be updated from the ancestor. E.g. the app requests
@@ -1699,7 +1705,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            onConfigurationChanged(parent.getConfiguration());
        }
        onDescendantOrientationChanged(requestingContainer);
        }
        return resolvedOrientation;
    }

    @ScreenOrientation