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

Commit 5f175e3d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move orientation request into hierarchy."

parents ce3083dc 90b04281
Loading
Loading
Loading
Loading
+0 −6
Original line number Original line Diff line number Diff line
@@ -107,12 +107,6 @@ interface IWindowManager
      */
      */
    void endProlongedAnimations();
    void endProlongedAnimations();


    // Re-evaluate the current orientation from the caller's state.
    // If there is a change, the new Configuration is returned and the
    // caller must call setNewConfiguration() sometime later.
    Configuration updateOrientationFromAppTokens(in Configuration currentConfig,
            IBinder freezeThisOneIfNeeded, int displayId);

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


+4 −20
Original line number Original line Diff line number Diff line
@@ -2486,36 +2486,20 @@ final class ActivityRecord extends ConfigurationContainer {
    }
    }


    void setRequestedOrientation(int requestedOrientation) {
    void setRequestedOrientation(int requestedOrientation) {
        final int displayId = getDisplayId();
        setOrientation(requestedOrientation, mayFreezeScreenLocked(app));
        final Configuration displayConfig =
                mRootActivityContainer.getDisplayOverrideConfiguration(displayId);

        final Configuration config = setOrientation(requestedOrientation,
                displayId, displayConfig, mayFreezeScreenLocked(app));
        if (config != null) {
            frozenBeforeDestroy = true;
            if (!mAtmService.updateDisplayOverrideConfigurationLocked(config, this,
                    false /* deferResume */, displayId)) {
                mRootActivityContainer.resumeFocusedStacksTopActivities();
            }
        }
        mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
        mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
                task.taskId, requestedOrientation);
                task.taskId, requestedOrientation);
    }
    }


    Configuration setOrientation(int requestedOrientation, int displayId,
    private void setOrientation(int requestedOrientation, boolean freezeScreenIfNeeded) {
            Configuration displayConfig, boolean freezeScreenIfNeeded) {
        if (mAppWindowToken == null) {
        if (mAppWindowToken == null) {
            Slog.w(TAG_WM,
            Slog.w(TAG_WM,
                    "Attempted to set orientation of non-existing app token: " + appToken);
                    "Attempted to set orientation of non-existing app token: " + appToken);
            return null;
            return;
        }
        }


        mAppWindowToken.setOrientation(requestedOrientation);

        final IBinder binder = freezeScreenIfNeeded ? appToken.asBinder() : null;
        final IBinder binder = freezeScreenIfNeeded ? appToken.asBinder() : null;
        return mAtmService.mWindowManager.updateOrientationFromAppTokens(displayConfig, binder,
        mAppWindowToken.setOrientation(requestedOrientation, binder, this);
                displayId);
    }
    }


    int getOrientation() {
    int getOrientation() {
+82 −2
Original line number Original line Diff line number Diff line
@@ -397,10 +397,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    private final Matrix mTmpMatrix = new Matrix();
    private final Matrix mTmpMatrix = new Matrix();
    private final Region mTmpRegion = new Region();
    private final Region mTmpRegion = new Region();



    /** Used for handing back size of display */
    /** Used for handing back size of display */
    private final Rect mTmpBounds = new Rect();
    private final Rect mTmpBounds = new Rect();


    private final Configuration mTmpConfiguration = new Configuration();

    /** Remove this display when animation on it has completed. */
    /** Remove this display when animation on it has completed. */
    private boolean mDeferredRemoval;
    private boolean mDeferredRemoval;


@@ -1156,6 +1157,36 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
        mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
    }
    }


    @Override
    boolean onDescendantOrientationChanged(IBinder freezeDisplayToken,
            ConfigurationContainer requestingContainer) {
        final Configuration config = updateOrientationFromAppTokens(
                getRequestedOverrideConfiguration(), freezeDisplayToken, false);
        // If display rotation class tells us that it doesn't consider app requested orientation,
        // this display won't rotate just because of an app changes its requested orientation. Thus
        // it indicates that this display chooses not to handle this request.
        final boolean handled = getDisplayRotation().respectAppRequestedOrientation();
        if (config == null) {
            return handled;
        }

        if (handled && requestingContainer instanceof ActivityRecord) {
            final ActivityRecord activityRecord = (ActivityRecord) requestingContainer;
            final boolean kept = mWmService.mAtmService.updateDisplayOverrideConfigurationLocked(
                    config, activityRecord, false /* deferResume */, getDisplayId());
            activityRecord.frozenBeforeDestroy = true;
            if (!kept) {
                mWmService.mAtmService.mRootActivityContainer.resumeFocusedStacksTopActivities();
            }
        } else {
            // We have a new configuration to push so we need to update ATMS for now.
            // TODO: Clean up display configuration push between ATMS and WMS after unification.
            mWmService.mAtmService.updateDisplayOverrideConfigurationLocked(
                    config, null /* starting */, false /* deferResume */, getDisplayId());
        }
        return handled;
    }

    /**
    /**
     * Determine the new desired orientation of this display.
     * Determine the new desired orientation of this display.
     *
     *
@@ -1169,7 +1200,56 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return updateOrientationFromAppTokens(false /* forceUpdate */);
        return updateOrientationFromAppTokens(false /* forceUpdate */);
    }
    }


    boolean updateOrientationFromAppTokens(boolean forceUpdate) {
    /**
     * Update orientation of the target display, returning a non-null new Configuration if it has
     * changed from the current orientation. If a non-null configuration is returned, someone must
     * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration,
     * DisplayContent)} to tell the window manager it can unfreeze the screen. This will typically
     * be done by calling {@link WindowManagerService#sendNewConfiguration(int)}.
     */
    Configuration updateOrientationFromAppTokens(Configuration currentConfig,
            IBinder freezeDisplayToken, boolean forceUpdate) {
        if (!mDisplayReady) {
            return null;
        }

        Configuration config = null;
        if (updateOrientationFromAppTokens(forceUpdate)) {
            // If we changed the orientation but mOrientationChangeComplete is already true,
            // we used seamless rotation, and we don't need to freeze the screen.
            if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) {
                final AppWindowToken atoken = getAppWindowToken(freezeDisplayToken);
                if (atoken != null) {
                    atoken.startFreezingScreen();
                }
            }
            config = new Configuration();
            computeScreenConfiguration(config);
        } else if (currentConfig != null) {
            // No obvious action we need to take, but if our current state mismatches the
            // activity manager's, update it, disregarding font scale, which should remain set
            // to the value of the previous configuration.
            // Here we're calling Configuration#unset() instead of setToDefaults() because we
            // need to keep override configs clear of non-empty values (e.g. fontSize).
            mTmpConfiguration.unset();
            mTmpConfiguration.updateFrom(currentConfig);
            computeScreenConfiguration(mTmpConfiguration);
            if (currentConfig.diff(mTmpConfiguration) != 0) {
                mWaitingForConfig = true;
                setLayoutNeeded();
                int[] anim = new int[2];
                getDisplayPolicy().selectRotationAnimationLw(anim);

                mWmService.startFreezingDisplayLocked(anim[0], anim[1], this);
                config = new Configuration(mTmpConfiguration);
            }
        }

        return config;
    }


    private boolean updateOrientationFromAppTokens(boolean forceUpdate) {
        final int req = getOrientation();
        final int req = getOrientation();
        if (req != mLastOrientation || forceUpdate) {
        if (req != mLastOrientation || forceUpdate) {
            mLastOrientation = req;
            mLastOrientation = req;
+9 −0
Original line number Original line Diff line number Diff line
@@ -329,6 +329,15 @@ public class DisplayRotation {
        return mFixedToUserRotation;
        return mFixedToUserRotation;
    }
    }


    /**
     * Returns {@code true} if this display rotation takes app requested orientation into
     * consideration; {@code false} otherwise. For the time being the only case where this is {@code
     * false} is when {@link #isFixedToUserRotation()} is {@code true}.
     */
    boolean respectAppRequestedOrientation() {
        return !mFixedToUserRotation;
    }

    public int getLandscapeRotation() {
    public int getLandscapeRotation() {
        return mLandscapeRotation;
        return mLandscapeRotation;
    }
    }
+9 −5
Original line number Original line Diff line number Diff line
@@ -597,11 +597,15 @@ class RootActivityContainer extends ConfigurationContainer


        // Force-update the orientation from the WindowManager, since we need the true configuration
        // Force-update the orientation from the WindowManager, since we need the true configuration
        // to send to the client now.
        // to send to the client now.
        final Configuration config = mWindowManager.updateOrientationFromAppTokens(
        final DisplayContent displayContent = mRootWindowContainer.getDisplayContent(displayId);
        Configuration config = null;
        if (displayContent != null) {
            config = displayContent.updateOrientationFromAppTokens(
                    getDisplayOverrideConfiguration(displayId),
                    getDisplayOverrideConfiguration(displayId),
                    starting != null && starting.mayFreezeScreenLocked(starting.app)
                    starting != null && starting.mayFreezeScreenLocked(starting.app)
                            ? starting.appToken : null,
                            ? starting.appToken : null,
                displayId, true /* forceUpdate */);
                    true /* forceUpdate */);
        }
        if (starting != null && markFrozenIfConfigChanged && config != null) {
        if (starting != null && markFrozenIfConfigChanged && config != null) {
            starting.frozenBeforeDestroy = true;
            starting.frozenBeforeDestroy = true;
        }
        }
Loading