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

Commit 24897f67 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Merge "Blind fix for InterruptedException in runBlocking." into...

Merge "Merge "Blind fix for InterruptedException in runBlocking." into tm-qpr-dev am: 3d2e83aa am: a96b721a" into udc-dev am: f4d14c65

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21918539



Change-Id: Id55deffcf6be8c12e5eee4395ca31259e2f138cc
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d8bffe7b f4d14c65
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -26,18 +26,21 @@ import android.util.ArrayMap
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@SysUISingleton
class KeyguardRemotePreviewManager
@Inject
constructor(
    private val previewRendererFactory: KeyguardPreviewRendererFactory,
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
    @Background private val backgroundHandler: Handler,
) {
@@ -55,7 +58,13 @@ constructor(

            // Destroy any previous renderer associated with this token.
            activePreviews[renderer.hostToken]?.let { destroyObserver(it) }
            observer = PreviewLifecycleObserver(renderer, mainDispatcher, ::destroyObserver)
            observer =
                PreviewLifecycleObserver(
                    renderer,
                    applicationScope,
                    mainDispatcher,
                    ::destroyObserver,
                )
            activePreviews[renderer.hostToken] = observer
            renderer.render()
            renderer.hostToken?.linkToDeath(observer, 0)
@@ -92,13 +101,18 @@ constructor(

    private class PreviewLifecycleObserver(
        private val renderer: KeyguardPreviewRenderer,
        private val scope: CoroutineScope,
        private val mainDispatcher: CoroutineDispatcher,
        private val requestDestruction: (PreviewLifecycleObserver) -> Unit,
    ) : Handler.Callback, IBinder.DeathRecipient {

        private var isDestroyed = false
        private var isDestroyedOrDestroying = false

        override fun handleMessage(message: Message): Boolean {
            if (isDestroyedOrDestroying) {
                return true
            }

            when (message.what) {
                KeyguardQuickAffordancePreviewConstants.MESSAGE_ID_SLOT_SELECTED -> {
                    message.data
@@ -118,14 +132,14 @@ constructor(
        }

        fun onDestroy(): IBinder? {
            if (isDestroyed) {
            if (isDestroyedOrDestroying) {
                return null
            }

            isDestroyed = true
            isDestroyedOrDestroying = true
            val hostToken = renderer.hostToken
            hostToken?.unlinkToDeath(this, 0)
            runBlocking(mainDispatcher) { renderer.destroy() }
            scope.launch(mainDispatcher) { renderer.destroy() }
            return hostToken
        }
    }
+1 −0
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ class CustomizationProviderTest : SysuiTestCase() {
            )
        underTest.previewManager =
            KeyguardRemotePreviewManager(
                applicationScope = testScope.backgroundScope,
                previewRendererFactory = previewRendererFactory,
                mainDispatcher = testDispatcher,
                backgroundHandler = backgroundHandler,