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

Commit 924e23a1 authored by Xiang Wang's avatar Xiang Wang
Browse files

Revert "Use the latest temperature read as base for headroom calculation"

Bug: 343809405
Test: atest ThermalManagerServiceTest

This reverts commit d83dcae2.
Change-Id: If9b02192e7795720eea3c8812f7b097303b796de
parent cb5ee5bf
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -74,7 +74,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collection;
import java.util.Iterator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.NoSuchElementException;
@@ -1610,7 +1609,7 @@ public class ThermalManagerService extends SystemService {
        /** Map of skin temperature sensor name to a corresponding list of samples */
        /** Map of skin temperature sensor name to a corresponding list of samples */
        @GuardedBy("mSamples")
        @GuardedBy("mSamples")
        @VisibleForTesting
        @VisibleForTesting
        final ArrayMap<String, LinkedList<Sample>> mSamples = new ArrayMap<>();
        final ArrayMap<String, ArrayList<Sample>> mSamples = new ArrayMap<>();


        /** Map of skin temperature sensor name to the corresponding SEVERE temperature threshold */
        /** Map of skin temperature sensor name to the corresponding SEVERE temperature threshold */
        @GuardedBy("mSamples")
        @GuardedBy("mSamples")
@@ -1707,10 +1706,10 @@ public class ThermalManagerService extends SystemService {
                        continue;
                        continue;
                    }
                    }


                    LinkedList<Sample> samples = mSamples.computeIfAbsent(temperature.getName(),
                    ArrayList<Sample> samples = mSamples.computeIfAbsent(temperature.getName(),
                            k -> new LinkedList<>());
                            k -> new ArrayList<>(RING_BUFFER_SIZE));
                    if (samples.size() == RING_BUFFER_SIZE) {
                    if (samples.size() == RING_BUFFER_SIZE) {
                        samples.removeFirst();
                        samples.remove(0);
                    }
                    }
                    samples.add(new Sample(now, temperature.getValue()));
                    samples.add(new Sample(now, temperature.getValue()));
                }
                }
@@ -1725,7 +1724,8 @@ public class ThermalManagerService extends SystemService {
        float getSlopeOf(List<Sample> samples) {
        float getSlopeOf(List<Sample> samples) {
            long sumTimes = 0L;
            long sumTimes = 0L;
            float sumTemperatures = 0.0f;
            float sumTemperatures = 0.0f;
            for (final Sample sample : samples) {
            for (int s = 0; s < samples.size(); ++s) {
                Sample sample = samples.get(s);
                sumTimes += sample.time;
                sumTimes += sample.time;
                sumTemperatures += sample.temperature;
                sumTemperatures += sample.temperature;
            }
            }
@@ -1734,7 +1734,8 @@ public class ThermalManagerService extends SystemService {


            long sampleVariance = 0L;
            long sampleVariance = 0L;
            float sampleCovariance = 0.0f;
            float sampleCovariance = 0.0f;
            for (final Sample sample : samples) {
            for (int s = 0; s < samples.size(); ++s) {
                Sample sample = samples.get(s);
                long timeDelta = sample.time - meanTime;
                long timeDelta = sample.time - meanTime;
                float temperatureDelta = sample.temperature - meanTemperature;
                float temperatureDelta = sample.temperature - meanTemperature;
                sampleVariance += timeDelta * timeDelta;
                sampleVariance += timeDelta * timeDelta;
@@ -1794,9 +1795,9 @@ public class ThermalManagerService extends SystemService {


                float maxNormalized = Float.NaN;
                float maxNormalized = Float.NaN;
                int noThresholdSampleCount = 0;
                int noThresholdSampleCount = 0;
                for (Map.Entry<String, LinkedList<Sample>> entry : mSamples.entrySet()) {
                for (Map.Entry<String, ArrayList<Sample>> entry : mSamples.entrySet()) {
                    String name = entry.getKey();
                    String name = entry.getKey();
                    LinkedList<Sample> samples = entry.getValue();
                    ArrayList<Sample> samples = entry.getValue();


                    Float threshold = mSevereThresholds.get(name);
                    Float threshold = mSevereThresholds.get(name);
                    if (threshold == null) {
                    if (threshold == null) {
@@ -1805,7 +1806,7 @@ public class ThermalManagerService extends SystemService {
                        continue;
                        continue;
                    }
                    }


                    float currentTemperature = samples.getLast().temperature;
                    float currentTemperature = samples.get(0).temperature;


                    if (samples.size() < MINIMUM_SAMPLE_COUNT) {
                    if (samples.size() < MINIMUM_SAMPLE_COUNT) {
                        // Don't try to forecast, just use the latest one we have
                        // Don't try to forecast, just use the latest one we have
+3 −4
Original line number Original line Diff line number Diff line
@@ -68,7 +68,6 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.HashSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;


@@ -514,7 +513,7 @@ public class ThermalManagerServiceTest {
    @Test
    @Test
    public void testTemperatureWatcherGetSlopeOf() throws RemoteException {
    public void testTemperatureWatcherGetSlopeOf() throws RemoteException {
        TemperatureWatcher watcher = mService.mTemperatureWatcher;
        TemperatureWatcher watcher = mService.mTemperatureWatcher;
        List<TemperatureWatcher.Sample> samples = new LinkedList<>();
        List<TemperatureWatcher.Sample> samples = new ArrayList<>();
        for (int i = 0; i < 30; ++i) {
        for (int i = 0; i < 30; ++i) {
            samples.add(watcher.createSampleForTesting(i, (float) (i / 2 * 2)));
            samples.add(watcher.createSampleForTesting(i, (float) (i / 2 * 2)));
        }
        }
@@ -539,7 +538,7 @@ public class ThermalManagerServiceTest {
    public void testTemperatureWatcherGetForecast() throws RemoteException {
    public void testTemperatureWatcherGetForecast() throws RemoteException {
        TemperatureWatcher watcher = mService.mTemperatureWatcher;
        TemperatureWatcher watcher = mService.mTemperatureWatcher;


        LinkedList<TemperatureWatcher.Sample> samples = new LinkedList<>();
        ArrayList<TemperatureWatcher.Sample> samples = new ArrayList<>();


        // Add a single sample
        // Add a single sample
        samples.add(watcher.createSampleForTesting(0, 25.0f));
        samples.add(watcher.createSampleForTesting(0, 25.0f));
@@ -552,7 +551,7 @@ public class ThermalManagerServiceTest {


        // Add some time-series data
        // Add some time-series data
        for (int i = 1; i < 20; ++i) {
        for (int i = 1; i < 20; ++i) {
            samples.add(watcher.createSampleForTesting(1000 * i, 25.0f + 0.5f * i));
            samples.add(0, watcher.createSampleForTesting(1000 * i, 25.0f + 0.5f * i));
        }
        }


        // Now the forecast should vary depending on how far ahead we are trying to predict
        // Now the forecast should vary depending on how far ahead we are trying to predict