Debian Codegraph @

core/java/android/window/TaskFragmentInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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 android.window;
18
19 import static android.app.WindowConfiguration.WindowingMode;
20
21 import static java.util.Objects.requireNonNull;
22
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.annotation.TestApi;
26 import android.content.pm.ActivityInfo;
27 import android.content.res.Configuration;
28 import android.graphics.Point;
29 import android.graphics.Rect;
30 import android.os.IBinder;
31 import android.os.Parcel;
32 import android.os.Parcelable;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 /**
38 * Stores information about a particular TaskFragment.
39 * @hide
40 */
41 @TestApi
42 public final class TaskFragmentInfo implements Parcelable {
43
44 /**
45 * Client assigned unique token in {@link TaskFragmentCreationParams#getFragmentToken()} to
46 * create this TaskFragment with.
47 */
48 @NonNull
49 private final IBinder mFragmentToken;
50
51 @NonNull
52 private final WindowContainerToken mToken;
53
54 @NonNull
55 private final Configuration mConfiguration = new Configuration();
56
57 /** The number of the running activities in the TaskFragment. */
58 private final int mRunningActivityCount;
59
60 /** Whether this TaskFragment is visible on the window hierarchy. */
61 private final boolean mIsVisible;
62
63 /**
64 * List of Activity tokens that are children of this TaskFragment. It only contains Activities
65 * that belong to the organizer process for security.
66 */
67 @NonNull
68 private final List<IBinder> mActivities = new ArrayList<>();
69
70 /** Relative position of the fragment's top left corner in the parent container. */
71 private final Point mPositionInParent = new Point();
72
73 /**
74 * Whether the last running activity in the TaskFragment was finished due to clearing task while
75 * launching an activity in the host Task.
76 */
77 private final boolean mIsTaskClearedForReuse;
78
79 /**
80 * Whether the last running activity in the TaskFragment was reparented to a different Task
81 * because it is entering PiP.
82 */
83 private final boolean mIsTaskFragmentClearedForPip;
84
85 /**
86 * Whether the last running activity of the TaskFragment was removed because it was reordered to
87 * front of the Task.
88 */
89 private final boolean mIsClearedForReorderActivityToFront;
90
91 /**
92 * The maximum {@link ActivityInfo.WindowLayout#minWidth} and
93 * {@link ActivityInfo.WindowLayout#minHeight} aggregated from the TaskFragment's child
94 * activities.
95 */
96 @NonNull
97 private final Point mMinimumDimensions = new Point();
98
99 /** @hide */
100 public TaskFragmentInfo(
101 @NonNull IBinder fragmentToken, @NonNull WindowContainerToken token,
102 @NonNull Configuration configuration, int runningActivityCount,
103 boolean isVisible, @NonNull List<IBinder> activities, @NonNull Point positionInParent,
104 boolean isTaskClearedForReuse, boolean isTaskFragmentClearedForPip,
105 boolean isClearedForReorderActivityToFront, @NonNull Point minimumDimensions) {
106 mFragmentToken = requireNonNull(fragmentToken);
107 mToken = requireNonNull(token);
108 mConfiguration.setTo(configuration);
109 mRunningActivityCount = runningActivityCount;
110 mIsVisible = isVisible;
111 mActivities.addAll(activities);
112 mPositionInParent.set(positionInParent);
113 mIsTaskClearedForReuse = isTaskClearedForReuse;
114 mIsTaskFragmentClearedForPip = isTaskFragmentClearedForPip;
115 mIsClearedForReorderActivityToFront = isClearedForReorderActivityToFront;
116 mMinimumDimensions.set(minimumDimensions);
117 }
118
119 @NonNull
120 public IBinder getFragmentToken() {
121 return mFragmentToken;
122 }
123
124 @NonNull
125 public WindowContainerToken getToken() {
126 return mToken;
127 }
128
129 @NonNull
130 public Configuration getConfiguration() {
131 return mConfiguration;
132 }
133
134 public boolean isEmpty() {
135 return mRunningActivityCount == 0;
136 }
137
138 public boolean hasRunningActivity() {
139 return mRunningActivityCount > 0;
140 }
141
142 public int getRunningActivityCount() {
143 return mRunningActivityCount;
144 }
145
146 public boolean isVisible() {
147 return mIsVisible;
148 }
149
150 @NonNull
151 public List<IBinder> getActivities() {
152 return mActivities;
153 }
154
155 /** Returns the relative position of the fragment's top left corner in the parent container. */
156 @NonNull
157 public Point getPositionInParent() {
158 return mPositionInParent;
159 }
160
161 public boolean isTaskClearedForReuse() {
162 return mIsTaskClearedForReuse;
163 }
164
165 /** @hide */
166 public boolean isTaskFragmentClearedForPip() {
167 return mIsTaskFragmentClearedForPip;
168 }
169
170 /** @hide */
171 public boolean isClearedForReorderActivityToFront() {
172 return mIsClearedForReorderActivityToFront;
173 }
174
175 @WindowingMode
176 public int getWindowingMode() {
177 return mConfiguration.windowConfiguration.getWindowingMode();
178 }
179
180 /**
181 * Returns the minimum width this TaskFragment can be resized to.
182 * Client side must not {@link WindowContainerTransaction#setBounds(WindowContainerToken, Rect)}
183 * that {@link Rect#width()} is shorter than the reported value.
184 * @hide pending unhide
185 */
186 public int getMinimumWidth() {
187 return mMinimumDimensions.x;
188 }
189
190 /**
191 * Returns the minimum width this TaskFragment can be resized to.
192 * Client side must not {@link WindowContainerTransaction#setBounds(WindowContainerToken, Rect)}
193 * that {@link Rect#height()} is shorter than the reported value.
194 * @hide pending unhide
195 */
196 public int getMinimumHeight() {
197 return mMinimumDimensions.y;
198 }
199
200 /**
201 * Returns {@code true} if the parameters that are important for task fragment organizers are
202 * equal between this {@link TaskFragmentInfo} and {@param that}.
203 * Note that this method is usually called with
204 * {@link com.android.server.wm.WindowOrganizerController#configurationsAreEqualForOrganizer(
205 * Configuration, Configuration)} to determine if this {@link TaskFragmentInfo} should
206 * be dispatched to the client.
207 */
208 public boolean equalsForTaskFragmentOrganizer(@Nullable TaskFragmentInfo that) {
209 if (that == null) {
210 return false;
211 }
212
213 return mFragmentToken.equals(that.mFragmentToken)
214 && mToken.equals(that.mToken)
215 && mRunningActivityCount == that.mRunningActivityCount
216 && mIsVisible == that.mIsVisible
217 && getWindowingMode() == that.getWindowingMode()
218 && mActivities.equals(that.mActivities)
219 && mPositionInParent.equals(that.mPositionInParent)
220 && mIsTaskClearedForReuse == that.mIsTaskClearedForReuse
221 && mIsTaskFragmentClearedForPip == that.mIsTaskFragmentClearedForPip
222 && mIsClearedForReorderActivityToFront == that.mIsClearedForReorderActivityToFront
223 && mMinimumDimensions.equals(that.mMinimumDimensions);
224 }
225
226 private TaskFragmentInfo(Parcel in) {
227 mFragmentToken = in.readStrongBinder();
228 mToken = in.readTypedObject(WindowContainerToken.CREATOR);
229 mConfiguration.readFromParcel(in);
230 mRunningActivityCount = in.readInt();
231 mIsVisible = in.readBoolean();
232 in.readBinderList(mActivities);
233 mPositionInParent.readFromParcel(in);
234 mIsTaskClearedForReuse = in.readBoolean();
235 mIsTaskFragmentClearedForPip = in.readBoolean();
236 mIsClearedForReorderActivityToFront = in.readBoolean();
237 mMinimumDimensions.readFromParcel(in);
238 }
239
240 /** @hide */
241 @Override
242 public void writeToParcel(@NonNull Parcel dest, int flags) {
243 dest.writeStrongBinder(mFragmentToken);
244 dest.writeTypedObject(mToken, flags);
245 mConfiguration.writeToParcel(dest, flags);
246 dest.writeInt(mRunningActivityCount);
247 dest.writeBoolean(mIsVisible);
248 dest.writeBinderList(mActivities);
249 mPositionInParent.writeToParcel(dest, flags);
250 dest.writeBoolean(mIsTaskClearedForReuse);
251 dest.writeBoolean(mIsTaskFragmentClearedForPip);
252 dest.writeBoolean(mIsClearedForReorderActivityToFront);
253 mMinimumDimensions.writeToParcel(dest, flags);
254 }
255
256 @NonNull
257 public static final Creator<TaskFragmentInfo> CREATOR =
258 new Creator<TaskFragmentInfo>() {
259 @Override
260 public TaskFragmentInfo createFromParcel(Parcel in) {
261 return new TaskFragmentInfo(in);
262 }
263
264 @Override
265 public TaskFragmentInfo[] newArray(int size) {
266 return new TaskFragmentInfo[size];
267 }
268 };
269
270 @Override
271 public String toString() {
272 return "TaskFragmentInfo{"
273 + " fragmentToken=" + mFragmentToken
274 + " token=" + mToken
275 + " runningActivityCount=" + mRunningActivityCount
276 + " isVisible=" + mIsVisible
277 + " activities=" + mActivities
278 + " positionInParent=" + mPositionInParent
279 + " isTaskClearedForReuse=" + mIsTaskClearedForReuse
280 + " isTaskFragmentClearedForPip=" + mIsTaskFragmentClearedForPip
281 + " mIsClearedForReorderActivityToFront=" + mIsClearedForReorderActivityToFront
282 + " minimumDimensions=" + mMinimumDimensions
283 + "}";
284 }
285
286 /** @hide */
287 @Override
288 public int describeContents() {
289 return 0;
290 }
291 }