Merge "Fix for DropBoxManagerService on devices with large storage"

This commit is contained in:
Tobias Thierer
2019-05-09 12:00:34 +00:00
committed by Gerrit Code Review

View File

@@ -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;
}