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

Commit cdadee63 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix some divide by zero errors that could crash the system.

Change-Id: I66273df84e45de59b5b161f4d13de67a9e0f46d5
parent 1ad66b2f
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -619,8 +619,11 @@ public class ProcessStats {
    }
    
    final public float getTotalCpuPercent() {
        return ((float)(mRelUserTime+mRelSystemTime+mRelIrqTime)*100)
                / (mRelUserTime+mRelSystemTime+mRelIrqTime+mRelIdleTime);
        int denom = mRelUserTime+mRelSystemTime+mRelIrqTime+mRelIdleTime;
        if (denom <= 0) {
            return 0;
        }
        return ((float)(mRelUserTime+mRelSystemTime+mRelIrqTime)*100) / denom;
    }
    
    final void buildWorkingProcs() {
@@ -699,7 +702,7 @@ public class ProcessStats {

        long sampleTime = mCurrentSampleTime - mLastSampleTime;
        long sampleRealTime = mCurrentSampleRealTime - mLastSampleRealTime;
        long percAwake = (sampleTime*100) / sampleRealTime;
        long percAwake = sampleRealTime > 0 ? ((sampleTime*100) / sampleRealTime) : 0;
        if (percAwake != 100) {
            pw.print(" with ");
            pw.print(percAwake);