From cbb5000b70025105870c6dbbe8cc619c064c5a6b Mon Sep 17 00:00:00 2001 From: Dmytro Chystiakov Date: Sun, 28 Apr 2019 17:06:36 -0700 Subject: [PATCH] Fix for DropBoxManagerService on devices with large storage DropBoxManagerService does not save any data to the storage due to int overflow when it's trying to get available space on devices with large storage (like 1TB) Bug: b/131354250 Test: Run CTS with command "run cts -m CtsIncidentHostTestCases -t com.android.server.cts.ErrorsTest" Change-Id: Ib1b0d4decb48e9e771ef39127364131e6aa05662 Signed-off-by: Dmytro Chystiakov --- .../java/com/android/server/DropBoxManagerService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/DropBoxManagerService.java b/services/core/java/com/android/server/DropBoxManagerService.java index 887de74f1cf9a..09fa006c76693 100644 --- a/services/core/java/com/android/server/DropBoxManagerService.java +++ b/services/core/java/com/android/server/DropBoxManagerService.java @@ -861,10 +861,13 @@ public final class DropBoxManagerService extends SystemService { } catch (IllegalArgumentException e) { // restat throws this on error throw new IOException("Can't restat: " + mDropBoxDir); } - int available = mStatFs.getAvailableBlocks(); - int nonreserved = available - mStatFs.getBlockCount() * reservePercent / 100; + long available = mStatFs.getAvailableBlocksLong(); + long nonreserved = available - mStatFs.getBlockCountLong() * reservePercent / 100; + long maxAvailableLong = nonreserved * quotaPercent / 100; + int maxAvailable = Math.toIntExact(Math.max(0, + Math.min(maxAvailableLong, Integer.MAX_VALUE))); int maximum = quotaKb * 1024 / mBlockSize; - mCachedQuotaBlocks = Math.min(maximum, Math.max(0, nonreserved * quotaPercent / 100)); + mCachedQuotaBlocks = Math.min(maximum, maxAvailable); mCachedQuotaUptimeMillis = uptimeMillis; }