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

Commit 1daf1924 authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Android (Google) Code Review
Browse files

Merge "Adding supportedModes to DisplayDeviceConfig SensorData" into main

parents fe810dc2 fdbb6326
Loading
Loading
Loading
Loading
+26 −96
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ import com.android.server.display.config.RefreshRateThrottlingPoint;
import com.android.server.display.config.RefreshRateZone;
import com.android.server.display.config.SdrHdrRatioMap;
import com.android.server.display.config.SdrHdrRatioPoint;
import com.android.server.display.config.SensorDetails;
import com.android.server.display.config.SensorData;
import com.android.server.display.config.ThermalStatus;
import com.android.server.display.config.ThermalThrottling;
import com.android.server.display.config.ThresholdPoint;
@@ -349,6 +349,20 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *      <proxSensor>
 *        <type>android.sensor.proximity</type>
 *        <name>1234 Proximity Sensor</name>
 *        <refreshRate>
 *             <minimum>60</minimum>
 *             <maximum>60</maximum>
 *         </refreshRate>
 *         <supportedModes>
 *             <point>
 *                 <first>60</first>   // refreshRate
 *                 <second>60</second> //vsyncRate
 *             </point>
 *             <point>
 *                 <first>120</first>   // refreshRate
 *                 <second>120</second> //vsyncRate
 *             </point>
 *          </supportedModes>
 *      </proxSensor>
 *
 *      <ambientLightHorizonLong>10001</ambientLightHorizonLong>
