Create a new ProcessStats instance for each file read

As the existing instance could be accessed by another thread in
the meanwhile.

Bug: 260727845
Test: b/260727845#comment6
Change-Id: I941ea853b9c01ed0eba4f5c6df924b6d1dacc1fc
This commit is contained in:
Jing Ji
2022-12-08 23:55:21 -08:00
parent 9c1c17544b
commit 90b8057e6f

View File

@@ -634,7 +634,6 @@ public final class ProcessStatsService extends IProcessStats.Stub {
if (files != null) {
String highWaterMarkStr =
DateFormat.format("yyyy-MM-dd-HH-mm-ss", highWaterMarkMs).toString();
ProcessStats stats = new ProcessStats(false);
for (int i = files.size() - 1; i >= 0; i--) {
String fileName = files.get(i);
try {
@@ -647,7 +646,7 @@ public final class ProcessStatsService extends IProcessStats.Stub {
new File(fileName),
ParcelFileDescriptor.MODE_READ_ONLY);
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
stats.reset();
final ProcessStats stats = new ProcessStats(false);
stats.read(is);
is.close();
if (stats.mTimePeriodStartClock > newHighWaterMark) {