Skip to content

Commit 69bddaa

Browse files
committed
Prevent crashes on devices before Oreo version
1 parent 3919384 commit 69bddaa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,15 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
286286
if (storageVolume.isPrimary) {
287287
// internal storage
288288
volumeName = PRIMARY_VOLUME_NAME
289-
val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
290-
val uuid = StorageManager.UUID_DEFAULT
291-
totalStorageSpace = storageStatsManager.getTotalBytes(uuid)
292-
freeStorageSpace = storageStatsManager.getFreeBytes(uuid)
289+
if (isOreoPlus()) {
290+
val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
291+
val uuid = StorageManager.UUID_DEFAULT
292+
totalStorageSpace = storageStatsManager.getTotalBytes(uuid)
293+
freeStorageSpace = storageStatsManager.getFreeBytes(uuid)
294+
} else {
295+
totalStorageSpace = file.totalSpace
296+
freeStorageSpace = file.freeSpace
297+
}
293298
} else {
294299
volumeName = storageVolume.uuid!!.lowercase(Locale.US)
295300
totalStorageSpace = file.totalSpace

0 commit comments

Comments
 (0)