diff --git a/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt b/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt index 0d9c0b0a..db4a92ab 100644 --- a/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt @@ -187,7 +187,7 @@ private class CreatePartDataHolder(val vm: WizardActivityState): ProgressListene @Composable fun lateInit() { noobMode = LocalContext.current.getSharedPreferences("abm", 0).getBoolean("noob_mode", BuildConfig.DEFAULT_NOOB_MODE) - meta = SDUtils.generateMeta(vm.deviceInfo!!) + meta = SDUtils.generateMeta(vm.deviceInfo) (meta?.s?.find { vm.activity.intent.getLongExtra("part_sid", -1L) == it.startSector } as SDUtils.Partition.FreeSpace?)?.also { p = it } } @@ -800,41 +800,7 @@ private fun Download(c: CreatePartDataHolder) { } }) } - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth() - ) { - Column { - Text(stringResource(id = R.string.installer_sh)) - } - Column { - if (c.vm.flashes.containsKey("InstallShFlashType")) { - Button(onClick = { - c.vm.flashes.remove("InstallShFlashType") - }) { - Text(stringResource(R.string.undo)) - } - } else { - if (c.scriptInet != null) { - Button(onClick = { - c.vm.flashes["InstallShFlashType"] = Pair(Uri.parse(c.scriptInet!!), c.scriptShaInet) - }) { - Text(stringResource(R.string.download)) - } - } - Button(onClick = { - c.vm.activity.chooseFile("*/*") { - c.vm.flashes["InstallShFlashType"] = Pair(it, null) - } - }) { - Text(stringResource(R.string.choose)) - } - } - } - } - for (i in c.idNeeded) { - val inet = c.inetAvailable.containsKey(i) + for (i in (c.idNeeded + listOf("_install.sh_"))) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, @@ -843,7 +809,8 @@ private fun Download(c: CreatePartDataHolder) { Column { Text(i) Text( - if (c.inetDesc.containsKey(i)) c.inetDesc[i]!! else stringResource(R.string.user_selected), + if (c.inetDesc.containsKey(i)) c.inetDesc[i]!! else stringResource( + if (i == "_install.sh_") R.string.installer_sh else R.string.user_selected), color = MaterialTheme.colorScheme.onSurfaceVariant ) } @@ -856,7 +823,7 @@ private fun Download(c: CreatePartDataHolder) { Text(stringResource(R.string.undo)) } } else { - if (inet) { + if (c.inetAvailable.containsKey(i) || i == "_install.sh_") { Button(onClick = { downloading = true progressText = c.vm.activity.getString(R.string.connecting_text) @@ -874,7 +841,8 @@ private fun Download(c: CreatePartDataHolder) { try { val downloadedFile = File(c.vm.logic.cacheDir, i) val request = - Request.Builder().url(c.inetAvailable[i]!!).build() + Request.Builder().url(if (i == "_install.sh_") + c.scriptInet!! else c.inetAvailable[i]!!).build() val call = c.client.newCall(request) val response = call.execute() @@ -919,7 +887,7 @@ private fun Download(c: CreatePartDataHolder) { } } c.vm.btnsOverride = true - if (c.idNeeded.find { !c.chosen.containsKey(it) } == null) { + if (c.idNeeded.find { !c.chosen.containsKey(it) } == null && c.chosen.containsKey("_install.sh_")) { c.vm.onNext.value = { it.navigate("flash") } c.vm.nextText.value = stringResource(id = R.string.install) } else { @@ -939,14 +907,13 @@ private fun Flash(c: CreatePartDataHolder) { val gn = c.t3.value terminal.add(vm.activity.getString(R.string.term_f_name, fn)) terminal.add(vm.activity.getString(R.string.term_g_name, gn)) - val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir) - vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile) + val tmpFile = c.chosen["_install.sh_"]!!.toFile(vm) tmpFile.setExecutable(true) terminal.add(vm.activity.getString(R.string.term_creating_pt)) // After creating partitions: fun installMore() { - val meta = SDUtils.generateMeta(vm.deviceInfo!!) + val meta = SDUtils.generateMeta(vm.deviceInfo) if (meta == null) { terminal.add(vm.activity.getString(R.string.term_cant_get_meta)) return @@ -1007,7 +974,6 @@ private fun Flash(c: CreatePartDataHolder) { cmd += " " + i.value } val result = vm.logic.runShFileWithArgs(cmd).to(terminal).exec() - tmpFile.delete() if (!result.isSuccess) { terminal.add(vm.activity.getString(R.string.term_failure)) return @@ -1045,7 +1011,7 @@ private fun Flash(c: CreatePartDataHolder) { terminal.add(vm.activity.getString(R.string.term_reboot_asap)) } parts[it] = c.meta!!.nid - c.meta = SDUtils.generateMeta(c.vm.deviceInfo!!) + 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 } @@ -1056,7 +1022,7 @@ private fun Flash(c: CreatePartDataHolder) { makeOne(it + 1) } else { terminal.add(vm.activity.getString(R.string.term_created_pt)) - vm.logic.mountBootset(vm.deviceInfo!!) + vm.logic.mountBootset(vm.deviceInfo) installMore() } } else { diff --git a/app/src/main/java/org/andbootmgr/app/DeviceInfo.kt b/app/src/main/java/org/andbootmgr/app/DeviceInfo.kt index 31c0da32..02ea1fc7 100644 --- a/app/src/main/java/org/andbootmgr/app/DeviceInfo.kt +++ b/app/src/main/java/org/andbootmgr/app/DeviceInfo.kt @@ -95,11 +95,12 @@ class JsonDeviceInfoFactory(private val ctx: Context) { } val jsonRoot = JSONTokener(jsonText).nextValue() as JSONObject? ?: return null val json = jsonRoot.getJSONObject("deviceInfo") - if (BuildConfig.VERSION_CODE < json.getInt("minAppVersion")) + if (BuildConfig.VERSION_CODE < jsonRoot.getInt("minAppVersion")) throw IllegalStateException("please upgrade app") if (fromNet) { val newRoot = JSONObject() newRoot.put("deviceInfo", json) + newRoot.put("minAppVersion", jsonRoot.getInt("minAppVersion")) File(ctx.filesDir, "abm_dd_cache.json").writeText(newRoot.toString()) } if (!json.getBoolean("metaOnSd")) diff --git a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt index 1cc44e5f..cf44477f 100644 --- a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt @@ -38,7 +38,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) { 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) "shSel" else + NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else (if (!vm.deviceInfo.isBooted(vm.logic)) "select" else "flash")) } ) { Input(vm) @@ -48,7 +48,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) { ) { SelectInstallSh(vm) }, WizardPage("select", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "input") }, + NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "input") }, NavButton("") {} ) { SelectDroidBoot(vm) @@ -68,7 +68,7 @@ private fun Start(vm: WizardActivityState) { ) { Text(stringResource(R.string.welcome_text)) Text( - if (vm.deviceInfo!!.isBooted(vm.logic)) { + if (vm.deviceInfo.isBooted(vm.logic)) { stringResource(R.string.install_abm) } else { stringResource(R.string.install_abm_dboot) @@ -171,7 +171,7 @@ fun SelectDroidBoot(vm: WizardActivityState) { // shared across DroidBootFlow, UpdateDroidBootFlow, FixDroidBootFlow @Composable -fun SelectInstallSh(vm: WizardActivityState) { +fun SelectInstallSh(vm: WizardActivityState, update: Boolean = false) { val nextButtonAvailable = remember { mutableStateOf(false) } val flashType = "InstallShFlashType" @@ -181,7 +181,7 @@ fun SelectInstallSh(vm: WizardActivityState) { if (nextButtonAvailable.value) { Text(stringResource(id = R.string.successfully_selected)) vm.nextText.value = stringResource(id = R.string.next) - vm.onNext.value = { it.navigate(if (!vm.deviceInfo!!.isBooted(vm.logic)) "select" else "flash") } + vm.onNext.value = { it.navigate(if (!vm.deviceInfo.isBooted(vm.logic) || update) "select" else "flash") } } else { Text(stringResource(R.string.choose_install_s_online)) Button(onClick = { @@ -242,7 +242,7 @@ private fun Flash(vm: WizardActivityState) { } } - if (vm.deviceInfo!!.metaonsd) { + if (vm.deviceInfo.metaonsd) { var meta = SDUtils.generateMeta(vm.deviceInfo) if (meta == null) { terminal.add(vm.activity.getString(R.string.term_cant_get_meta)) diff --git a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt index 50fb9785..e5d333e9 100644 --- a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt @@ -19,7 +19,7 @@ class FixDroidBootWizardPageFactory(private val vm: WizardActivityState) { fun get(): 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(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "select") }) { Start(vm) }, WizardPage("shSel", @@ -28,7 +28,7 @@ class FixDroidBootWizardPageFactory(private val vm: WizardActivityState) { ) { SelectInstallSh(vm) },WizardPage("select", - NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "start") }, + NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "start") }, NavButton("") {} ) { SelectDroidBoot(vm) diff --git a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt index 47620e1b..6906cb40 100644 --- a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt @@ -26,7 +26,7 @@ class UpdateDroidBootWizardPageFactory(private val vm: WizardActivityState) { NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") }, NavButton("") {} ) { - SelectInstallSh(vm) + SelectInstallSh(vm, update = true) },WizardPage("select", NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "start") }, NavButton("") {} diff --git a/app/src/main/res/drawable/ut_logo.xml b/app/src/main/res/drawable/ut_logo.xml index cb4ae57f..a47e682c 100644 --- a/app/src/main/res/drawable/ut_logo.xml +++ b/app/src/main/res/drawable/ut_logo.xml @@ -2,11 +2,9 @@ xmlns:tools="http://schemas.android.com/tools" android:width="48dp" android:height="48dp" + android:tint="?attr/colorControlNormal" android:viewportWidth="425.197" android:viewportHeight="425.197"> -