app: use userspace copy

This commit is contained in:
vvb2060
2025-09-30 14:50:31 +08:00
committed by John Wu
parent 4ee1590cc8
commit 483901f3cd
4 changed files with 5 additions and 14 deletions

View File

@@ -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()
}

View File

@@ -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 &lt; 29}"
android:layout_height="wrap_content"
android:text="@string/download_patch_file" />

View File

@@ -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<String>,

View File

@@ -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") {