Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ private long getAvailableSpace(File directory, long maxSpaceNeeded) {
try {
StorageManager storageManager = appContext.getSystemService(StorageManager.class);
UUID appSpecificInternalDirUuid = storageManager.getUuidForPath(directory);
long availableSpace = storageManager.getAllocatableBytes(appSpecificInternalDirUuid);
// Get the minimum amount of allocatable space.
long spaceToAllocate =
Math.min(
storageManager.getAllocatableBytes(appSpecificInternalDirUuid),
maxSpaceNeeded);
long spaceToAllocate = Math.min(availableSpace, maxSpaceNeeded);
// Ensure the space is available by asking the OS to clear stale cache if needed.
storageManager.allocateBytes(appSpecificInternalDirUuid, spaceToAllocate);
return spaceToAllocate;
return availableSpace;
} catch (IOException e) {
Log.w(RumConstants.OTEL_RUM_LOG_TAG, "Failed to get available space", e);
return getLegacyAvailableSpace(directory, maxSpaceNeeded);
Expand All @@ -80,6 +78,6 @@ private long getLegacyAvailableSpace(File directory, long maxSpaceNeeded) {
String.format(
"Getting legacy available space for %s max needed is: %s",
directory, maxSpaceNeeded));
return Math.min(directory.getUsableSpace(), maxSpaceNeeded);
return directory.getUsableSpace();
}
}