1 /* 2 * Copyright (C) 2022 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.windowdecor; 18 19 import android.app.ActivityManager; 20 import android.os.IBinder; 21 import android.view.SurfaceControl; 22 import android.window.TransitionInfo; 23 24 import com.android.wm.shell.freeform.FreeformTaskTransitionStarter; 25 import com.android.wm.shell.splitscreen.SplitScreenController; 26 27 /** 28 * The interface used by some {@link com.android.wm.shell.ShellTaskOrganizer.TaskListener} to help 29 * customize {@link WindowDecoration}. Its implementations are responsible to interpret user's 30 * interactions with UI widgets in window decorations and send corresponding requests to system 31 * servers. 32 */ 33 public interface WindowDecorViewModel { 34 /** 35 * Sets the transition starter that starts freeform task transitions. Only called when 36 * {@link com.android.wm.shell.transition.Transitions#ENABLE_SHELL_TRANSITIONS} is {@code true}. 37 * 38 * @param transitionStarter the transition starter that starts freeform task transitions 39 */ setFreeformTaskTransitionStarter(FreeformTaskTransitionStarter transitionStarter)40 void setFreeformTaskTransitionStarter(FreeformTaskTransitionStarter transitionStarter); 41 42 /** 43 * Sets the {@link SplitScreenController} if available. 44 */ setSplitScreenController(SplitScreenController splitScreenController)45 void setSplitScreenController(SplitScreenController splitScreenController); 46 47 /** 48 * Creates a window decoration for the given task. Can be {@code null} for Fullscreen tasks but 49 * not Freeform ones. 50 * 51 * @param taskInfo the initial task info of the task 52 * @param taskSurface the surface of the task 53 * @param startT the start transaction to be applied before the transition 54 * @param finishT the finish transaction to restore states after the transition 55 * @return {@code true} if window decoration was created, {@code false} otherwise 56 */ onTaskOpening( ActivityManager.RunningTaskInfo taskInfo, SurfaceControl taskSurface, SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT)57 boolean onTaskOpening( 58 ActivityManager.RunningTaskInfo taskInfo, 59 SurfaceControl taskSurface, 60 SurfaceControl.Transaction startT, 61 SurfaceControl.Transaction finishT); 62 63 /** 64 * Notifies a task info update on the given task, with the window decoration created previously 65 * for this task by {@link #onTaskOpening}. 66 * 67 * @param taskInfo the new task info of the task 68 */ onTaskInfoChanged(ActivityManager.RunningTaskInfo taskInfo)69 void onTaskInfoChanged(ActivityManager.RunningTaskInfo taskInfo); 70 71 /** 72 * Notifies a transition is about to start about the given task to give the window decoration a 73 * chance to prepare for this transition. Unlike {@link #onTaskInfoChanged}, this method creates 74 * a window decoration if one does not exist but is required. 75 * 76 * @param taskInfo the initial task info of the task 77 * @param taskSurface the surface of the task 78 * @param startT the start transaction to be applied before the transition 79 * @param finishT the finish transaction to restore states after the transition 80 */ onTaskChanging( ActivityManager.RunningTaskInfo taskInfo, SurfaceControl taskSurface, SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT)81 void onTaskChanging( 82 ActivityManager.RunningTaskInfo taskInfo, 83 SurfaceControl taskSurface, 84 SurfaceControl.Transaction startT, 85 SurfaceControl.Transaction finishT); 86 87 /** 88 * Notifies that the given task is about to close to give the window decoration a chance to 89 * prepare for this transition. 90 * 91 * @param taskInfo the initial task info of the task 92 * @param startT the start transaction to be applied before the transition 93 * @param finishT the finish transaction to restore states after the transition 94 */ onTaskClosing( ActivityManager.RunningTaskInfo taskInfo, SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT)95 void onTaskClosing( 96 ActivityManager.RunningTaskInfo taskInfo, 97 SurfaceControl.Transaction startT, 98 SurfaceControl.Transaction finishT); 99 100 /** 101 * Destroys the window decoration of the give task. 102 * 103 * @param taskInfo the info of the task 104 */ destroyWindowDecoration(ActivityManager.RunningTaskInfo taskInfo)105 void destroyWindowDecoration(ActivityManager.RunningTaskInfo taskInfo); 106 107 /** 108 * Notifies that a shell transition is about to start. If the transition is of type 109 * TRANSIT_ENTER_DESKTOP, it will save that transition to unpause relayout for the transitioning 110 * task after the transition has ended. 111 * 112 * @param transition the ready transaction 113 * @param info of Transition to check if relayout needs to be paused for a task 114 * @param change a change in the given transition 115 */ onTransitionReady(IBinder transition, TransitionInfo info, TransitionInfo.Change change)116 default void onTransitionReady(IBinder transition, TransitionInfo info, 117 TransitionInfo.Change change) {} 118 119 /** 120 * Notifies that a shell transition is about to merge with another to give the window 121 * decoration a chance to prepare for this merge. 122 * 123 * @param merged the transaction being merged 124 * @param playing the transaction being merged into 125 */ onTransitionMerged(IBinder merged, IBinder playing)126 default void onTransitionMerged(IBinder merged, IBinder playing) {} 127 128 /** 129 * Notifies that a shell transition is about to finish to give the window decoration a chance 130 * to clean up. 131 * 132 * @param transaction 133 */ onTransitionFinished(IBinder transaction)134 default void onTransitionFinished(IBinder transaction) {} 135 136 }