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

Commit 748b287e authored by Xiang Wang's avatar Xiang Wang
Browse files

Always return 1.0 headroom thresholds for severe status

Bug: 314274383
Bug: 288119641

Test: atest ThermalManagerServiceTest
Change-Id: I42d3d735bf613761eb4fe9eb45d874ff2210742c
parent 6b1f843d
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -1492,9 +1492,10 @@ public class ThermalManagerService extends SystemService {
                            threshold.hotThrottlingThresholds[ThrottlingSeverity.SEVERE];
                    if (!Float.isNaN(severeThreshold)) {
                        mSevereThresholds.put(threshold.name, severeThreshold);
                        if (Flags.allowThermalHeadroomThresholds()) {
                            for (int severity = ThrottlingSeverity.LIGHT;
                                    severity <= ThrottlingSeverity.SHUTDOWN; severity++) {
                            if (Flags.allowThermalHeadroomThresholds()
                                if (severity != ThrottlingSeverity.SEVERE
                                        && threshold.hotThrottlingThresholds.length > severity) {
                                    updateHeadroomThreshold(severity,
                                            threshold.hotThrottlingThresholds[severity],
@@ -1505,12 +1506,17 @@ public class ThermalManagerService extends SystemService {
                    }
                }
            }
        }

        // For a older device with multiple SKIN sensors, we will set a severity's headroom
        // For an older device with multiple SKIN sensors, we will set a severity's headroom
        // threshold based on the minimum value of all as a workaround.
        void updateHeadroomThreshold(int severity, float threshold, float severeThreshold) {
            if (!Float.isNaN(threshold)) {
                synchronized (mSamples) {
                    if (severity == ThrottlingSeverity.SEVERE) {
                        mHeadroomThresholds[severity] = 1.0f;
                        return;
                    }
                    float headroom = normalizeTemperature(threshold, severeThreshold);
                    if (Float.isNaN(mHeadroomThresholds[severity])) {
                        mHeadroomThresholds[severity] = headroom;
+29 −0
Original line number Diff line number Diff line
@@ -481,6 +481,35 @@ public class ThermalManagerServiceTest {
        assertEquals(thresholds1, thresholds2);
    }

    @Test
    public void testGetThermalHeadroomThresholdsOnDefaultHalResult() throws Exception  {
        TemperatureWatcher watcher = mService.mTemperatureWatcher;
        ArrayList<TemperatureThreshold> thresholds = new ArrayList<>();
        mFakeHal.mTemperatureThresholdList = thresholds;
        watcher.updateThresholds();
        synchronized (watcher.mSamples) {
            assertArrayEquals(
                    new float[]{Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN,
                            Float.NaN},
                    watcher.mHeadroomThresholds, 0.01f);
        }
        TemperatureThreshold nanThresholds = new TemperatureThreshold();
        nanThresholds.name = "nan";
        nanThresholds.type = Temperature.TYPE_SKIN;
        nanThresholds.hotThrottlingThresholds = new float[ThrottlingSeverity.SHUTDOWN  + 1];
        nanThresholds.coldThrottlingThresholds = new float[ThrottlingSeverity.SHUTDOWN  + 1];
        Arrays.fill(nanThresholds.hotThrottlingThresholds, Float.NaN);
        Arrays.fill(nanThresholds.coldThrottlingThresholds, Float.NaN);
        thresholds.add(nanThresholds);
        watcher.updateThresholds();
        synchronized (watcher.mSamples) {
            assertArrayEquals(
                    new float[]{Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN,
                            Float.NaN},
                    watcher.mHeadroomThresholds, 0.01f);
        }
    }

    @Test
    public void testTemperatureWatcherGetSlopeOf() throws RemoteException {
        TemperatureWatcher watcher = mService.mTemperatureWatcher;