feat: copy apk to storage after patching is done

This commit is contained in:
Canny 2022-10-10 20:56:57 +03:00
parent ea1641bcea
commit 5408199dab
No known key found for this signature in database
GPG Key ID: 395CCB0AA979F27B
2 changed files with 15 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.os.Environment
import android.os.PowerManager import android.os.PowerManager
import android.util.Log import android.util.Log
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -40,7 +41,6 @@ import java.nio.file.StandardCopyOption
class PatcherWorker(context: Context, parameters: WorkerParameters, private val api: API) : class PatcherWorker(context: Context, parameters: WorkerParameters, private val api: API) :
CoroutineWorker(context, parameters), KoinComponent { CoroutineWorker(context, parameters), KoinComponent {
val tag = "ReVanced Manager" val tag = "ReVanced Manager"
private val workdir = createWorkDir() private val workdir = createWorkDir()
@ -107,6 +107,8 @@ class PatcherWorker(context: Context, parameters: WorkerParameters, private val
applicationContext.filesDir.resolve("framework").also { it.mkdirs() }.absolutePath applicationContext.filesDir.resolve("framework").also { it.mkdirs() }.absolutePath
val integrationsCacheDir = val integrationsCacheDir =
applicationContext.filesDir.resolve("integrations-cache").also { it.mkdirs() } applicationContext.filesDir.resolve("integrations-cache").also { it.mkdirs() }
val reVancedFolder =
Environment.getExternalStorageDirectory().resolve("ReVanced").also { it.mkdirs() }
val appInfo = selectedAppPackage.value.get() val appInfo = selectedAppPackage.value.get()
Logging.log += "Checking prerequisites\n" Logging.log += "Checking prerequisites\n"
@ -195,6 +197,14 @@ class PatcherWorker(context: Context, parameters: WorkerParameters, private val
Logging.log += "Signing apk\n" Logging.log += "Signing apk\n"
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outputFile) Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outputFile)
Logging.log += "Successfully patched!\n" Logging.log += "Successfully patched!\n"
withContext(Dispatchers.IO) {
Files.copy(
outputFile.inputStream(),
reVancedFolder.resolve(appInfo.packageName + ".apk").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
Logging.log += "Copied file to storage!\n"
} finally { } finally {
Log.d(tag, "Deleting workdir") Log.d(tag, "Deleting workdir")
workdir.deleteRecursively() workdir.deleteRecursively()
@ -210,7 +220,6 @@ class PatcherWorker(context: Context, parameters: WorkerParameters, private val
} }
private fun createWorkDir(): File { private fun createWorkDir(): File {
return applicationContext.filesDir.resolve("tmp-${System.currentTimeMillis()}") return applicationContext.filesDir.resolve("tmp-${System.currentTimeMillis()}")
.also { it.mkdirs() } .also { it.mkdirs() }

View File

@ -12,6 +12,7 @@ import app.revanced.manager.Variables.selectedAppPackage
import app.revanced.manager.Variables.selectedPatches import app.revanced.manager.Variables.selectedPatches
import app.revanced.manager.api.API import app.revanced.manager.api.API
import app.revanced.manager.ui.Resource import app.revanced.manager.ui.Resource
import app.revanced.manager.util.tag
import app.revanced.patcher.data.Context import app.revanced.patcher.data.Context
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.options import app.revanced.patcher.extensions.PatchExtensions.options
@ -24,7 +25,6 @@ import kotlinx.parcelize.Parcelize
class PatcherScreenViewModel(private val app: Application, private val api: API) : ViewModel() { class PatcherScreenViewModel(private val app: Application, private val api: API) : ViewModel() {
private lateinit var patchBundleFile: String private lateinit var patchBundleFile: String
private val tag = "ReVanced Manager"
init { init {
viewModelScope.launch { viewModelScope.launch {
@ -71,8 +71,9 @@ class PatcherScreenViewModel(private val app: Application, private val api: API)
selectedAppPackage.value.get().publicSourceDir, selectedAppPackage.value.get().publicSourceDir,
PackageManager.GET_META_DATA PackageManager.GET_META_DATA
) )
} else {
return null
} }
else {return null}
} }
fun checkSplitApk(): Boolean { fun checkSplitApk(): Boolean {