Query available cache size before writing report to disk #592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
Currently
FileStore
writes an arbitrary 128 files to disk, which was a decision made in #97. When additional metadata is added to a report and the system is low on space, this may have the effect of making it more likely for the OS to reclaim space from our application.Changeset
The changeset makes several alterations which will reduce the likelihood of our cached files being deleted by the OS:
context.cacheDir
and thebugsnag-errors
directory File as fields, reducing duplicationdiscardOldFilesIfNeeded()
into lock, reducing the potential for aReport
serializing a cachedError
to suffer aFileNotFoundException
getUsableSpace()
to determine whether < 10Mb is available for use in the cache directory, and if so, delete old files.Discussion
getCacheQuotaBytes()
andgetCacheSizeBytes()
are available on API 26+ which would allow us to determine whether we are over the cache quota more precisely. However, the documentation warns that these calls can take several seconds to complete, and would not resolve any caching issues on older devices, leading to the approach in this PR.See: https://developer.android.com/reference/android/os/storage/StorageManager