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

Commit 31a3779b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Check config change for reporting resize and requesting redraw

Since multi-window mode is supported, the orientation change is
not the only source that requires redraw. It is confusing to use
"set orientation change" to handle other cases that also need to
redraw. So simplify the condition to check if there is a config
change of the window. While drag-resizing is similar, the end of
drag-resizing should also trigger a config change.

Also
- Reset mLastConfigReportedToClient only if the config is changed.
  This can avoid unnecessary redraw request if a window is reparented
  to another container with the same configuration.
- Set mWaitingForConfig for 180 rotation because since
  WindowConfiguration was introduced, there will be always a
  configuration change for rotation change.
- Add trace for global config change.

Bug: 159103089
Test: WindowStateTests

Change-Id: I50d4c5b741be960bd2850e4bcd0ab62ad32c19dc
parent a9233ab0
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -919,12 +919,6 @@
      "group": "WM_ERROR",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-1270148832": {
      "message": "Resize start waiting for draw, mDrawState=DRAW_PENDING in %s, surfaceController %s",
      "level": "VERBOSE",
      "group": "WM_DEBUG_RESIZE",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "-1263316010": {
      "message": "Computed rotation=%s (%d) for display id=%d based on lastOrientation=%s (%d) and oldRotation=%s (%d)",
      "level": "VERBOSE",
@@ -2305,12 +2299,6 @@
      "group": "WM_DEBUG_RECENTS_ANIMATIONS",
      "at": "com\/android\/server\/wm\/RecentsAnimationController.java"
    },
    "25888308": {
      "message": "Resize reasons for w=%s:  %s configChanged=%b dragResizingChanged=%b",
      "level": "VERBOSE",
      "group": "WM_DEBUG_RESIZE",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "34682671": {
      "message": "Not moving display (displayId=%d) to top. Top focused displayId=%d. Reason: FLAG_STEAL_TOP_FOCUS_DISABLED",
      "level": "INFO",
@@ -3097,6 +3085,12 @@
      "group": "WM_DEBUG_RESIZE",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "686185515": {
      "message": "Resize reasons for w=%s:  %s configChanged=%b didFrameInsetsChange=%b",
      "level": "VERBOSE",
      "group": "WM_DEBUG_RESIZE",
      "at": "com\/android\/server\/wm\/WindowState.java"
    },
    "691515534": {
      "message": "  Commit wallpaper becoming invisible: %s",
      "level": "VERBOSE",
+4 −0
Original line number Diff line number Diff line
@@ -4397,6 +4397,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            return 0;
        }

        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateGlobalConfiguration");
        ProtoLog.i(WM_DEBUG_CONFIGURATION, "Updating global configuration "
                + "to: %s", values);
        writeConfigurationChanged(changes);
@@ -4482,9 +4483,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                mAmInternal, changes, initLocale);
        mH.sendMessage(msg);

        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "RootConfigChange");
        // Update stored global config and notify everyone about the change.
        mRootWindowContainer.onConfigurationChanged(mTempConfig);
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);

        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        return changes;
    }

+1 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.util.RotationUtils.deltaRotation;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
@@ -575,13 +574,10 @@ public class DisplayRotation {
                "Display id=%d rotation changed to %d from %d, lastOrientation=%d",
                        displayId, rotation, oldRotation, lastOrientation);

        if (deltaRotation(oldRotation, rotation) != Surface.ROTATION_180) {
            mDisplayContent.mWaitingForConfig = true;
        }

        mRotation = rotation;

        mDisplayContent.setLayoutNeeded();
        mDisplayContent.mWaitingForConfig = true;

        if (mDisplayContent.mTransitionController.isShellTransitionsEnabled()) {
            final boolean wasCollecting = mDisplayContent.mTransitionController.isCollecting();
+2 −1
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ public class WindowFrames {
    }

    String getInsetsChangedInfo() {
        return "forceReportingResized=" + mLastForceReportingResized;
        return "forceReportingResized=" + mLastForceReportingResized
                + " insetsChanged=" + mInsetsChanged;
    }
}
+18 −54
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.AppOpsManager.MODE_DEFAULT;
import static android.app.AppOpsManager.OP_NONE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.graphics.GraphicsProtos.dumpPointProto;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
@@ -1475,15 +1476,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
        }

        final boolean dragResizingChanged = isDragResizeChanged()
                && !isDragResizingChangeReported();

        final boolean attachedFrameChanged = LOCAL_LAYOUT
                && mLayoutAttached && getParentWindow().frameChanged();

        if (DEBUG) {
            Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
                    + " dragResizingChanged=" + dragResizingChanged
                    + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
        }

