Loading services/core/java/com/android/server/power/hint/HintManagerService.java +63 −4 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ import com.android.server.utils.Slogf; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; Loading Loading @@ -1480,6 +1481,7 @@ public final class HintManagerService extends SystemService { if (!mSupportInfo.headroom.isCpuSupported) { throw new UnsupportedOperationException(); } checkCpuHeadroomParams(params); final CpuHeadroomParams halParams = new CpuHeadroomParams(); halParams.tids = new int[]{Binder.getCallingPid()}; halParams.calculationType = params.calculationType; Loading @@ -1487,10 +1489,6 @@ public final class HintManagerService extends SystemService { if (params.usesDeviceHeadroom) { halParams.tids = new int[]{}; } else if (params.tids != null && params.tids.length > 0) { if (params.tids.length > 5) { throw new IllegalArgumentException( "More than 5 TIDs is requested: " + params.tids.length); } if (SystemProperties.getBoolean(PROPERTY_CHECK_HEADROOM_TID, true)) { final int tgid = Process.getThreadGroupLeader(Binder.getCallingPid()); for (int tid : params.tids) { Loading Loading @@ -1530,11 +1528,45 @@ public final class HintManagerService extends SystemService { } } private void checkCpuHeadroomParams(CpuHeadroomParamsInternal params) { boolean calculationTypeMatched = false; try { for (final Field field : CpuHeadroomParams.CalculationType.class.getDeclaredFields()) { if (field.getType() == byte.class) { byte value = field.getByte(null); if (value == params.calculationType) { calculationTypeMatched = true; break; } } } } catch (IllegalAccessException e) { Slog.wtf(TAG, "Checking the calculation type was unexpectedly not allowed"); } if (!calculationTypeMatched) { throw new IllegalArgumentException( "Unknown CPU headroom calculation type " + (int) params.calculationType); } if (params.calculationWindowMillis < 50 || params.calculationWindowMillis > 10000) { throw new IllegalArgumentException( "Invalid CPU headroom calculation window, expected [50, 10000] but got " + params.calculationWindowMillis); } if (!params.usesDeviceHeadroom) { if (params.tids != null && params.tids.length > 5) { throw new IllegalArgumentException( "More than 5 TIDs requested: " + params.tids.length); } } } @Override public GpuHeadroomResult getGpuHeadroom(@NonNull GpuHeadroomParamsInternal params) { if (!mSupportInfo.headroom.isGpuSupported) { throw new UnsupportedOperationException(); } checkGpuHeadroomParams(params); final GpuHeadroomParams halParams = new GpuHeadroomParams(); halParams.calculationType = params.calculationType; halParams.calculationWindowMillis = params.calculationWindowMillis; Loading Loading @@ -1565,6 +1597,33 @@ public final class HintManagerService extends SystemService { } } private void checkGpuHeadroomParams(GpuHeadroomParamsInternal params) { boolean calculationTypeMatched = false; try { for (final Field field : GpuHeadroomParams.CalculationType.class.getDeclaredFields()) { if (field.getType() == byte.class) { byte value = field.getByte(null); if (value == params.calculationType) { calculationTypeMatched = true; break; } } } } catch (IllegalAccessException e) { Slog.wtf(TAG, "Checking the calculation type was unexpectedly not allowed"); } if (!calculationTypeMatched) { throw new IllegalArgumentException( "Unknown GPU headroom calculation type " + (int) params.calculationType); } if (params.calculationWindowMillis < 50 || params.calculationWindowMillis > 10000) { throw new IllegalArgumentException( "Invalid GPU headroom calculation window, expected [50, 10000] but got " + params.calculationWindowMillis); } } @Override public long getCpuHeadroomMinIntervalMillis() { if (!mSupportInfo.headroom.isCpuSupported) { Loading services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -1273,6 +1273,53 @@ public class HintManagerServiceTest { }); } @Test public void testCpuHeadroomInvalidParams() { HintManagerService service = createService(); final CpuHeadroomParamsInternal param1 = new CpuHeadroomParamsInternal(); param1.calculationType = 100; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param1); }); final CpuHeadroomParamsInternal param2 = new CpuHeadroomParamsInternal(); param2.calculationWindowMillis = 49; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param2); }); param2.calculationWindowMillis = 10001; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param2); }); final CpuHeadroomParamsInternal param3 = new CpuHeadroomParamsInternal(); param3.tids = new int[]{1, 2, 3, 4, 5, 6}; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param3); }); } @Test public void testGpuHeadroomInvalidParams() { HintManagerService service = createService(); final GpuHeadroomParamsInternal param1 = new GpuHeadroomParamsInternal(); param1.calculationType = 100; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param1); }); final GpuHeadroomParamsInternal param2 = new GpuHeadroomParamsInternal(); param2.calculationWindowMillis = 49; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param2); }); param2.calculationWindowMillis = 10001; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param2); }); } @Test public void testCpuHeadroomCache() throws Exception { CpuHeadroomParamsInternal params1 = new CpuHeadroomParamsInternal(); Loading Loading
services/core/java/com/android/server/power/hint/HintManagerService.java +63 −4 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ import com.android.server.utils.Slogf; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; Loading Loading @@ -1480,6 +1481,7 @@ public final class HintManagerService extends SystemService { if (!mSupportInfo.headroom.isCpuSupported) { throw new UnsupportedOperationException(); } checkCpuHeadroomParams(params); final CpuHeadroomParams halParams = new CpuHeadroomParams(); halParams.tids = new int[]{Binder.getCallingPid()}; halParams.calculationType = params.calculationType; Loading @@ -1487,10 +1489,6 @@ public final class HintManagerService extends SystemService { if (params.usesDeviceHeadroom) { halParams.tids = new int[]{}; } else if (params.tids != null && params.tids.length > 0) { if (params.tids.length > 5) { throw new IllegalArgumentException( "More than 5 TIDs is requested: " + params.tids.length); } if (SystemProperties.getBoolean(PROPERTY_CHECK_HEADROOM_TID, true)) { final int tgid = Process.getThreadGroupLeader(Binder.getCallingPid()); for (int tid : params.tids) { Loading Loading @@ -1530,11 +1528,45 @@ public final class HintManagerService extends SystemService { } } private void checkCpuHeadroomParams(CpuHeadroomParamsInternal params) { boolean calculationTypeMatched = false; try { for (final Field field : CpuHeadroomParams.CalculationType.class.getDeclaredFields()) { if (field.getType() == byte.class) { byte value = field.getByte(null); if (value == params.calculationType) { calculationTypeMatched = true; break; } } } } catch (IllegalAccessException e) { Slog.wtf(TAG, "Checking the calculation type was unexpectedly not allowed"); } if (!calculationTypeMatched) { throw new IllegalArgumentException( "Unknown CPU headroom calculation type " + (int) params.calculationType); } if (params.calculationWindowMillis < 50 || params.calculationWindowMillis > 10000) { throw new IllegalArgumentException( "Invalid CPU headroom calculation window, expected [50, 10000] but got " + params.calculationWindowMillis); } if (!params.usesDeviceHeadroom) { if (params.tids != null && params.tids.length > 5) { throw new IllegalArgumentException( "More than 5 TIDs requested: " + params.tids.length); } } } @Override public GpuHeadroomResult getGpuHeadroom(@NonNull GpuHeadroomParamsInternal params) { if (!mSupportInfo.headroom.isGpuSupported) { throw new UnsupportedOperationException(); } checkGpuHeadroomParams(params); final GpuHeadroomParams halParams = new GpuHeadroomParams(); halParams.calculationType = params.calculationType; halParams.calculationWindowMillis = params.calculationWindowMillis; Loading Loading @@ -1565,6 +1597,33 @@ public final class HintManagerService extends SystemService { } } private void checkGpuHeadroomParams(GpuHeadroomParamsInternal params) { boolean calculationTypeMatched = false; try { for (final Field field : GpuHeadroomParams.CalculationType.class.getDeclaredFields()) { if (field.getType() == byte.class) { byte value = field.getByte(null); if (value == params.calculationType) { calculationTypeMatched = true; break; } } } } catch (IllegalAccessException e) { Slog.wtf(TAG, "Checking the calculation type was unexpectedly not allowed"); } if (!calculationTypeMatched) { throw new IllegalArgumentException( "Unknown GPU headroom calculation type " + (int) params.calculationType); } if (params.calculationWindowMillis < 50 || params.calculationWindowMillis > 10000) { throw new IllegalArgumentException( "Invalid GPU headroom calculation window, expected [50, 10000] but got " + params.calculationWindowMillis); } } @Override public long getCpuHeadroomMinIntervalMillis() { if (!mSupportInfo.headroom.isCpuSupported) { Loading
services/tests/performancehinttests/src/com/android/server/power/hint/HintManagerServiceTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -1273,6 +1273,53 @@ public class HintManagerServiceTest { }); } @Test public void testCpuHeadroomInvalidParams() { HintManagerService service = createService(); final CpuHeadroomParamsInternal param1 = new CpuHeadroomParamsInternal(); param1.calculationType = 100; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param1); }); final CpuHeadroomParamsInternal param2 = new CpuHeadroomParamsInternal(); param2.calculationWindowMillis = 49; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param2); }); param2.calculationWindowMillis = 10001; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param2); }); final CpuHeadroomParamsInternal param3 = new CpuHeadroomParamsInternal(); param3.tids = new int[]{1, 2, 3, 4, 5, 6}; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getCpuHeadroom(param3); }); } @Test public void testGpuHeadroomInvalidParams() { HintManagerService service = createService(); final GpuHeadroomParamsInternal param1 = new GpuHeadroomParamsInternal(); param1.calculationType = 100; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param1); }); final GpuHeadroomParamsInternal param2 = new GpuHeadroomParamsInternal(); param2.calculationWindowMillis = 49; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param2); }); param2.calculationWindowMillis = 10001; assertThrows(IllegalArgumentException.class, () -> { service.getBinderServiceInstance().getGpuHeadroom(param2); }); } @Test public void testCpuHeadroomCache() throws Exception { CpuHeadroomParamsInternal params1 = new CpuHeadroomParamsInternal(); Loading