Skip to content

Commit 658699d

Browse files
Axelen123oSumAtrIX
authored andcommitted
fix: patch count remaining at zero when using process runtime (#2542)
1 parent 222089a commit 658699d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/src/main/java/app/revanced/manager/patcher/runtime/ProcessRuntime.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
111111
}
112112

113113
val patching = CompletableDeferred<Unit>()
114+
val scope = this
114115

115116
launch(Dispatchers.IO) {
116117
val binder = awaitBinderConnection()
@@ -124,7 +125,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
124125
override fun log(level: String, msg: String) = logger.log(enumValueOf(level), msg)
125126

126127
override fun patchSucceeded() {
127-
launch { onPatchCompleted() }
128+
scope.launch { onPatchCompleted() }
128129
}
129130

130131
override fun progress(name: String?, state: String?, msg: String?) =
@@ -179,7 +180,7 @@ class ProcessRuntime(private val context: Context) : Runtime(context) {
179180
}
180181

181182
/**
182-
* An [Exception] occured in the remote process while patching.
183+
* An [Exception] occurred in the remote process while patching.
183184
*
184185
* @param originalStackTrace The stack trace of the original [Exception].
185186
*/

app/src/main/java/app/revanced/manager/patcher/runtime/process/PatcherProcess.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package app.revanced.manager.patcher.runtime.process
22

3+
import android.annotation.SuppressLint
34
import android.app.ActivityThread
45
import android.content.Context
56
import android.content.Intent
7+
import android.os.Build
68
import android.os.Bundle
79
import android.os.Looper
810
import app.revanced.manager.BuildConfig
@@ -95,6 +97,10 @@ class PatcherProcess(private val context: Context) : IPatcherProcess.Stub() {
9597
}
9698

9799
companion object {
100+
private val longArrayClass = LongArray::class.java
101+
private val emptyLongArray = LongArray(0)
102+
103+
@SuppressLint("PrivateApi")
98104
@JvmStatic
99105
fun main(args: Array<String>) {
100106
Looper.prepare()
@@ -105,6 +111,15 @@ class PatcherProcess(private val context: Context) : IPatcherProcess.Stub() {
105111
val systemContext = ActivityThread.systemMain().systemContext as Context
106112
val appContext = systemContext.createPackageContext(managerPackageName, 0)
107113

114+
// Avoid annoying logs. See https://github.com/robolectric/robolectric/blob/ad0484c6b32c7d11176c711abeb3cb4a900f9258/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java#L376-L388
115+
Class.forName("android.app.AppCompatCallbacks").apply {
116+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
117+
getDeclaredMethod("install", longArrayClass, longArrayClass).also { it.isAccessible = true }(null, emptyLongArray, emptyLongArray)
118+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
119+
getDeclaredMethod("install", longArrayClass).also { it.isAccessible = true }(null, emptyLongArray)
120+
}
121+
}
122+
108123
val ipcInterface = PatcherProcess(appContext)
109124

110125
appContext.sendBroadcast(Intent().apply {

0 commit comments

Comments
 (0)