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

Commit e70b2c2b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add Display#canHostTasks()" into main

parents 27224f9c 5ff2cfab
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -2055,6 +2055,22 @@ public final class Display {
        }
    }

    /**
     * Returns whether the display is eligible for hosting tasks.
     *
     * For example, if the display is used for mirroring, this will return {@code false}.
     *
     * TODO (b/383666349): Rename this later once there is a better option.
     *
     * @hide
     */
    public boolean canHostTasks() {
        synchronized (mLock) {
            updateDisplayInfoLocked();
            return mIsValid && mDisplayInfo.canHostTasks;
        }
    }

    /**
     * Returns true if the specified UID has access to this display.
     * @hide
+16 −1
Original line number Diff line number Diff line
@@ -408,6 +408,15 @@ public final class DisplayInfo implements Parcelable {
    @Nullable
    public String thermalBrightnessThrottlingDataId;

    /**
     * Indicates whether the display is eligible for hosting tasks.
     *
     * For example, if the display is used for mirroring, this will be {@code false}.
     *
     * @hide
     */
    public boolean canHostTasks;

    public static final @android.annotation.NonNull Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
        @Override
        public DisplayInfo createFromParcel(Parcel source) {
@@ -493,7 +502,8 @@ public final class DisplayInfo implements Parcelable {
                && BrightnessSynchronizer.floatEquals(hdrSdrRatio, other.hdrSdrRatio)
                && thermalRefreshRateThrottling.contentEquals(other.thermalRefreshRateThrottling)
                && Objects.equals(
                thermalBrightnessThrottlingDataId, other.thermalBrightnessThrottlingDataId);
                thermalBrightnessThrottlingDataId, other.thermalBrightnessThrottlingDataId)
                && canHostTasks == other.canHostTasks;
    }

    @Override
@@ -561,6 +571,7 @@ public final class DisplayInfo implements Parcelable {
        hdrSdrRatio = other.hdrSdrRatio;
        thermalRefreshRateThrottling = other.thermalRefreshRateThrottling;
        thermalBrightnessThrottlingDataId = other.thermalBrightnessThrottlingDataId;
        canHostTasks = other.canHostTasks;
    }

    public void readFromParcel(Parcel source) {
@@ -642,6 +653,7 @@ public final class DisplayInfo implements Parcelable {
        thermalRefreshRateThrottling = source.readSparseArray(null,
                SurfaceControl.RefreshRateRange.class);
        thermalBrightnessThrottlingDataId = source.readString8();
        canHostTasks = source.readBoolean();
    }

    @Override
@@ -717,6 +729,7 @@ public final class DisplayInfo implements Parcelable {
        dest.writeFloat(hdrSdrRatio);
        dest.writeSparseArray(thermalRefreshRateThrottling);
        dest.writeString8(thermalBrightnessThrottlingDataId);
        dest.writeBoolean(canHostTasks);
    }

    @Override
@@ -1020,6 +1033,8 @@ public final class DisplayInfo implements Parcelable {
        sb.append(thermalRefreshRateThrottling);
        sb.append(", thermalBrightnessThrottlingDataId ");
        sb.append(thermalBrightnessThrottlingDataId);
        sb.append(", canHostTasks ");
        sb.append(canHostTasks);
        sb.append("}");
        return sb.toString();
    }
+8 −0
Original line number Diff line number Diff line
@@ -305,6 +305,14 @@ abstract class DisplayDevice {
    public void onOverlayChangedLocked() {
    }

    /**
     * Returns if the display should only mirror another display rather than showing other content
     * until it is destroyed.
     */
    public boolean shouldOnlyMirror() {
        return false;
    }

    /**
     * Sets the display layer stack while in a transaction.
     */
+23 −6
Original line number Diff line number Diff line
@@ -199,7 +199,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;


/**
 * Manages attached displays.
 * <p>
@@ -906,6 +905,16 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    @VisibleForTesting
    ContentObserver getSettingsObserver() {
        return mSettingsObserver;
    }

    @VisibleForTesting
    boolean shouldMirrorBuiltInDisplay() {
        return mMirrorBuiltInDisplay;
    }

    DisplayNotificationManager getDisplayNotificationManager() {
        return mDisplayNotificationManager;
    }
@@ -1230,11 +1239,6 @@ public final class DisplayManagerService extends SystemService {
    }

    private void updateMirrorBuiltInDisplaySettingLocked() {
        if (!mFlags.isDisplayContentModeManagementEnabled()) {
            Slog.e(TAG, "MirrorBuiltInDisplay setting shouldn't be updated when the flag is off.");
            return;
        }

        synchronized (mSyncRoot) {
            ContentResolver resolver = mContext.getContentResolver();
            final boolean mirrorBuiltInDisplay = Settings.Secure.getIntForUser(resolver,
@@ -1243,6 +1247,9 @@ public final class DisplayManagerService extends SystemService {
                return;
            }
            mMirrorBuiltInDisplay = mirrorBuiltInDisplay;
            if (mFlags.isDisplayContentModeManagementEnabled()) {
                mLogicalDisplayMapper.forEachLocked(this::updateCanHostTasksIfNeededLocked);
            }
        }
    }

@@ -2308,6 +2315,10 @@ public final class DisplayManagerService extends SystemService {
        mDisplayBrightnesses.append(displayId,
                new BrightnessPair(brightnessDefault, brightnessDefault));

        if (mFlags.isDisplayContentModeManagementEnabled()) {
            updateCanHostTasksIfNeededLocked(display);
        }

        DisplayManagerGlobal.invalidateLocalDisplayInfoCaches();
    }

@@ -2630,6 +2641,12 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    private void updateCanHostTasksIfNeededLocked(LogicalDisplay display) {
        if (display.setCanHostTasksLocked(!mMirrorBuiltInDisplay)) {
            sendDisplayEventIfEnabledLocked(display, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
        }
    }

    private void recordTopInsetLocked(@Nullable LogicalDisplay d) {
        // We must only persist the inset after boot has completed, otherwise we will end up
        // overwriting the persisted value before the masking flag has been loaded from the
+4 −2
Original line number Diff line number Diff line
@@ -217,8 +217,10 @@ class ExternalDisplayPolicy {

        mExternalDisplayStatsService.onDisplayConnected(logicalDisplay);

        if ((Build.IS_ENG || Build.IS_USERDEBUG)
                && SystemProperties.getBoolean(ENABLE_ON_CONNECT, false)) {
        if (((Build.IS_ENG || Build.IS_USERDEBUG)
                        && SystemProperties.getBoolean(ENABLE_ON_CONNECT, false))
                || (mFlags.isDisplayContentModeManagementEnabled()
                        && logicalDisplay.canHostTasksLocked())) {
            Slog.w(TAG, "External display is enabled by default, bypassing user consent.");
            mInjector.sendExternalDisplayEventLocked(logicalDisplay, EVENT_DISPLAY_CONNECTED);
            return;
Loading