fix: patch count remaining at zero when using process runtime (#2542)

This commit is contained in:
Ax333l 2025-05-11 19:30:12 +02:00 committed by oSumAtrIX
parent 222089a7ec
commit 658699dd81
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 18 additions and 2 deletions

View File

@ -111,6 +111,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
} }
val patching = CompletableDeferred<Unit>() val patching = CompletableDeferred<Unit>()
val scope = this
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
val binder = awaitBinderConnection() val binder = awaitBinderConnection()
@ -124,7 +125,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
override fun log(level: String, msg: String) = logger.log(enumValueOf(level), msg) override fun log(level: String, msg: String) = logger.log(enumValueOf(level), msg)
override fun patchSucceeded() { override fun patchSucceeded() {
launch { onPatchCompleted() } scope.launch { onPatchCompleted() }
} }
override fun progress(name: String?, state: String?, msg: String?) = override fun progress(name: String?, state: String?, msg: String?) =
@ -179,7 +180,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
} }
/** /**
* An [Exception] occured in the remote process while patching. * An [Exception] occurred in the remote process while patching.
* *
* @param originalStackTrace The stack trace of the original [Exception]. * @param originalStackTrace The stack trace of the original [Exception].
*/ */

View File

@ -1,8 +1,10 @@
package app.revanced.manager.patcher.runtime.process package app.revanced.manager.patcher.runtime.process
import android.annotation.SuppressLint
import android.app.ActivityThread import android.app.ActivityThread
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
import app.revanced.manager.BuildConfig import app.revanced.manager.BuildConfig
@ -95,6 +97,10 @@ class PatcherProcess(private val context: Context) : IPatcherProcess.Stub() {
} }
companion object { companion object {
private val longArrayClass = LongArray::class.java
private val emptyLongArray = LongArray(0)
@SuppressLint("PrivateApi")
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
Looper.prepare() Looper.prepare()
@ -105,6 +111,15 @@ class PatcherProcess(private val context: Context) : IPatcherProcess.Stub() {
val systemContext = ActivityThread.systemMain().systemContext as Context val systemContext = ActivityThread.systemMain().systemContext as Context
val appContext = systemContext.createPackageContext(managerPackageName, 0) val appContext = systemContext.createPackageContext(managerPackageName, 0)
// Avoid annoying logs. See https://github.com/robolectric/robolectric/blob/ad0484c6b32c7d11176c711abeb3cb4a900f9258/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java#L376-L388
Class.forName("android.app.AppCompatCallbacks").apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
getDeclaredMethod("install", longArrayClass, longArrayClass).also { it.isAccessible = true }(null, emptyLongArray, emptyLongArray)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getDeclaredMethod("install", longArrayClass).also { it.isAccessible = true }(null, emptyLongArray)
}
}
val ipcInterface = PatcherProcess(appContext) val ipcInterface = PatcherProcess(appContext)
appContext.sendBroadcast(Intent().apply { appContext.sendBroadcast(Intent().apply {