镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

ANR caused by main-thread work in onMalwareDetected (reflection + PackageManager calls) #214

Open

Description

@ahan530

:::writing{variant=“standard” id=“92741”}
Title: ANR caused by main-thread work in onMalwareDetected (reflection + PackageManager calls)

⸻

Description

We encountered ANR issues caused by heavy work being executed on the main thread inside onMalwareDetected.

From the stack trace, the callback triggers:
• Reflection (Class.getMethod)
• OEM framework hooks (TranReflectHelper)
• PackageManager calls (getApplicationLabel)
• Resource loading

All of these are happening on the UI thread, leading to freezes and ANR.

⸻

Stack Trace (key part)

at java.lang.Class.getMethod
at com.transsion.hubcore.proxy.TranReflectHelper.getMethod
at android.app.ApplicationPackageManager.getApplicationLabel
at com.aheaditec.freerasp.ExtensionsKt.toPigeon
at com.aheaditec.freerasp.handlers.MethodCallHandler$sink$1.onMalwareDetected

⸻

Root Cause

Inside onMalwareDetected, this line performs heavy work on the main thread:

val pigeonPackageInfo = packageInfo.map { it.toPigeon(context) }

toPigeon(context) internally calls:
• PackageManager
• resource loading
• label resolution

This blocks the main thread.

⸻

Original Code

override fun onMalwareDetected(packageInfo: List) {
context?.let { context ->
val pigeonPackageInfo = packageInfo.map { it.toPigeon(context) }
talsecPigeon?.onMalwareDetected(pigeonPackageInfo) { result ->
result.getOrElse {
Log.e("MethodCallHandlerSink", "Result ended with failure")
throw it
}
}
}
}

⸻

Proposed Fix

Move heavy processing off the main thread:

override fun onMalwareDetected(packageInfo: List) {
val ctx = context ?: return
backgroundHandler.post {
val pigeonPackageInfo = packageInfo.map { it.toPigeon(ctx) }
mainHandler.post {
talsecPigeon?.onMalwareDetected(pigeonPackageInfo) { result ->
result.getOrElse {
Log.e("MethodCallHandlerSink", "Result ended with failure")
throw it
}
}
}
}
}

⸻

Expected Behavior
• No heavy work should run on the main thread
• Detection callbacks should be non-blocking

⸻

Impact
• UI freeze
• ANR on certain devices (especially Transsion / OEM-modified systems)

⸻

Please consider moving heavy operations (like toPigeon) off the main thread internally or documenting this requirement clearly.

Thanks.

Activity

  1. SirionRazzer commented on Apr 8, 2026

    @SirionRazzer
    Member

    Hi @ahan530 , thank you for bringing this up and providing a detailed write-up of the issue; we will take a look. We will be happy to receive any further feedback regarding the free malware detection capabilities! You may also check out the premium malware detection product (also comes with online DB of malware!), which offers enhanced capabilities, fast SLA, and full support for commercial projects: https://docs.talsec.app/premium-products/product/malware-detection

  2. ahan530 commented on Apr 10, 2026

    @ahan530
    Author

    OK, received. Thanks for following up.

  3. SirionRazzer commented on Apr 21, 2026

    @SirionRazzer
    Member

    Hi @ahan530 ,
    this is a very rare issue, however we managed to trace it and we will release the fix in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions