-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevicestore.kt
More file actions
36 lines (36 loc) · 1.13 KB
/
devicestore.kt
File metadata and controls
36 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.askquickly.utils
import android.os.Environment
import android.os.StatFs
object DiskUtils {
private val MEGA_BYTE:Long = 1048576
fun totalSpace(external:Boolean):Int {
val statFs = getStats(external)
val total = ((statFs.getBlockCount() as Long) * (statFs.getBlockSize() as Long)) / MEGA_BYTE
return total.toInt()
}
fun freeSpace(external:Boolean):Int {
val statFs = getStats(external)
val availableBlocks = statFs.getAvailableBlocks()
val blockSize = statFs.getBlockSize()
val freeBytes = availableBlocks * blockSize
return (freeBytes / MEGA_BYTE).toInt()
}
fun busySpace(external:Boolean):Int {
val statFs = getStats(external)
val total = (statFs.getBlockCount() * statFs.getBlockSize())
val free = (statFs.getAvailableBlocks() * statFs.getBlockSize())
return ((total - free) / MEGA_BYTE).toInt()
}
private fun getStats(external:Boolean):StatFs {
val path:String
if (external)
{
path = Environment.getExternalStorageDirectory().getAbsolutePath()
}
else
{
path = Environment.getRootDirectory().getAbsolutePath()
}
return StatFs(path)
}
}