Debian Codegraph @

core/java/android/window/TaskFragmentCreationParams.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.WINDOWING_MODE_UNDEFINED;
20 import static android.app.WindowConfiguration.WindowingMode;
21
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.TestApi;
25 import android.graphics.Rect;
26 import android.os.IBinder;
27 import android.os.Parcel;
28 import android.os.Parcelable;
29
30 /**
31 * Data object for options to create TaskFragment with.
32 * @hide
33 */
34 @TestApi
35 public final class TaskFragmentCreationParams implements Parcelable {
36
37 /** The organizer that will organize this TaskFragment. */
38 @NonNull
39 private final TaskFragmentOrganizerToken mOrganizer;
40
41 /**
42 * Unique token assigned from the client organizer to identify the {@link TaskFragmentInfo} when
43 * a new TaskFragment is created with this option.
44 */
45 @NonNull
46 private final IBinder mFragmentToken;
47
48 /**
49 * Activity token used to identify the leaf Task to create the TaskFragment in. It has to belong
50 * to the same app as the root Activity of the target Task.
51 */
52 @NonNull
53 private final IBinder mOwnerToken;
54
55 /** The initial bounds of the TaskFragment. Fills parent if empty. */
56 @NonNull
57 private final Rect mInitialBounds = new Rect();
58
59 /** The initial windowing mode of the TaskFragment. Inherits from parent if not set. */
60 @WindowingMode
61 private final int mWindowingMode;
62
63 /**
64 * The fragment token of the paired primary TaskFragment.
65 * When it is set, the new TaskFragment will be positioned right above the paired TaskFragment.
66 * Otherwise, the new TaskFragment will be positioned on the top of the Task by default.
67 *
68 * This is different from {@link WindowContainerTransaction#setAdjacentTaskFragments} as we may
69 * set this when the pair of TaskFragments are stacked, while adjacent is only set on the pair
70 * of TaskFragments that are in split.
71 *
72 * This is needed in case we need to launch a placeholder Activity to split below a transparent
73 * always-expand Activity.
74 */
75 @Nullable
76 private final IBinder mPairedPrimaryFragmentToken;
77
78 private TaskFragmentCreationParams(
79 @NonNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken,
80 @NonNull IBinder ownerToken, @NonNull Rect initialBounds,
81 @WindowingMode int windowingMode, @Nullable IBinder pairedPrimaryFragmentToken) {
82 mOrganizer = organizer;
83 mFragmentToken = fragmentToken;
84 mOwnerToken = ownerToken;
85 mInitialBounds.set(initialBounds);
86 mWindowingMode = windowingMode;
87 mPairedPrimaryFragmentToken = pairedPrimaryFragmentToken;
88 }
89
90 @NonNull
91 public TaskFragmentOrganizerToken getOrganizer() {
92 return mOrganizer;
93 }
94
95 @NonNull
96 public IBinder getFragmentToken() {
97 return mFragmentToken;
98 }
99
100 @NonNull
101 public IBinder getOwnerToken() {
102 return mOwnerToken;
103 }
104
105 @NonNull
106 public Rect getInitialBounds() {
107 return mInitialBounds;
108 }
109
110 @WindowingMode
111 public int getWindowingMode() {
112 return mWindowingMode;
113 }
114
115 /**
116 * TODO(b/232476698): remove the hide with adding CTS for this in next release.
117 * @hide
118 */
119 @Nullable
120 public IBinder getPairedPrimaryFragmentToken() {
121 return mPairedPrimaryFragmentToken;
122 }
123
124 private TaskFragmentCreationParams(Parcel in) {
125 mOrganizer = TaskFragmentOrganizerToken.CREATOR.createFromParcel(in);
126 mFragmentToken = in.readStrongBinder();
127 mOwnerToken = in.readStrongBinder();
128 mInitialBounds.readFromParcel(in);
129 mWindowingMode = in.readInt();
130 mPairedPrimaryFragmentToken = in.readStrongBinder();
131 }
132
133 /** @hide */
134 @Override
135 public void writeToParcel(@NonNull Parcel dest, int flags) {
136 mOrganizer.writeToParcel(dest, flags);
137 dest.writeStrongBinder(mFragmentToken);
138 dest.writeStrongBinder(mOwnerToken);
139 mInitialBounds.writeToParcel(dest, flags);
140 dest.writeInt(mWindowingMode);
141 dest.writeStrongBinder(mPairedPrimaryFragmentToken);
142 }
143
144 @NonNull
145 public static final Creator<TaskFragmentCreationParams> CREATOR =
146 new Creator<TaskFragmentCreationParams>() {
147 @Override
148 public TaskFragmentCreationParams createFromParcel(Parcel in) {
149 return new TaskFragmentCreationParams(in);
150 }
151
152 @Override
153 public TaskFragmentCreationParams[] newArray(int size) {
154 return new TaskFragmentCreationParams[size];
155 }
156 };
157
158 @Override
159 public String toString() {
160 return "TaskFragmentCreationParams{"
161 + " organizer=" + mOrganizer
162 + " fragmentToken=" + mFragmentToken
163 + " ownerToken=" + mOwnerToken
164 + " initialBounds=" + mInitialBounds
165 + " windowingMode=" + mWindowingMode
166 + " pairedFragmentToken=" + mPairedPrimaryFragmentToken
167 + "}";
168 }
169
170 /** @hide */
171 @Override
172 public int describeContents() {
173 return 0;
174 }
175
176 /** Builder to construct the options to create TaskFragment with. */
177 public static final class Builder {
178
179 @NonNull
180 private final TaskFragmentOrganizerToken mOrganizer;
181
182 @NonNull
183 private final IBinder mFragmentToken;
184
185 @NonNull
186 private final IBinder mOwnerToken;
187
188 @NonNull
189 private final Rect mInitialBounds = new Rect();
190
191 @WindowingMode
192 private int mWindowingMode = WINDOWING_MODE_UNDEFINED;
193
194 @Nullable
195 private IBinder mPairedPrimaryFragmentToken;
196
197 public Builder(@NonNull TaskFragmentOrganizerToken organizer,
198 @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken) {
199 mOrganizer = organizer;
200 mFragmentToken = fragmentToken;
201 mOwnerToken = ownerToken;
202 }
203
204 /** Sets the initial bounds for the TaskFragment. */
205 @NonNull
206 public Builder setInitialBounds(@NonNull Rect bounds) {
207 mInitialBounds.set(bounds);
208 return this;
209 }
210
211 /** Sets the initial windowing mode for the TaskFragment. */
212 @NonNull
213 public Builder setWindowingMode(@WindowingMode int windowingMode) {
214 mWindowingMode = windowingMode;
215 return this;
216 }
217
218 /**
219 * Sets the fragment token of the paired primary TaskFragment.
220 * When it is set, the new TaskFragment will be positioned right above the paired
221 * TaskFragment. Otherwise, the new TaskFragment will be positioned on the top of the Task
222 * by default.
223 *
224 * This is needed in case we need to launch a placeholder Activity to split below a
225 * transparent always-expand Activity.
226 *
227 * TODO(b/232476698): remove the hide with adding CTS for this in next release.
228 * @hide
229 */
230 @NonNull
231 public Builder setPairedPrimaryFragmentToken(@Nullable IBinder fragmentToken) {
232 mPairedPrimaryFragmentToken = fragmentToken;
233 return this;
234 }
235
236 /** Constructs the options to create TaskFragment with. */
237 @NonNull
238 public TaskFragmentCreationParams build() {
239 return new TaskFragmentCreationParams(mOrganizer, mFragmentToken, mOwnerToken,
240 mInitialBounds, mWindowingMode, mPairedPrimaryFragmentToken);
241 }
242 }
243 }