diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 661f40dea..53abaff82 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -82,9 +82,7 @@ class FlashViewModel : BaseViewModel() { MagiskInstaller.Patch(uri, outItems, logItems).exec() } Const.Value.DOWNLOAD -> { - if (uri == null || Build.VERSION.SDK_INT < 29) { - return@launch - } + uri ?: return@launch showReboot = false MagiskInstaller.Download(uri.toString(), outItems, logItems).exec() } diff --git a/app/apk/src/main/res/layout/fragment_install_md2.xml b/app/apk/src/main/res/layout/fragment_install_md2.xml index 5305a87a2..0999f025d 100644 --- a/app/apk/src/main/res/layout/fragment_install_md2.xml +++ b/app/apk/src/main/res/layout/fragment_install_md2.xml @@ -194,7 +194,6 @@ android:id="@+id/method_download" style="@style/WidgetFoundation.RadioButton" android:layout_width="match_parent" - gone="@{android.os.Build.VERSION.SDK_INT < 29}" android:layout_height="wrap_content" android:text="@string/download_patch_file" /> diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index 945203905..a3e558071 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -1,10 +1,8 @@ package com.topjohnwu.magisk.core.tasks import android.net.Uri -import android.os.FileUtils import android.os.Process import android.system.Os -import androidx.annotation.RequiresApi import androidx.annotation.WorkerThread import androidx.core.os.postDelayed import com.topjohnwu.magisk.StubApk @@ -364,7 +362,7 @@ abstract class MagiskInstallImpl protected constructor( // raw image outFile = MediaStoreUtils.getFile("$destName.img") outStream = outFile.uri.outputStream() - val channel = FileInputStream(uri.openFd("r").fileDescriptor).channel + val channel = FileInputStream(uri.openFd().fileDescriptor).channel val boot = installDir.getChildFile("boot.img") try { @@ -432,7 +430,6 @@ abstract class MagiskInstallImpl protected constructor( return true } - @RequiresApi(29) private fun processUrl(url: String): Boolean { // Download image from url try { @@ -454,9 +451,9 @@ abstract class MagiskInstallImpl protected constructor( val outFile = MediaStoreUtils.getFile("$destName.img") try { val newBoot = installDir.getChildFile("new-boot.img") - outFile.uri.openFd().use { out -> + outFile.uri.outputStream().use { out -> FileInputStream(newBoot).use { input -> - FileUtils.copy(input, FileOutputStream(out.fileDescriptor)) + input.copyTo(out) } } newBoot.delete() @@ -531,7 +528,6 @@ abstract class MagiskInstallImpl protected constructor( protected suspend fun patchFile(file: Uri) = extractFiles() && processFile(file) - @RequiresApi(29) protected suspend fun patchFile(url: String) = extractFiles() && processUrl(url) protected suspend fun direct() = findImage() && extractFiles() && patchBoot() && flashBoot() @@ -601,7 +597,6 @@ class MagiskInstaller { override suspend fun operations() = patchFile(uri) } - @RequiresApi(29) class Download( private val url: String, console: MutableList, diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt index 3e6f92539..fc69e990c 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt @@ -98,8 +98,7 @@ object MediaStoreUtils { fun Uri.outputStream() = cr.openOutputStream(this, "rwt") ?: throw FileNotFoundException() - fun Uri.openFd(mode: String = "rwt") = cr.openFileDescriptor(this, mode) - ?: throw FileNotFoundException() + fun Uri.openFd() = cr.openFileDescriptor(this, "r") ?: throw FileNotFoundException() val Uri.displayName: String get() { if (scheme == "file") {