Commit 3e19180c authored by jlok's avatar jlok Committed by Mehdi Achour

fix: safe guard getFreeDiskStorage() and getTotalDiskCapacity() (#322)

parent d03f20a1
......@@ -2,6 +2,8 @@
### Next
* Fix crash on `getFreeDiskStorage` and `getTotalDiskCapacity` from invalid filesystem path (https://github.com/rebeccahughes/react-native-device-info/issues/320)
### 0.15.1
* Fix Android compatibility for `getFreeDiskStorage` and `getTotalDiskCapacity` (https://github.com/rebeccahughes/react-native-device-info/pull/319)
......
......@@ -127,15 +127,25 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
}
@ReactMethod
public int getTotalDiskCapacity() {
public Integer getTotalDiskCapacity() {
try {
StatFs root = new StatFs(Environment.getRootDirectory().getAbsolutePath());
return root.getBlockCount() * root.getBlockSize();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@ReactMethod
public int getFreeDiskStorage() {
public Integer getFreeDiskStorage() {
try {
StatFs external = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
return external.getAvailableBlocks() * external.getBlockSize();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment