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

Commit f6205bfa authored by Tiger Huang's avatar Tiger Huang
Browse files

Refine updateSystemUiVisibilityLw for performance

- It doesn't change the visibilities of system bars, but some other
  attributes, such as appearance, behavior, and disable flags. So
  this CL renames it to updateSystemBarAttributes.
- Changing the attributes won't affect any window layout at all, so we
  don't re-do layout after executing it. The method returns void now.

This CL also avoids redundant calls to performSurfacePlacement while
the visibilities of insets are changed. setClientVisible can be called
in a row while the visibilities of multiple types are changed. In this
case, only one LAYOUT_AND_ASSIGN_WINDOW_LAYERS_IF_NEEDED is needed to be
scheduled.

Fix: 194186241
Test: atest WindowAddRemovePerfTest DisplayPolicyLayoutTests
Test: Use "Window Insets Tests" > "Window Insets Controller" to
      show/hide system bars, and see if the window layout is expected.
Change-Id: Ic66c00b1ad205c466424c033d27e7eaa2acd8fc1
parent 5eb2ccc3
Loading
Loading
Loading
Loading
+2 −13
Original line number Original line Diff line number Diff line
@@ -134,7 +134,6 @@ import static com.android.server.wm.WindowManagerService.H.REPORT_HARD_KEYBOARD_
import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
@@ -434,6 +433,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    // Accessed directly by all users.
    // Accessed directly by all users.
    private boolean mLayoutNeeded;
    private boolean mLayoutNeeded;
    int pendingLayoutChanges;
    int pendingLayoutChanges;
    boolean mLayoutAndAssignWindowLayersScheduled;


    /**
    /**
     * Used to gate application window layout until we have sent the complete configuration.
     * Used to gate application window layout until we have sent the complete configuration.
@@ -3424,13 +3424,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            }
            }
        }
        }


        int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
        getDisplayPolicy().focusChangedLw(oldFocus, newFocus);


        if (imWindowChanged && oldFocus != mInputMethodWindow) {
        if (imWindowChanged && oldFocus != mInputMethodWindow) {
            // Focus of the input method window changed. Perform layout if needed.
            // Focus of the input method window changed. Perform layout if needed.
            if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
            if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
                performLayout(true /*initial*/,  updateInputWindows);
                performLayout(true /*initial*/,  updateInputWindows);
                focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
            } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
            } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
                // Client will do the layout, but we need to assign layers
                // Client will do the layout, but we need to assign layers
                // for handleNewWindowLocked() below.
                // for handleNewWindowLocked() below.
@@ -3438,16 +3437,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            }
            }
        }
        }


        if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
            // The change in focus caused us to need to do a layout.  Okay.
            setLayoutNeeded();
            if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
                performLayout(true /*initial*/, updateInputWindows);
            } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
                mWmService.mRoot.performSurfacePlacement();
            }
        }

        if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
        if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
            // If we defer assigning layers, then the caller is responsible for doing this part.
            // If we defer assigning layers, then the caller is responsible for doing this part.
            getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
            getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
