diff options
author | Brad Fitzpatrick <bradfitz@google.com> | 2009-09-21 15:30:21 +0400 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@google.com> | 2009-09-21 15:30:21 +0400 |
commit | 2eb239f92dbde5cd0fb6b8f665009878cbc63356 (patch) | |
tree | a48f3963e379c75fced315f347bea1bfe8e1436b /services/java | |
parent | 5feb428f349a3d9f481ba98b8ce11d25e05f2eb3 (diff) | |
download | frameworks_base-2eb239f92dbde5cd0fb6b8f665009878cbc63356.zip frameworks_base-2eb239f92dbde5cd0fb6b8f665009878cbc63356.tar.gz frameworks_base-2eb239f92dbde5cd0fb6b8f665009878cbc63356.tar.bz2 |
Fix NPE crash-loop when cpufreq not available in the kernel.
Diffstat (limited to 'services/java')
-rw-r--r-- | services/java/com/android/server/ProcessStats.java | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/services/java/com/android/server/ProcessStats.java b/services/java/com/android/server/ProcessStats.java index eaab3eb..ac3b723 100644 --- a/services/java/com/android/server/ProcessStats.java +++ b/services/java/com/android/server/ProcessStats.java @@ -509,23 +509,26 @@ public class ProcessStats { } int speed = 0; String file = readFile("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state", '\0'); - StringTokenizer st = new StringTokenizer(file, "\n "); - while (st.hasMoreElements()) { - String token = st.nextToken(); - try { - long val = Long.parseLong(token); - tempSpeeds[speed] = val; - token = st.nextToken(); - val = Long.parseLong(token); - tempTimes[speed] = val; - speed++; - if (speed == MAX_SPEEDS) break; // No more - if (localLOGV && out == null) { - Log.v(TAG, "First time : Speed/Time = " + tempSpeeds[speed - 1] - + "\t" + tempTimes[speed - 1]); + // Note: file may be null on kernels without cpufreq (i.e. the emulator's) + if (file != null) { + StringTokenizer st = new StringTokenizer(file, "\n "); + while (st.hasMoreElements()) { + String token = st.nextToken(); + try { + long val = Long.parseLong(token); + tempSpeeds[speed] = val; + token = st.nextToken(); + val = Long.parseLong(token); + tempTimes[speed] = val; + speed++; + if (speed == MAX_SPEEDS) break; // No more + if (localLOGV && out == null) { + Log.v(TAG, "First time : Speed/Time = " + tempSpeeds[speed - 1] + + "\t" + tempTimes[speed - 1]); + } + } catch (NumberFormatException nfe) { + Log.i(TAG, "Unable to parse time_in_state"); } - } catch (NumberFormatException nfe) { - Log.i(TAG, "Unable to parse time_in_state"); } } if (out == null) { |