Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e5e8d7e authored by Lakshman Annadorai's avatar Lakshman Annadorai
Browse files

Handle negative CPU availability percent in CpuMonitorService.

Test: m; atest CpuMonitorServiceTest.
Bug: 278142170
Change-Id: I21999ac56bbdc85990ed06354a427c5008061054
parent 5bb61ba0
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -653,8 +653,17 @@ public final class CpuMonitorService extends SystemService {
            }

            public int getAverageAvailableCpuFreqPercent() {
                return (int) ((totalNormalizedAvailableCpuFreqKHz * 100.0)
                int percent = (int) ((totalNormalizedAvailableCpuFreqKHz * 100.0)
                        / totalOnlineMaxCpuFreqKHz);
                if (percent < 0) {
                    // TODO(b/279478586): This case should never happen. But this case happens
                    // rarely on certain hardware, which indicates a deeper issue. Once this
                    // issue is reproduced, use this log to debug the issue and fix it.
                    Slogf.wtf(TAG, "Computed negative CPU availability percent(%d) for %s ",
                            percent, toString());
                    return 0;
                }
                return percent;
            }

            @Override