From 318a67d81fb990b015ae96a3d15d74887f4860db Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Sat, 10 Feb 2018 20:05:22 -0800 Subject: Update the internal state before sending the deltas to callback. It's possible that the callback can trigger removing the cpu time correspoding to a particular uid, we don't want to re-add the state for that uid after this. Fixes: 63144979 Test: cts-tradefed run singleCommand cts-dev -m CtsIncidentHostTestCases -t \ com.android.server.cts.BatteryStatsValidationTest Change-Id: I29f208ea5cb18f05ad16dfc22f8dea077cc186fb --- .../java/com/android/internal/os/KernelUidCpuTimeReader.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'core/java') diff --git a/core/java/com/android/internal/os/KernelUidCpuTimeReader.java b/core/java/com/android/internal/os/KernelUidCpuTimeReader.java index 65615c0ffb02..444049e7e415 100644 --- a/core/java/com/android/internal/os/KernelUidCpuTimeReader.java +++ b/core/java/com/android/internal/os/KernelUidCpuTimeReader.java @@ -78,10 +78,11 @@ public class KernelUidCpuTimeReader { final long userTimeUs = Long.parseLong(splitter.next(), 10); final long systemTimeUs = Long.parseLong(splitter.next(), 10); + boolean notifyCallback = false; + long userTimeDeltaUs = userTimeUs; + long systemTimeDeltaUs = systemTimeUs; // Only report if there is a callback and if this is not the first read. if (callback != null && mLastTimeReadUs != 0) { - long userTimeDeltaUs = userTimeUs; - long systemTimeDeltaUs = systemTimeUs; int index = mLastUserTimeUs.indexOfKey(uid); if (index >= 0) { userTimeDeltaUs -= mLastUserTimeUs.valueAt(index); @@ -114,12 +115,13 @@ public class KernelUidCpuTimeReader { } } - if (userTimeDeltaUs != 0 || systemTimeDeltaUs != 0) { - callback.onUidCpuTime(uid, userTimeDeltaUs, systemTimeDeltaUs); - } + notifyCallback = (userTimeDeltaUs != 0 || systemTimeDeltaUs != 0); } mLastUserTimeUs.put(uid, userTimeUs); mLastSystemTimeUs.put(uid, systemTimeUs); + if (notifyCallback) { + callback.onUidCpuTime(uid, userTimeDeltaUs, systemTimeDeltaUs); + } } } catch (IOException e) { Slog.e(TAG, "Failed to read uid_cputime: " + e.getMessage()); -- cgit v1.2.3