Merge "ThermalManagerService: validate input for getThermalHeadroom API"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9f579cca49
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -396,6 +397,14 @@ public class ThermalManagerServiceTest {
|
||||
CoolingDevice.TYPE_CPU)));
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
Reference in New Issue
Block a user