• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 package com.android.wm.shell.taskview;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.app.ActivityManager;
21 import android.app.ActivityOptions;
22 import android.app.PendingIntent;
23 import android.content.Intent;
24 import android.content.pm.LauncherApps;
25 import android.content.pm.ShortcutInfo;
26 import android.graphics.Rect;
27 import android.view.SurfaceControl;
28 import android.window.WindowContainerToken;
29 import android.window.WindowContainerTransaction;
30 
31 import com.android.wm.shell.ShellTaskOrganizer;
32 
33 /**
34  * Interface which provides methods to control TaskView properties and state.
35  *
36  * <ul>
37  *     <li>To start an activity based task view, use {@link #startActivity}</li>
38  *
39  *     <li>To start an activity (represented by {@link ShortcutInfo}) based task view, use
40  *     {@link #startShortcutActivity}
41  *     </li>
42  *
43  *     <li>To start a root-task based task view, use {@link #startRootTask}.
44  *     This method is special as it doesn't create a root task and instead expects that the
45  *     launch root task is already created and started. This method just attaches the taskInfo to
46  *     the TaskView.
47  *     </li>
48  * </ul>
49  */
50 public interface TaskViewController {
51     /** Registers a TaskView with this controller. */
registerTaskView(@onNull TaskViewTaskController tv)52     void registerTaskView(@NonNull TaskViewTaskController tv);
53 
54     /** Un-registers a TaskView from this controller. */
unregisterTaskView(@onNull TaskViewTaskController tv)55     void unregisterTaskView(@NonNull TaskViewTaskController tv);
56 
57     /**
58      * Launch an activity represented by {@link ShortcutInfo}.
59      * <p>The owner of this container must be allowed to access the shortcut information,
60      * as defined in {@link LauncherApps#hasShortcutHostPermission()} to use this method.
61      *
62      * @param destination  the TaskView to start the shortcut into.
63      * @param shortcut     the shortcut used to launch the activity.
64      * @param options      options for the activity.
65      * @param launchBounds the bounds (window size and position) that the activity should be
66      *                     launched in, in pixels and in screen coordinates.
67      */
startShortcutActivity(@onNull TaskViewTaskController destination, @NonNull ShortcutInfo shortcut, @NonNull ActivityOptions options, @Nullable Rect launchBounds)68     void startShortcutActivity(@NonNull TaskViewTaskController destination,
69             @NonNull ShortcutInfo shortcut,
70             @NonNull ActivityOptions options, @Nullable Rect launchBounds);
71 
72     /**
73      * Launch a new activity into a TaskView
74      *
75      * @param destination   The TaskView to start the activity into.
76      * @param pendingIntent Intent used to launch an activity.
77      * @param fillInIntent  Additional Intent data, see {@link Intent#fillIn Intent.fillIn()}
78      * @param options       options for the activity.
79      * @param launchBounds  the bounds (window size and position) that the activity should be
80      *                      launched in, in pixels and in screen coordinates.
81      */
startActivity(@onNull TaskViewTaskController destination, @NonNull PendingIntent pendingIntent, @Nullable Intent fillInIntent, @NonNull ActivityOptions options, @Nullable Rect launchBounds)82     void startActivity(@NonNull TaskViewTaskController destination,
83             @NonNull PendingIntent pendingIntent, @Nullable Intent fillInIntent,
84             @NonNull ActivityOptions options, @Nullable Rect launchBounds);
85 
86     /**
87      * Attaches the given root task {@code taskInfo} in the task view.
88      *
89      * <p> Since {@link ShellTaskOrganizer#createRootTask(int, int,
90      * ShellTaskOrganizer.TaskListener)} does not use the shell transitions flow, this method is
91      * used as an entry point for an already-created root-task in the task view.
92      *
93      * @param destination The TaskView to put the root-task into.
94      * @param taskInfo    the task info of the root task.
95      * @param leash       the {@link android.content.pm.ShortcutInfo.Surface} of the root task
96      * @param wct         The Window container work that should happen as part of this set up.
97      */
startRootTask(@onNull TaskViewTaskController destination, ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash, @Nullable WindowContainerTransaction wct)98     void startRootTask(@NonNull TaskViewTaskController destination,
99             ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash,
100             @Nullable WindowContainerTransaction wct);
101 
102     /**
103      * Closes a taskview and removes the task from window manager. This task will not appear in
104      * recents.
105      */
removeTaskView(@onNull TaskViewTaskController taskView, @Nullable WindowContainerToken taskToken)106     void removeTaskView(@NonNull TaskViewTaskController taskView,
107             @Nullable WindowContainerToken taskToken);
108 
109     /**
110      * Moves the current task in TaskView out of the view and back to fullscreen.
111      */
moveTaskViewToFullscreen(@onNull TaskViewTaskController taskView)112     void moveTaskViewToFullscreen(@NonNull TaskViewTaskController taskView);
113 
114     /**
115      * Starts a new transition to make the given {@code taskView} visible and optionally change
116      * the task order.
117      *
118      * @param taskView the task view which the visibility is being changed for
119      * @param visible  the new visibility of the task view
120      */
setTaskViewVisible(TaskViewTaskController taskView, boolean visible)121     void setTaskViewVisible(TaskViewTaskController taskView, boolean visible);
122 
123     /**
124      * Sets the task bounds to {@code boundsOnScreen}.
125      * Usually called when the taskview's position or size has changed.
126      *
127      * @param boundsOnScreen the on screen bounds of the surface view.
128      */
setTaskBounds(TaskViewTaskController taskView, Rect boundsOnScreen)129     void setTaskBounds(TaskViewTaskController taskView, Rect boundsOnScreen);
130 
131     /** Whether shell-transitions are currently enabled. */
isUsingShellTransitions()132     boolean isUsingShellTransitions();
133 }
134