@@ -581,15 +595,15 @@ public class DisplayDeviceConfig {
    private final Context mContext;

    // The details of the ambient light sensor associated with this display.
    private final SensorData mAmbientLightSensor = new SensorData();
    private SensorData mAmbientLightSensor;

    // The details of the doze brightness sensor associated with this display.
    private final SensorData mScreenOffBrightnessSensor = new SensorData();
    private SensorData mScreenOffBrightnessSensor;

    // The details of the proximity sensor associated with this display.
    // Is null when no sensor should be used for that display
    @Nullable
    private SensorData mProximitySensor = new SensorData();
    private SensorData mProximitySensor;

    private final List<RefreshRateLimitation> mRefreshRateLimitations =
            new ArrayList<>(2 /*initialCapacity*/);
@@ -1913,9 +1927,10 @@ public class DisplayDeviceConfig {
                loadLuxThrottling(config);
                loadQuirks(config);
                loadBrightnessRamps(config);
                loadAmbientLightSensorFromDdc(config);
                loadScreenOffBrightnessSensorFromDdc(config);
                loadProxSensorFromDdc(config);
                mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(config,
                        mContext.getResources());
                mScreenOffBrightnessSensor = SensorData.loadScreenOffBrightnessSensorConfig(config);
                mProximitySensor = SensorData.loadProxSensorConfig(config);
                loadAmbientHorizonFromDdc(config);
                loadBrightnessChangeThresholds(config);
                loadAutoBrightnessConfigValues(config);
@@ -1940,9 +1955,9 @@ public class DisplayDeviceConfig {
        loadBrightnessConstraintsFromConfigXml();
        loadBrightnessMapFromConfigXml();
        loadBrightnessRampsFromConfigXml();
        loadAmbientLightSensorFromConfigXml();
        mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(mContext.getResources());
        mProximitySensor = SensorData.loadSensorUnspecifiedConfig();
        loadBrightnessChangeThresholdsFromXml();
        setProxSensorUnspecified();
        loadAutoBrightnessConfigsFromConfigXml();
        loadAutoBrightnessAvailableFromConfigXml();
        loadRefreshRateSetting(null);
@@ -1966,8 +1981,8 @@ public class DisplayDeviceConfig {
        mBrightnessRampDecreaseMaxIdleMillis = 0;
        mBrightnessRampIncreaseMaxIdleMillis = 0;
        setSimpleMappingStrategyValues();
        loadAmbientLightSensorFromConfigXml();
        setProxSensorUnspecified();
        mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(mContext.getResources());
        mProximitySensor = SensorData.loadSensorUnspecifiedConfig();
        loadAutoBrightnessAvailableFromConfigXml();
    }

@@ -2919,64 +2934,10 @@ public class DisplayDeviceConfig {
        mBrightnessRampSlowDecrease = mBrightnessRampSlowIncrease;
    }

    private void loadAmbientLightSensorFromConfigXml() {
        mAmbientLightSensor.name = "";
        mAmbientLightSensor.type = mContext.getResources().getString(
                com.android.internal.R.string.config_displayLightSensorType);
    }

    private void loadAutoBrightnessConfigsFromConfigXml() {
        loadAutoBrightnessDisplayBrightnessMapping(null /*AutoBrightnessConfig*/);
    }

    private void loadAmbientLightSensorFromDdc(DisplayConfiguration config) {
        final SensorDetails sensorDetails = config.getLightSensor();
        if (sensorDetails != null) {
            loadSensorData(sensorDetails, mAmbientLightSensor);
        } else {
            loadAmbientLightSensorFromConfigXml();
        }
    }

    private void setProxSensorUnspecified() {
        mProximitySensor = new SensorData();
    }

    private void loadScreenOffBrightnessSensorFromDdc(DisplayConfiguration config) {
        final SensorDetails sensorDetails = config.getScreenOffBrightnessSensor();
        if (sensorDetails != null) {
            loadSensorData(sensorDetails, mScreenOffBrightnessSensor);
        }
    }

    private void loadProxSensorFromDdc(DisplayConfiguration config) {
        SensorDetails sensorDetails = config.getProxSensor();
        if (sensorDetails != null) {
            String name = sensorDetails.getName();
            String type = sensorDetails.getType();
            if ("".equals(name) && "".equals(type)) {
                // <proxSensor> with empty values to the config means no sensor should be used
                mProximitySensor = null;
            } else {
                mProximitySensor = new SensorData();
                loadSensorData(sensorDetails, mProximitySensor);
            }
        } else {
            setProxSensorUnspecified();
        }
    }

    private void loadSensorData(@NonNull SensorDetails sensorDetails,
            @NonNull SensorData sensorData) {
        sensorData.name = sensorDetails.getName();
        sensorData.type = sensorDetails.getType();
        final RefreshRateRange rr = sensorDetails.getRefreshRate();
        if (rr != null) {
            sensorData.minRefreshRate = rr.getMinimum().floatValue();
            sensorData.maxRefreshRate = rr.getMaximum().floatValue();
        }
    }

    private void loadBrightnessChangeThresholdsFromXml() {
        loadBrightnessChangeThresholds(/* config= */ null);
    }
@@ -3389,37 +3350,6 @@ public class DisplayDeviceConfig {
                : null;
    }

    /**
     * Uniquely identifies a Sensor, with the combination of Type and Name.
     */
    public static class SensorData {
        public String type;
        public String name;
        public float minRefreshRate = 0.0f;
        public float maxRefreshRate = Float.POSITIVE_INFINITY;

        @Override
        public String toString() {
            return "Sensor{"
                    + "type: " + type
                    + ", name: " + name
                    + ", refreshRateRange: [" + minRefreshRate + ", " + maxRefreshRate + "]"
                    + "} ";
        }

        /**
         * @return True if the sensor matches both the specified name and type, or one if only one
         * is specified (not-empty). Always returns false if both parameters are null or empty.
         */
        public boolean matches(String sensorName, String sensorType) {
            final boolean isNameSpecified = !TextUtils.isEmpty(sensorName);
            final boolean isTypeSpecified = !TextUtils.isEmpty(sensorType);
            return (isNameSpecified || isTypeSpecified)
                    && (!isNameSpecified || sensorName.equals(name))
                    && (!isTypeSpecified || sensorType.equals(type));
        }
    }

    /**
     * Container for high brightness mode configuration data.
     */
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.UiThread;
import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
import com.android.server.display.DisplayDeviceConfig.SensorData;
import com.android.server.display.config.SensorData;
import com.android.server.display.feature.DeviceConfigParameterProvider;
import com.android.server.display.feature.DisplayManagerFlags;
import com.android.server.display.layout.Layout;
+184 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.display.config;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.Resources;
import android.text.TextUtils;

import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Uniquely identifies a Sensor, with the combination of Type and Name.
 */
public class SensorData {

    @Nullable
    public final String type;
    @Nullable
    public final String name;
    public final float minRefreshRate;
    public final float maxRefreshRate;
    public final List<SupportedMode> supportedModes;

    @VisibleForTesting
    public SensorData() {
        this(/* type= */ null, /* name= */ null);
    }

    @VisibleForTesting
    public SensorData(String type, String name) {
        this(type, name, /* minRefreshRate= */ 0f, /* maxRefreshRate= */ Float.POSITIVE_INFINITY);
    }

    @VisibleForTesting
    public SensorData(String type, String name, float minRefreshRate, float maxRefreshRate) {
        this(type, name, minRefreshRate, maxRefreshRate, /* supportedModes= */ List.of());
    }

    @VisibleForTesting
    public SensorData(String type, String name, float minRefreshRate, float maxRefreshRate,
            List<SupportedMode> supportedModes) {
        this.type = type;
        this.name = name;
        this.minRefreshRate = minRefreshRate;
        this.maxRefreshRate = maxRefreshRate;
        this.supportedModes = Collections.unmodifiableList(supportedModes);
    }

    /**
     * @return True if the sensor matches both the specified name and type, or one if only one
     * is specified (not-empty). Always returns false if both parameters are null or empty.
     */
    public boolean matches(String sensorName, String sensorType) {
        final boolean isNameSpecified = !TextUtils.isEmpty(sensorName);
        final boolean isTypeSpecified = !TextUtils.isEmpty(sensorType);
        return (isNameSpecified || isTypeSpecified)
                && (!isNameSpecified || sensorName.equals(name))
                && (!isTypeSpecified || sensorType.equals(type));
    }

    @Override
    public String toString() {
        return "SensorData{"
                + "type= " + type
                + ", name= " + name
                + ", refreshRateRange: [" + minRefreshRate + ", " + maxRefreshRate + "]"
                + ", supportedModes=" + supportedModes
                + '}';
    }

    /**
     * Loads ambient light sensor data from DisplayConfiguration and if missing from resources xml
     */
    public static SensorData loadAmbientLightSensorConfig(DisplayConfiguration config,
            Resources resources) {
        SensorDetails sensorDetails = config.getLightSensor();
        if (sensorDetails != null) {
            return loadSensorData(sensorDetails);
        } else {
            return loadAmbientLightSensorConfig(resources);
        }
    }

    /**
     * Loads ambient light sensor data from resources xml
     */
    public static SensorData loadAmbientLightSensorConfig(Resources resources) {
        return new SensorData(
                resources.getString(com.android.internal.R.string.config_displayLightSensorType),
                /* name= */ "");
    }

    /**
     * Loads screen off brightness sensor data from DisplayConfiguration
     */
    public static SensorData loadScreenOffBrightnessSensorConfig(DisplayConfiguration config) {
        SensorDetails sensorDetails = config.getScreenOffBrightnessSensor();
        if (sensorDetails != null) {
            return loadSensorData(sensorDetails);
        } else {
            return new 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)) {
                // <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);
            }
        } else {
            return new SensorData();
        }
    }

    /**
     * Loads sensor unspecified config, this means system should use default sensor.
     * See also {@link com.android.server.display.utils.SensorUtils}
     */
    @NonNull
    public static SensorData loadSensorUnspecifiedConfig() {
        return new SensorData();
    }

    private static SensorData loadSensorData(@NonNull SensorDetails sensorDetails) {
        float minRefreshRate = 0f;
        float maxRefreshRate = Float.POSITIVE_INFINITY;
        RefreshRateRange rr = sensorDetails.getRefreshRate();
        if (rr != null) {
            minRefreshRate = rr.getMinimum().floatValue();
            maxRefreshRate = rr.getMaximum().floatValue();
        }
        ArrayList<SupportedMode> supportedModes = new ArrayList<>();
        NonNegativeFloatToFloatMap configSupportedModes = sensorDetails.getSupportedModes();
        if (configSupportedModes != null) {
            for (NonNegativeFloatToFloatPoint supportedMode : configSupportedModes.getPoint()) {
                supportedModes.add(new SupportedMode(supportedMode.getFirst().floatValue(),
                        supportedMode.getSecond().floatValue()));
            }
        }

        return new SensorData(sensorDetails.getType(), sensorDetails.getName(), minRefreshRate,
                maxRefreshRate, supportedModes);
    }

    public static class SupportedMode {
        public final float refreshRate;
        public final float vsyncRate;

        public SupportedMode(float refreshRate, float vsyncRate) {
            this.refreshRate = refreshRate;
            this.vsyncRate = vsyncRate;
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.text.TextUtils;

import com.android.server.display.DisplayDeviceConfig;
import com.android.server.display.config.SensorData;

import java.util.List;

@@ -36,7 +36,7 @@ public class SensorUtils {
     */
    @Nullable
    public static Sensor findSensor(@Nullable SensorManager sensorManager,
            @Nullable DisplayDeviceConfig.SensorData sensorData, int fallbackType) {
            @Nullable SensorData sensorData, int fallbackType) {
        if (sensorData == null) {
            return null;
        } else {
+14 −0
Original line number Diff line number Diff line
@@ -455,6 +455,20 @@
                <xs:annotation name="nullable"/>
                <xs:annotation name="final"/>
            </xs:element>
            <!-- list of supported modes when sensor is ON. Each point corresponds to one mode.
            Mode format is : first = refreshRate, second = vsyncRate. E.g. :
            <supportedModes>
                <point>
                    <first>60</first>   // refreshRate
                    <second>60</second> //vsyncRate
                </point>
                ....
            </supportedModes>
             -->
            <xs:element type="nonNegativeFloatToFloatMap" name="supportedModes" minOccurs="0">
                <xs:annotation name="nullable"/>
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

Loading