Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter device.freeDisk to collect usable space in data directory #589

Merged
merged 3 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## TBD

* Alter device.freeDisk to collect usable space in data directory
[#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