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

Commit ad386ccb authored by Graciela Putri's avatar Graciela Putri
Browse files

Return null if task not found in ActivityLetterboxLifecycleEventFactory

Flag: com.android.window.flags.app_compat_refactoring
Bug: 409043134
Test: atest WMShellUnitTests:ActivityLetterboxLifecycleEventFactoryTest
Change-Id: Ie79350494dfd2778af09d416a30334f511e9d454
parent e7864abe
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.wm.shell.compatui.letterbox.lifecycle

import android.window.TransitionInfo.Change
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.compatui.letterbox.state.LetterboxTaskInfoRepository
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT

/**
 * [LetterboxLifecycleEventFactory] implementation which creates a [LetterboxLifecycleEvent] from
@@ -26,20 +28,26 @@ import com.android.wm.shell.compatui.letterbox.state.LetterboxTaskInfoRepository
class ActivityLetterboxLifecycleEventFactory(
    private val taskRepository: LetterboxTaskInfoRepository
) : LetterboxLifecycleEventFactory {

    companion object {
        @JvmStatic
        private val TAG = "ActivityLetterboxLifecycleEventFactory"
    }

    override fun canHandle(change: Change): Boolean = change.activityTransitionInfo != null

    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent {
    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent? {
        val activityTransitionInfo = change.activityTransitionInfo
        val taskBounds = change.endAbsBounds

        val letterboxBoundsTmp = activityTransitionInfo?.appCompatTransitionInfo?.letterboxBounds
        val taskId = activityTransitionInfo?.taskId ?: -1

        taskRepository.find(taskId)?.let {
            val isLetterboxed = letterboxBoundsTmp != taskBounds
            // Letterbox bounds are null when the activity is not letterboxed.
            val letterboxBounds = if (isLetterboxed) letterboxBoundsTmp else null
        val taskToken = taskRepository.find(taskId)?.containerToken
        val taskLeash = taskRepository.find(taskId)?.containerLeash
            val taskToken = it.containerToken
            val taskLeash = it.containerLeash
            return LetterboxLifecycleEvent(
                type = change.asLetterboxLifecycleEventType(),
                taskId = taskId,
@@ -49,4 +57,7 @@ class ActivityLetterboxLifecycleEventFactory(
                containerToken = taskToken
            )
        }
        ProtoLog.w(WM_SHELL_APP_COMPAT, "$TAG: Task not found for taskId: $taskId")
        return null
    }
}