Loading services/core/java/com/android/server/power/ThermalManagerService.java +14 −8 Original line number Diff line number Diff line Loading @@ -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], Loading @@ -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; Loading services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading
services/core/java/com/android/server/power/ThermalManagerService.java +14 −8 Original line number Diff line number Diff line Loading @@ -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], Loading @@ -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; Loading
services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading