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

Commit 4ce70799 authored by Fiona Campbell's avatar Fiona Campbell Committed by Android (Google) Code Review
Browse files

Merge "DisplayConfig: Add flag-protected option to select Fusion Proximity sensor." into main

parents f788d809 a6c764c7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2139,7 +2139,7 @@ public class DisplayDeviceConfig {
                mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(config,
                        mContext.getResources());
                mScreenOffBrightnessSensor = SensorData.loadScreenOffBrightnessSensorConfig(config);
                mProximitySensor = SensorData.loadProxSensorConfig(config);
                mProximitySensor = SensorData.loadProxSensorConfig(mFlags, config);
                mTempSensor = SensorData.loadTempSensorConfig(mFlags, config);
                loadAmbientHorizonFromDdc(config);
                loadBrightnessChangeThresholds(config);
+36 −11
Original line number Diff line number Diff line
@@ -129,21 +129,46 @@ public class SensorData {
     * Loads proximity sensor data from DisplayConfiguration
     */
    @Nullable
    public static SensorData loadProxSensorConfig(DisplayConfiguration config) {
        SensorDetails sensorDetails = config.getProxSensor();
        if (sensorDetails != null) {
            String name = sensorDetails.getName();
            String type = sensorDetails.getType();
            if ("".equals(name) && "".equals(type)) {
    public static SensorData loadProxSensorConfig(
            DisplayManagerFlags flags, DisplayConfiguration config) {
        SensorData DEFAULT_SENSOR = new SensorData();
        List<SensorDetails> sensorDetailsList = config.getProxSensor();
        if (sensorDetailsList.isEmpty()) {
            return DEFAULT_SENSOR;
        }

        SensorData selectedSensor = DEFAULT_SENSOR;
        // Prioritize flagged sensors.
        for (SensorDetails sensorDetails : sensorDetailsList) {
            String flagStr = sensorDetails.getFeatureFlag();
            if (flags.isUseFusionProxSensorEnabled() &&
                flags.getUseFusionProxSensorFlagName().equals(flagStr)) {
                selectedSensor = loadSensorData(sensorDetails);
                break;
            }
        }

        // Check for normal un-flagged sensor if a flagged one wasn't found.
        if (DEFAULT_SENSOR == selectedSensor) {
            for (SensorDetails sensorDetails : sensorDetailsList) {
                if (sensorDetails.getFeatureFlag() != null) {
                    continue;
                }
                selectedSensor = loadSensorData(sensorDetails);
                break;
            }
        }

        // Check if we shouldn't use a sensor at all.
        if (DEFAULT_SENSOR != selectedSensor) {
            if ("".equals(selectedSensor.name) && "".equals(selectedSensor.type)) {
                // <proxSensor> with empty values to the config means no sensor should be used.
                // See also {@link com.android.server.display.utils.SensorUtils}
                return null;
            } else {
                return loadSensorData(sensorDetails);
                selectedSensor = null;
            }
        } else {
            return new SensorData();
        }

        return selectedSensor;
    }

    /**
+17 −1
Original line number Diff line number Diff line
@@ -144,12 +144,15 @@ public class DisplayManagerFlags {
            Flags::idleScreenRefreshRateTimeout
    );


    private final FlagState mRefactorDisplayPowerController = new FlagState(
            Flags.FLAG_REFACTOR_DISPLAY_POWER_CONTROLLER,
            Flags::refactorDisplayPowerController
    );

    private final FlagState mUseFusionProxSensor = new FlagState(
            Flags.FLAG_USE_FUSION_PROX_SENSOR,
            Flags::useFusionProxSensor
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
@@ -301,6 +304,14 @@ public class DisplayManagerFlags {
        return mRefactorDisplayPowerController.isEnabled();
    }

    public boolean isUseFusionProxSensorEnabled() {
        return mUseFusionProxSensor.isEnabled();
    }

    public String getUseFusionProxSensorFlagName() {
        return mUseFusionProxSensor.getName();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -331,6 +342,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mIdleScreenRefreshRateTimeout);
        pw.println(" " + mRefactorDisplayPowerController);
        pw.println(" " + mResolutionBackupRestore);
        pw.println(" " + mUseFusionProxSensor);
    }

    private static class FlagState {
@@ -346,6 +358,10 @@ public class DisplayManagerFlags {
            mFlagFunction = flagFunction;
        }

        private String getName() {
            return mName;
        }

        private boolean isEnabled() {
            if (mEnabledSet) {
                if (DEBUG) {
+8 −0
Original line number Diff line number Diff line
@@ -235,3 +235,11 @@ flag {
    bug: "310026579"
    is_fixed_read_only: true
}

flag {
    name: "use_fusion_prox_sensor"
    namespace: "display_manager"
    description: "Feature flag to control usage of a Fusion Proximity sensor if configued."
    bug: "306203895"
    is_fixed_read_only: true
}
+2 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@
                <xs:element type="sensorDetails" name="screenOffBrightnessSensor">
                    <xs:annotation name="final"/>
                </xs:element>
                <xs:element type="sensorDetails" name="proxSensor">
                <xs:element type="sensorDetails" name="proxSensor" maxOccurs="2">
                    <xs:annotation name="final"/>
                </xs:element>
                <xs:element type="sensorDetails" name="tempSensor">
@@ -478,6 +478,7 @@
    </xs:simpleType>

    <xs:complexType name="sensorDetails">
        <xs:attribute name="featureFlag" type="xs:string" use="optional"/>
        <xs:sequence>
            <xs:element type="xs:string" name="type" minOccurs="0" maxOccurs="1">
                <xs:annotation name="nullable"/>
Loading