• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /**
56      * The initial relative bounds of the TaskFragment in parent coordinate.
57      * Fills parent if empty.
58      */
59     @NonNull
60     private final Rect mInitialRelativeBounds = new Rect();
61 
62     /** The initial windowing mode of the TaskFragment. Inherits from parent if not set. */
63     @WindowingMode
64     private final int mWindowingMode;
65 
66     /**
67      * The fragment token of the paired primary TaskFragment.
68      * When it is set, the new TaskFragment will be positioned right above the paired TaskFragment.
69      * Otherwise, the new TaskFragment will be positioned on the top of the Task by default.
70      *
71      * This is different from {@link WindowContainerTransaction#setAdjacentTaskFragments} as we may
72      * set this when the pair of TaskFragments are stacked, while adjacent is only set on the pair
73      * of TaskFragments that are in split.
74      *
75      * This is needed in case we need to launch a placeholder Activity to split below a transparent
76      * always-expand Activity.
77      *
78      * This should not be used with {@link #mPairedActivityToken}.
79      */
80     @Nullable
81     private final IBinder mPairedPrimaryFragmentToken;
82 
83     /**
84      * The Activity token to place the new TaskFragment on top of.
85      * When it is set, the new TaskFragment will be positioned right above the target Activity.
86      * Otherwise, the new TaskFragment will be positioned on the top of the Task by default.
87      *
88      * This is needed in case we need to place an Activity into TaskFragment to launch placeholder
89      * below a transparent always-expand Activity, or when there is another Intent being started in
90      * a TaskFragment above.
91      *
92      * This should not be used with {@link #mPairedPrimaryFragmentToken}.
93      */
94     @Nullable
95     private final IBinder mPairedActivityToken;
96 
TaskFragmentCreationParams( @onNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken, @NonNull Rect initialRelativeBounds, @WindowingMode int windowingMode, @Nullable IBinder pairedPrimaryFragmentToken, @Nullable IBinder pairedActivityToken)97     private TaskFragmentCreationParams(
98             @NonNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken,
99             @NonNull IBinder ownerToken, @NonNull Rect initialRelativeBounds,
100             @WindowingMode int windowingMode, @Nullable IBinder pairedPrimaryFragmentToken,
101             @Nullable IBinder pairedActivityToken) {
102         if (pairedPrimaryFragmentToken != null && pairedActivityToken != null) {
103             throw new IllegalArgumentException("pairedPrimaryFragmentToken and"
104                     + " pairedActivityToken should not be set at the same time.");
105         }
106         mOrganizer = organizer;
107         mFragmentToken = fragmentToken;
108         mOwnerToken = ownerToken;
109         mInitialRelativeBounds.set(initialRelativeBounds);
110         mWindowingMode = windowingMode;
111         mPairedPrimaryFragmentToken = pairedPrimaryFragmentToken;
112         mPairedActivityToken = pairedActivityToken;
113     }
114 
115     @NonNull
getOrganizer()116     public TaskFragmentOrganizerToken getOrganizer() {
117         return mOrganizer;
118     }
119 
120     @NonNull
getFragmentToken()121     public IBinder getFragmentToken() {
122         return mFragmentToken;
123     }
124 
125     @NonNull
getOwnerToken()126     public IBinder getOwnerToken() {
127         return mOwnerToken;
128     }
129 
130     @NonNull
getInitialRelativeBounds()131     public Rect getInitialRelativeBounds() {
132         return mInitialRelativeBounds;
133     }
134 
135     @WindowingMode
getWindowingMode()136     public int getWindowingMode() {
137         return mWindowingMode;
138     }
139 
140     /**
141      * TODO(b/232476698): remove the hide with adding CTS for this in next release.
142      * @hide
143      */
144     @Nullable
getPairedPrimaryFragmentToken()145     public IBinder getPairedPrimaryFragmentToken() {
146         return mPairedPrimaryFragmentToken;
147     }
148 
149     /**
150      * TODO(b/232476698): remove the hide with adding CTS for this in next release.
151      * @hide
152      */
153     @Nullable
getPairedActivityToken()154     public IBinder getPairedActivityToken() {
155         return mPairedActivityToken;
156     }
157 
TaskFragmentCreationParams(Parcel in)158     private TaskFragmentCreationParams(Parcel in) {
159         mOrganizer = TaskFragmentOrganizerToken.CREATOR.createFromParcel(in);
160         mFragmentToken = in.readStrongBinder();
161         mOwnerToken = in.readStrongBinder();
162         mInitialRelativeBounds.readFromParcel(in);
163         mWindowingMode = in.readInt();
164         mPairedPrimaryFragmentToken = in.readStrongBinder();
165         mPairedActivityToken = in.readStrongBinder();
166     }
167 
168     /** @hide */
169     @Override
writeToParcel(@onNull Parcel dest, int flags)170     public void writeToParcel(@NonNull Parcel dest, int flags) {
171         mOrganizer.writeToParcel(dest, flags);
172         dest.writeStrongBinder(mFragmentToken);
173         dest.writeStrongBinder(mOwnerToken);
174         mInitialRelativeBounds.writeToParcel(dest, flags);
175         dest.writeInt(mWindowingMode);
176         dest.writeStrongBinder(mPairedPrimaryFragmentToken);
177         dest.writeStrongBinder(mPairedActivityToken);
178     }
179 
180     @NonNull
181     public static final Creator<TaskFragmentCreationParams> CREATOR =
182             new Creator<TaskFragmentCreationParams>() {
183                 @Override
184                 public TaskFragmentCreationParams createFromParcel(Parcel in) {
185                     return new TaskFragmentCreationParams(in);
186                 }
187 
188                 @Override
189                 public TaskFragmentCreationParams[] newArray(int size) {
190                     return new TaskFragmentCreationParams[size];
191                 }
192             };
193 
194     @Override
toString()195     public String toString() {
196         return "TaskFragmentCreationParams{"
197                 + " organizer=" + mOrganizer
198                 + " fragmentToken=" + mFragmentToken
199                 + " ownerToken=" + mOwnerToken
200                 + " initialRelativeBounds=" + mInitialRelativeBounds
201                 + " windowingMode=" + mWindowingMode
202                 + " pairedFragmentToken=" + mPairedPrimaryFragmentToken
203                 + " pairedActivityToken=" + mPairedActivityToken
204                 + "}";
205     }
206 
207     /** @hide */
208     @Override
describeContents()209     public int describeContents() {
210         return 0;
211     }
212 
213     /** Builder to construct the options to create TaskFragment with. */
214     public static final class Builder {
215 
216         @NonNull
217         private final TaskFragmentOrganizerToken mOrganizer;
218 
219         @NonNull
220         private final IBinder mFragmentToken;
221 
222         @NonNull
223         private final IBinder mOwnerToken;
224 
225         @NonNull
226         private final Rect mInitialRelativeBounds = new Rect();
227 
228         @WindowingMode
229         private int mWindowingMode = WINDOWING_MODE_UNDEFINED;
230 
231         @Nullable
232         private IBinder mPairedPrimaryFragmentToken;
233 
234         @Nullable
235         private IBinder mPairedActivityToken;
236 
Builder(@onNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken)237         public Builder(@NonNull TaskFragmentOrganizerToken organizer,
238                 @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken) {
239             mOrganizer = organizer;
240             mFragmentToken = fragmentToken;
241             mOwnerToken = ownerToken;
242         }
243 
244         /**
245          * Sets the initial relative bounds for the TaskFragment in parent coordinate.
246          * Set to empty to fill parent.
247          */
248         @NonNull
setInitialRelativeBounds(@onNull Rect bounds)249         public Builder setInitialRelativeBounds(@NonNull Rect bounds) {
250             mInitialRelativeBounds.set(bounds);
251             return this;
252         }
253 
254         /** Sets the initial windowing mode for the TaskFragment. */
255         @NonNull
setWindowingMode(@indowingMode int windowingMode)256         public Builder setWindowingMode(@WindowingMode int windowingMode) {
257             mWindowingMode = windowingMode;
258             return this;
259         }
260 
261         /**
262          * Sets the fragment token of the paired primary TaskFragment.
263          * When it is set, the new TaskFragment will be positioned right above the paired
264          * TaskFragment. Otherwise, the new TaskFragment will be positioned on the top of the Task
265          * by default.
266          *
267          * This is needed in case we need to launch a placeholder Activity to split below a
268          * transparent always-expand Activity.
269          *
270          * This should not be used with {@link #setPairedActivityToken}.
271          *
272          * TODO(b/232476698): remove the hide with adding CTS for this in next release.
273          * @hide
274          */
275         @NonNull
setPairedPrimaryFragmentToken(@ullable IBinder fragmentToken)276         public Builder setPairedPrimaryFragmentToken(@Nullable IBinder fragmentToken) {
277             mPairedPrimaryFragmentToken = fragmentToken;
278             return this;
279         }
280 
281         /**
282          * Sets the Activity token to place the new TaskFragment on top of.
283          * When it is set, the new TaskFragment will be positioned right above the target Activity.
284          * Otherwise, the new TaskFragment will be positioned on the top of the Task by default.
285          *
286          * This is needed in case we need to place an Activity into TaskFragment to launch
287          * placeholder below a transparent always-expand Activity, or when there is another Intent
288          * being started in a TaskFragment above.
289          *
290          * This should not be used with {@link #setPairedPrimaryFragmentToken}.
291          *
292          * TODO(b/232476698): remove the hide with adding CTS for this in next release.
293          * @hide
294          */
295         @NonNull
setPairedActivityToken(@ullable IBinder activityToken)296         public Builder setPairedActivityToken(@Nullable IBinder activityToken) {
297             mPairedActivityToken = activityToken;
298             return this;
299         }
300 
301         /** Constructs the options to create TaskFragment with. */
302         @NonNull
build()303         public TaskFragmentCreationParams build() {
304             return new TaskFragmentCreationParams(mOrganizer, mFragmentToken, mOwnerToken,
305                     mInitialRelativeBounds, mWindowingMode, mPairedPrimaryFragmentToken,
306                     mPairedActivityToken);
307         }
308     }
309 }
310