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

Commit a643556a authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Automerger Merge Worker
Browse files

Merge "More initialisation for external displays Change the...

Merge "More initialisation for external displays Change the FLAG_DEFAULT_DISPLAY to FLAG_SUPPORTS_DEFAULT_DISPLAY When the default display of the default layout is removed, find another display and make it default" into tm-dev am: a3a39631

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17071392



Change-Id: Idca7eff8ab59fc0b6b1e718ab4817ad697fb598b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 311db3a0 a3a39631
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -30,9 +30,8 @@ import android.util.Slog;
import android.util.Spline;
import android.view.DisplayAddress;

import com.android.internal.annotations.VisibleForTesting;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.display.config.BrightnessThresholds;
import com.android.server.display.config.BrightnessThrottlingMap;
@@ -296,9 +295,9 @@ public class DisplayDeviceConfig {
     * @return A configuration instance for the specified display.
     */
    public static DisplayDeviceConfig create(Context context, long physicalDisplayId,
            boolean isDefaultDisplay) {
            boolean isFirstDisplay) {
        final DisplayDeviceConfig config = createWithoutDefaultValues(context, physicalDisplayId,
                isDefaultDisplay);
                isFirstDisplay);

        config.copyUninitializedValuesFromSecondaryConfig(loadDefaultConfigurationXml(context));
        return config;
@@ -323,7 +322,7 @@ public class DisplayDeviceConfig {
    }

    private static DisplayDeviceConfig createWithoutDefaultValues(Context context,
            long physicalDisplayId, boolean isDefaultDisplay) {
            long physicalDisplayId, boolean isFirstDisplay) {
        DisplayDeviceConfig config;

        config = loadConfigFromDirectory(context, Environment.getProductDirectory(),
@@ -341,7 +340,7 @@ public class DisplayDeviceConfig {
        // If no config can be loaded from any ddc xml at all,
        // prepare a whole config using the global config.xml.
        // Guaranteed not null
        return create(context, isDefaultDisplay);
        return create(context, isFirstDisplay);
    }

    private static DisplayConfiguration loadDefaultConfigurationXml(Context context) {
+3 −3
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ final class DisplayDeviceInfo {
     * Flag: Indicates that this display device should be considered the default display
     * device of the system.
     */
    public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
    public static final int FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY = 1 << 0;

    /**
     * Flag: Indicates that the orientation of this display device is coupled to the
@@ -538,8 +538,8 @@ final class DisplayDeviceInfo {

    private static String flagsToString(int flags) {
        StringBuilder msg = new StringBuilder();
        if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
            msg.append(", FLAG_DEFAULT_DISPLAY");
        if ((flags & FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY) != 0) {
            msg.append(", FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY");
        }
        if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
            msg.append(", FLAG_ROTATES_WITH_CONTENT");
+2 −4
Original line number Diff line number Diff line
@@ -397,8 +397,7 @@ public final class DisplayManagerService extends SystemService {
    private final ArrayList<DisplayViewport> mTempViewports = new ArrayList<>();

    // The default color mode for default displays. Overrides the usual
    // Display.Display.COLOR_MODE_DEFAULT for displays with the
    // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
    // Display.Display.COLOR_MODE_DEFAULT for local displays.
    private final int mDefaultDisplayDefaultColorMode;

    // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
@@ -1682,8 +1681,7 @@ public final class DisplayManagerService extends SystemService {
        if (display.getPrimaryDisplayDeviceLocked() == device) {
            int colorMode = mPersistentDataStore.getColorMode(device);
            if (colorMode == Display.COLOR_MODE_INVALID) {
                if ((device.getDisplayDeviceInfoLocked().flags
                     & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
                if (display.getDisplayIdLocked() == Display.DEFAULT_DISPLAY) {
                    colorMode = mDefaultDisplayDefaultColorMode;
                } else {
                    colorMode = Display.COLOR_MODE_DEFAULT;
+12 −12
Original line number Diff line number Diff line
@@ -141,9 +141,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            LocalDisplayDevice device = mDevices.get(physicalDisplayId);
            if (device == null) {
                // Display was added.
                final boolean isDefaultDisplay = mDevices.size() == 0;
                final boolean isFirstDisplay = mDevices.size() == 0;
                device = new LocalDisplayDevice(displayToken, physicalDisplayId, staticInfo,
                        dynamicInfo, modeSpecs, isDefaultDisplay);
                        dynamicInfo, modeSpecs, isFirstDisplay);
                mDevices.put(physicalDisplayId, device);
                sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
            } else if (device.updateDisplayPropertiesLocked(staticInfo, dynamicInfo,
@@ -187,7 +187,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>();
        private final DisplayModeDirector.DesiredDisplayModeSpecs mDisplayModeSpecs =
                new DisplayModeDirector.DesiredDisplayModeSpecs();
        private final boolean mIsDefaultDisplay;
        private final boolean mIsFirstDisplay;
        private final BacklightAdapter mBacklightAdapter;
        private final SidekickInternal mSidekickInternal;

@@ -226,14 +226,14 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        LocalDisplayDevice(IBinder displayToken, long physicalDisplayId,
                SurfaceControl.StaticDisplayInfo staticDisplayInfo,
                SurfaceControl.DynamicDisplayInfo dynamicInfo,
                SurfaceControl.DesiredDisplayModeSpecs modeSpecs, boolean isDefaultDisplay) {
                SurfaceControl.DesiredDisplayModeSpecs modeSpecs, boolean isFirstDisplay) {
            super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + physicalDisplayId,
                    getContext());
            mPhysicalDisplayId = physicalDisplayId;
            mIsDefaultDisplay = isDefaultDisplay;
            mIsFirstDisplay = isFirstDisplay;
            updateDisplayPropertiesLocked(staticDisplayInfo, dynamicInfo, modeSpecs);
            mSidekickInternal = LocalServices.getService(SidekickInternal.class);
            mBacklightAdapter = new BacklightAdapter(displayToken, isDefaultDisplay,
            mBacklightAdapter = new BacklightAdapter(displayToken, isFirstDisplay,
                    mSurfaceControlProxy);
            mActiveDisplayModeAtStartId = dynamicInfo.activeDisplayModeId;
        }
@@ -480,7 +480,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            // Load display device config
            final Context context = getOverlayContext();
            mDisplayDeviceConfig = DisplayDeviceConfig.create(context, mPhysicalDisplayId,
                    mIsDefaultDisplay);
                    mIsFirstDisplay);

            // Load brightness HWC quirk
            mBacklightAdapter.setForceSurfaceControl(mDisplayDeviceConfig.hasQuirk(
@@ -652,9 +652,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {

                final Resources res = getOverlayContext().getResources();

                if (mIsDefaultDisplay) {
                    mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY;
                mInfo.flags |= DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY;

                if (mIsFirstDisplay) {
                    if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound)
                            || (Build.IS_EMULATOR
                            && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) {
@@ -1438,9 +1438,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {

        /**
         * @param displayToken Token for display associated with this backlight.
         * @param isDefaultDisplay {@code true} if it is the default display.
         * @param isFirstDisplay {@code true} if it is the first display.
         */
        BacklightAdapter(IBinder displayToken, boolean isDefaultDisplay,
        BacklightAdapter(IBinder displayToken, boolean isFirstDisplay,
                SurfaceControlProxy surfaceControlProxy) {
            mDisplayToken = displayToken;
            mSurfaceControlProxy = surfaceControlProxy;
@@ -1448,7 +1448,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            mUseSurfaceControlBrightness = mSurfaceControlProxy
                    .getDisplayBrightnessSupport(mDisplayToken);

            if (!mUseSurfaceControlBrightness && isDefaultDisplay) {
            if (!mUseSurfaceControlBrightness && isFirstDisplay) {
                LightsManager lights = LocalServices.getService(LightsManager.class);
                mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT);
            } else {
+48 −11
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.display;

import static android.view.Display.DEFAULT_DISPLAY;

import android.annotation.NonNull;
import android.content.Context;
import android.hardware.devicestate.DeviceStateManager;
@@ -204,6 +206,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                if (DEBUG) {
                    Slog.d(TAG, "Display device removed: " + device.getDisplayDeviceInfoLocked());
                }
                handleDisplayDeviceRemovedLocked(device);
                updateLogicalDisplaysLocked();
                break;
        }
@@ -529,12 +532,12 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {

    private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
        DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
        // Internal Displays need to have additional initialization.
        // This initializes a default dynamic display layout for INTERNAL
        // devices, which is used as a fallback in case no static layout definitions
        // The default Display needs to have additional initialization.
        // This initializes a default dynamic display layout for the default
        // device, which is used as a fallback in case no static layout definitions
        // exist or cannot be loaded.
        if (deviceInfo.type == Display.TYPE_INTERNAL) {
            initializeInternalDisplayDeviceLocked(device);
        if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY) != 0) {
            initializeDefaultDisplayDeviceLocked(device);
        }

        // Create a logical display for the new display device
@@ -545,6 +548,38 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        updateLogicalDisplaysLocked();
    }

    private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
        final Layout layout = mDeviceStateToLayoutMap.get(DeviceStateToLayoutMap.STATE_DEFAULT);
        Layout.Display layoutDisplay = layout.getById(DEFAULT_DISPLAY);
        if (layoutDisplay == null) {
            return;
        }
        DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();

        if (layoutDisplay.getAddress().equals(deviceInfo.address)) {
            layout.removeDisplayLocked(DEFAULT_DISPLAY);

            // Need to find another local display and make it default
            for (int i = 0; i < mLogicalDisplays.size(); i++) {
                LogicalDisplay nextDisplay = mLogicalDisplays.valueAt(i);
                DisplayDevice nextDevice = nextDisplay.getPrimaryDisplayDeviceLocked();
                if (nextDevice == null) {
                    continue;
                }
                DisplayDeviceInfo nextDeviceInfo = nextDevice.getDisplayDeviceInfoLocked();

                if ((nextDeviceInfo.flags
                        & DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY) != 0
                        && !nextDeviceInfo.address.equals(deviceInfo.address)) {
                    layout.createDisplayLocked(nextDeviceInfo.address,
                            /* isDefault= */ true, /* isEnabled= */ true);
                    applyLayoutLocked();
                    return;
                }
            }
        }
    }

    /**
     * Updates the rest of the display system once all the changes are applied for display
     * devices and logical displays. The includes releasing invalid/empty LogicalDisplays,
@@ -900,16 +935,18 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        return isOwnDisplayGroup ? mNextNonDefaultGroupId++ : Display.DEFAULT_DISPLAY_GROUP;
    }

    private void initializeInternalDisplayDeviceLocked(DisplayDevice device) {
    private void initializeDefaultDisplayDeviceLocked(DisplayDevice device) {
        // We always want to make sure that our default layout creates a logical
        // display for every internal display device that is found.
        // To that end, when we are notified of a new internal display, we add it to
        // display for the default display device that is found.
        // To that end, when we are notified of a new default display, we add it to
        // the default layout definition if it is not already there.
        final Layout layout = mDeviceStateToLayoutMap.get(DeviceStateToLayoutMap.STATE_DEFAULT);
        if (layout.getById(DEFAULT_DISPLAY) != null) {
            // The layout should only have one default display
            return;
        }
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        final boolean isDefault = (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
        final boolean isEnabled = isDefault || mSupportsConcurrentInternalDisplays;
        layout.createDisplayLocked(info.address, isDefault, isEnabled);
        layout.createDisplayLocked(info.address, /* isDefault= */ true, /* isEnabled= */ true);
    }

    private int assignLayerStackLocked(int displayId) {
Loading