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 android.window; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.graphics.Rect; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * Stores the window information about a particular Activity. 27 * It contains the info that is not part of {@link android.content.res.Configuration}. 28 * @hide 29 */ 30 public final class ActivityWindowInfo implements Parcelable { 31 32 private boolean mIsEmbedded; 33 34 @NonNull 35 private final Rect mTaskBounds = new Rect(); 36 37 @NonNull 38 private final Rect mTaskFragmentBounds = new Rect(); 39 ActivityWindowInfo()40 public ActivityWindowInfo() {} 41 ActivityWindowInfo(@onNull ActivityWindowInfo info)42 public ActivityWindowInfo(@NonNull ActivityWindowInfo info) { 43 set(info); 44 } 45 46 /** Copies fields from {@code info}. */ set(@onNull ActivityWindowInfo info)47 public void set(@NonNull ActivityWindowInfo info) { 48 set(info.mIsEmbedded, info.mTaskBounds, info.mTaskFragmentBounds); 49 } 50 51 /** Sets to the given values. */ set(boolean isEmbedded, @NonNull Rect taskBounds, @NonNull Rect taskFragmentBounds)52 public void set(boolean isEmbedded, @NonNull Rect taskBounds, 53 @NonNull Rect taskFragmentBounds) { 54 mIsEmbedded = isEmbedded; 55 mTaskBounds.set(taskBounds); 56 mTaskFragmentBounds.set(taskFragmentBounds); 57 } 58 59 /** 60 * Whether this activity is embedded, which means it is a TaskFragment that doesn't fill the 61 * leaf Task. 62 */ isEmbedded()63 public boolean isEmbedded() { 64 return mIsEmbedded; 65 } 66 67 /** 68 * The bounds of the leaf Task window in display space. 69 */ 70 @NonNull getTaskBounds()71 public Rect getTaskBounds() { 72 return mTaskBounds; 73 } 74 75 /** 76 * The bounds of the leaf TaskFragment window in display space. 77 * This can be referring to the bounds of the same window as {@link #getTaskBounds()} when 78 * the activity is not embedded. 79 */ 80 @NonNull getTaskFragmentBounds()81 public Rect getTaskFragmentBounds() { 82 return mTaskFragmentBounds; 83 } 84 ActivityWindowInfo(@onNull Parcel in)85 private ActivityWindowInfo(@NonNull Parcel in) { 86 mIsEmbedded = in.readBoolean(); 87 mTaskBounds.readFromParcel(in); 88 mTaskFragmentBounds.readFromParcel(in); 89 } 90 91 @Override writeToParcel(@onNull Parcel dest, int flags)92 public void writeToParcel(@NonNull Parcel dest, int flags) { 93 dest.writeBoolean(mIsEmbedded); 94 mTaskBounds.writeToParcel(dest, flags); 95 mTaskFragmentBounds.writeToParcel(dest, flags); 96 } 97 98 @NonNull 99 public static final Creator<ActivityWindowInfo> CREATOR = 100 new Creator<>() { 101 @Override 102 public ActivityWindowInfo createFromParcel(@NonNull Parcel in) { 103 return new ActivityWindowInfo(in); 104 } 105 106 @Override 107 public ActivityWindowInfo[] newArray(int size) { 108 return new ActivityWindowInfo[size]; 109 } 110 }; 111 112 @Override describeContents()113 public int describeContents() { 114 return 0; 115 } 116 117 @Override equals(@ullable Object o)118 public boolean equals(@Nullable Object o) { 119 if (this == o) { 120 return true; 121 } 122 if (o == null || getClass() != o.getClass()) { 123 return false; 124 } 125 final ActivityWindowInfo other = (ActivityWindowInfo) o; 126 return mIsEmbedded == other.mIsEmbedded 127 && mTaskBounds.equals(other.mTaskBounds) 128 && mTaskFragmentBounds.equals(other.mTaskFragmentBounds); 129 } 130 131 @Override hashCode()132 public int hashCode() { 133 int result = 17; 134 result = 31 * result + (mIsEmbedded ? 1 : 0); 135 result = 31 * result + mTaskBounds.hashCode(); 136 result = 31 * result + mTaskFragmentBounds.hashCode(); 137 return result; 138 } 139 140 @Override toString()141 public String toString() { 142 return "ActivityWindowInfo{isEmbedded=" + mIsEmbedded 143 + ", taskBounds=" + mTaskBounds 144 + ", taskFragmentBounds=" + mTaskFragmentBounds 145 + "}"; 146 } 147 } 148