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

Commit 870fd130 authored by sashwinbalaji's avatar sashwinbalaji
Browse files

display: Allow temperature sensor to be specified per display.

Add a temp sensor field in display device configuration.
The sensor will be used to monitor the thermal status of display
hotspot instead of always relying on SKIN(overall device) temp.
If config not given we will fall back to SKIN temp.

Add feature flag sensor_based_brightness_throttling to track tempSensor.

Bug: 279114539
Test: atest DisplayDeviceConfigTest
Change-Id: I5179b15671a20c5d12e690b51509f298ba515b3b
parent ab38681a
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -384,6 +384,10 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *             </point>
 *          </supportedModes>
 *      </proxSensor>
 *      <tempSensor>
 *        <type>DISPLAY</type>
 *        <name>VIRTUAL-SKIN-DISPLAY</name>
 *      </tempSensor>
 *
 *      <ambientLightHorizonLong>10001</ambientLightHorizonLong>
 *      <ambientLightHorizonShort>2001</ambientLightHorizonShort>
@@ -625,6 +629,12 @@ public class DisplayDeviceConfig {
    @Nullable
    private SensorData mProximitySensor;

    // The details of the temperature sensor associated with this display.
    // Throttling will be based on thermal status of this sensor.
    // For empty values default back to sensor of TYPE_SKIN.
    @NonNull
    private SensorData mTempSensor;

    private final List<RefreshRateLimitation> mRefreshRateLimitations =
            new ArrayList<>(2 /*initialCapacity*/);

@@ -1489,6 +1499,13 @@ public class DisplayDeviceConfig {
        return mProximitySensor;
    }

    /**
     * @return temperature sensor data associated with the display.
     */
    public SensorData getTempSensor() {
        return mTempSensor;
    }

    boolean isAutoBrightnessAvailable() {
        return mAutoBrightnessAvailable;
    }
@@ -1871,6 +1888,7 @@ public class DisplayDeviceConfig {
                + "mAmbientLightSensor=" + mAmbientLightSensor
                + ", mScreenOffBrightnessSensor=" + mScreenOffBrightnessSensor
                + ", mProximitySensor=" + mProximitySensor
                + ", mTempSensor=" + mTempSensor
                + ", mRefreshRateLimitations= " + Arrays.toString(mRefreshRateLimitations.toArray())
                + ", mDensityMapping= " + mDensityMapping
                + ", mAutoBrightnessBrighteningLightDebounce= "
@@ -1972,6 +1990,7 @@ public class DisplayDeviceConfig {
                        mContext.getResources());
                mScreenOffBrightnessSensor = SensorData.loadScreenOffBrightnessSensorConfig(config);
                mProximitySensor = SensorData.loadProxSensorConfig(config);
                mTempSensor = SensorData.loadTempSensorConfig(mFlags, config);
                loadAmbientHorizonFromDdc(config);
                loadBrightnessChangeThresholds(config);
                loadAutoBrightnessConfigValues(config);
@@ -1999,6 +2018,7 @@ public class DisplayDeviceConfig {
        loadBrightnessRampsFromConfigXml();
        mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(mContext.getResources());
        mProximitySensor = SensorData.loadSensorUnspecifiedConfig();
        mTempSensor = SensorData.loadTempSensorUnspecifiedConfig();
        loadBrightnessChangeThresholdsFromXml();
        loadAutoBrightnessConfigsFromConfigXml();
        loadAutoBrightnessAvailableFromConfigXml();
@@ -2026,6 +2046,7 @@ public class DisplayDeviceConfig {
        setSimpleMappingStrategyValues();
        mAmbientLightSensor = SensorData.loadAmbientLightSensorConfig(mContext.getResources());
        mProximitySensor = SensorData.loadSensorUnspecifiedConfig();
        mTempSensor = SensorData.loadTempSensorUnspecifiedConfig();
        loadAutoBrightnessAvailableFromConfigXml();
    }

+30 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.res.Resources;
import android.text.TextUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.feature.DisplayManagerFlags;

import java.util.ArrayList;
import java.util.Collections;
@@ -32,6 +33,9 @@ import java.util.List;
 */
public class SensorData {

    public static final String TEMPERATURE_TYPE_DISPLAY = "DISPLAY";
    public static final String TEMPERATURE_TYPE_SKIN = "SKIN";

    @Nullable
    public final String type;
    @Nullable
@@ -142,6 +146,32 @@ public class SensorData {
        }
    }

    /**
     * Loads temperature sensor data for no config case. (Type: SKIN, Name: null)
     */
    public static SensorData loadTempSensorUnspecifiedConfig() {
        return new SensorData(TEMPERATURE_TYPE_SKIN, null);
    }

    /**
     * Loads temperature sensor data from given display config.
     * If empty or null config given default to (Type: SKIN, Name: null)
     */
    public static SensorData loadTempSensorConfig(DisplayManagerFlags flags,
            DisplayConfiguration config) {
        SensorDetails sensorDetails = config.getTempSensor();
        if (!flags.isSensorBasedBrightnessThrottlingEnabled() || sensorDetails == null) {
            return new SensorData(TEMPERATURE_TYPE_SKIN, null);
        }
        String name = sensorDetails.getName();
        String type = sensorDetails.getType();
        if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) {
            type = TEMPERATURE_TYPE_SKIN;
            name = null;
        }
        return new SensorData(type, name);
    }

    /**
     * Loads sensor unspecified config, this means system should use default sensor.
     * See also {@link com.android.server.display.utils.SensorUtils}
+10 −0
Original line number Diff line number Diff line
@@ -121,6 +121,11 @@ public class DisplayManagerFlags {
            Flags::refreshRateVotingTelemetry
    );

    private final FlagState mSensorBasedBrightnessThrottling = new FlagState(
            Flags.FLAG_SENSOR_BASED_BRIGHTNESS_THROTTLING,
            Flags::sensorBasedBrightnessThrottling
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
     */
@@ -247,6 +252,10 @@ public class DisplayManagerFlags {
        return mRefreshRateVotingTelemetry.isEnabled();
    }

    public boolean isSensorBasedBrightnessThrottlingEnabled() {
        return mSensorBasedBrightnessThrottling.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -270,6 +279,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mAutoBrightnessModesFlagState);
        pw.println(" " + mFastHdrTransitions);
        pw.println(" " + mRefreshRateVotingTelemetry);
        pw.println(" " + mSensorBasedBrightnessThrottling);
    }

    private static class FlagState {
+8 −0
Original line number Diff line number Diff line
@@ -184,3 +184,11 @@ flag {
    bug: "310029108"
    is_fixed_read_only: true
}

flag {
    name: "sensor_based_brightness_throttling"
    namespace: "display_manager"
    description: "Feature flag for enabling brightness throttling using sensor from config."
    bug: "294900859"
    is_fixed_read_only: true
}
+15 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package com.android.server.display.utils;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Temperature;
import android.text.TextUtils;

import com.android.server.display.config.SensorData;
@@ -70,4 +72,17 @@ public class SensorUtils {
        return null;
    }

    /**
     * Convert string temperature type to its corresponding integer value.
     */
    public static int getSensorTemperatureType(@NonNull SensorData tempSensor) {
        if (tempSensor.type.equalsIgnoreCase(SensorData.TEMPERATURE_TYPE_DISPLAY)) {
            return Temperature.TYPE_DISPLAY;
        } else if (tempSensor.type.equalsIgnoreCase(SensorData.TEMPERATURE_TYPE_SKIN)) {
            return Temperature.TYPE_SKIN;
        }
        throw new IllegalArgumentException(
            "tempSensor doesn't support type: " + tempSensor.type);
    }

}
Loading