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

Commit 436e7d8b authored by Xiang Wang's avatar Xiang Wang
Browse files

Use the latest temperature read as base for headroom calculation

It was unexpectedly using the oldest temperature which can be 30s old
and not accurately reflect the current device's temperature

The unit test used to add new temperatures to the front of ring
buffer, which was inconsistent with the implementation which add
to the back instead, which is now fixed

Bug: 343809405
Bug: 346425206
Test: atest ThermalManagerServiceTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e23c5ede71d096aa85fd16033efa1716020c1b24)
Merged-In: I706933e7f4bbd1b9abd6591255a605d7643ad7ee
Change-Id: I706933e7f4bbd1b9abd6591255a605d7643ad7ee
parent fcf13527
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1709,7 +1709,7 @@ public class ThermalManagerService extends SystemService {
                    ArrayList<Sample> samples = mSamples.computeIfAbsent(temperature.getName(),
                            k -> new ArrayList<>(RING_BUFFER_SIZE));
                    if (samples.size() == RING_BUFFER_SIZE) {
                        samples.remove(0);
                        samples.removeFirst();
                    }
                    samples.add(new Sample(now, temperature.getValue()));
                }
@@ -1806,7 +1806,7 @@ public class ThermalManagerService extends SystemService {
                        continue;
                    }

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

                    if (samples.size() < MINIMUM_SAMPLE_COUNT) {
                        // Don't try to forecast, just use the latest one we have
+1 −1
Original line number Diff line number Diff line
@@ -551,7 +551,7 @@ public class ThermalManagerServiceTest {

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

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