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,