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

Commit 6ceb215e authored by Lingyu Feng's avatar Lingyu Feng Committed by Android (Google) Code Review
Browse files

Merge "Modify conditions of LogicalDisplay#validateCanHostTasksLocked()" into main

parents 1d79be47 9bc7379d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -315,6 +315,14 @@ abstract class DisplayDevice {
        return false;
    }

    /**
     * Returns whether content should be automatically mirrored on the display when no content is
     * currently being shown.
     */
    boolean shouldAutoMirror() {
        return false;
    }

    /**
     * Sets the display layer stack while in a transaction.
     */
+16 −0
Original line number Diff line number Diff line
@@ -998,6 +998,22 @@ final class LogicalDisplay {
            return true;
        }

        // The display that should always show system decorations can always host tasks.
        // See DisplayDeviceInfo#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS.
        final boolean shouldAlwaysShowSysDecors =
                (mPrimaryDisplayDevice.getDisplayDeviceInfoLocked().flags
                        & DisplayDeviceInfo.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0;
        if (shouldAlwaysShowSysDecors) {
            return true;
        }

        // The display that should auto mirror can always host tasks.
        // TODO(b/426331944): Change the behavior of VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR and returns
        // false for this
        if (mPrimaryDisplayDevice.shouldAutoMirror()) {
            return true;
        }

        return canHostTasks;
    }

+9 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUST
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.IBrightnessListener;
import android.hardware.display.IVirtualDisplayCallback;
import android.hardware.display.VirtualDisplayConfig;
@@ -547,6 +548,14 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
            return mProjection != null;
        }

        /**
         * See {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
         */
        @Override
        boolean shouldAutoMirror() {
            return (mFlags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0;
        }

        public void setSurfaceLocked(Surface surface) {
            if (!mStopped && mSurface != surface) {
                if (mDisplayState == Display.STATE_ON
+28 −0
Original line number Diff line number Diff line
@@ -692,4 +692,32 @@ public class LogicalDisplayTest {
        mLogicalDisplay.setCanHostTasksLocked(false);
        assertTrue(mLogicalDisplay.canHostTasksLocked());
    }

    @Test
    public void testSetCanHostTasks_nonDefaultShouldAlwaysShowSysDecors() {
        mDisplayDeviceInfo.flags = DisplayDeviceInfo.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS;
        mLogicalDisplay =
                new LogicalDisplay(Display.DEFAULT_DISPLAY + 1, LAYER_STACK, mDisplayDevice);

        mLogicalDisplay.setCanHostTasksLocked(true);
        assertTrue(mLogicalDisplay.canHostTasksLocked());

        mLogicalDisplay.setCanHostTasksLocked(false);
        assertTrue(mLogicalDisplay.canHostTasksLocked());
    }

    @Test
    public void testSetCanHostTasks_nonDefaultNeverBlank() {
        mDisplayDeviceInfo.type = Display.TYPE_VIRTUAL;
        when(mDisplayDevice.shouldAutoMirror()).thenReturn(true);
        mLogicalDisplay =
                new LogicalDisplay(Display.DEFAULT_DISPLAY + 1, LAYER_STACK, mDisplayDevice);
        mLogicalDisplay.updateLocked(mDeviceRepo, mSyntheticModeManager);

        mLogicalDisplay.setCanHostTasksLocked(true);
        assertTrue(mLogicalDisplay.canHostTasksLocked());

        mLogicalDisplay.setCanHostTasksLocked(false);
        assertTrue(mLogicalDisplay.canHostTasksLocked());
    }
}