Horis 2 سال پیش
والد
کامیت
d8e75c41eb

+ 1 - 0
app/src/main/java/io/legado/app/data/entities/BaseSource.kt

@@ -97,6 +97,7 @@ interface BaseSource : JsExtensions {
      * 解析header规则
      */
     fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
+        if (checkRhinoRecursiveCall()) return@apply
         header?.let {
             GSON.fromJsonObject<Map<String, String>>(
                 when {

+ 22 - 0
app/src/main/java/io/legado/app/utils/RhinoContextExtensions.kt

@@ -0,0 +1,22 @@
+package io.legado.app.utils
+
+import org.mozilla.javascript.Context
+
+private val enterCountField by lazy {
+    Context::class.java.getDeclaredField("enterCount").apply {
+        isAccessible = true
+    }
+}
+
+fun Context?.getEnterCount(): Int {
+    this ?: return 0
+    return enterCountField.get(this) as Int
+}
+
+fun checkRhinoRecursiveCall(): Boolean {
+    return Context.getCurrentContext().getEnterCount() > 1
+}
+
+fun checkRhinoCall(): Boolean {
+    return Context.getCurrentContext() != null
+}