@@ -1492,13 +1489,12 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (didFrameInsetsChange
                || configChanged
                || insetsChanged
                || dragResizingChanged
                || shouldSendRedrawForSync()
                || attachedFrameChanged) {
            ProtoLog.v(WM_DEBUG_RESIZE,
                        "Resize reasons for w=%s:  %s configChanged=%b dragResizingChanged=%b",
                        "Resize reasons for w=%s:  %s configChanged=%b didFrameInsetsChange=%b",
                        this, mWindowFrames.getInsetsChangedInfo(),
                        configChanged, dragResizingChanged);
                        configChanged, didFrameInsetsChange);

            if (insetsChanged) {
                mWindowFrames.setInsetsChanged(false);
@@ -1518,18 +1514,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            onResizeHandled();
            mWmService.makeWindowFreezingScreenIfNeededLocked(this);

            // If the orientation is changing, or we're starting or ending a drag resizing action,
            // or we're resizing an embedded Activity, then we need to hold off on unfreezing the
            // display until this window has been redrawn; to do that, we need to go through the
            // process of getting informed by the application when it has finished drawing.
            if (getOrientationChanging() || dragResizingChanged
                    || isEmbeddedActivityResizeChanged()) {
                if (dragResizingChanged) {
                    ProtoLog.v(WM_DEBUG_RESIZE,
                            "Resize start waiting for draw, "
                                    + "mDrawState=DRAW_PENDING in %s, surfaceController %s",
                            this, winAnimator.mSurfaceController);
                }
            // Reset the drawn state if the window need to redraw for the change, so the transition
            // can wait until it has finished drawing to start.
            if ((configChanged || getOrientationChanging()) && isVisibleRequested()) {
                winAnimator.mDrawState = DRAW_PENDING;
                if (mActivityRecord != null) {
                    mActivityRecord.clearAllDrawn();
@@ -1560,6 +1547,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    }

    boolean getOrientationChanging() {
        if (mTransitionController.isShellTransitionsEnabled()) {
            // Shell transition doesn't use the methods for display frozen state.
            return false;
        }
        // In addition to the local state flag, we must also consider the difference in the last
        // reported configuration vs. the current state. If the client code has not been informed of
        // the change, logic dependent on having finished processing the orientation, such as
@@ -2361,21 +2352,21 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    @Override
    public void onConfigurationChanged(Configuration newParentConfig) {
        if (getDisplayContent().getImeInputTarget() != this && !isImeLayeringTarget()) {
            super.onConfigurationChanged(newParentConfig);
            return;
        }

        mTempConfiguration.setTo(getConfiguration());
        super.onConfigurationChanged(newParentConfig);
        final boolean windowConfigChanged = mTempConfiguration.windowConfiguration
                .diff(newParentConfig.windowConfiguration, false) != 0;
        final int diff = getConfiguration().diff(mTempConfiguration);
        if (diff != 0) {
            mLastConfigReportedToClient = false;
        }

        if (getDisplayContent().getImeInputTarget() != this && !isImeLayeringTarget()) {
            return;
        }
        // When the window configuration changed, we need to update the IME control target in
        // case the app may lose the IME inets control when exiting from split-screen mode, or the
        // IME parent may failed to attach to the app during rotating the screen.
        // See DisplayContent#shouldImeAttachedToApp, DisplayContent#isImeControlledByApp
        if (windowConfigChanged) {
        if ((diff & CONFIG_WINDOW_CONFIGURATION) != 0) {
            // If the window was the IME layering target, updates the IME surface parent in case
            // the IME surface may be wrongly positioned when the window configuration affects the
            // IME surface association. (e.g. Attach IME surface on the display instead of the
@@ -2384,12 +2375,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
    }

    @Override
    void onMergedOverrideConfigurationChanged() {
        super.onMergedOverrideConfigurationChanged();
        mLastConfigReportedToClient = false;
    }

    void onWindowReplacementTimeout() {
        if (mWillReplaceWindow) {
            // Since the window already timed out, remove it immediately now.
@@ -4142,20 +4127,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return mActivityRecord == null || mActivityRecord.isFullyTransparentBarAllowed(frame);
    }

    /**
     * Whether this window belongs to a resizing embedded activity.
     */
    private boolean isEmbeddedActivityResizeChanged() {
        if (mActivityRecord == null || !isVisibleRequested()) {
            // No need to update if the window is in the background.
            return false;
        }

        final TaskFragment embeddedTaskFragment = mActivityRecord.getOrganizedTaskFragment();
        return embeddedTaskFragment != null
                && mDisplayContent.mChangingContainers.contains(embeddedTaskFragment);
    }

    boolean isDragResizeChanged() {
        return mDragResizing != computeDragResizing();
    }
@@ -4168,13 +4139,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        super.setWaitingForDrawnIfResizingChanged();
    }

    /**
     * @return Whether we reported a drag resize change to the application or not already.
     */
    private boolean isDragResizingChangeReported() {
        return mDragResizingChangeReported;
    }

    /**
     * Resets the state whether we reported a drag resize change to the app.
     */
Loading