Skip to content

Commit

Permalink
Merge pull request #589 from bugsnag/alter-free-disk
Browse files Browse the repository at this point in the history
Alter device.freeDisk to collect usable space in data directory
  • Loading branch information
fractalwrench authored Sep 12, 2019
2 parents 58406b2 + a8093cc commit bd54113
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## TBD

### Bug fixes

* Alter value collected for device.freeDisk to collect usable space in internal storage,
rather than total space in internal/external storage
[#589](https://github.com/bugsnag/bugsnag-android/pull/589)

* Buffer io when reading from cached error file
[#573](https://github.com/bugsnag/bugsnag-android/pull/573)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bugsnag.android;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -253,25 +254,14 @@ private String[] getCpuAbi() {
}

/**
* Get the free disk space on the smallest disk
* Get the usable disk space on internal storage's data directory
*/
@Nullable
@SuppressWarnings("deprecation") // ignore blockSizeLong suggestions for now (requires API 18)
private Long calculateFreeDisk() {
try {
StatFs externalStat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long externalBytesAvailable =
(long) externalStat.getBlockSize() * (long) externalStat.getBlockCount();

StatFs internalStat = new StatFs(Environment.getDataDirectory().getPath());
long internalBytesAvailable =
(long) internalStat.getBlockSize() * (long) internalStat.getBlockCount();

return Math.min(internalBytesAvailable, externalBytesAvailable);
} catch (Exception exception) {
Logger.warn("Could not get freeDisk");
}
return null;
@SuppressLint("UsableSpace")
private long calculateFreeDisk() {
// for this specific case we want the currently usable space, not
// StorageManager#allocatableBytes() as the UsableSpace lint inspection suggests
File dataDirectory = Environment.getDataDirectory();
return dataDirectory.getUsableSpace();
}

/**
Expand Down

0 comments on commit bd54113

Please sign in to comment.