Skip to content

Commit 6d5edbd

Browse files
committed
some sdless work
1 parent 31f4823 commit 6d5edbd

File tree

10 files changed

+53
-33
lines changed

10 files changed

+53
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private class CreateBackupDataHolder(val vm: WizardState, val pi: Int?, val part
5454
private fun ChooseAction(c: CreateBackupDataHolder) {
5555
if (c.vm.deviceInfo.metaonsd) {
5656
LaunchedEffect(Unit) {
57-
c.meta = SDUtils.generateMeta(c.vm.deviceInfo)
57+
c.meta = SDUtils.generateMeta(c.vm.deviceInfo.asMetaOnSdDeviceInfo())
5858
}
5959
}
6060

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private fun Start(c: CreatePartDataHolder) {
137137
LaunchedEffect(Unit) {
138138
if (c.meta == null) {
139139
withContext(Dispatchers.IO) {
140-
val meta = SDUtils.generateMeta(c.vm.deviceInfo)!! // TODO !metaonsd
140+
val meta = SDUtils.generateMeta(c.vm.deviceInfo.asMetaOnSdDeviceInfo())!! // TODO !metaonsd
141141
c.p =
142142
meta.s.find { c.desiredStartSector == it.startSector } as SDUtils.Partition.FreeSpace
143143
c.meta = meta
@@ -650,7 +650,7 @@ private fun Flash(c: CreatePartDataHolder) {
650650
terminal.add(vm.activity.getString(R.string.term_reboot_asap))
651651
}
652652
createdParts.add(Pair(part, c.meta!!.nid))
653-
c.meta = SDUtils.generateMeta(c.vm.deviceInfo)
653+
c.meta = SDUtils.generateMeta(c.vm.deviceInfo.asMetaOnSdDeviceInfo())
654654
// do not assert there is leftover space if we just created the last partition we want to create
655655
if (index < c.parts.size - 1) {
656656
c.p =
@@ -665,7 +665,7 @@ private fun Flash(c: CreatePartDataHolder) {
665665
}
666666
terminal.add(vm.activity.getString(R.string.term_created_pt))
667667
vm.logic.mountBootset(vm.deviceInfo)
668-
val meta = SDUtils.generateMeta(vm.deviceInfo)
668+
val meta = SDUtils.generateMeta(vm.deviceInfo.asMetaOnSdDeviceInfo())
669669
if (meta == null) {
670670
terminal.add(vm.activity.getString(R.string.term_cant_get_meta))
671671
return@WizardTerminalWork

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import java.net.URL
2020
interface DeviceInfo {
2121
val codename: String
2222
val blBlock: String
23-
val bdev: String
24-
val pbdev: String
2523
val metaonsd: Boolean
2624
val postInstallScript: Boolean
2725
val havedtbo: Boolean
2826
fun isInstalled(logic: DeviceLogic): Boolean
2927
@SuppressLint("PrivateApi")
3028
fun isBooted(logic: DeviceLogic): Boolean {
29+
// TODO migrate all modern BL to one of these three variants
3130
try {
3231
val c = Class.forName("android.os.SystemProperties")
3332
val getBoolean: Method = c.getMethod(
@@ -48,7 +47,11 @@ interface DeviceInfo {
4847
fun getAbmSettings(logic: DeviceLogic): String?
4948
}
5049

50+
fun DeviceInfo.asMetaOnSdDeviceInfo() = this as MetaOnSdDeviceInfo
51+
5152
abstract class MetaOnSdDeviceInfo : DeviceInfo {
53+
abstract val bdev: String
54+
abstract val pbdev: String
5255
override val metaonsd = true
5356
override fun isInstalled(logic: DeviceLogic): Boolean {
5457
return SuFile.open(bdev).exists() && SDUtils.generateMeta(this)?.let { meta ->
@@ -84,7 +87,7 @@ abstract class SdLessDeviceInfo : DeviceInfo {
8487
}
8588
}
8689

87-
class JsonDeviceInfo(
90+
class JsonMetaOnSdDeviceInfo(
8891
override val codename: String,
8992
override val blBlock: String,
9093
override val bdev: String,
@@ -93,6 +96,13 @@ class JsonDeviceInfo(
9396
override val havedtbo: Boolean
9497
) : MetaOnSdDeviceInfo()
9598

99+
class JsonSdLessDeviceInfo(
100+
override val codename: String,
101+
override val blBlock: String,
102+
override val postInstallScript: Boolean,
103+
override val havedtbo: Boolean
104+
) : SdLessDeviceInfo()
105+
96106
class JsonDeviceInfoFactory(private val ctx: Context) {
97107
suspend fun get(codename: String): DeviceInfo? {
98108
return try {
@@ -124,16 +134,23 @@ class JsonDeviceInfoFactory(private val ctx: Context) {
124134
File(ctx.filesDir, "abm_dd_cache.json").writeText(newRoot.toString())
125135
}
126136
}
127-
if (!json.getBoolean("metaOnSd"))
128-
throw IllegalArgumentException("sd less currently not implemented")
129-
JsonDeviceInfo(
130-
json.getString("codename"),
131-
json.getString("blBlock"),
132-
json.getString("sdBlock"),
133-
json.getString("sdBlockP"),
134-
json.getBoolean("postInstallScript"),
135-
json.getBoolean("haveDtbo")
136-
)
137+
if (json.getBoolean("metaOnSd")) {
138+
JsonMetaOnSdDeviceInfo(
139+
json.getString("codename"),
140+
json.getString("blBlock"),
141+
json.getString("sdBlock"),
142+
json.getString("sdBlockP"),
143+
json.getBoolean("postInstallScript"),
144+
json.getBoolean("haveDtbo")
145+
)
146+
} else {
147+
JsonSdLessDeviceInfo(
148+
json.getString("codename"),
149+
json.getString("blBlock"),
150+
json.getBoolean("postInstallScript"),
151+
json.getBoolean("haveDtbo")
152+
)
153+
}
137154
}
138155
} catch (e: Exception) {
139156
Log.e("ABM device info", Log.getStackTraceString(e))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DeviceLogic(private val ctx: Context) {
1919
val abmSdLessBootset = File("/data/abm")
2020
val abmSdLessBootsetImg = File(abmSdLessBootset, "bootset.img")
2121
private val metadata = File("/metadata")
22-
val metadataMap = File(metadata, "bootset.map")
22+
val metadataMap = File(metadata, "abm_settings.map")
2323
val dmBase = File("/dev/block/mapper")
2424
val dmName = "abmbootset"
2525
val dmPath = File(dmBase, dmName)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,21 @@ private fun Flash(d: DroidBootFlowDataHolder) {
210210
}
211211

212212
if (vm.deviceInfo.metaonsd) {
213-
var meta = SDUtils.generateMeta(vm.deviceInfo)
213+
var meta = SDUtils.generateMeta(vm.deviceInfo.asMetaOnSdDeviceInfo())
214214
if (meta == null) {
215215
terminal.add(vm.activity.getString(R.string.term_cant_get_meta))
216216
return@WizardTerminalWork
217217
}
218218
if (!Shell.cmd(SDUtils.umsd(meta)).to(terminal).exec().isSuccess) {
219219
terminal.add(vm.activity.getString(R.string.term_failed_umount_drive))
220220
}
221-
if (!Shell.cmd("sgdisk --mbrtogpt --clear ${vm.deviceInfo.bdev}").to(terminal)
221+
if (!Shell.cmd("sgdisk --mbrtogpt --clear ${vm.deviceInfo.asMetaOnSdDeviceInfo().bdev}").to(terminal)
222222
.exec().isSuccess
223223
) {
224224
terminal.add(vm.activity.getString(R.string.term_failed_create_pt))
225225
return@WizardTerminalWork
226226
}
227-
meta = SDUtils.generateMeta(vm.deviceInfo)
227+
meta = SDUtils.generateMeta(vm.deviceInfo.asMetaOnSdDeviceInfo())
228228
if (meta == null) {
229229
terminal.add(vm.activity.getString(R.string.term_cant_get_meta))
230230
return@WizardTerminalWork

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fun Start(vm: MainActivityState) {
7272
corrupt = remember { vm.deviceInfo!!.isCorrupt(vm.logic!!) }
7373
mounted = vm.logic!!.mounted
7474
metaOnSd = vm.deviceInfo!!.metaonsd
75-
sdPresent = if (metaOnSd) remember { SuFile.open(vm.deviceInfo!!.bdev).exists() } else false
75+
sdPresent = if (metaOnSd) remember { SuFile.open(vm.deviceInfo!!.asMetaOnSdDeviceInfo().bdev).exists() } else false
7676
} else {
7777
installed = false
7878
booted = false
@@ -193,7 +193,7 @@ private fun PartTool(vm: MainActivityState) {
193193
)
194194
) { filter = it }
195195

196-
var parts by remember { mutableStateOf(SDUtils.generateMeta(vm.deviceInfo!!)) }
196+
var parts by remember { mutableStateOf(SDUtils.generateMeta(vm.deviceInfo!!.asMetaOnSdDeviceInfo())) }
197197
if (parts == null) {
198198
Text(stringResource(R.string.part_wizard_err))
199199
return
@@ -325,7 +325,7 @@ private fun PartTool(vm: MainActivityState) {
325325
vm, editPartID!!, simplified = filterUnifiedView,
326326
onClose = { editPartID = null }, onPtChanged = {
327327
// TODO don't call generateMeta on main thread
328-
parts = SDUtils.generateMeta(vm.deviceInfo!!)
328+
parts = SDUtils.generateMeta(vm.deviceInfo!!.asMetaOnSdDeviceInfo())
329329
editPartID = if (it) null else
330330
parts?.s!!.findLast { it.id == editPartID!!.id }
331331
}
@@ -347,7 +347,7 @@ private fun PartTool(vm: MainActivityState) {
347347
if (it) {
348348
entries!!.remove(editEntryID!!.also { editEntryID = null })
349349
// TODO don't call generateMeta on main thread
350-
parts = SDUtils.generateMeta(vm.deviceInfo!!)
350+
parts = SDUtils.generateMeta(vm.deviceInfo!!.asMetaOnSdDeviceInfo())
351351
} else
352352
editEntryID = null
353353
}, onOpenUpdater = {
@@ -429,7 +429,7 @@ private fun OsEditor(vm: MainActivityState, parts: SDUtils.SDPartitionMeta?, e:
429429
vm.unmountBootset()
430430
for (p in allp) { // Do not chain, but regenerate meta and unmount every time. Thanks vold
431431
p.meta = if (parts != null) parts.also { parts = null }
432-
else SDUtils.generateMeta(vm.deviceInfo!!)!!
432+
else SDUtils.generateMeta(vm.deviceInfo!!.asMetaOnSdDeviceInfo())!!
433433
val r = vm.logic!!.delete(p).exec()
434434
tresult += r.out.joinToString("\n") + r.err.joinToString("\n") + "\n"
435435
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private fun Flash(u: UpdateFlowDataHolder) {
210210
u.vm.logic.extractToolkit(terminal)
211211
u.vm.downloadRemainingFiles(terminal)
212212
val sp = u.e!!["xpart"]!!.split(":")
213-
val meta = SDUtils.generateMeta(u.vm.deviceInfo)!! // TODO !metaonsd
213+
val meta = SDUtils.generateMeta(u.vm.deviceInfo.asMetaOnSdDeviceInfo())!! // TODO !metaonsd
214214
Shell.cmd(SDUtils.umsd(meta)).exec()
215215
val tmpFile = if (u.vm.idNeeded.contains("_install.sh_")) {
216216
u.vm.chosen["_install.sh_"]!!.toFile(u.vm).also {

app/src/main/java/org/andbootmgr/app/themes/Simulator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Simulator : AppCompatActivity() {
4747
stop()
4848
}
4949
})
50-
f = File(intent.getStringExtra("sdCardBlock")!!)
50+
f = File(intent.getStringExtra("sdCardBlock")!!) // TODO support sd-less with "bootsetBlock"
5151
val l = LinearLayout(this)
5252
v = object : View(this) {
5353
private var firstTime = true

app/src/main/java/org/andbootmgr/app/themes/Themes.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import kotlinx.coroutines.launch
5353
import org.andbootmgr.app.AppContent
5454
import org.andbootmgr.app.MainActivityState
5555
import org.andbootmgr.app.R
56+
import org.andbootmgr.app.asMetaOnSdDeviceInfo
5657
import org.andbootmgr.app.util.AbmTheme
5758

5859
/*
@@ -130,7 +131,11 @@ fun Themes(vm: ThemeViewModel) {
130131
vm.mvm.activity,
131132
Simulator::class.java
132133
).apply {
133-
putExtra("sdCardBlock", vm.mvm.deviceInfo!!.bdev)
134+
if (vm.mvm.deviceInfo!!.metaonsd)
135+
putExtra("sdCardBlock",
136+
vm.mvm.deviceInfo!!.asMetaOnSdDeviceInfo().bdev)
137+
else
138+
putExtra("bootsetBlock", vm.mvm.logic!!.abmSdLessBootsetImg)
134139
}
135140
)
136141
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.andbootmgr.app.util
22

33
import android.util.Log
44
import com.topjohnwu.superuser.Shell
5-
import org.andbootmgr.app.DeviceInfo
5+
import org.andbootmgr.app.MetaOnSdDeviceInfo
66
import java.util.*
77
import java.util.stream.Collectors
88
import kotlin.jvm.optionals.getOrElse
@@ -17,9 +17,7 @@ object SDUtils {
1717
return if (e.isEmpty()) "true" else e.substring(0, e.length - 4)
1818
}
1919

20-
fun generateMeta(deviceInfo: DeviceInfo): SDPartitionMeta? {
21-
if (!deviceInfo.metaonsd)
22-
throw IllegalStateException("App bug: generateMeta should _never_ be called on sd-less ports")
20+
fun generateMeta(deviceInfo: MetaOnSdDeviceInfo): SDPartitionMeta? {
2321
val meta: SDPartitionMeta
2422
val r =
2523
Shell.cmd("printf \"mm:%d:%d\\n\" `stat -c '0x%t 0x%T' ${deviceInfo.bdev}` && sgdisk ${deviceInfo.bdev} --print")

0 commit comments

Comments
 (0)