Prevent crashes on devices before Oreo version

This commit is contained in:
Ensar Sarajčić 2023-09-07 12:57:31 +02:00
parent 3919384928
commit 69bddaa3d7
1 changed files with 9 additions and 4 deletions

View File

@ -286,10 +286,15 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
if (storageVolume.isPrimary) {
// internal storage
volumeName = PRIMARY_VOLUME_NAME
val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
val uuid = StorageManager.UUID_DEFAULT
totalStorageSpace = storageStatsManager.getTotalBytes(uuid)
freeStorageSpace = storageStatsManager.getFreeBytes(uuid)
if (isOreoPlus()) {
val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
val uuid = StorageManager.UUID_DEFAULT
totalStorageSpace = storageStatsManager.getTotalBytes(uuid)
freeStorageSpace = storageStatsManager.getFreeBytes(uuid)
} else {
totalStorageSpace = file.totalSpace
freeStorageSpace = file.freeSpace
}
} else {
volumeName = storageVolume.uuid!!.lowercase(Locale.US)
totalStorageSpace = file.totalSpace