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