1 /* <lambda>null2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wm.shell.compatui.letterbox 18 19 import android.graphics.Rect 20 import android.os.IBinder 21 import android.view.SurfaceControl 22 import android.window.TransitionInfo 23 import com.android.internal.protolog.ProtoLog 24 import com.android.window.flags.Flags.appCompatRefactoring 25 import com.android.wm.shell.common.transition.TransitionStateHolder 26 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT 27 import com.android.wm.shell.shared.TransitionUtil.isClosingType 28 import com.android.wm.shell.sysui.ShellInit 29 import com.android.wm.shell.transition.Transitions 30 31 /** 32 * The [TransitionObserver] to handle Letterboxing events in Shell. 33 */ 34 class LetterboxTransitionObserver( 35 shellInit: ShellInit, 36 private val transitions: Transitions, 37 private val letterboxController: LetterboxController, 38 private val transitionStateHolder: TransitionStateHolder, 39 private val letterboxModeStrategy: LetterboxControllerStrategy 40 ) : Transitions.TransitionObserver { 41 42 companion object { 43 @JvmStatic 44 private val TAG = "LetterboxTransitionObserver" 45 @JvmStatic 46 private val EMPTY_BOUNDS = Rect() 47 } 48 49 init { 50 if (appCompatRefactoring()) { 51 logV("Initializing LetterboxTransitionObserver") 52 shellInit.addInitCallback({ 53 transitions.registerObserver(this) 54 }, this) 55 } 56 } 57 58 override fun onTransitionReady( 59 transition: IBinder, 60 info: TransitionInfo, 61 startTransaction: SurfaceControl.Transaction, 62 finishTransaction: SurfaceControl.Transaction 63 ) { 64 // We recognise the operation to execute and delegate to the LetterboxController 65 // the related operation. 66 // TODO(b/377875151): Identify Desktop Windowing Transactions. 67 // TODO(b/371500295): Handle input events detection. 68 for (change in info.changes) { 69 change.taskInfo?.let { ti -> 70 val key = LetterboxKey(ti.displayId, ti.taskId) 71 val taskBounds = Rect( 72 change.endRelOffset.x, 73 change.endRelOffset.y, 74 change.endAbsBounds.width(), 75 change.endAbsBounds.height() 76 ) 77 with(letterboxController) { 78 // TODO(b/380274087) Handle return to home from a recents transition. 79 if (isClosingType(change.mode) && 80 !transitionStateHolder.isRecentsTransitionRunning()) { 81 // For the other types of close we need to check the recents. 82 destroyLetterboxSurface(key, finishTransaction) 83 } else { 84 val isTopActivityLetterboxed = ti.appCompatTaskInfo.isTopActivityLetterboxed 85 if (isTopActivityLetterboxed) { 86 letterboxModeStrategy.configureLetterboxMode() 87 createLetterboxSurface( 88 key, 89 startTransaction, 90 change.leash 91 ) 92 val activityBounds = 93 ti.appCompatTaskInfo.topActivityLetterboxBounds ?: EMPTY_BOUNDS 94 updateLetterboxSurfaceBounds( 95 key, 96 startTransaction, 97 taskBounds, 98 activityBounds 99 ) 100 } 101 updateLetterboxSurfaceVisibility( 102 key, 103 startTransaction, 104 isTopActivityLetterboxed 105 ) 106 } 107 dump() 108 } 109 } 110 } 111 } 112 113 private fun logV(msg: String) { 114 ProtoLog.v(WM_SHELL_APP_COMPAT, "%s: %s", TAG, msg) 115 } 116 } 117