DawnImpulse / wallup-android

Hand curated Images & 'Auto Wallpaper'
ISC License
32 stars 4 forks source link

Cache directory doesn't exist #3

Closed DawnImpulse closed 5 years ago

DawnImpulse commented 5 years ago

Issue

App crashes when checking for the total size of the cache directory.

Info

From Crashlytics

Fatal Exception: java.lang.IllegalArgumentException: /data/user/0/com.dawnimpulse.wallup/cache/image_manager_disk_cache/b8e6a3a1baa07dcaf58c4a98db9747975c8058a03777cf50cf60fe295ed20919.0.tmp does not exist
       at org.apache.commons.io.FileUtils.sizeOf(FileUtils.java:2413)
       at org.apache.commons.io.FileUtils.sizeOfDirectory(FileUtils.java:2479)
       at org.apache.commons.io.FileUtils.sizeOf(FileUtils.java:2417)
       at org.apache.commons.io.FileUtils.sizeOfDirectory(FileUtils.java:2479)
       at com.dawnimpulse.wallup.utils.F$appCache$1.invokeSuspend(F.kt:291)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
       at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)

Possible Solution

Need help to figure out this issue / possible fix

mohammaduvez commented 5 years ago

That's not a good way of calculating size of cache dir.

[StorageStats#getCacheBytes()](https://developer.android.com/reference/android/app/usage/StorageStats.html#getCacheBytes()) is available from O.

For older versions hacky reflections available PackageStats#cacheSize

DawnImpulse commented 5 years ago

@mohammaduvez ohh thats a very easy solution. Thanks a lot :)

DawnImpulse commented 5 years ago

@mohammaduvez I completely agree on your solution and it is very good although not so easy to implement also after very careful analysis I found that to get just the app cache size, my approach is very efficient actually.

The crash mentioned above was only the single instance in the past 9 months & there are a lot of users on this application on all kinds of devices. So, for now, I am going to stick with my approach.

Although thanks a lot for giving such good advice and it is very helpful in many situations where my approach will simply fail. So again thanks for that