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

Commit 3531fba7 authored by Uma Maheshwari Bhiram's avatar Uma Maheshwari Bhiram Committed by Linux Build Service Account
Browse files

ProcessCpuTracker: Fix ArrayIndexOutofBoundsException in tempSpeeds

If time_in_state file is not available mCpuSpeeds is created with size 0
and subsequent call if the file becomes available there is an
ArrayIndexOutofBoundsException.
This change avoids the crash by breaking out of the loop, also adds error
logging

CRs-Fixed: 553569
Change-Id: Id5e219ca1cd3f058f714aecd5902ec2f6c11ae03
parent 8dd70add
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -591,6 +591,10 @@ public class ProcessCpuTracker {
                String token = st.nextToken();
                try {
                    long val = Long.parseLong(token);
                    //skip the iteration if the index is out of bounds
                    if(speed >= tempSpeeds.length) {
                        break;
                    }
                    tempSpeeds[speed] = val;
                    token = st.nextToken();
                    val = Long.parseLong(token);
@@ -605,6 +609,8 @@ public class ProcessCpuTracker {
                    Slog.i(TAG, "Unable to parse time_in_state");
                }
            }
        } else {
            if(DEBUG) Slog.i(TAG, "time_in_state file does not exist");
        }
        if (out == null) {
            out = new long[speed];