{"record":{"id":"e6049cc8b1bc6db7","repo":"Tencent/matrix","slug":"field-viewrootimpl-mview-not-found","errorCode":null,"errorMessage":"Field_ViewRootImpl_mView not found","messagePattern":"Field_ViewRootImpl_mView not found","errorType":"exception","errorClass":"ClassNotFoundException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/OverlayWindowLifecycleOwner.kt","lineNumber":130,"sourceCode":"    private fun prepareWindowGlobal() {\n        if (WindowManagerGlobal_mRoots == null) {\n            if (fallbacked) {\n                throw ClassNotFoundException(\"WindowManagerGlobal_mRoots not found\")\n            }\n            MatrixLog.i(TAG, \"monitor disabled, fallback init\")\n            fallbacked = true\n            WindowManagerGlobal_mRoots = safeLetOrNull(TAG) {\n                Class.forName(\"android.view.WindowManagerGlobal\").let {\n                    val instance = ReflectUtils.invoke<Any>(it, \"getInstance\", null)\n                    ReflectUtils.get(it, \"mRoots\", instance)\n                }\n            }\n        }\n        if (WindowManagerGlobal_mRoots == null) {\n            throw ClassNotFoundException(\"WindowManagerGlobal_mRoots not found\")\n        }\n        if (Field_ViewRootImpl_mView == null) {\n            throw ClassNotFoundException(\"Field_ViewRootImpl_mView not found\")\n        }\n    }\n\n    /**\n     * including Activity window, for fallback checks\n     */\n    fun hasVisibleWindow() = safeLet(TAG, log = true, defVal = false) {\n        prepareWindowGlobal()\n        return@safeLet WindowManagerGlobal_mRoots!!.any {\n            val v = Field_ViewRootImpl_mView!!.get(it)\n            // windowVisibility is determined by app vibility\n            // until the PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY is set, which is blocked in Q\n            return@any v != null && View.VISIBLE == v.visibility && View.VISIBLE == v.windowVisibility\n        }\n    }\n\n    fun hasOverlayWindow() = if (injected) {\n        active()","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/OverlayWindowLifecycleOwner.kt#L112-L148","documentation":"prepareWindowGlobal() also requires the reflected ViewRootImpl 'mView' field (Field_ViewRootImpl_mView) to walk from window roots to the root view. If that reflection failed, it throws ClassNotFoundException('Field_ViewRootImpl_mView not found') even when mRoots resolved.","triggerScenarios":"Calling hasVisibleWindow(), hasOverlayWindow(), or getAllViews() on a device where ReflectUtils fails to resolve the mView field on android.view.ViewRootImpl.","commonSituations":"Newer Android versions or OEM ROMs where hidden-API restrictions block reflective access to ViewRootImpl.mView while WindowManagerGlobal.mRoots is still accessible.","solutions":["Catch ClassNotFoundException around the overlay/window query APIs and degrade gracefully.","Check hidden-API access policy for the device's Android version; whitelist via debug hidden-api exemptions only in development.","Update Matrix to a version matching the current Android/ROM reflection surface."],"exampleFix":"// before\nval has = OverlayWindowLifecycleOwner.hasOverlayWindow()\n// after\nval has = try {\n    OverlayWindowLifecycleOwner.hasOverlayWindow()\n} catch (e: ClassNotFoundException) {\n    MatrixLog.w(TAG, \"ViewRootImpl.mView unavailable\", e)\n    false\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"val has = try {\n    OverlayWindowLifecycleOwner.hasOverlayWindow()\n} catch (e: ClassNotFoundException) {\n    MatrixLog.w(TAG, \"ViewRootImpl.mView reflection failed\", e)\n    false\n}","preventionTips":["Check hidden-API access lists for your targetSdkVersion.","Use the debug hidden-API exemption only during development, not as a production fix.","Provide product-level fallbacks when window inspection is unavailable."],"tags":["android","reflection","hidden-api","class-not-found"],"backgroundTag":"class-not-found","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}