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

Commit 4f9796e0 authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge changes Ib2def344,Ifd15736b

* changes:
  Permit layout when stopped if reporting draw
  Refactor computeScreenConfigurationLocked and more.
parents df337277 72d6f219
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1342,7 +1342,7 @@ public final class ViewRootImpl implements ViewParent,

        boolean insetsChanged = false;

        boolean layoutRequested = mLayoutRequested && !mStopped;
        boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw);
        if (layoutRequested) {

            final Resources res = mView.getContext().getResources();
@@ -1774,7 +1774,7 @@ public final class ViewRootImpl implements ViewParent,
                }
            }

            if (!mStopped) {
            if (!mStopped || mReportNextDraw) {
                boolean focusChangedDueToTouchMode = ensureTouchModeLocally(
                        (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0);
                if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth()
@@ -1847,7 +1847,7 @@ public final class ViewRootImpl implements ViewParent,
            }
        }

        final boolean didLayout = layoutRequested && !mStopped;
        final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw);
        boolean triggerGlobalLayoutListener = didLayout
                || mAttachInfo.mRecomputeGlobalAttributes;
        if (didLayout) {
+1 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Slog;
import android.util.TypedValue;
import android.view.Display;
import android.view.Surface;

import com.android.server.EventLogTags;
@@ -371,7 +370,7 @@ public class TaskStack {
            for (int appNdx = appWindowTokens.size() - 1; appNdx >= 0; --appNdx) {
                final WindowList appWindows = appWindowTokens.get(appNdx).allAppWindows;
                for (int winNdx = appWindows.size() - 1; winNdx >= 0; --winNdx) {
                    mService.removeWindowInnerLocked(null, appWindows.get(winNdx));
                    mService.removeWindowInnerLocked(appWindows.get(winNdx));
                    doAnotherLayoutPass = true;
                }
            }
+60 −83
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ public class WindowManagerService extends IWindowManager.Stub
     * This is set when we have run out of memory, and will either be an empty
     * list or contain windows that need to be force removed.
     */
    ArrayList<WindowState> mForceRemoves;
    final ArrayList<WindowState> mForceRemoves = new ArrayList<>();

    /**
     * Windows that clients are waiting to have drawn.
@@ -1731,10 +1731,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
    static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;

    int adjustWallpaperWindowsLocked() {
    boolean adjustWallpaperWindowsLocked() {
        mInnerFields.mWallpaperMayChange = false;
        boolean targetChanged = false;

@@ -1961,13 +1958,12 @@ public class WindowManagerService extends IWindowManager.Stub

        // Start stepping backwards from here, ensuring that our wallpaper windows
        // are correctly placed.
        int changed = 0;
        boolean changed = false;
        for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) {
            WindowToken token = mWallpaperTokens.get(curTokenNdx);
            if (token.hidden == visible) {
                if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
                        "Wallpaper token " + token + " hidden=" + !visible);
                changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
                token.hidden = !visible;
                // Need to do a layout to ensure the wallpaper now has the correct size.
                getDefaultDisplayContentLocked().layoutNeeded = true;
@@ -2028,7 +2024,7 @@ public class WindowManagerService extends IWindowManager.Stub

                windows.add(insertionIndex, wallpaper);
                mWindowsChanged = true;
                changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
                changed = true;
            }
        }

@@ -2649,7 +2645,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        removeWindowInnerLocked(session, win);
        removeWindowInnerLocked(win);
        // Removing a visible window will effect the computed orientation
        // So just update orientation if needed.
        if (wasVisible && updateOrientationFromAppTokensLocked(false)) {
@@ -2659,7 +2655,7 @@ public class WindowManagerService extends IWindowManager.Stub
        Binder.restoreCallingIdentity(origId);
    }

    void removeWindowInnerLocked(Session session, WindowState win) {
    void removeWindowInnerLocked(WindowState win) {
        if (win.mRemoved) {
            // Nothing to do.
            return;
@@ -2669,7 +2665,7 @@ public class WindowManagerService extends IWindowManager.Stub
            WindowState cwin = win.mChildWindows.get(i);
            Slog.w(TAG, "Force-removing child win " + cwin + " from container "
                    + win);
            removeWindowInnerLocked(cwin.mSession, cwin);
            removeWindowInnerLocked(cwin);
        }

        win.mRemoved = true;
@@ -3776,6 +3772,9 @@ public class WindowManagerService extends IWindowManager.Stub

    private Configuration updateOrientationFromAppTokensLocked(
            Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
        if (!mDisplayReady) {
            return null;
        }
        Configuration config = null;

        if (updateOrientationFromAppTokensLocked(false)) {
@@ -3794,7 +3793,7 @@ public class WindowManagerService extends IWindowManager.Stub
            // the value of the previous configuration.
            mTempConfiguration.setToDefaults();
            mTempConfiguration.fontScale = currentConfig.fontScale;
            if (computeScreenConfigurationLocked(mTempConfiguration)) {
            computeScreenConfigurationLocked(mTempConfiguration);
            if (currentConfig.diff(mTempConfiguration) != 0) {
                mWaitingForConfig = true;
                final DisplayContent displayContent = getDefaultDisplayContentLocked();
@@ -3809,7 +3808,6 @@ public class WindowManagerService extends IWindowManager.Stub
                config = new Configuration(mTempConfiguration);
            }
        }
        }

        return config;
    }
@@ -6899,9 +6897,11 @@ public class WindowManagerService extends IWindowManager.Stub

    public Configuration computeNewConfiguration() {
        synchronized (mWindowMap) {
            if (!mDisplayReady) {
                return null;
            }
            Configuration config = computeNewConfigurationLocked();
            if (config == null && mWaitingForConfig) {
                // Nothing changed but we are waiting for something... stop that!
            if (mWaitingForConfig) {
                mWaitingForConfig = false;
                mLastFinishedFreezeSource = "new-config";
                performLayoutAndPlaceSurfacesLocked();
@@ -6913,9 +6913,7 @@ public class WindowManagerService extends IWindowManager.Stub
    Configuration computeNewConfigurationLocked() {
        Configuration config = new Configuration();
        config.fontScale = 0;
        if (!computeScreenConfigurationLocked(config)) {
            return null;
        }
        computeScreenConfigurationLocked(config);
        return config;
    }

@@ -7022,11 +7020,8 @@ public class WindowManagerService extends IWindowManager.Stub
        return sw;
    }

    /** Do not call if mDisplayReady == false */
    DisplayInfo updateDisplayAndOrientationLocked() {
        if (!mDisplayReady) {
            return null;
        }

        // TODO(multidisplay): For now, apply Configuration to main screen only.
        final DisplayContent displayContent = getDefaultDisplayContentLocked();

@@ -7083,11 +7078,9 @@ public class WindowManagerService extends IWindowManager.Stub
        return displayInfo;
    }

    boolean computeScreenConfigurationLocked(Configuration config) {
    /** Do not call if mDisplayReady == false */
    void computeScreenConfigurationLocked(Configuration config) {
        final DisplayInfo displayInfo = updateDisplayAndOrientationLocked();
        if (displayInfo == null) {
            return false;
        }

        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;
@@ -7172,8 +7165,6 @@ public class WindowManagerService extends IWindowManager.Stub
        config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
        config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
        mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);

        return true;
    }

    public boolean isHardKeyboardAvailable() {
@@ -8302,17 +8293,17 @@ public class WindowManagerService extends IWindowManager.Stub
    // displayContent must not be null
    private void reconfigureDisplayLocked(DisplayContent displayContent) {
        // TODO: Multidisplay: for now only use with default display.
        if (!mDisplayReady) {
            return;
        }
        configureDisplayPolicyLocked(displayContent);
        displayContent.layoutNeeded = true;

        boolean configChanged = updateOrientationFromAppTokensLocked(false);
        mTempConfiguration.setToDefaults();
        mTempConfiguration.fontScale = mCurConfiguration.fontScale;
        if (computeScreenConfigurationLocked(mTempConfiguration)) {
            if (mCurConfiguration.diff(mTempConfiguration) != 0) {
                configChanged = true;
            }
        }
        computeScreenConfigurationLocked(mTempConfiguration);
        configChanged |= mCurConfiguration.diff(mTempConfiguration) != 0;

        if (configChanged) {
            mWaitingForConfig = true;
@@ -8613,18 +8604,16 @@ public class WindowManagerService extends IWindowManager.Stub

        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
        mInLayout = true;
        boolean recoveringMemory = false;

        try {
            if (mForceRemoves != null) {
        boolean recoveringMemory = false;
        if (!mForceRemoves.isEmpty()) {
            recoveringMemory = true;
            // Wait a little bit for things to settle down, and off we go.
                for (int i=0; i<mForceRemoves.size(); i++) {
                    WindowState ws = mForceRemoves.get(i);
            while (!mForceRemoves.isEmpty()) {
                WindowState ws = mForceRemoves.remove(0);
                Slog.i(TAG, "Force removing: " + ws);
                    removeWindowInnerLocked(ws.mSession, ws);
                removeWindowInnerLocked(ws);
            }
                mForceRemoves = null;
            Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
            Object tmp = new Object();
            synchronized (tmp) {
@@ -8634,9 +8623,6 @@ public class WindowManagerService extends IWindowManager.Stub
                }
            }
        }
        } catch (RuntimeException e) {
            Slog.wtf(TAG, "Unhandled exception while force removing for memory", e);
        }

        try {
            performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
@@ -9311,13 +9297,11 @@ public class WindowManagerService extends IWindowManager.Stub

    /**
     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
     *
     *  @param w WindowState this method is applied to.
     * @param currentTime The time which animations use for calculating transitions.
     * @param innerDw Width of app window.
     * @param innerDh Height of app window.
     */
    private void handleNotObscuredLocked(final WindowState w, final long currentTime,
    private void handleNotObscuredLocked(final WindowState w,
            final int innerDw, final int innerDh) {
        final WindowManager.LayoutParams attrs = w.mAttrs;
        final int attrFlags = attrs.flags;
@@ -9437,8 +9421,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    + Debug.getCallers(3));
        }

        final long currentTime = SystemClock.uptimeMillis();

        int i;
        boolean updateInputWindowsNeeded = false;

@@ -9529,8 +9511,7 @@ public class WindowManagerService extends IWindowManager.Stub

                    if ((displayContent.pendingLayoutChanges &
                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
                            (adjustWallpaperWindowsLocked() &
                                    ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
                            adjustWallpaperWindowsLocked()) {
                        assignLayersLocked(windows);
                        displayContent.layoutNeeded = true;
                    }
@@ -9595,7 +9576,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    // Update effect.
                    w.mObscured = mInnerFields.mObscured;
                    if (!mInnerFields.mObscured) {
                        handleNotObscuredLocked(w, currentTime, innerDw, innerDh);
                        handleNotObscuredLocked(w, innerDw, innerDh);
                    }

                    if (stack != null && !stack.testDimmingTag()) {
@@ -9974,7 +9955,7 @@ public class WindowManagerService extends IWindowManager.Stub
            DisplayContentList displayList = new DisplayContentList();
            for (i = 0; i < N; i++) {
                WindowState w = mPendingRemoveTmp[i];
                removeWindowInnerLocked(w.mSession, w);
                removeWindowInnerLocked(w);
                final DisplayContent displayContent = w.getDisplayContent();
                if (displayContent != null && !displayList.contains(displayContent)) {
                    displayList.add(displayContent);
@@ -10150,10 +10131,6 @@ public class WindowManagerService extends IWindowManager.Stub
        EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
                winAnimator.mSession.mPid, operation);

        if (mForceRemoves == null) {
            mForceRemoves = new ArrayList<WindowState>();
        }

        long callingIdentity = Binder.clearCallingIdentity();
        try {
            // There was some problem...   first, do a sanity check of the
@@ -10335,6 +10312,10 @@ public class WindowManagerService extends IWindowManager.Stub
                + ", flags=" + win.mAttrs.flags
                + ", canReceive=" + win.canReceiveKeys());

            if (!win.canReceiveKeys()) {
                continue;
            }

            AppWindowToken wtoken = win.mAppToken;

            // If this window's application has been removed, just skip it.
@@ -10344,10 +10325,6 @@ public class WindowManagerService extends IWindowManager.Stub
                continue;
            }

            if (!win.canReceiveKeys()) {
                continue;
            }

            // Descend through all of the app tokens and find the first that either matches
            // win.mAppToken (return win) or mFocusedApp (return null).
            if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING &&