diff --git a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt index c96761d6..12d6d80f 100644 --- a/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt @@ -44,7 +44,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) { Input(vm) }, WizardPage("shSel", NavButton(vm.activity.getString(R.string.prev)) { it.navigate("input") }, - NavButton(vm.activity.getString(R.string.next)) {} + NavButton("") {} ) { SelectInstallSh(vm) }, WizardPage("select", @@ -150,7 +150,7 @@ fun SelectDroidBoot(vm: WizardActivityState) { val json = JSONTokener(jsonText).nextValue() as JSONObject val bl = json.getJSONObject("bootloader") val url = bl.getString("url") - val sha = bl.getString("sha256") + val sha = if (bl.has("sha256")) bl.getString("sha256") else null vm.flashes[flashType] = Pair(Uri.parse(url), sha) nextButtonAvailable.value = true } catch (e: Exception) { @@ -181,7 +181,7 @@ fun SelectInstallSh(vm: WizardActivityState) { vm.nextText.value = stringResource(id = R.string.next) vm.onNext.value = { it.navigate(if (!vm.deviceInfo!!.isBooted(vm.logic)) "select" else "flash") } } else { - Text(stringResource(R.string.choose_droidboot_online)) + Text(stringResource(R.string.choose_install_s_online)) Button(onClick = { vm.activity.chooseFile("*/*") { vm.flashes[flashType] = Pair(it, null) @@ -197,16 +197,16 @@ fun SelectInstallSh(vm: WizardActivityState) { 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 - val bl = json.getJSONObject("installScript") - val url = bl.getString("url") - val sha = bl.getString("sha256") + 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.value = true } 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)) + Log.e("ABM install json", Log.getStackTraceString(e)) } }.start() }) { @@ -345,6 +345,7 @@ private fun Flash(vm: WizardActivityState) { "BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=true " + "${tmpFile.absolutePath} real" ).to(terminal).exec() + tmpFile.delete() } terminal.add(vm.activity.getString(R.string.term_success)) vm.logic.unmountBootset() diff --git a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt index b6acae1d..50fb9785 100644 --- a/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt @@ -77,6 +77,7 @@ private fun Flash(vm: WizardActivityState) { "BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=true " + "${tmpFile.absolutePath} real" ).to(terminal).exec() + tmpFile.delete() } terminal.add(vm.activity.getString(R.string.term_success)) vm.activity.runOnUiThread { diff --git a/app/src/main/java/org/andbootmgr/app/MainActivity.kt b/app/src/main/java/org/andbootmgr/app/MainActivity.kt index b00fcfde..d8c77aa8 100644 --- a/app/src/main/java/org/andbootmgr/app/MainActivity.kt +++ b/app/src/main/java/org/andbootmgr/app/MainActivity.kt @@ -776,9 +776,11 @@ private fun PartTool(vm: MainActivityState) { Button(onClick = { processing = true delete = false + val wasMounted = vm.logic!!.mounted vm.logic!!.unmountBootset() vm.logic!!.delete(p).submit { vm.logic!!.mountBootset(vm.deviceInfo!!) + if (wasMounted != vm.logic!!.mounted) vm.activity!!.finish() processing = false editPartID = null parts = SDUtils.generateMeta(vm.deviceInfo!!) diff --git a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt index e1b42d59..47620e1b 100644 --- a/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt +++ b/app/src/main/java/org/andbootmgr/app/UpdateDroidBootFlow.kt @@ -77,6 +77,7 @@ private fun Flash(vm: WizardActivityState) { "BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=false " + "${tmpFile.absolutePath} real" ).to(terminal).exec() + tmpFile.delete() } terminal.add(vm.activity.getString(R.string.term_success)) vm.activity.runOnUiThread { diff --git a/app/src/main/java/org/andbootmgr/app/ext.kt b/app/src/main/java/org/andbootmgr/app/ext.kt index 354e0318..e85ecc17 100644 --- a/app/src/main/java/org/andbootmgr/app/ext.kt +++ b/app/src/main/java/org/andbootmgr/app/ext.kt @@ -19,7 +19,7 @@ class ActionAbortedCleanlyError(e: Exception?) : ActionAbortedError(e) @Throws(IOException::class) private fun generateFile(prefix: String, suffix: String, dir: File?): File { - var n = Math.random().toLong() + var n = (Math.random() * Long.MAX_VALUE).toLong() n = if (n == Long.MIN_VALUE) { 0 // corner case } else { @@ -44,7 +44,7 @@ fun createTempFileSu( var f: File do { f = generateFile(prefix, suffix ?: ".tmp", tmpdir) - } while (!f.exists()) + } while (f.exists()) val ff = SuFile.open(f.toURI()) if (!ff.createNewFile()) throw IOException("Unable to create temporary file") diff --git a/app/src/main/java/org/andbootmgr/app/util/Toolkit.kt b/app/src/main/java/org/andbootmgr/app/util/Toolkit.kt index b150d505..8c3b2402 100644 --- a/app/src/main/java/org/andbootmgr/app/util/Toolkit.kt +++ b/app/src/main/java/org/andbootmgr/app/util/Toolkit.kt @@ -14,9 +14,7 @@ class Toolkit(private val ctx: Context) { private val targetPath = File(ctx.filesDir.parentFile, "assets") fun copyAssets(uinf: Runnable, callback: Consumer) { - if (!targetPath.exists()) fail = fail or !targetPath.mkdir() - if (!File(ctx.filesDir.parentFile, "files").exists()) fail = fail or !File(ctx.filesDir.parentFile, "files").mkdir() - if (!File(ctx.filesDir.parentFile, "cache").exists()) fail = fail or !File(ctx.filesDir.parentFile, "cache").mkdir() + val shell = Shell.Builder.create().setFlags(FLAG_NON_ROOT_SHELL).setTimeout(30).setContext(ctx).build() var input: InputStream var b: ByteArray try { @@ -40,12 +38,15 @@ class Toolkit(private val ctx: Context) { val s2 = String(b).trim() if (s != s2) { uinf.run() + shell.newJob().add("rm -rf " + targetPath.absolutePath).exec() + if (!targetPath.exists()) fail = fail or !targetPath.mkdir() + if (!File(ctx.filesDir.parentFile, "files").exists()) fail = fail or !File(ctx.filesDir.parentFile, "files").mkdir() + if (!File(ctx.filesDir.parentFile, "cache").exists()) fail = fail or !File(ctx.filesDir.parentFile, "cache").mkdir() copyAssets("Toolkit", "Toolkit") copyAssets("Scripts", "Scripts") copyAssets("cp", "") } - Shell.Builder.create().setFlags(FLAG_NON_ROOT_SHELL).setTimeout(30).setContext(ctx).build().newJob() - .add("chmod -R +x " + targetPath.absolutePath).exec() + shell.newJob().add("chmod -R +x " + targetPath.absolutePath).exec() callback.accept(fail) }