summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/power/ThermalManagerService.java13
-rw-r--r--services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java9
2 files changed, 22 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/power/ThermalManagerService.java b/services/core/java/com/android/server/power/ThermalManagerService.java
index 96823c8ae9ab..f3785885e4ec 100644
--- a/services/core/java/com/android/server/power/ThermalManagerService.java
+++ b/services/core/java/com/android/server/power/ThermalManagerService.java
@@ -72,6 +72,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ThermalManagerService extends SystemService {
private static final String TAG = ThermalManagerService.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
+ /** Input range limits for getThermalHeadroom API */
+ public static final int MIN_FORECAST_SEC = 0;
+ public static final int MAX_FORECAST_SEC = 60;
+
/** Lock to protect listen list. */
private final Object mLock = new Object();
@@ -478,6 +484,13 @@ public class ThermalManagerService extends SystemService {
return Float.NaN;
}
+ if (forecastSeconds < MIN_FORECAST_SEC || forecastSeconds > MAX_FORECAST_SEC) {
+ if (DEBUG) {
+ Slog.d(TAG, "Invalid forecastSeconds: " + forecastSeconds);
+ }
+ return Float.NaN;
+ }
+
return mTemperatureWatcher.getForecast(forecastSeconds);
}
diff --git a/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
index 36e988f36577..3848babdc912 100644
--- a/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
@@ -381,6 +381,7 @@ public class ThermalManagerServiceTest {
assertEquals(0, Arrays.asList(mService.mService.getCurrentTemperaturesWithType(
Temperature.TYPE_SKIN)).size());
assertEquals(Temperature.THROTTLING_NONE, mService.mService.getCurrentThermalStatus());
+ assertTrue(Float.isNaN(mService.mService.getThermalHeadroom(0)));
}
@Test
@@ -397,6 +398,14 @@ public class ThermalManagerServiceTest {
}
@Test
+ public void testGetThermalHeadroomInputRange() throws RemoteException {
+ assertTrue(Float.isNaN(mService.mService.getThermalHeadroom(
+ ThermalManagerService.MIN_FORECAST_SEC - 1)));
+ assertTrue(Float.isNaN(mService.mService.getThermalHeadroom(
+ ThermalManagerService.MAX_FORECAST_SEC + 1)));
+ }
+
+ @Test
public void testTemperatureWatcherUpdateSevereThresholds() throws RemoteException {
ThermalManagerService.TemperatureWatcher watcher = mService.mTemperatureWatcher;
watcher.mSevereThresholds.erase();