From 9d6b131a0b764e1b0d4969852b6f31d298ee8f35 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Wed, 19 Jan 2022 23:21:02 +0000 Subject: [PATCH] Declare size outside the loop. Bug: 206518483 Change-Id: Ibeb5b287c549d6641000987acbd36c297df8b8e6 Test: treehugger --- .../java/com/android/server/usage/AppIdleHistory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java b/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java index 4de8ec8d12418..dd102bdd726e6 100644 --- a/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +++ b/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java @@ -892,7 +892,8 @@ public class AppIdleHistory { } if (history.bucketExpiryTimesMs != null) { xml.startTag(null, TAG_BUCKET_EXPIRY_TIMES); - for (int j = 0; j < history.bucketExpiryTimesMs.size(); ++j) { + final int size = history.bucketExpiryTimesMs.size(); + for (int j = 0; j < size; ++j) { final long expiryTimeMs = history.bucketExpiryTimesMs.valueAt(j); // Skip writing to disk if the expiry time already elapsed. if (expiryTimeMs < elapsedTimeMs) { @@ -994,7 +995,8 @@ public class AppIdleHistory { return; } idpw.print("("); - for (int i = 0; i < appUsageHistory.bucketExpiryTimesMs.size(); ++i) { + final int size = appUsageHistory.bucketExpiryTimesMs.size(); + for (int i = 0; i < size; ++i) { final int bucket = appUsageHistory.bucketExpiryTimesMs.keyAt(i); final long expiryTimeMs = appUsageHistory.bucketExpiryTimesMs.valueAt(i); if (i != 0) {