mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-04-28 12:03:09 -07:00
app: use userspace copy
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user