Skip to content

Commit 31f4823

Browse files
committed
initial sdless support for home page
1 parent 46d02ba commit 31f4823

File tree

4 files changed

+132
-19
lines changed

4 files changed

+132
-19
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import java.io.FileNotFoundException
5959
import java.math.BigDecimal
6060
import java.net.URL
6161

62-
class CreatePartFlow(private val desiredStartSector: Long): WizardFlow() {
62+
class CreatePartFlow(private val desiredStartSector: Long?): WizardFlow() {
6363
override fun get(vm: WizardState): List<IWizardPage> {
6464
val c = CreatePartDataHolder(vm, desiredStartSector)
6565
return listOf(WizardPage("start",
@@ -91,7 +91,7 @@ class CreatePartFlow(private val desiredStartSector: Long): WizardFlow() {
9191
}
9292
}
9393

94-
private class CreatePartDataHolder(val vm: WizardState, val desiredStartSector: Long) {
94+
private class CreatePartDataHolder(val vm: WizardState, val desiredStartSector: Long?) {
9595
var meta by mutableStateOf<SDUtils.SDPartitionMeta?>(null)
9696
lateinit var p: SDUtils.Partition.FreeSpace
9797
var startSectorRelative = 0L

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

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.andbootmgr.app
22

33
import android.annotation.SuppressLint
4-
import android.util.Log
54
import android.widget.Toast
65
import androidx.compose.foundation.clickable
76
import androidx.compose.foundation.layout.Arrangement
@@ -204,14 +203,7 @@ private fun PartTool(vm: MainActivityState) {
204203
LaunchedEffect(Unit) {
205204
withContext(Dispatchers.IO) {
206205
val outList = mutableStateMapOf<ConfigFile, File>()
207-
val list = SuFile.open(vm.logic!!.abmEntries.absolutePath).listFiles()
208-
for (i in list!!) {
209-
try {
210-
outList[ConfigFile.importFromFile(i)] = i
211-
} catch (e: ActionAbortedCleanlyError) {
212-
Log.e("ABM", Log.getStackTraceString(e))
213-
}
214-
}
206+
outList.putAll(ConfigFile.importFromFolder(vm.logic!!.abmEntries))
215207
entries = outList
216208
}
217209
}
@@ -320,12 +312,11 @@ private fun PartTool(vm: MainActivityState) {
320312
)
321313
}
322314
}
323-
val e = ConfigFile()
324315
Row(horizontalArrangement = Arrangement.SpaceEvenly,
325316
verticalAlignment = Alignment.CenterVertically,
326317
modifier = Modifier
327318
.fillMaxWidth()
328-
.clickable { editEntryID = e }) {
319+
.clickable { editEntryID = ConfigFile() }) {
329320
Text(stringResource(R.string.new_entry))
330321
}
331322
}
@@ -352,7 +343,7 @@ private fun PartTool(vm: MainActivityState) {
352343
}
353344
)
354345
} else if (editEntryID != null) {
355-
OsEditor(vm, editEntryID!!, entries!![editEntryID!!]!!, onClose = {
346+
OsEditor(vm, parts, editEntryID!!, entries!![editEntryID!!]!!, onClose = {
356347
if (it) {
357348
entries!!.remove(editEntryID!!.also { editEntryID = null })
358349
// TODO don't call generateMeta on main thread
@@ -368,7 +359,7 @@ private fun PartTool(vm: MainActivityState) {
368359
}
369360

370361
@Composable
371-
private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
362+
private fun OsEditor(vm: MainActivityState, parts: SDUtils.SDPartitionMeta?, e: ConfigFile, f: File,
372363
onClose: (newPt: Boolean) -> Unit, onOpenUpdater: () -> Unit) {
373364
var processing by remember { mutableStateOf(false) }
374365
var delete by remember { mutableStateOf(false) }
@@ -389,6 +380,8 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
389380
enabled = e.has("xupdate") && !e["xupdate"].isNullOrBlank()) {
390381
Text(stringResource(R.string.update))
391382
}
383+
// TODO add button to open backup & restore tool (by asking which partition should
384+
// be backed up / restored)
392385
Button(
393386
onClick = {
394387
delete = true
@@ -429,8 +422,8 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
429422
delete = false
430423
CoroutineScope(Dispatchers.Default).launch {
431424
var tresult = ""
432-
if (e.has("xpart") && !e["xpart"].isNullOrBlank()) {
433-
var parts = SDUtils.generateMeta(vm.deviceInfo!!)
425+
if (e.has("xpart") && !e["xpart"].isNullOrBlank() && vm.deviceInfo!!.metaonsd) {
426+
var parts = parts
434427
val allp = e["xpart"]!!.split(":")
435428
.map { parts!!.dumpKernelPartition(Integer.valueOf(it)) }
436429
vm.unmountBootset()
@@ -441,6 +434,10 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
441434
tresult += r.out.joinToString("\n") + r.err.joinToString("\n") + "\n"
442435
}
443436
vm.mountBootset()
437+
} else if (!vm.deviceInfo!!.metaonsd) {
438+
val f3 = SuFile(vm.logic!!.abmSdLessBootset, f.nameWithoutExtension)
439+
if (!f3.deleteRecursive())
440+
tresult += vm.activity!!.getString(R.string.cannot_delete, f3.absolutePath)
444441
}
445442
val f2 = SuFile(vm.logic!!.abmBootset, f.nameWithoutExtension)
446443
if (!f2.deleteRecursive())
@@ -577,7 +574,7 @@ private fun PartitionEditor(vm: MainActivityState, p: SDUtils.Partition, simplif
577574
}
578575
}
579576
Button(onClick = {
580-
vm.currentWizardFlow = BackupRestoreFlow(p.id, null) // TODO !metaonsd
577+
vm.currentWizardFlow = BackupRestoreFlow(p.id, null)
581578
}) {
582579
Text(stringResource(R.string.backupnrestore))
583580
}
@@ -852,5 +849,104 @@ private fun EntryEditor(vm: MainActivityState, e: ConfigFile, f: File?, onClose:
852849

853850
@Composable
854851
private fun BootsetTool(vm: MainActivityState) {
855-
Text("insert code here") // TODO !metaonsd
852+
var filterEntryView by remember { mutableStateOf(false) }
853+
if (!vm.noobMode)
854+
MyFilterChipBar(
855+
if (filterEntryView) 1 else 0,
856+
listOf(
857+
stringResource(R.string.unified),
858+
stringResource(R.string.entries)
859+
)
860+
) { filterEntryView = it == 1 }
861+
862+
@SuppressLint("MutableCollectionMutableState") // lol
863+
var entries by remember { mutableStateOf<SnapshotStateMap<ConfigFile, File>?>(null) }
864+
LaunchedEffect(Unit) {
865+
withContext(Dispatchers.IO) {
866+
val outList = mutableStateMapOf<ConfigFile, File>()
867+
outList.putAll(ConfigFile.importFromFolder(vm.logic!!.abmEntries))
868+
entries = outList
869+
}
870+
}
871+
var editEntryID by remember { mutableStateOf<ConfigFile?>(null) }
872+
Column(
873+
Modifier
874+
.verticalScroll(rememberScrollState())
875+
.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally
876+
) {
877+
if (vm.noobMode)
878+
MyInfoCard(stringResource(R.string.click2inspect), padding = 5.dp)
879+
if (entries != null) {
880+
for (e in entries!!.keys) {
881+
val spaceUsage = null // TODO compute space usage of installed OS
882+
Row(horizontalArrangement = Arrangement.SpaceEvenly,
883+
verticalAlignment = Alignment.CenterVertically,
884+
modifier = Modifier
885+
.fillMaxWidth()
886+
.clickable { editEntryID = e }) {
887+
/* format:
888+
entry["title"] = str
889+
entry["linux"] = path(str)
890+
entry["initrd"] = path(str)
891+
entry["dtb"] = path(str)
892+
entry["options"] = str
893+
entry["xtype"] = str
894+
entry["xpart"] = array (str.split(":"))
895+
entry["xupdate"] = uri(str)
896+
*/
897+
Text(
898+
(if (e.has("title")) {
899+
stringResource(R.string.entry_title, e["title"]!!)
900+
} else {
901+
stringResource(R.string.invalid_entry)
902+
}).let {
903+
if (spaceUsage != null)
904+
stringResource(R.string.entry_space_usage, spaceUsage, it)
905+
else it
906+
}
907+
)
908+
}
909+
}
910+
if (filterEntryView) {
911+
Row(horizontalArrangement = Arrangement.SpaceEvenly,
912+
verticalAlignment = Alignment.CenterVertically,
913+
modifier = Modifier
914+
.fillMaxWidth()
915+
.clickable { editEntryID = ConfigFile() }) {
916+
Text(stringResource(R.string.new_entry))
917+
}
918+
} else {
919+
Row(horizontalArrangement = Arrangement.SpaceEvenly,
920+
verticalAlignment = Alignment.CenterVertically,
921+
modifier = Modifier
922+
.fillMaxWidth()
923+
.clickable { vm.currentWizardFlow = CreatePartFlow(null) }) {
924+
Text(stringResource(R.string.install_os))
925+
}
926+
}
927+
}
928+
// TODO we eventually want portable partitions for !metaonsd, but not supported yet
929+
if (editEntryID != null && filterEntryView) {
930+
EntryEditor(
931+
vm, editEntryID!!, entries!![editEntryID!!],
932+
onClose = { editEntryID = null },
933+
onDeleted = {
934+
entries!!.remove(editEntryID!!.also { editEntryID = null })
935+
},
936+
onEdited = {
937+
entries!![editEntryID!!.also { editEntryID = null }] = it
938+
}
939+
)
940+
} else if (editEntryID != null) {
941+
OsEditor(vm, null, editEntryID!!, entries!![editEntryID!!]!!, onClose = {
942+
if (it) {
943+
entries!!.remove(editEntryID!!.also { editEntryID = null })
944+
} else
945+
editEntryID = null
946+
}, onOpenUpdater = {
947+
vm.currentWizardFlow = UpdateFlow(entries!![editEntryID!!]!!.name)
948+
editEntryID = null
949+
})
950+
}
951+
}
856952
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.andbootmgr.app.util
22

3+
import android.util.Log
4+
import androidx.compose.runtime.mutableStateMapOf
5+
import com.topjohnwu.superuser.io.SuFile
36
import com.topjohnwu.superuser.io.SuFileInputStream
47
import com.topjohnwu.superuser.io.SuFileOutputStream
58
import org.andbootmgr.app.ActionAbortedCleanlyError
69
import org.andbootmgr.app.ActionAbortedError
710
import java.io.*
11+
import kotlin.collections.set
812

913

1014
class ConfigFile(private val data: MutableMap<String, String> = HashMap()) {
@@ -77,5 +81,17 @@ class ConfigFile(private val data: MutableMap<String, String> = HashMap()) {
7781
}
7882
return importFromString(s.toString())
7983
}
84+
85+
fun importFromFolder(f: File): Map<ConfigFile, File> {
86+
val out = hashMapOf<ConfigFile, File>()
87+
for (i in SuFile.open(f.absolutePath).listFiles()!!) {
88+
try {
89+
out[importFromFile(i)] = i
90+
} catch (e: ActionAbortedCleanlyError) {
91+
Log.e("ABM", Log.getStackTraceString(e))
92+
}
93+
}
94+
return out
95+
}
8096
}
8197
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<string name="invalid_entry2">Invalid entry</string>
132132
<string name="entry_title">Entry \"%s\"</string>
133133
<string name="free_space_item">Free space (%s)</string>
134+
<string name="entry_space_usage">%s (%s)</string>
134135
<string name="part_item">Partition %d \"%s\"</string>
135136
<string name="new_entry">(Create new entry)</string>
136137
<string name="new_entry2">New entry</string>

0 commit comments

Comments
 (0)