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

Commit f7c057d4 authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "Return null if task not found in ActivityLetterboxLifecycleEventFactory" into main

parents bd907600 ad386ccb
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
    }
}