nisrulz / easydeviceinfo

:iphone: [Android Library] Get device information in a super easy way.
Apache License 2.0
1.76k stars 228 forks source link

Invalid External Storage Path #24

Open rayliverified opened 5 years ago

rayliverified commented 5 years ago

I got the following crash from an user on a Samsung Galaxy Tab 2 (Android 9.0)

Fatal Exception: java.lang.IllegalArgumentException
Invalid path: /storage/emulated/0
android.os.StatFs.doStat (StatFs.java:51)
android.os.StatFs.<init> (StatFs.java:41)
github.nisrulz.easydeviceinfo.base.EasyMemoryMod.getAvailableExternalMemorySize (EasyMemoryMod.java:147)
Caused by android.system.ErrnoException
statvfs failed: ENOENT (No such file or directory)
libcore.io.Linux.statvfs (Linux.java)
libcore.io.BlockGuardOs.statvfs (BlockGuardOs.java:333)
android.system.Os.statvfs (Os.java:570)
android.os.StatFs.doStat (StatFs.java:49)
android.os.StatFs.<init> (StatFs.java:41)
github.nisrulz.easydeviceinfo.base.EasyMemoryMod.getAvailableExternalMemorySize (EasyMemoryMod.java:147)

A quick StackOverflow search shows me that the reason it crashes is because you can't assume that an external storage exists.

Currently wrapping getAvailableExternalMemorySize() in a try catch to prevent crash.

rayliverified commented 5 years ago

Thanks for creating this library, it's fantastic :)

nisrulz commented 5 years ago

Good catch. I will add that and more fixes related to this soon.

Thank you for reporting this issue.