Merge "Blind fix for InterruptedException in runBlocking." into tm-qpr-dev
This commit is contained in:
@@ -26,18 +26,21 @@ import android.util.ArrayMap
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
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.Background
|
||||||
import com.android.systemui.dagger.qualifiers.Main
|
import com.android.systemui.dagger.qualifiers.Main
|
||||||
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
|
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class KeyguardRemotePreviewManager
|
class KeyguardRemotePreviewManager
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val previewRendererFactory: KeyguardPreviewRendererFactory,
|
private val previewRendererFactory: KeyguardPreviewRendererFactory,
|
||||||
|
@Application private val applicationScope: CoroutineScope,
|
||||||
@Main private val mainDispatcher: CoroutineDispatcher,
|
@Main private val mainDispatcher: CoroutineDispatcher,
|
||||||
@Background private val backgroundHandler: Handler,
|
@Background private val backgroundHandler: Handler,
|
||||||
) {
|
) {
|
||||||
@@ -55,7 +58,13 @@ constructor(
|
|||||||
|
|
||||||
// Destroy any previous renderer associated with this token.
|
// Destroy any previous renderer associated with this token.
|
||||||
activePreviews[renderer.hostToken]?.let { destroyObserver(it) }
|
activePreviews[renderer.hostToken]?.let { destroyObserver(it) }
|
||||||
observer = PreviewLifecycleObserver(renderer, mainDispatcher, ::destroyObserver)
|
observer =
|
||||||
|
PreviewLifecycleObserver(
|
||||||
|
renderer,
|
||||||
|
applicationScope,
|
||||||
|
mainDispatcher,
|
||||||
|
::destroyObserver,
|
||||||
|
)
|
||||||
activePreviews[renderer.hostToken] = observer
|
activePreviews[renderer.hostToken] = observer
|
||||||
renderer.render()
|
renderer.render()
|
||||||
renderer.hostToken?.linkToDeath(observer, 0)
|
renderer.hostToken?.linkToDeath(observer, 0)
|
||||||
@@ -92,13 +101,18 @@ constructor(
|
|||||||
|
|
||||||
private class PreviewLifecycleObserver(
|
private class PreviewLifecycleObserver(
|
||||||
private val renderer: KeyguardPreviewRenderer,
|
private val renderer: KeyguardPreviewRenderer,
|
||||||
|
private val scope: CoroutineScope,
|
||||||
private val mainDispatcher: CoroutineDispatcher,
|
private val mainDispatcher: CoroutineDispatcher,
|
||||||
private val requestDestruction: (PreviewLifecycleObserver) -> Unit,
|
private val requestDestruction: (PreviewLifecycleObserver) -> Unit,
|
||||||
) : Handler.Callback, IBinder.DeathRecipient {
|
) : Handler.Callback, IBinder.DeathRecipient {
|
||||||
|
|
||||||
private var isDestroyed = false
|
private var isDestroyedOrDestroying = false
|
||||||
|
|
||||||
override fun handleMessage(message: Message): Boolean {
|
override fun handleMessage(message: Message): Boolean {
|
||||||
|
if (isDestroyedOrDestroying) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
when (message.what) {
|
when (message.what) {
|
||||||
KeyguardQuickAffordancePreviewConstants.MESSAGE_ID_SLOT_SELECTED -> {
|
KeyguardQuickAffordancePreviewConstants.MESSAGE_ID_SLOT_SELECTED -> {
|
||||||
message.data
|
message.data
|
||||||
@@ -118,14 +132,14 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onDestroy(): IBinder? {
|
fun onDestroy(): IBinder? {
|
||||||
if (isDestroyed) {
|
if (isDestroyedOrDestroying) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
isDestroyed = true
|
isDestroyedOrDestroying = true
|
||||||
val hostToken = renderer.hostToken
|
val hostToken = renderer.hostToken
|
||||||
hostToken?.unlinkToDeath(this, 0)
|
hostToken?.unlinkToDeath(this, 0)
|
||||||
runBlocking(mainDispatcher) { renderer.destroy() }
|
scope.launch(mainDispatcher) { renderer.destroy() }
|
||||||
return hostToken
|
return hostToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ class CustomizationProviderTest : SysuiTestCase() {
|
|||||||
)
|
)
|
||||||
underTest.previewManager =
|
underTest.previewManager =
|
||||||
KeyguardRemotePreviewManager(
|
KeyguardRemotePreviewManager(
|
||||||
|
applicationScope = testScope.backgroundScope,
|
||||||
previewRendererFactory = previewRendererFactory,
|
previewRendererFactory = previewRendererFactory,
|
||||||
mainDispatcher = testDispatcher,
|
mainDispatcher = testDispatcher,
|
||||||
backgroundHandler = backgroundHandler,
|
backgroundHandler = backgroundHandler,
|
||||||
|
|||||||
Reference in New Issue
Block a user