Loading core/java/android/os/PerformanceHintManager.java +16 −8 Original line number Diff line number Diff line Loading @@ -313,25 +313,33 @@ public final class PerformanceHintManager { * close to the target duration. * * @param workDuration the work duration of each component. * @throws IllegalArgumentException if work period start timestamp is not positive, or * actual total duration is not positive, or actual CPU duration is not positive, * or actual GPU duration is negative. * @throws IllegalArgumentException if * the work period start timestamp or the total duration are less than or equal to zero, * if either the actual CPU duration or actual GPU duration is less than zero, * or if both the CPU and GPU durations are zero. */ @FlaggedApi(Flags.FLAG_ADPF_GPU_REPORT_ACTUAL_WORK_DURATION) public void reportActualWorkDuration(@NonNull WorkDuration workDuration) { if (workDuration.mWorkPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( "the work period start timestamp should be positive."); "the work period start timestamp should be greater than zero."); } if (workDuration.mActualTotalDurationNanos <= 0) { throw new IllegalArgumentException("the actual total duration should be positive."); throw new IllegalArgumentException( "the actual total duration should be greater than zero."); } if (workDuration.mActualCpuDurationNanos <= 0) { throw new IllegalArgumentException("the actual CPU duration should be positive."); if (workDuration.mActualCpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual CPU duration should be greater than or equal to zero."); } if (workDuration.mActualGpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual GPU duration should be non negative."); "the actual GPU duration should be greater than or equal to zero."); } if (workDuration.mActualCpuDurationNanos + workDuration.mActualGpuDurationNanos <= 0) { throw new IllegalArgumentException( "either the actual CPU duration or the actual GPU duration should be greater" + "than zero."); } nativeReportActualWorkDuration(mNativeSessionPtr, workDuration.mWorkPeriodStartTimestampNanos, Loading core/java/android/os/WorkDuration.java +8 −5 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public final class WorkDuration implements Parcelable { public void setWorkPeriodStartTimestampNanos(long workPeriodStartTimestampNanos) { if (workPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( "the work period start timestamp should be positive."); "the work period start timestamp should be greater than zero."); } mWorkPeriodStartTimestampNanos = workPeriodStartTimestampNanos; } Loading @@ -95,7 +95,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualTotalDurationNanos(long actualTotalDurationNanos) { if (actualTotalDurationNanos <= 0) { throw new IllegalArgumentException("the actual total duration should be positive."); throw new IllegalArgumentException( "the actual total duration should be greater than zero."); } mActualTotalDurationNanos = actualTotalDurationNanos; } Loading @@ -106,8 +107,9 @@ public final class WorkDuration implements Parcelable { * All timings should be in {@link SystemClock#uptimeNanos()}. */ public void setActualCpuDurationNanos(long actualCpuDurationNanos) { if (actualCpuDurationNanos <= 0) { throw new IllegalArgumentException("the actual CPU duration should be positive."); if (actualCpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual CPU duration should be greater than or equal to zero."); } mActualCpuDurationNanos = actualCpuDurationNanos; } Loading @@ -119,7 +121,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualGpuDurationNanos(long actualGpuDurationNanos) { if (actualGpuDurationNanos < 0) { throw new IllegalArgumentException("the actual GPU duration should be non negative."); throw new IllegalArgumentException( "the actual GPU duration should be greater than or equal to zero."); } mActualGpuDurationNanos = actualGpuDurationNanos; } Loading core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +17 −1 Original line number Diff line number Diff line Loading @@ -219,6 +219,22 @@ public class PerformanceHintManagerTest { workDuration.setActualGpuDurationNanos(6); s.reportActualWorkDuration(workDuration); } { WorkDuration workDuration = new WorkDuration(); workDuration.setWorkPeriodStartTimestampNanos(1); workDuration.setActualTotalDurationNanos(14); workDuration.setActualCpuDurationNanos(0); workDuration.setActualGpuDurationNanos(6); s.reportActualWorkDuration(workDuration); } { WorkDuration workDuration = new WorkDuration(); workDuration.setWorkPeriodStartTimestampNanos(1); workDuration.setActualTotalDurationNanos(14); workDuration.setActualCpuDurationNanos(7); workDuration.setActualGpuDurationNanos(0); s.reportActualWorkDuration(workDuration); } } @Test Loading @@ -242,7 +258,7 @@ public class PerformanceHintManagerTest { s.reportActualWorkDuration(new WorkDuration(1, 12, -1, 6, 1)); }); assertThrows(IllegalArgumentException.class, () -> { s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 6, 1)); s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 0, 1)); }); assertThrows(IllegalArgumentException.class, () -> { s.reportActualWorkDuration(new WorkDuration(1, 12, 8, -1, 1)); Loading native/android/performance_hint.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -484,8 +484,9 @@ int APerformanceHint_reportActualWorkDuration2(APerformanceHintSession* session, WorkDuration& workDuration = *static_cast<WorkDuration*>(workDurationPtr); VALIDATE_INT(workDuration.workPeriodStartTimestampNanos, > 0) VALIDATE_INT(workDuration.actualTotalDurationNanos, > 0) VALIDATE_INT(workDuration.actualCpuDurationNanos, > 0) VALIDATE_INT(workDuration.actualCpuDurationNanos, >= 0) VALIDATE_INT(workDuration.actualGpuDurationNanos, >= 0) VALIDATE_INT(workDuration.actualGpuDurationNanos + workDuration.actualCpuDurationNanos, > 0) return session->reportActualWorkDuration(workDurationPtr); } Loading Loading @@ -517,7 +518,7 @@ void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* aWorkDuration, void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* aWorkDuration, int64_t actualCpuDurationNanos) { VALIDATE_PTR(aWorkDuration) WARN_INT(actualCpuDurationNanos, > 0) WARN_INT(actualCpuDurationNanos, >= 0) static_cast<WorkDuration*>(aWorkDuration)->actualCpuDurationNanos = actualCpuDurationNanos; } Loading services/core/java/com/android/server/power/hint/HintManagerService.java +13 −3 Original line number Diff line number Diff line Loading @@ -691,14 +691,24 @@ public final class HintManagerService extends SystemService { TextUtils.formatSimple("Actual total duration (%d) should be greater than 0", workDuration.getActualTotalDurationNanos())); } if (workDuration.getActualCpuDurationNanos() <= 0) { if (workDuration.getActualCpuDurationNanos() < 0) { throw new IllegalArgumentException( TextUtils.formatSimple("Actual CPU duration (%d) should be greater than 0", TextUtils.formatSimple( "Actual CPU duration (%d) should be greater than or equal to 0", workDuration.getActualCpuDurationNanos())); } if (workDuration.getActualGpuDurationNanos() < 0) { throw new IllegalArgumentException( TextUtils.formatSimple("Actual GPU duration (%d) should be non negative", TextUtils.formatSimple( "Actual GPU duration (%d) should greater than or equal to 0", workDuration.getActualGpuDurationNanos())); } if (workDuration.getActualCpuDurationNanos() + workDuration.getActualGpuDurationNanos() <= 0) { throw new IllegalArgumentException( TextUtils.formatSimple( "The actual CPU duration (%d) and the actual GPU duration (%d)" + " should not both be 0", workDuration.getActualCpuDurationNanos(), workDuration.getActualGpuDurationNanos())); } } Loading Loading
core/java/android/os/PerformanceHintManager.java +16 −8 Original line number Diff line number Diff line Loading @@ -313,25 +313,33 @@ public final class PerformanceHintManager { * close to the target duration. * * @param workDuration the work duration of each component. * @throws IllegalArgumentException if work period start timestamp is not positive, or * actual total duration is not positive, or actual CPU duration is not positive, * or actual GPU duration is negative. * @throws IllegalArgumentException if * the work period start timestamp or the total duration are less than or equal to zero, * if either the actual CPU duration or actual GPU duration is less than zero, * or if both the CPU and GPU durations are zero. */ @FlaggedApi(Flags.FLAG_ADPF_GPU_REPORT_ACTUAL_WORK_DURATION) public void reportActualWorkDuration(@NonNull WorkDuration workDuration) { if (workDuration.mWorkPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( "the work period start timestamp should be positive."); "the work period start timestamp should be greater than zero."); } if (workDuration.mActualTotalDurationNanos <= 0) { throw new IllegalArgumentException("the actual total duration should be positive."); throw new IllegalArgumentException( "the actual total duration should be greater than zero."); } if (workDuration.mActualCpuDurationNanos <= 0) { throw new IllegalArgumentException("the actual CPU duration should be positive."); if (workDuration.mActualCpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual CPU duration should be greater than or equal to zero."); } if (workDuration.mActualGpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual GPU duration should be non negative."); "the actual GPU duration should be greater than or equal to zero."); } if (workDuration.mActualCpuDurationNanos + workDuration.mActualGpuDurationNanos <= 0) { throw new IllegalArgumentException( "either the actual CPU duration or the actual GPU duration should be greater" + "than zero."); } nativeReportActualWorkDuration(mNativeSessionPtr, workDuration.mWorkPeriodStartTimestampNanos, Loading
core/java/android/os/WorkDuration.java +8 −5 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public final class WorkDuration implements Parcelable { public void setWorkPeriodStartTimestampNanos(long workPeriodStartTimestampNanos) { if (workPeriodStartTimestampNanos <= 0) { throw new IllegalArgumentException( "the work period start timestamp should be positive."); "the work period start timestamp should be greater than zero."); } mWorkPeriodStartTimestampNanos = workPeriodStartTimestampNanos; } Loading @@ -95,7 +95,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualTotalDurationNanos(long actualTotalDurationNanos) { if (actualTotalDurationNanos <= 0) { throw new IllegalArgumentException("the actual total duration should be positive."); throw new IllegalArgumentException( "the actual total duration should be greater than zero."); } mActualTotalDurationNanos = actualTotalDurationNanos; } Loading @@ -106,8 +107,9 @@ public final class WorkDuration implements Parcelable { * All timings should be in {@link SystemClock#uptimeNanos()}. */ public void setActualCpuDurationNanos(long actualCpuDurationNanos) { if (actualCpuDurationNanos <= 0) { throw new IllegalArgumentException("the actual CPU duration should be positive."); if (actualCpuDurationNanos < 0) { throw new IllegalArgumentException( "the actual CPU duration should be greater than or equal to zero."); } mActualCpuDurationNanos = actualCpuDurationNanos; } Loading @@ -119,7 +121,8 @@ public final class WorkDuration implements Parcelable { */ public void setActualGpuDurationNanos(long actualGpuDurationNanos) { if (actualGpuDurationNanos < 0) { throw new IllegalArgumentException("the actual GPU duration should be non negative."); throw new IllegalArgumentException( "the actual GPU duration should be greater than or equal to zero."); } mActualGpuDurationNanos = actualGpuDurationNanos; } Loading
core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +17 −1 Original line number Diff line number Diff line Loading @@ -219,6 +219,22 @@ public class PerformanceHintManagerTest { workDuration.setActualGpuDurationNanos(6); s.reportActualWorkDuration(workDuration); } { WorkDuration workDuration = new WorkDuration(); workDuration.setWorkPeriodStartTimestampNanos(1); workDuration.setActualTotalDurationNanos(14); workDuration.setActualCpuDurationNanos(0); workDuration.setActualGpuDurationNanos(6); s.reportActualWorkDuration(workDuration); } { WorkDuration workDuration = new WorkDuration(); workDuration.setWorkPeriodStartTimestampNanos(1); workDuration.setActualTotalDurationNanos(14); workDuration.setActualCpuDurationNanos(7); workDuration.setActualGpuDurationNanos(0); s.reportActualWorkDuration(workDuration); } } @Test Loading @@ -242,7 +258,7 @@ public class PerformanceHintManagerTest { s.reportActualWorkDuration(new WorkDuration(1, 12, -1, 6, 1)); }); assertThrows(IllegalArgumentException.class, () -> { s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 6, 1)); s.reportActualWorkDuration(new WorkDuration(1, 12, 0, 0, 1)); }); assertThrows(IllegalArgumentException.class, () -> { s.reportActualWorkDuration(new WorkDuration(1, 12, 8, -1, 1)); Loading
native/android/performance_hint.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -484,8 +484,9 @@ int APerformanceHint_reportActualWorkDuration2(APerformanceHintSession* session, WorkDuration& workDuration = *static_cast<WorkDuration*>(workDurationPtr); VALIDATE_INT(workDuration.workPeriodStartTimestampNanos, > 0) VALIDATE_INT(workDuration.actualTotalDurationNanos, > 0) VALIDATE_INT(workDuration.actualCpuDurationNanos, > 0) VALIDATE_INT(workDuration.actualCpuDurationNanos, >= 0) VALIDATE_INT(workDuration.actualGpuDurationNanos, >= 0) VALIDATE_INT(workDuration.actualGpuDurationNanos + workDuration.actualCpuDurationNanos, > 0) return session->reportActualWorkDuration(workDurationPtr); } Loading Loading @@ -517,7 +518,7 @@ void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* aWorkDuration, void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* aWorkDuration, int64_t actualCpuDurationNanos) { VALIDATE_PTR(aWorkDuration) WARN_INT(actualCpuDurationNanos, > 0) WARN_INT(actualCpuDurationNanos, >= 0) static_cast<WorkDuration*>(aWorkDuration)->actualCpuDurationNanos = actualCpuDurationNanos; } Loading
services/core/java/com/android/server/power/hint/HintManagerService.java +13 −3 Original line number Diff line number Diff line Loading @@ -691,14 +691,24 @@ public final class HintManagerService extends SystemService { TextUtils.formatSimple("Actual total duration (%d) should be greater than 0", workDuration.getActualTotalDurationNanos())); } if (workDuration.getActualCpuDurationNanos() <= 0) { if (workDuration.getActualCpuDurationNanos() < 0) { throw new IllegalArgumentException( TextUtils.formatSimple("Actual CPU duration (%d) should be greater than 0", TextUtils.formatSimple( "Actual CPU duration (%d) should be greater than or equal to 0", workDuration.getActualCpuDurationNanos())); } if (workDuration.getActualGpuDurationNanos() < 0) { throw new IllegalArgumentException( TextUtils.formatSimple("Actual GPU duration (%d) should be non negative", TextUtils.formatSimple( "Actual GPU duration (%d) should greater than or equal to 0", workDuration.getActualGpuDurationNanos())); } if (workDuration.getActualCpuDurationNanos() + workDuration.getActualGpuDurationNanos() <= 0) { throw new IllegalArgumentException( TextUtils.formatSimple( "The actual CPU duration (%d) and the actual GPU duration (%d)" + " should not both be 0", workDuration.getActualCpuDurationNanos(), workDuration.getActualGpuDurationNanos())); } } Loading