Commit 9560a2d6 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #4829: Provide more details for display already acquired exception

parent 8202c7fc
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.permission.PermissionRequest
import org.mozilla.geckoview.GeckoResult
import java.lang.IllegalStateException

/**
 * Gecko-based EngineView implementation.
@@ -25,6 +26,19 @@ class GeckoEngineView @JvmOverloads constructor(
) : FrameLayout(context, attrs, defStyleAttr), EngineView {
    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    internal var currentGeckoView = object : NestedGeckoView(context) {

        override fun onAttachedToWindow() {
            try {
                super.onAttachedToWindow()
            } catch (e: IllegalStateException) {
                // This is to debug "display already acquired" crashes
                val otherActivityClassName =
                    this.session?.accessibility?.view?.context?.javaClass?.simpleName
                val activityClassName = context.javaClass.simpleName
                val msg = "ATTACH VIEW: Current activity: $activityClassName Other activity: $otherActivityClassName"
                throw IllegalStateException(msg, e)
            }
        }
        override fun onDetachedFromWindow() {
            // We are releasing the session before GeckoView gets detached from the window. Otherwise
            // GeckoView will close the session automatically and we do not want that.
@@ -82,7 +96,16 @@ class GeckoEngineView @JvmOverloads constructor(
                currentGeckoView.releaseSession()
            }

            try {
                currentGeckoView.setSession(internalSession.geckoSession)
            } catch (e: IllegalStateException) {
                // This is to debug "display already acquired" crashes
                val otherActivityClassName =
                    internalSession.geckoSession.accessibility.view?.context?.javaClass?.simpleName
                val activityClassName = context.javaClass.simpleName
                val msg = "SET SESSION: Current activity: $activityClassName Other activity: $otherActivityClassName"
                throw IllegalStateException(msg, e)
            }
        }
    }