From 7a0134f195571eeb60de3360a2904e56a5246554 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 10 Oct 2023 10:14:43 +0800 Subject: [PATCH] Not call refreshStats() in setDuration() refreshStats() needs to be called on worker thread, and all usage places call refreshStats() after setDuration(). So no need to call refreshStats() in setDuration(), this also prevent ANRs. Fix: 241167275 Test: manual - on dev options Change-Id: I8f4ad57c3843f14f6baee1d06d29eea1341509f1 --- .../settings/applications/ProcStatsData.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/com/android/settings/applications/ProcStatsData.java b/src/com/android/settings/applications/ProcStatsData.java index 7742e98b56e..aedb06640d0 100644 --- a/src/com/android/settings/applications/ProcStatsData.java +++ b/src/com/android/settings/applications/ProcStatsData.java @@ -29,6 +29,8 @@ import android.util.Log; import android.util.LongSparseArray; import android.util.SparseArray; +import androidx.annotation.WorkerThread; + import com.android.internal.app.ProcessMap; import com.android.internal.app.procstats.DumpUtils; import com.android.internal.app.procstats.IProcessStats; @@ -85,24 +87,10 @@ public class ProcStatsData { } } - public void setTotalTime(int totalTime) { - memTotalTime = totalTime; - } - public void xferStats() { sStatsXfer = mStats; } - public void setMemStates(int[] memStates) { - mMemStates = memStates; - refreshStats(false); - } - - public void setStats(int[] stats) { - this.mStates = stats; - refreshStats(false); - } - public int getMemState() { int factor = mStats.mMemFactor; if (factor == ProcessStats.ADJ_NOTHING) { @@ -118,15 +106,13 @@ public class ProcStatsData { return mMemInfo; } - public long getElapsedTime() { - return mStats.mTimePeriodEndRealtime - mStats.mTimePeriodStartRealtime; - } - + /** + * Sets the duration. + * + *

Note: {@link #refreshStats(boolean)} needs to called manually to take effect. + */ public void setDuration(long duration) { - if (duration != mDuration) { - mDuration = duration; - refreshStats(true); - } + mDuration = duration; } public long getDuration() { @@ -137,6 +123,12 @@ public class ProcStatsData { return pkgEntries; } + /** + * Refreshes the stats. + * + *

Note: This needs to be called manually to take effect. + */ + @WorkerThread public void refreshStats(boolean forceLoad) { if (mStats == null || forceLoad) { load();