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

Commit 8d3c1295 authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Improve topology logging

- log new topology when display added/removed
- don't log the reason why display isn't in the topology every time display changes

Bug: 403256972
Bug: 401302003
Test: adb logcat, DisplayTopologyTest
Flag: EXEMPT log only update
Change-Id: If1ed85edc1c66fcc77cd1552c2424a2db45fba98
parent 34f9f07e
Loading
Loading
Loading
Loading
+18 −37
Original line number Diff line number Diff line
@@ -169,7 +169,23 @@ public final class DisplayTopology implements Parcelable {
     * @hide
     */
    public void addDisplay(int displayId, float width, float height) {
        addDisplay(displayId, width, height, /* shouldLog= */ true);
        if (findDisplay(displayId, mRoot) != null) {
            return;
        }
        if (mRoot == null) {
            mRoot = new TreeNode(displayId, width, height, POSITION_LEFT, /* offset= */ 0);
            mPrimaryDisplayId = displayId;
        } else if (mRoot.mChildren.isEmpty()) {
            // This is the 2nd display. Align the middles of the top and bottom edges.
            float offset = mRoot.mWidth / 2 - width / 2;
            TreeNode display = new TreeNode(displayId, width, height, POSITION_TOP, offset);
            mRoot.mChildren.add(display);
        } else {
            TreeNode rightMostDisplay = findRightMostDisplay(mRoot, mRoot.mWidth).first;
            TreeNode newDisplay = new TreeNode(displayId, width, height, POSITION_RIGHT,
                    /* offset= */ 0);
            rightMostDisplay.mChildren.add(newDisplay);
        }
    }

    /**
@@ -216,7 +232,7 @@ public final class DisplayTopology implements Parcelable {
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            if (node.mDisplayId != displayId) {
                addDisplay(node.mDisplayId, node.mWidth, node.mHeight, /* shouldLog= */ false);
                addDisplay(node.mDisplayId, node.mWidth, node.mHeight);
            }
            queue.addAll(node.mChildren);
        }
@@ -227,10 +243,6 @@ public final class DisplayTopology implements Parcelable {
            } else {
                mPrimaryDisplayId = Display.INVALID_DISPLAY;
            }
            Slog.i(TAG,  "Primary display with ID " + displayId
                    + " removed, new primary display: " + mPrimaryDisplayId);
        } else {
            Slog.i(TAG, "Display with ID " + displayId + " removed");
        }
        return true;
    }
@@ -598,37 +610,6 @@ public final class DisplayTopology implements Parcelable {
        return out.toString();
    }

    private void addDisplay(int displayId, float width, float height, boolean shouldLog) {
        if (findDisplay(displayId, mRoot) != null) {
            return;
        }
        if (mRoot == null) {
            mRoot = new TreeNode(displayId, width, height, POSITION_LEFT, /* offset= */ 0);
            mPrimaryDisplayId = displayId;
            if (shouldLog) {
                Slog.i(TAG, "First display added: " + mRoot);
            }
        } else if (mRoot.mChildren.isEmpty()) {
            // This is the 2nd display. Align the middles of the top and bottom edges.
            float offset = mRoot.mWidth / 2 - width / 2;
            TreeNode display = new TreeNode(displayId, width, height, POSITION_TOP, offset);
            mRoot.mChildren.add(display);
            if (shouldLog) {
                Slog.i(TAG, "Second display added: " + display + ", parent ID: "
                        + mRoot.mDisplayId);
            }
        } else {
            TreeNode rightMostDisplay = findRightMostDisplay(mRoot, mRoot.mWidth).first;
            TreeNode newDisplay = new TreeNode(displayId, width, height, POSITION_RIGHT,
                    /* offset= */ 0);
            rightMostDisplay.mChildren.add(newDisplay);
            if (shouldLog) {
                Slog.i(TAG, "Display added: " + newDisplay + ", parent ID: "
                        + rightMostDisplay.mDisplayId);
            }
        }
    }

    /**
     * @param display The display from which the search should start.
     * @param xPos The x position of the right edge of that display.
+17 −9
Original line number Diff line number Diff line
@@ -111,13 +111,14 @@ class DisplayTopologyCoordinator {
     * @param info The display info
     */
    void onDisplayAdded(DisplayInfo info) {
        if (!isDisplayAllowedInTopology(info)) {
        if (!isDisplayAllowedInTopology(info, /* shouldLog= */ true)) {
            return;
        }
        synchronized (mSyncRoot) {
            addDisplayIdMappingLocked(info);
            mDensities.put(info.displayId, info.logicalDensityDpi);
            mTopology.addDisplay(info.displayId, getWidth(info), getHeight(info));
            Slog.i(TAG, "Display " + info.displayId + " added, new topology: " + mTopology);
            restoreTopologyLocked();
            sendTopologyUpdateLocked();
        }
@@ -128,7 +129,7 @@ class DisplayTopologyCoordinator {
     * @param info The new display info
     */
    void onDisplayChanged(DisplayInfo info) {
        if (!isDisplayAllowedInTopology(info)) {
        if (!isDisplayAllowedInTopology(info, /* shouldLog= */ false)) {
            return;
        }
        synchronized (mSyncRoot) {
@@ -149,6 +150,7 @@ class DisplayTopologyCoordinator {
        synchronized (mSyncRoot) {
            mDensities.delete(displayId);
            if (mTopology.removeDisplay(displayId)) {
                Slog.i(TAG, "Display " + displayId + " removed, new topology: " + mTopology);
                removeDisplayIdMappingLocked(displayId);
                restoreTopologyLocked();
                sendTopologyUpdateLocked();
@@ -249,22 +251,28 @@ class DisplayTopologyCoordinator {
        return pxToDp(info.logicalHeight, info.logicalDensityDpi);
    }

    private boolean isDisplayAllowedInTopology(DisplayInfo info) {
    private boolean isDisplayAllowedInTopology(DisplayInfo info, boolean shouldLog) {
        if (info.type != Display.TYPE_INTERNAL && info.type != Display.TYPE_EXTERNAL
                && info.type != Display.TYPE_OVERLAY) {
            if (shouldLog) {
                Slog.d(TAG, "Display " + info.displayId + " not allowed in topology because "
                        + "type is not INTERNAL, EXTERNAL or OVERLAY");
            }
            return false;
        }
        if (info.type == Display.TYPE_INTERNAL && info.displayId != Display.DEFAULT_DISPLAY) {
            if (shouldLog) {
                Slog.d(TAG, "Display " + info.displayId + " not allowed in topology because "
                        + "it is a non-default internal display");
            }
            return false;
        }
        if ((info.type == Display.TYPE_EXTERNAL || info.type == Display.TYPE_OVERLAY)
                && !mIsExtendedDisplayAllowed.getAsBoolean()) {
            if (shouldLog) {
                Slog.d(TAG, "Display " + info.displayId + " not allowed in topology because "
                        + "type is EXTERNAL or OVERLAY and !mIsExtendedDisplayAllowed");
            }
            return false;
        }
        return true;