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

Commit b22903f8 authored by Kshitij Gupta's avatar Kshitij Gupta
Browse files

KeyguardPreviewRenderer: Drop usages of runBlocking

- This CL refactors KeyguardPreviewRenderer to eliminate runBlocking
  usage for `SurfaceControlViewHost` creation, using Handler.post
  instead
- Previously, the SurfaceControlViewHost was created within a
  runBlocking block on the main dispatcher. This blocks the
  calling thread, potentially causing UI jank or ANRs during Keyguard
  preview initialization.
- SurfaceControlViewHost creation and its disposal logic are now posted
  to the mainHandler. This allows the operation to be scheduled on the
  main thread's message queue, executing asynchronously without blocking
  the initiating thread. The class member "host" is now lateinit to
  accommodate its deferred initialization.

Bug: 423462317
Flag: com.android.systemui.do_not_use_run_blocking
Change-Id: Ic93c30d0af2ed5067711de2e7bca984d05ce3d5d
parent 6517fbf0
Loading
Loading
Loading
Loading
+24 −13
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.core.view.isInvisible
import com.android.app.tracing.coroutines.runBlockingTraced as runBlocking
import com.android.keyguard.ClockEventController
import com.android.systemui.Flags
import com.android.systemui.animation.view.LaunchableImageView
import com.android.systemui.biometrics.domain.interactor.UdfpsOverlayInteractor
import com.android.systemui.broadcast.BroadcastDispatcher
@@ -122,7 +123,7 @@ constructor(
    private val keyguardQuickAffordanceViewBinder: KeyguardQuickAffordanceViewBinder,
    private val wallpaperFocalAreaInteractor: WallpaperFocalAreaInteractor,
) {
    private var host: SurfaceControlViewHost
    private lateinit var host: SurfaceControlViewHost

    private var _surfacePackage: SurfaceControlViewHost.SurfacePackage? = null
    val surfacePackage: SurfaceControlViewHost.SurfacePackage
@@ -148,7 +149,18 @@ constructor(
            shouldHighlightSelectedAffordance = previewViewModel.shouldHighlightSelectedAffordance,
        )

        if (Flags.doNotUseRunBlocking()) {
            mainHandler.post {
                provideSurfaceControlViewHost(displayManager)
            }
        } else {
            runBlocking(context = mainDispatcher) {
                provideSurfaceControlViewHost(displayManager)
            }
        }
    }

    private fun provideSurfaceControlViewHost(displayManager: DisplayManager) {
        host =
            SurfaceControlViewHost(
                context,
@@ -162,7 +174,6 @@ constructor(
            host.release()
        }
    }
    }

    fun render() {
        mainHandler.post {