Skip to content

Commit

Permalink
it should now work again:D
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Jul 31, 2024
1 parent 9b58861 commit d5765f7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ private fun Flash(c: CreatePartDataHolder) {
val vm = c.vm
Terminal(vm, logFile = "install_${System.currentTimeMillis()}.txt") { terminal ->
if (c.t == null) { // OS install
val parts = ArrayMap<Int, String>()
val parts = ArrayMap<Int, Int>()
val fn = c.t2.value
val gn = c.t3.value
terminal.add(vm.activity.getString(R.string.term_f_name, fn))
Expand All @@ -920,7 +920,7 @@ private fun Flash(c: CreatePartDataHolder) {
entry["dtbo"] = "$fn/dtbo.dtbo"
entry["options"] = c.cmdline
entry["xtype"] = c.rtype
entry["xpart"] = parts.values.join(":")
entry["xpart"] = parts.values.joinToString(":")
if (c.dmaMeta.contains("updateJson") && c.dmaMeta["updateJson"] != null)
entry["xupdate"] = c.dmaMeta["updateJson"]!!
entry.exportToFile(File(vm.logic.abmEntries, "$fn.conf"))
Expand All @@ -935,7 +935,7 @@ private fun Flash(c: CreatePartDataHolder) {
val j = c.idVals.indexOf(i)
terminal.add(vm.activity.getString(R.string.term_flashing_s, i))
val f = c.chosen[i]!!
val tp = File(meta.dumpKernelPartition(j).path)
val tp = File(meta.dumpKernelPartition(parts[j]!!).path)
if (c.sparseVals[j]) {
val f2 = f.toFile(c.vm)
val result2 = Shell.cmd(
Expand Down Expand Up @@ -1004,7 +1004,7 @@ private fun Flash(c: CreatePartDataHolder) {
if (r.out.join("\n").contains("kpartx")) {
terminal.add(vm.activity.getString(R.string.term_reboot_asap))
}
parts[it] = c.meta!!.nid.toString()
parts[it] = c.meta!!.nid
c.meta = SDUtils.generateMeta(c.vm.deviceInfo!!)
if (it + 1 < c.count.intValue) {
c.p = c.meta!!.s.find { it1 -> it1.type == SDUtils.PartitionType.FREE && (offset + k) < it1.startSector } as SDUtils.Partition.FreeSpace
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/org/andbootmgr/app/DeviceInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ interface DeviceInfo {
abstract class MetaOnSdDeviceInfo : DeviceInfo {
override val metaonsd: Boolean = true
override fun isInstalled(logic: DeviceLogic): Boolean {
return SuFile.open(bdev).exists() && run {
val meta = SDUtils.generateMeta(this)
meta?.let { (meta.p.isNotEmpty()) && (meta.dumpKernelPartition(0).type == SDUtils.PartitionType.RESERVED) } == true
}
return SuFile.open(bdev).exists() && SDUtils.generateMeta(this)?.let { meta ->
meta.p.isNotEmpty() && meta.dumpKernelPartition(1).type == SDUtils.PartitionType.RESERVED
} == true
}
override fun isCorrupt(logic: DeviceLogic): Boolean {
return !SuFile.open(logic.abmDb, "db.conf").exists()
Expand All @@ -53,7 +52,7 @@ abstract class MetaOnSdDeviceInfo : DeviceInfo {
if (SuFile.open(bdev).exists())
SDUtils.generateMeta(this)?.let { meta ->
if (meta.p.isNotEmpty()) {
val part = meta.dumpKernelPartition(0)
val part = meta.dumpKernelPartition(1)
if (part.type == SDUtils.PartitionType.RESERVED)
return part.path
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/andbootmgr/app/DeviceLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DeviceLogic(ctx: Context) {
fun mountBootset(d: DeviceInfo): Boolean {
if (checkMounted()) return true
val ast = d.getAbmSettings(this) ?: return false
if (!abmBootset.exists()) abmBootset.mkdir()
val result = Shell
.cmd("mount $ast ${abmBootset.absolutePath}")
.exec()
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/andbootmgr/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,19 @@ class MainActivity : ComponentActivity() {
Shell.getShell { shell ->
vm.root = shell.isRoot
vm.deviceInfo = HardcodedDeviceInfoFactory.get(Build.DEVICE)
// == temp migration code start ==
if (Shell.cmd("mountpoint -q /data/abm/bootset").exec().isSuccess) {
Shell.cmd("umount /data/abm/bootset").exec()
}
SuFile.open("/data/abm").let {
if (it.exists())
Shell.cmd("rm -rf /data/abm").exec()
}
// == temp migration code end ==
if (vm.deviceInfo != null && vm.deviceInfo!!.isInstalled(vm.logic!!)) {
vm.logic!!.mountBootset(vm.deviceInfo!!)
} else {
Log.i("ABM", "not installed, not trying to mount")
}
if (vm.deviceInfo != null) {
vm.isOk = ((vm.deviceInfo!!.isInstalled(vm.logic!!)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private fun Flash(vm: WizardActivityState) {
val f = SuFile.open(vm.deviceInfo!!.blBlock)
if (!f.canWrite())
terminal.add(vm.activity.getString(R.string.term_cant_write_bl))
vm.copyPriv(SuFileInputStream.open(vm.deviceInfo.blBlock), File(vm.logic.abmDir, "backup2_lk.img"))
vm.copyPriv(SuFileInputStream.open(vm.deviceInfo.blBlock), File(vm.logic.fileDir, "backup2_lk.img"))
try {
vm.copyPriv(vm.flashStream(flashType), File(vm.deviceInfo.blBlock))
} catch (e: IOException) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/andbootmgr/app/util/SDUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.andbootmgr.app.DeviceInfo
import org.andbootmgr.app.join
import java.util.*
import java.util.stream.Collectors
import kotlin.jvm.optionals.getOrElse

object SDUtils {

Expand Down Expand Up @@ -306,7 +307,8 @@ object SDUtils {

// Get partition by kernel id
fun dumpKernelPartition(id: Int): Partition {
return p.stream().filter { it.id == id }.findFirst().get()
return p.stream().filter { it.id == id }.findFirst().getOrElse {
throw IllegalArgumentException("no such partition with id $id, have: ${this.p}") }
}
}
}

0 comments on commit d5765f7

Please sign in to comment.