Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0316f00e authored by Jiaming Cheng's avatar Jiaming Cheng
Browse files

[QSDetailedView] Fix the crash when reopening Internet Details

When reopening the internet details view, the app would crash
with an `IllegalStateException`. This was because the
LifecycleRegistry was being moved to a DESTROYED state when
the view was closed, and then an attempt was made to move it
back to a CREATED state upon reopening.

This change fixes the issue by re-initializing the
LifecycleRegistry every time the view is bound.

Bug: 430127786
Flag: com.android.systemui.qs_tile_detailed_view
Test: InternetDetailsContentManagerTest
Change-Id: I77cbd4808b076be6de5eb42198cf867f676a3ab2
parent 72ffc42e
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -198,18 +198,21 @@ constructor(
    }

    /**
     * Initializes the LifecycleRegistry if it hasn't been initialized yet. It sets the initial
     * state of the LifecycleRegistry to Lifecycle.State.CREATED.
     * Initializes the LifecycleRegistry. It sets the initial state of the LifecycleRegistry to
     * Lifecycle.State.CREATED.
     */
    fun initializeLifecycle() {
        if (!::lifecycleRegistry.isInitialized) {
        // If a lifecycle already exists, destroy it before creating a new one.
        if (::lifecycleRegistry.isInitialized) {
            lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
        }

        lifecycleOwner =
            object : LifecycleOwner {
                override val lifecycle: Lifecycle
                    get() = lifecycleRegistry
            }
        lifecycleRegistry = LifecycleRegistry(lifecycleOwner!!)
        }
        lifecycleRegistry.currentState = Lifecycle.State.CREATED
    }