+10 −23
Original line number Original line Diff line number Diff line
@@ -1984,11 +1984,7 @@ public class DisplayPolicy {
            mTopIsFullscreen = topIsFullscreen;
            mTopIsFullscreen = topIsFullscreen;
        }
        }


        if (updateSystemUiVisibilityLw()) {
        updateSystemBarAttributes();
            // If the navigation bar has been hidden or shown, we need to do another
            // layout pass to update that window.
            changes |= FINISH_LAYOUT_REDO_LAYOUT;
        }


        if (mShowingDream != mLastShowingDream) {
        if (mShowingDream != mLastShowingDream) {
            mLastShowingDream = mShowingDream;
            mLastShowingDream = mShowingDream;
@@ -2524,18 +2520,13 @@ public class DisplayPolicy {
    /**
    /**
     * A new window has been focused.
     * A new window has been focused.
     */
     */
    public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
    public void focusChangedLw(WindowState lastFocus, WindowState newFocus) {
        mFocusedWindow = newFocus;
        mFocusedWindow = newFocus;
        mLastFocusedWindow = lastFocus;
        mLastFocusedWindow = lastFocus;
        if (mDisplayContent.isDefaultDisplay) {
        if (mDisplayContent.isDefaultDisplay) {
            mService.mPolicy.onDefaultDisplayFocusChangedLw(newFocus);
            mService.mPolicy.onDefaultDisplayFocusChangedLw(newFocus);
        }
        }
        if (updateSystemUiVisibilityLw()) {
        updateSystemBarAttributes();
            // If the navigation bar has been hidden or shown, we need to do another
            // layout pass to update that window.
            return FINISH_LAYOUT_REDO_LAYOUT;
        }
        return 0;
    }
    }


    private void requestTransientBars(WindowState swipeTarget) {
    private void requestTransientBars(WindowState swipeTarget) {
@@ -2611,21 +2602,18 @@ public class DisplayPolicy {
        return mDisplayContent.getInsetsPolicy();
        return mDisplayContent.getInsetsPolicy();
    }
    }


    void resetSystemUiVisibilityLw() {
    void resetSystemBarAttributes() {
        mLastDisableFlags = 0;
        mLastDisableFlags = 0;
        updateSystemUiVisibilityLw();
        updateSystemBarAttributes();
    }
    }


    /**
    void updateSystemBarAttributes() {
     * @return {@code true} if the update may affect the layout.
     */
    boolean updateSystemUiVisibilityLw() {
        // If there is no window focused, there will be nobody to handle the events
        // If there is no window focused, there will be nobody to handle the events
        // anyway, so just hang on in whatever state we're in until things settle down.
        // anyway, so just hang on in whatever state we're in until things settle down.
        WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
        WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
                : mTopFullscreenOpaqueWindowState;
                : mTopFullscreenOpaqueWindowState;
        if (winCandidate == null) {
        if (winCandidate == null) {
            return false;
            return;
        }
        }


        // The immersive mode confirmation should never affect the system bar visibility, otherwise
        // The immersive mode confirmation should never affect the system bar visibility, otherwise
@@ -2641,7 +2629,7 @@ public class DisplayPolicy {
                    : lastFocusCanReceiveKeys ? mLastFocusedWindow
                    : lastFocusCanReceiveKeys ? mLastFocusedWindow
                            : mTopFullscreenOpaqueWindowState;
                            : mTopFullscreenOpaqueWindowState;
            if (winCandidate == null) {
            if (winCandidate == null) {
                return false;
                return;
            }
            }
        }
        }
        final WindowState win = winCandidate;
        final WindowState win = winCandidate;
@@ -2680,7 +2668,7 @@ public class DisplayPolicy {
                && Objects.equals(mFocusedApp, focusedApp)
                && Objects.equals(mFocusedApp, focusedApp)
                && mLastFocusIsFullscreen == isFullscreen
                && mLastFocusIsFullscreen == isFullscreen
                && Arrays.equals(mLastStatusBarAppearanceRegions, appearanceRegions)) {
                && Arrays.equals(mLastStatusBarAppearanceRegions, appearanceRegions)) {
            return false;
            return;
        }
        }
        if (mDisplayContent.isDefaultDisplay && mLastFocusIsFullscreen != isFullscreen
        if (mDisplayContent.isDefaultDisplay && mLastFocusIsFullscreen != isFullscreen
                && ((mLastAppearance ^ appearance) & APPEARANCE_LOW_PROFILE_BARS) != 0) {
                && ((mLastAppearance ^ appearance) & APPEARANCE_LOW_PROFILE_BARS) != 0) {
@@ -2698,7 +2686,6 @@ public class DisplayPolicy {
        callStatusBarSafely(statusBar -> statusBar.onSystemBarAttributesChanged(displayId,
        callStatusBarSafely(statusBar -> statusBar.onSystemBarAttributesChanged(displayId,
                appearance, appearanceRegions, isNavbarColorManagedByIme, behavior,
                appearance, appearanceRegions, isNavbarColorManagedByIme, behavior,
                requestedVisibilities, focusedApp));
                requestedVisibilities, focusedApp));
        return true;
    }
    }


    private int getStatusBarAppearance(WindowState opaque, WindowState opaqueOrDimming) {
    private int getStatusBarAppearance(WindowState opaque, WindowState opaqueOrDimming) {
@@ -2970,7 +2957,7 @@ public class DisplayPolicy {
                    return;
                    return;
                }
                }
                mPendingPanicGestureUptime = SystemClock.uptimeMillis();
                mPendingPanicGestureUptime = SystemClock.uptimeMillis();
                updateSystemUiVisibilityLw();
                updateSystemBarAttributes();
            }
            }
        }
        }
    };
    };
