Skip to content

Commit aecf889

Browse files
committed
calculate free space
1 parent ccb6449 commit aecf889

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private fun StartSdLess(c: CreatePartDataHolder) {
273273
if (c.freeSpace == null) {
274274
LaunchedEffect(Unit) {
275275
withContext(Dispatchers.IO) {
276-
c.freeSpace = SDLessUtils.getFreeSpaceBytes()
276+
c.freeSpace = SDLessUtils.getFreeSpaceBytes(c.vm.logic)
277277
}
278278
}
279279
LoadingCircle(stringResource(R.string.loading), modifier = Modifier.fillMaxSize())

app/src/main/java/org/andbootmgr/app/util/SDLessUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import com.topjohnwu.superuser.Shell
44
import com.topjohnwu.superuser.io.SuFile
55
import org.andbootmgr.app.DeviceLogic
66
import java.io.File
7+
import kotlin.math.max
78

89
object SDLessUtils {
9-
fun getFreeSpaceBytes(): Long {
10-
return 4L * 1024L * 1024L * 1024L // TODO
10+
fun getFreeSpaceBytes(logic: DeviceLogic): Long {
11+
val raw = Shell.cmd("stat -f ${logic.abmSdLessBootset} -c '%f:%S'").exec().out.joinToString("\n").split(":").map { it.trim().toLong() }
12+
return max(raw[0] * raw[1] - 1024L * 1024L * 1024L, 0)
1113
}
1214

1315
fun getSpaceUsageBytes(logic: DeviceLogic, fn: String): Long? {

0 commit comments

Comments
 (0)