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

Commit 272f0dfe authored by Catherine Liang's avatar Catherine Liang
Browse files

Enable separate keyguard previews based on screen id

The surface view host token is used to distinguish between different
PreviewLifecycleObservers, but the 2 different surface views for the
dual display preview return the same host token. To distinguish the 2
surface views, both a host token and a display id is used as identifier.

This CL is based on changes in the launcher preview renderer:
Iba9518e93c09f0f8304cbce4c3bee9f8753cd583

Test: manually verified
Bug: 303313708
Change-Id: If1a7b9d6b4f7bdbd91b3cdd8f4a9714175e6399e
parent 90feea4d
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -127,12 +127,19 @@ constructor(
            false,
        )

    private val displayId = bundle.getInt(KEY_DISPLAY_ID, DEFAULT_DISPLAY)
    private val display: Display? = displayManager.getDisplay(displayId)
    /**
     * Returns a key that should make the KeyguardPreviewRenderer unique and if two of them have the
     * same key they will be treated as the same KeyguardPreviewRenderer. Primary this is used to
     * prevent memory leaks by allowing removal of the old KeyguardPreviewRenderer.
     */
    val id = Pair(hostToken, displayId)

    /** [shouldHideClock] here means that we never create and bind the clock views */
    private val shouldHideClock: Boolean =
        bundle.getBoolean(ClockPreviewConstants.KEY_HIDE_CLOCK, false)
    private val wallpaperColors: WallpaperColors? = bundle.getParcelable(KEY_COLORS)
    private val displayId = bundle.getInt(KEY_DISPLAY_ID, DEFAULT_DISPLAY)
    private val display: Display? = displayManager.getDisplay(displayId)

    private var host: SurfaceControlViewHost

+10 −10
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ constructor(
    @Main private val mainDispatcher: CoroutineDispatcher,
    @Background private val backgroundHandler: Handler,
) {
    private val activePreviews: ArrayMap<IBinder, PreviewLifecycleObserver> =
        ArrayMap<IBinder, PreviewLifecycleObserver>()
    private val activePreviews: ArrayMap<Pair<IBinder?, Int>, PreviewLifecycleObserver> =
        ArrayMap<Pair<IBinder?, Int>, PreviewLifecycleObserver>()

    fun preview(request: Bundle?): Bundle? {
        if (request == null) {
@@ -56,8 +56,6 @@ constructor(
        return try {
            val renderer = previewRendererFactory.create(request)

            // Destroy any previous renderer associated with this token.
            activePreviews[renderer.hostToken]?.let { destroyObserver(it) }
            observer =
                PreviewLifecycleObserver(
                    renderer,
@@ -65,7 +63,9 @@ constructor(
                    mainDispatcher,
                    ::destroyObserver,
                )
            activePreviews[renderer.hostToken] = observer
            // Destroy any previous renderer associated with this token.
            activePreviews[renderer.id]?.let { destroyObserver(it) }
            activePreviews[renderer.id] = observer
            renderer.render()
            renderer.hostToken?.linkToDeath(observer, 0)
            val result = Bundle()
@@ -92,9 +92,9 @@ constructor(
    }

    private fun destroyObserver(observer: PreviewLifecycleObserver) {
        observer.onDestroy()?.let { hostToken ->
            if (activePreviews[hostToken] === observer) {
                activePreviews.remove(hostToken)
        observer.onDestroy()?.let { identifier ->
            if (activePreviews[identifier] === observer) {
                activePreviews.remove(identifier)
            }
        }
    }
@@ -134,7 +134,7 @@ constructor(
            requestDestruction(this)
        }

        fun onDestroy(): IBinder? {
        fun onDestroy(): Pair<IBinder?, Int>? {
            if (isDestroyedOrDestroying) {
                return null
            }
@@ -143,7 +143,7 @@ constructor(
            val hostToken = renderer.hostToken
            hostToken?.unlinkToDeath(this, 0)
            scope.launch(mainDispatcher) { renderer.destroy() }
            return hostToken
            return renderer.id
        }
    }