+5 −2
Original line number Original line Diff line number Diff line
@@ -376,8 +376,11 @@ class InsetsSourceProvider {
            return;
            return;
        }
        }
        mClientVisible = clientVisible;
        mClientVisible = clientVisible;
        if (!mDisplayContent.mLayoutAndAssignWindowLayersScheduled) {
            mDisplayContent.mLayoutAndAssignWindowLayersScheduled = true;
            mDisplayContent.mWmService.mH.obtainMessage(
            mDisplayContent.mWmService.mH.obtainMessage(
                    LAYOUT_AND_ASSIGN_WINDOW_LAYERS_IF_NEEDED, mDisplayContent).sendToTarget();
                    LAYOUT_AND_ASSIGN_WINDOW_LAYERS_IF_NEEDED, mDisplayContent).sendToTarget();
        }
        updateVisibility();
        updateVisibility();
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -385,7 +385,7 @@ class InsetsStateController {
        if (changed) {
        if (changed) {
            notifyInsetsChanged();
            notifyInsetsChanged();
            mDisplayContent.updateSystemGestureExclusion();
            mDisplayContent.updateSystemGestureExclusion();
            mDisplayContent.getDisplayPolicy().updateSystemUiVisibilityLw();
            mDisplayContent.getDisplayPolicy().updateSystemBarAttributes();
        }
        }
    }
    }


+2 −1
Original line number Original line Diff line number Diff line
@@ -3050,7 +3050,7 @@ public class WindowManagerService extends IWindowManager.Stub
        mSettingsObserver.updateSystemUiSettings(true /* handleChange */);
        mSettingsObserver.updateSystemUiSettings(true /* handleChange */);
        synchronized (mGlobalLock) {
        synchronized (mGlobalLock) {
            // force a re-application of focused window sysui visibility on each display.
            // force a re-application of focused window sysui visibility on each display.
            mRoot.forAllDisplayPolicies(DisplayPolicy::resetSystemUiVisibilityLw);
            mRoot.forAllDisplayPolicies(DisplayPolicy::resetSystemBarAttributes);
        }
        }
    }
    }


@@ -5292,6 +5292,7 @@ public class WindowManagerService extends IWindowManager.Stub
                case LAYOUT_AND_ASSIGN_WINDOW_LAYERS_IF_NEEDED: {
                case LAYOUT_AND_ASSIGN_WINDOW_LAYERS_IF_NEEDED: {
                    synchronized (mGlobalLock) {
                    synchronized (mGlobalLock) {
                        final DisplayContent displayContent = (DisplayContent) msg.obj;
                        final DisplayContent displayContent = (DisplayContent) msg.obj;
                        displayContent.mLayoutAndAssignWindowLayersScheduled = false;
                        displayContent.layoutAndAssignWindowLayersIfNeeded();
                        displayContent.layoutAndAssignWindowLayersIfNeeded();
                    }
                    }
                    break;
                    break;
Loading