From aa590e60c584c3001746d4f59e44599a68d73253 Mon Sep 17 00:00:00 2001 From: nift4 Date: Fri, 23 Aug 2024 13:41:10 +0200 Subject: [PATCH] migrate to new download system in legacy flows part2 --- .../java/org/andbootmgr/app/CreatePartFlow.kt | 7 +- .../java/org/andbootmgr/app/DroidBootFlow.kt | 198 +++++------------- .../org/andbootmgr/app/FixDroidBootFlow.kt | 46 ++-- app/src/main/java/org/andbootmgr/app/Start.kt | 2 +- .../org/andbootmgr/app/UpdateDroidBootFlow.kt | 48 ++--- .../java/org/andbootmgr/app/UpdateFlow.kt | 30 ++- .../java/org/andbootmgr/app/WizardActivity.kt | 2 +- 7 files changed, 112 insertions(+), 221 deletions(-) diff --git a/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt b/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt index 73111141..dc4990d6 100644 --- a/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt @@ -378,16 +378,15 @@ private fun Shop(c: CreatePartDataHolder) { vm.inetAvailable[l.getString("id")] = WizardActivityState.Downloadable( l.getString("url"), - if (l.has("hash")) - l.getString("hash") else null, + l.optString("hash"), l.getString("desc") ) i++ } vm.idNeeded.add("_install.sh_") vm.inetAvailable["_install.sh_"] = WizardActivityState.Downloadable( - o.getString("scriptname"), if (o.has("scriptSha256")) - o.getString("scriptSha256") else null, + o.getString("scriptname"), + o.optString("scriptSha256"), vm.activity.getString(R.string.installer_sh) ) diff --git a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt index 648f62b5..f2ea95f0 100644 --- a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt @@ -54,8 +54,7 @@ class DroidBootFlow : WizardFlow() { Start(vm) }, WizardPage("input", NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") }, - NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript || !booted) - "dload" else "flash") } + NavButton("") {} ) { Input(vm) }, WizardPage("dload", @@ -92,9 +91,11 @@ private fun Start(vm: WizardActivityState) { } } +// shared across DroidBootFlow, UpdateDroidBootFlow, FixDroidBootFlow @Composable -private fun Input(vm: WizardActivityState) { +fun LoadDroidBootJson(vm: WizardActivityState, content: @Composable () -> Unit) { var loading by remember { mutableStateOf(!vm.deviceInfo.isBooted(vm.logic) || vm.deviceInfo.postInstallScript) } + var error by remember { mutableStateOf(false) } LaunchedEffect(Unit) { if (!loading) return@LaunchedEffect CoroutineScope(Dispatchers.IO).launch { @@ -107,7 +108,7 @@ private fun Input(vm: WizardActivityState) { if (!vm.deviceInfo.isBooted(vm.logic)) { val bl = json.getJSONObject("bootloader") val url = bl.getString("url") - val sha = if (bl.has("sha256")) bl.getString("sha256") else null + val sha = bl.optString("sha256") vm.inetAvailable["droidboot"] = WizardActivityState.Downloadable( url, sha, vm.activity.getString(R.string.droidboot_online) ) @@ -116,7 +117,7 @@ private fun Input(vm: WizardActivityState) { if (vm.deviceInfo.postInstallScript) { val i = json.getJSONObject("installScript") val url = i.getString("url") - val sha = if (i.has("sha256")) i.getString("sha256") else null + val sha = i.optString("sha256") vm.inetAvailable["install"] = WizardActivityState.Downloadable( url, sha, vm.activity.getString(R.string.installer_sh) ) @@ -128,156 +129,59 @@ private fun Input(vm: WizardActivityState) { Toast.makeText(vm.activity, R.string.dl_error, Toast.LENGTH_LONG).show() } Log.e("ABM droidboot json", Log.getStackTraceString(e)) + error = true } } } if (loading) { - LoadingCircle(stringResource(R.string.loading), modifier = Modifier.fillMaxSize()) - return - } - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() - ) { - LaunchedEffect(Unit) { // TODO can't I do this better? - if (vm.texts.isBlank()) - vm.texts = vm.activity.getString(R.string.android) - } - val e = vm.texts.isBlank() || !vm.texts.matches(Regex("[\\dA-Za-z]+")) - - Text(stringResource(R.string.enter_name_for_current), textAlign = TextAlign.Center, modifier = Modifier.padding(vertical = 5.dp)) - TextField( - value = vm.texts, - onValueChange = { - vm.texts = it - }, - label = { Text(stringResource(R.string.os_name)) }, - isError = e - ) - if (e) { - Text(stringResource(R.string.invalid_in), color = MaterialTheme.colorScheme.error) + if (error) { + Text(stringResource(R.string.dl_error)) } else { - Text("") // Budget spacer - } - LaunchedEffect(e) { - if (e) { - vm.nextText = "" - vm.onNext = {} - } else { - vm.nextText = vm.activity.getString(R.string.next) - vm.onNext = { it.navigate("select") } - } + LoadingCircle(stringResource(R.string.loading), modifier = Modifier.fillMaxSize()) } - } + } else content() } -// shared across DroidBootFlow, UpdateDroidBootFlow, FixDroidBootFlow @Composable -fun SelectDroidBoot(vm: WizardActivityState) { - var nextButtonAvailable by remember { mutableStateOf(false) } - - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() - ) { - Icon( - painterResource(R.drawable.ic_droidbooticon), - stringResource(R.string.droidboot_icon_content_desc), - Modifier.defaultMinSize(32.dp, 32.dp) - ) - - if (nextButtonAvailable) { - Text(stringResource(id = R.string.successfully_selected)) - } else { - //Text(stringResource(R.string.choose_droidboot_online)) - Button(onClick = { - vm.activity.chooseFile("*/*") { - vm.flashes["DroidBootFlashType"] = Pair(it, null) - nextButtonAvailable = true - vm.nextText = vm.activity.getString(R.string.next) - vm.onNext = { n -> n.navigate("flash") } - } - }) { - Text(stringResource(id = R.string.choose_file)) - } - val ctx = LocalContext.current - Button(onClick = { - CoroutineScope(Dispatchers.IO).launch { - try { - val jsonText = - URL("https://raw.githubusercontent.com/Android-Boot-Manager/ABM-json/master/devices/" + vm.codename + ".json").readText() - val json = JSONTokener(jsonText).nextValue() as JSONObject - if (BuildConfig.VERSION_CODE < json.getInt("minAppVersion")) - throw IllegalStateException("please upgrade app") - val bl = json.getJSONObject("bootloader") - val url = bl.getString("url") - val sha = if (bl.has("sha256")) bl.getString("sha256") else null - vm.flashes["DroidBootFlashType"] = Pair(Uri.parse(url), sha) - nextButtonAvailable = true - vm.nextText = vm.activity.getString(R.string.next) - vm.onNext = { n -> n.navigate("flash") } - } catch (e: Exception) { - Handler(Looper.getMainLooper()).post { - Toast.makeText(ctx, R.string.dl_error, Toast.LENGTH_LONG).show() - } - Log.e("ABM droidboot json", Log.getStackTraceString(e)) - } - } - }) { - Text(stringResource(id = R.string.download)) +private fun Input(vm: WizardActivityState) { + LoadDroidBootJson(vm) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxSize() + ) { + LaunchedEffect(Unit) { // TODO can't I do this better? + if (vm.texts.isBlank()) + vm.texts = vm.activity.getString(R.string.android) } - } - } -} - -// shared across DroidBootFlow, UpdateDroidBootFlow, FixDroidBootFlow -@Composable -fun SelectInstallSh(vm: WizardActivityState, update: Boolean = false) { - var nextButtonAvailable by remember { mutableStateOf(false) } - val flashType = "InstallShFlashType" + val e = vm.texts.isBlank() || !vm.texts.matches(Regex("[\\dA-Za-z]+")) - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() - ) { - if (nextButtonAvailable) { - Text(stringResource(id = R.string.successfully_selected)) - } else { - //Text(stringResource(R.string.choose_install_s_online)) - Button(onClick = { - vm.activity.chooseFile("*/*") { - vm.flashes[flashType] = Pair(it, null) - nextButtonAvailable = true - vm.nextText = vm.activity.getString(R.string.next) - vm.onNext = { n -> n.navigate( - if (!vm.deviceInfo.isBooted(vm.logic) || update) "select" else "flash") } - } - }) { - Text(stringResource(id = R.string.choose_file)) + Text( + stringResource(R.string.enter_name_for_current), + textAlign = TextAlign.Center, + modifier = Modifier.padding(vertical = 5.dp) + ) + TextField( + value = vm.texts, + onValueChange = { + vm.texts = it + }, + label = { Text(stringResource(R.string.os_name)) }, + isError = e + ) + if (e) { + Text(stringResource(R.string.invalid_in), color = MaterialTheme.colorScheme.error) + } else { + Text("") // Budget spacer } - val ctx = LocalContext.current - Button(onClick = { - CoroutineScope(Dispatchers.IO).launch { - try { - val jsonText = - URL("https://raw.githubusercontent.com/Android-Boot-Manager/ABM-json/master/devices/" + vm.codename + ".json").readText() - val json = JSONTokener(jsonText).nextValue() as JSONObject - if (BuildConfig.VERSION_CODE < json.getInt("minAppVersion")) - throw IllegalStateException("please upgrade app") - val i = json.getJSONObject("installScript") - val url = i.getString("url") - val sha = if (i.has("sha256")) i.getString("sha256") else null - vm.flashes[flashType] = Pair(Uri.parse(url), sha) - nextButtonAvailable = true - vm.nextText = vm.activity.getString(R.string.next) - vm.onNext = { n -> n.navigate( - if (!vm.deviceInfo.isBooted(vm.logic) || update) "select" else "flash") } - } catch (e: Exception) { - Handler(Looper.getMainLooper()).post { - Toast.makeText(ctx, R.string.dl_error, Toast.LENGTH_LONG).show() - } - Log.e("ABM install json", Log.getStackTraceString(e)) - } + LaunchedEffect(e) { + if (e) { + vm.nextText = "" + vm.onNext = {} + } else { + vm.nextText = vm.activity.getString(R.string.next) + vm.onNext = { it.navigate(if (vm.idNeeded.isNotEmpty()) "dload" else "flash") } } - }) { - Text(stringResource(id = R.string.download)) } } } @@ -372,7 +276,7 @@ private fun Flash(vm: WizardActivityState) { } val tmpFile = if (vm.deviceInfo.postInstallScript) { val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir) - vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile) + vm.copyPriv(vm.chosen["install"]!!.openInputStream(vm), tmpFile) tmpFile.setExecutable(true) tmpFile } else null @@ -401,18 +305,12 @@ private fun Flash(vm: WizardActivityState) { terminal.add(vm.activity.getString(R.string.term_cant_write_bl)) vm.copyPriv(SuFileInputStream.open(vm.deviceInfo.blBlock), backupLk) try { - vm.copyPriv(vm.flashStream(flashType), File(vm.deviceInfo.blBlock)) + vm.copyPriv(vm.chosen["droidboot"]!!.openInputStream(vm), File(vm.deviceInfo.blBlock)) } catch (e: IOException) { terminal.add(vm.activity.getString(R.string.term_bl_failed)) terminal.add(e.message ?: "(null)") terminal.add(vm.activity.getString(R.string.term_consult_doc)) return@Terminal - } catch (e: HashMismatchException) { - terminal.add(e.message ?: "(null)") - terminal.add(vm.activity.getString(R.string.restoring_backup)) - vm.copyPriv(SuFileInputStream.open(backupLk), File(vm.deviceInfo.blBlock)) - terminal.add(vm.activity.getString(R.string.term_consult_doc)) - return@Terminal } } if (vm.deviceInfo.postInstallScript) { diff --git a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt index d053d74b..9282a9e5 100644 --- a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -20,19 +21,14 @@ class FixDroidBootFlow(): WizardFlow() { override fun get(vm: WizardActivityState): List { return listOf(WizardPage("start", NavButton(vm.activity.getString(R.string.cancel)) { it.finish() }, - NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "select") }) + NavButton("") {}) { - Start() - }, WizardPage("shSel", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") }, - NavButton("") {} - ) { - SelectInstallSh(vm) - },WizardPage("select", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "start") }, + Start(vm) + }, WizardPage("dload", + NavButton(vm.activity.getString(R.string.cancel)) { it.finish() }, NavButton("") {} ) { - SelectDroidBoot(vm) + WizardDownloader(vm) }, WizardPage("flash", NavButton("") {}, NavButton("") {} @@ -43,12 +39,20 @@ class FixDroidBootFlow(): WizardFlow() { } @Composable -private fun Start() { - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() - ) { - Text(stringResource(id = R.string.welcome_text)) - Text(stringResource(R.string.reinstall_dboot)) +private fun Start(vm: WizardActivityState) { + LoadDroidBootJson(vm) { + LaunchedEffect(Unit) { + vm.nextText = vm.activity.getString(R.string.next) + vm.onNext = { it.navigate(if (vm.idNeeded.isNotEmpty()) "dload" else "flash") } + } + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxSize() + ) { + Text(stringResource(id = R.string.welcome_text)) + Text(stringResource(R.string.reinstall_dboot)) + } } } @@ -58,7 +62,7 @@ private fun Flash(vm: WizardActivityState) { vm.logic.extractToolkit(terminal) val tmpFile = if (vm.deviceInfo.postInstallScript) { val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir) - vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile) + vm.copyPriv(vm.chosen["install"]!!.openInputStream(vm), tmpFile) tmpFile.setExecutable(true) tmpFile } else null @@ -69,18 +73,12 @@ private fun Flash(vm: WizardActivityState) { terminal.add(vm.activity.getString(R.string.term_cant_write_bl)) vm.copyPriv(SuFileInputStream.open(vm.deviceInfo.blBlock), backupLk) try { - vm.copyPriv(vm.flashStream("DroidBootFlashType"), File(vm.deviceInfo.blBlock)) + vm.copyPriv(vm.chosen["droidboot"]!!.openInputStream(vm), File(vm.deviceInfo.blBlock)) } catch (e: IOException) { terminal.add(vm.activity.getString(R.string.term_bl_failed)) terminal.add(e.message ?: "(null)") terminal.add(vm.activity.getString(R.string.term_consult_doc)) return@Terminal - } catch (e: HashMismatchException) { - terminal.add(e.message ?: "(null)") - terminal.add(vm.activity.getString(R.string.restoring_backup)) - vm.copyPriv(SuFileInputStream.open(backupLk), File(vm.deviceInfo.blBlock)) - terminal.add(vm.activity.getString(R.string.term_consult_doc)) - return@Terminal } if (vm.deviceInfo.postInstallScript) { terminal.add(vm.activity.getString(R.string.term_device_setup)) diff --git a/app/src/main/java/org/andbootmgr/app/Start.kt b/app/src/main/java/org/andbootmgr/app/Start.kt index 18484d23..d56b0a90 100644 --- a/app/src/main/java/org/andbootmgr/app/Start.kt +++ b/app/src/main/java/org/andbootmgr/app/Start.kt @@ -593,7 +593,7 @@ private fun PartTool(vm: MainActivityState) { editEntryID = null }, title = { - Text(text = if (e.has("title")) "\"${e["title"]}\"" else if (f != null) stringResource(id = R.string.invalid_entry2) else stringResource(id = R.string.new_entry2)) + Text(text = if (e.has("title")) e["title"]!! else if (f != null) stringResource(id = R.string.invalid_entry2) else stringResource(id = R.string.new_entry2)) }, icon = { Icon(painterResource(id = R.drawable.ic_roms), stringResource(R.string.icon_content_desc)) diff --git a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt index 0a6582db..fe9b3f65 100644 --- a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -16,23 +17,18 @@ import org.andbootmgr.app.util.Terminal import java.io.File import java.io.IOException -class UpdateDroidBootFlow(): WizardFlow() { +class UpdateDroidBootFlow: WizardFlow() { override fun get(vm: WizardActivityState): List { return listOf(WizardPage("start", NavButton(vm.activity.getString(R.string.cancel)) { it.finish() }, - NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "select") }) + NavButton("") {}) { - Start() - }, WizardPage("shSel", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") }, - NavButton("") {} - ) { - SelectInstallSh(vm, update = true) - },WizardPage("select", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "start") }, + Start(vm) + }, WizardPage("dload", + NavButton(vm.activity.getString(R.string.cancel)) { it.finish() }, NavButton("") {} ) { - SelectDroidBoot(vm) + WizardDownloader(vm) }, WizardPage("flash", NavButton("") {}, NavButton("") {} @@ -43,12 +39,20 @@ class UpdateDroidBootFlow(): WizardFlow() { } @Composable -private fun Start() { - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() - ) { - Text(stringResource(id = R.string.welcome_text)) - Text(stringResource(R.string.update_droidboot_text)) +private fun Start(vm: WizardActivityState) { + LoadDroidBootJson(vm) { + LaunchedEffect(Unit) { + vm.nextText = vm.activity.getString(R.string.next) + vm.onNext = { it.navigate(if (vm.idNeeded.isNotEmpty()) "dload" else "flash") } + } + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxSize() + ) { + Text(stringResource(id = R.string.welcome_text)) + Text(stringResource(R.string.update_droidboot_text)) + } } } @@ -58,7 +62,7 @@ private fun Flash(vm: WizardActivityState) { vm.logic.extractToolkit(terminal) val tmpFile = if (vm.deviceInfo.postInstallScript) { val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir) - vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile) + vm.copyPriv(vm.chosen["install"]!!.openInputStream(vm), tmpFile) tmpFile.setExecutable(true) tmpFile } else null @@ -69,18 +73,12 @@ private fun Flash(vm: WizardActivityState) { terminal.add(vm.activity.getString(R.string.term_cant_write_bl)) vm.copyPriv(SuFileInputStream.open(vm.deviceInfo.blBlock), backupLk) try { - vm.copyPriv(vm.flashStream("DroidBootFlashType"), File(vm.deviceInfo.blBlock)) + vm.copyPriv(vm.chosen["droidboot"]!!.openInputStream(vm), File(vm.deviceInfo.blBlock)) } catch (e: IOException) { terminal.add(vm.activity.getString(R.string.term_bl_failed)) terminal.add(e.message ?: "(null)") terminal.add(vm.activity.getString(R.string.term_consult_doc)) return@Terminal - } catch (e: HashMismatchException) { - terminal.add(e.message ?: "(null)") - terminal.add(vm.activity.getString(R.string.restoring_backup)) - vm.copyPriv(SuFileInputStream.open(backupLk), File(vm.deviceInfo.blBlock)) - terminal.add(vm.activity.getString(R.string.term_consult_doc)) - return@Terminal } if (vm.deviceInfo.postInstallScript) { terminal.add(vm.activity.getString(R.string.term_device_setup)) diff --git a/app/src/main/java/org/andbootmgr/app/UpdateFlow.kt b/app/src/main/java/org/andbootmgr/app/UpdateFlow.kt index c279369c..a14ac912 100644 --- a/app/src/main/java/org/andbootmgr/app/UpdateFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/UpdateFlow.kt @@ -3,13 +3,10 @@ package org.andbootmgr.app import android.net.Uri import android.util.Log import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button -import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -19,10 +16,8 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.io.SuFile import kotlinx.coroutines.Dispatchers @@ -57,6 +52,7 @@ class UpdateFlow(private val entryName: String): WizardFlow() { NavButton(vm.activity.getString(R.string.online_update)) { vm.navigate("start") } ) { Local(c) + // TODO add dl }, WizardPage("flash", NavButton("") {}, NavButton("") {} @@ -117,17 +113,19 @@ private fun Start(u: UpdateFlowDataHolder) { try { u.run { val j = json!! - if (j.has("boot") && j.has("script")) { + if (j.has("extraIds") && j.has("script")) { val extraIdNeeded = j.getJSONArray("extraIds") var i = 0 while (i < extraIdNeeded.length()) { extraParts.add(extraIdNeeded.get(i) as String) i++ } - vm.flashes["InstallShFlashType"] = Pair( - Uri.parse(j.getString("script")), - if (j.has("scriptSha256")) j.getString("scriptSha256") else null + vm.inetAvailable["install"] = WizardActivityState.Downloadable( + j.getString("script"), + j.optString("scriptSha256"), + vm.activity.getString(R.string.installer_sh) ) + vm.idNeeded.add("install") } if (j.has("parts")) { val sp = u.e!!["xpart"]!!.split(":") @@ -175,16 +173,16 @@ private fun Local(u: UpdateFlowDataHolder) { } Column { Text(stringResource(R.string.script_name)) - if (u.vm.flashes.containsKey("InstallShFlashType")) { + if (u.vm.chosen.containsKey("install")) { Button(onClick = { - u.vm.flashes.remove("InstallShFlashType") + u.vm.chosen.remove("install") }) { Text(stringResource(id = R.string.undo)) } } else { Button(onClick = { u.vm.activity.chooseFile("*/*") { - u.vm.flashes["InstallShFlashType"] = Pair(it, null) + u.vm.chosen["install"] = DledFile(it, null) } }) { Text(stringResource(id = R.string.choose_file)) @@ -200,11 +198,11 @@ private fun Local(u: UpdateFlowDataHolder) { } if (u.sbootfile.isNotEmpty()) { Button(onClick = { - if (u.vm.flashes.containsKey("InstallShFlashType")) { + if (u.vm.chosen.containsKey("install")) { u.hasUpdate = false u.vm.navigate("flash") } - }, enabled = u.vm.flashes.containsKey("InstallShFlashType")) { + }, enabled = u.vm.chosen.containsKey("install")) { Text(stringResource(R.string.install_update)) } } @@ -296,7 +294,7 @@ private fun Flash(u: UpdateFlowDataHolder) { pmap[p.key] = f } val tmpFile = createTempFileSu("abm", ".sh", u.vm.logic.rootTmpDir) - u.vm.copyPriv(u.vm.flashStream("InstallShFlashType"), tmpFile) + u.vm.copyPriv(u.vm.chosen["install"]!!.openInputStream(u.vm), tmpFile) tmpFile.setExecutable(true) u.vm.nextText = "" u.vm.onNext = {} @@ -346,7 +344,7 @@ private fun Flash(u: UpdateFlowDataHolder) { } else if (u.sbootfile.isNotEmpty()) { val bootfile = ArrayList() val tmpFile = createTempFileSu("abm", ".sh", u.vm.logic.rootTmpDir) - u.vm.copyPriv(u.vm.flashStream("InstallShFlashType"), tmpFile) + u.vm.copyPriv(u.vm.chosen["flashes"]!!.openInputStream(u.vm), tmpFile) tmpFile.setExecutable(true) terminal.add(u.vm.activity.getString(R.string.term_patch_update)) u.sbootfile.forEach { diff --git a/app/src/main/java/org/andbootmgr/app/WizardActivity.kt b/app/src/main/java/org/andbootmgr/app/WizardActivity.kt index 791f6977..51b01c12 100644 --- a/app/src/main/java/org/andbootmgr/app/WizardActivity.kt +++ b/app/src/main/java/org/andbootmgr/app/WizardActivity.kt @@ -120,7 +120,7 @@ class WizardActivityState(val mvm: MainActivityState) { var onPrev by mutableStateOf<((WizardActivityState) -> Unit)?>(null) var onNext by mutableStateOf<((WizardActivityState) -> Unit)?>(null) - // TODO remove below two + // TODO remove flashes var flashes: HashMap> = HashMap() var texts by mutableStateOf("") val inetAvailable = HashMap()