1 /* 2 * Copyright (C) 2024 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 androidx.window.extensions.embedding; 18 19 import android.app.Activity; 20 import android.graphics.Rect; 21 import android.os.IBinder; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import androidx.annotation.NonNull; 26 import androidx.annotation.Nullable; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 /** 32 * This class holds the Parcelable data of a {@link TaskFragmentContainer}. 33 */ 34 class ParcelableTaskFragmentContainerData implements Parcelable { 35 36 /** 37 * Client-created token that uniquely identifies the task fragment container instance. 38 */ 39 @NonNull 40 final IBinder mToken; 41 42 /** 43 * The tag specified in launch options. {@code null} if this taskFragment container is not an 44 * overlay container. 45 */ 46 @Nullable 47 final String mOverlayTag; 48 49 /** 50 * The associated {@link Activity#getActivityToken()} of the overlay container. 51 * Must be {@code null} for non-overlay container. 52 * <p> 53 * If an overlay container is associated with an activity, this overlay container will be 54 * dismissed when the associated activity is destroyed. If the overlay container is visible, 55 * activity will be launched on top of the overlay container and expanded to fill the parent 56 * container. 57 */ 58 @Nullable 59 final IBinder mAssociatedActivityToken; 60 61 /** 62 * Bounds that were requested last via {@link android.window.WindowContainerTransaction}. 63 */ 64 @NonNull 65 final Rect mLastRequestedBounds; 66 67 /** 68 * Individual associated activity tokens in different containers that should be finished on 69 * exit. 70 */ 71 final List<IBinder> mActivitiesToFinishOnExit = new ArrayList<>(); 72 ParcelableTaskFragmentContainerData(@onNull IBinder token, @Nullable String overlayTag, @Nullable IBinder associatedActivityToken)73 ParcelableTaskFragmentContainerData(@NonNull IBinder token, @Nullable String overlayTag, 74 @Nullable IBinder associatedActivityToken) { 75 mToken = token; 76 mOverlayTag = overlayTag; 77 mAssociatedActivityToken = associatedActivityToken; 78 mLastRequestedBounds = new Rect(); 79 } 80 ParcelableTaskFragmentContainerData(Parcel in)81 private ParcelableTaskFragmentContainerData(Parcel in) { 82 mToken = in.readStrongBinder(); 83 mOverlayTag = in.readString(); 84 mAssociatedActivityToken = in.readStrongBinder(); 85 mLastRequestedBounds = in.readTypedObject(Rect.CREATOR); 86 in.readBinderList(mActivitiesToFinishOnExit); 87 } 88 89 public static final Creator<ParcelableTaskFragmentContainerData> CREATOR = new Creator<>() { 90 @Override 91 public ParcelableTaskFragmentContainerData createFromParcel(Parcel in) { 92 return new ParcelableTaskFragmentContainerData(in); 93 } 94 95 @Override 96 public ParcelableTaskFragmentContainerData[] newArray(int size) { 97 return new ParcelableTaskFragmentContainerData[size]; 98 } 99 }; 100 101 @Override describeContents()102 public int describeContents() { 103 return 0; 104 } 105 106 @Override writeToParcel(Parcel dest, int flags)107 public void writeToParcel(Parcel dest, int flags) { 108 dest.writeStrongBinder(mToken); 109 dest.writeString(mOverlayTag); 110 dest.writeStrongBinder(mAssociatedActivityToken); 111 dest.writeTypedObject(mLastRequestedBounds, flags); 112 dest.writeBinderList(mActivitiesToFinishOnExit); 113 } 114 } 115 116