Skip to content

Commit

Permalink
refactor & performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 20, 2024
1 parent 7c76cae commit 815e1bc
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build
app/build
app/.cxx
.gradle/*
.kotlin/*
local.properties
# User-specific stuff
.idea
Expand Down
7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("org.jetbrains.kotlinx.atomicfu")
id("com.mikepenz.aboutlibraries.plugin")
}

Expand Down Expand Up @@ -110,13 +111,19 @@ android {
}
}

atomicfu {
dependenciesVersion = "0.25.0"
jvmVariant = "FU"
}

tasks.register("setAssetTs", Task::class) {
doLast {
File("$rootDir/app/src/main/assets/cp/_ts").writeText((System.currentTimeMillis() / 1000L).toString())
}
}

dependencies {
compileOnly("org.jetbrains.kotlinx:atomicfu:0.25.0")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/andbootmgr/app/BackupRestoreFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private fun SelectDroidBoot(c: CreateBackupDataHolder) {
@Composable
private fun Flash(c: CreateBackupDataHolder) {
Terminal(logFile = "flash_${System.currentTimeMillis()}.txt") { terminal ->
c.vm.logic.extractToolkit(terminal)
terminal.add(c.vm.activity.getString(R.string.term_starting))
try {
val p = c.meta!!.dumpKernelPartition(c.pi)
Expand All @@ -143,8 +144,8 @@ private fun Flash(c: CreateBackupDataHolder) {
c.vm.copyUnpriv(c.vm.activity.contentResolver.openInputStream(c.path!!)!!, f)
val result2 = Shell.cmd(
File(
c.vm.logic.assetDir,
"Toolkit/simg2img"
c.vm.logic.toolkitDir,
"simg2img"
).absolutePath + " ${f.absolutePath} ${p.path}"
).to(terminal).exec()
if (!result2.isSuccess) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ private fun Download(c: CreatePartDataHolder) {
private fun Flash(c: CreatePartDataHolder) {
val vm = c.vm
Terminal(logFile = "install_${System.currentTimeMillis()}.txt") { terminal ->
c.vm.logic.extractToolkit(terminal)
if (c.t == null) { // OS install
val parts = ArrayMap<Int, Int>()
val fn = c.t2.value
Expand Down Expand Up @@ -962,8 +963,8 @@ private fun Flash(c: CreatePartDataHolder) {
val f2 = f.toFile(c.vm)
val result2 = Shell.cmd(
File(
c.vm.logic.assetDir,
"Toolkit/simg2img"
c.vm.logic.toolkitDir,
"simg2img"
).absolutePath + " ${f2.absolutePath} ${tp.absolutePath}"
).to(terminal).exec()
f.delete()
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/org/andbootmgr/app/DeviceLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import android.util.Log
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.io.SuFile
import org.andbootmgr.app.util.SDUtils
import org.andbootmgr.app.util.Toolkit
import java.io.File

class DeviceLogic(ctx: Context) {
class DeviceLogic(private val ctx: Context) {
private val rootDir = ctx.filesDir.parentFile!!
val assetDir = File(rootDir, "assets")
private val toolkitDir = File(assetDir, "Toolkit")
private val toolkit = Toolkit(ctx)
val fileDir = File(rootDir, "files")
val cacheDir = File(rootDir, "cache")
val toolkitDir = File(toolkit.targetPath, "Toolkit") // will occasionally be pruned by OS, but it's fine
val rootTmpDir = File("/data/local/tmp")
val abmBootset = File(rootTmpDir, ".abm_bootset")
val abmDb = File(abmBootset, "db")
Expand Down Expand Up @@ -86,4 +87,14 @@ class DeviceLogic(ctx: Context) {
"TMPDIR=\"${cacheDir.absolutePath}\" BOOTSET=\"${abmBootset.absolutePath}\" " +
"TK=\"${toolkitDir.absolutePath}\" && cd \"\$TK\" && $cmd")
}
suspend fun extractToolkit(terminal: MutableList<String>) {
try {
toolkit.copyAssets {
terminal.add(ctx.getString(R.string.toolkit_extracting))
}
} catch (e: Exception) {
terminal.add(ctx.getString(R.string.toolkit_error))
throw e
}
}
}
1 change: 1 addition & 0 deletions app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ fun SelectInstallSh(vm: WizardActivityState, update: Boolean = false) {
private fun Flash(vm: WizardActivityState) {
val flashType = "DroidBootFlashType"
Terminal(logFile = "blflash_${System.currentTimeMillis()}.txt") { terminal ->
vm.logic.extractToolkit(terminal)
terminal.add(vm.activity.getString(R.string.term_preparing_fs))
if (vm.logic.checkMounted()) {
terminal.add(vm.activity.getString(R.string.term_mount_state_bad))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private fun Start() {
@Composable
private fun Flash(vm: WizardActivityState) {
Terminal(logFile = "blfix_${System.currentTimeMillis()}.txt") { terminal ->
vm.logic.extractToolkit(terminal)
val tmpFile = if (vm.deviceInfo.postInstallScript) {
val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir)
vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile)
Expand Down
Loading

0 comments on commit 815e1bc

Please sign in to comment.