From 982993cfa3bbcc2a5871a719b06bbf2e6d842883 Mon Sep 17 00:00:00 2001 From: XiaoTong6666 <3278671549@qq.com> Date: Tue, 7 Jul 2026 04:44:53 +0800 Subject: [PATCH] Guard profile clearing against IPackageManager runtime drift On some Android 17 builds, the manager compile flow crashes `VectorDaemon` with a `NoSuchMethodError` in `ManagerService.clearApplicationProfileData()`. The daemon was compiled against a hidden `IPackageManager` stub that declares `clearApplicationProfileData(String)`, but some runtime `framework.jar` variants do not expose that method at all. We fix the issue by moving profile clearing behind a compatibility wrapper that reflectively probes `IPackageManager` for `clearApplicationProfileData(String)`. When the method is missing, we now log and skip profile clearing instead of crashing the daemon Binder thread. --- .../vector/daemon/ipc/ManagerService.kt | 2 +- .../vector/daemon/system/SystemExtensions.kt | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt index 412165747..26f832dbe 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt @@ -417,7 +417,7 @@ object ManagerService : ILSPManagerService.Stub() { override fun restartFor(intent: Intent) {} // No-op matching original override fun clearApplicationProfileData(packageName: String) { - packageManager?.clearApplicationProfileData(packageName) + packageManager?.clearApplicationProfileDataCompat(packageName) } override fun enableStatusNotification() = PreferenceStore.isStatusNotificationEnabled() diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/system/SystemExtensions.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/system/SystemExtensions.kt index 6aa5997ec..26b2fddab 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/system/SystemExtensions.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/system/SystemExtensions.kt @@ -28,6 +28,35 @@ const val MATCH_ALL_FLAGS = PackageManager.MATCH_UNINSTALLED_PACKAGES or MATCH_ANY_USER +private val clearApplicationProfileDataMethod: Method? by lazy { + IPackageManager::class + .java + .methods + .find { + it.name == "clearApplicationProfileData" && + it.parameterTypes.contentEquals(arrayOf(String::class.java)) + } + ?.apply { isAccessible = true } +} + +/** Android 17 may omit this hidden IPackageManager method from the runtime framework. */ +fun IPackageManager.clearApplicationProfileDataCompat(packageName: String): Boolean { + val method = clearApplicationProfileDataMethod + if (method == null) { + Log.w( + TAG, + "Runtime IPackageManager lacks clearApplicationProfileData; skipping profile clear for $packageName") + return false + } + + return runCatching { + method.invoke(this, packageName) + true + } + .onFailure { Log.e(TAG, "clearApplicationProfileDataCompat failed", it.cause ?: it) } + .getOrDefault(false) +} + @Throws(Exception::class) private fun IPackageManager.getPackageInfoCompatThrows( packageName: String,