• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.annotation.SuppressLint;
22 import android.annotation.TestApi;
23 import android.app.WindowConfiguration;
24 import android.content.res.Configuration;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 import android.view.SurfaceControl;
28 
29 import java.util.Objects;
30 
31 /**
32  * The information about the parent Task of a particular TaskFragment.
33  *
34  * @hide
35  */
36 @SuppressLint("UnflaggedApi") // @TestApi to replace legacy usages.
37 @TestApi
38 public final class TaskFragmentParentInfo implements Parcelable {
39     @NonNull
40     private final Configuration mConfiguration = new Configuration();
41 
42     private final int mDisplayId;
43 
44     private final int mTaskId;
45 
46     private final boolean mVisible;
47 
48     private final boolean mHasDirectActivity;
49 
50     @Nullable private final SurfaceControl mDecorSurface;
51 
52     /** @hide */
TaskFragmentParentInfo(@onNull Configuration configuration, int displayId, int taskId, boolean visible, boolean hasDirectActivity, @Nullable SurfaceControl decorSurface)53     public TaskFragmentParentInfo(@NonNull Configuration configuration, int displayId,
54             int taskId, boolean visible, boolean hasDirectActivity,
55             @Nullable SurfaceControl decorSurface) {
56         mConfiguration.setTo(configuration);
57         mDisplayId = displayId;
58         mTaskId = taskId;
59         mVisible = visible;
60         mHasDirectActivity = hasDirectActivity;
61         mDecorSurface = decorSurface;
62     }
63 
64     /** @hide */
TaskFragmentParentInfo(@onNull TaskFragmentParentInfo info)65     public TaskFragmentParentInfo(@NonNull TaskFragmentParentInfo info) {
66         mConfiguration.setTo(info.getConfiguration());
67         mDisplayId = info.mDisplayId;
68         mTaskId = info.mTaskId;
69         mVisible = info.mVisible;
70         mHasDirectActivity = info.mHasDirectActivity;
71         mDecorSurface = info.mDecorSurface;
72     }
73 
74     /**
75      * The {@link Configuration} of the parent Task
76      *
77      * @hide
78      */
79     @NonNull
getConfiguration()80     public Configuration getConfiguration() {
81         return mConfiguration;
82     }
83 
84     /**
85      * The display ID of the parent Task. {@link android.view.Display#INVALID_DISPLAY} means the
86      * Task is detached from previously associated display.
87      *
88      * @hide
89      */
getDisplayId()90     public int getDisplayId() {
91         return mDisplayId;
92     }
93 
94     /**
95      * The id of the parent Task.
96      *
97      * @hide
98      */
getTaskId()99     public int getTaskId() {
100         return mTaskId;
101     }
102 
103     /**
104      * Whether the parent Task is visible or not
105      *
106      * @hide
107      */
isVisible()108     public boolean isVisible() {
109         return mVisible;
110     }
111 
112     /**
113      * Whether the parent Task has any direct child activity, which is not embedded in any
114      * TaskFragment, or not.
115      *
116      * @hide
117      */
hasDirectActivity()118     public boolean hasDirectActivity() {
119         return mHasDirectActivity;
120     }
121 
122     /**
123      * Returns {@code true} if the parameters which are important for task fragment
124      * organizers are equal between this {@link TaskFragmentParentInfo} and {@code that}.
125      * Note that this method is usually called with
126      * {@link com.android.server.wm.WindowOrganizerController#configurationsAreEqualForOrganizer(
127      * Configuration, Configuration)} to determine if this {@link TaskFragmentParentInfo} should
128      * be dispatched to the client.
129      *
130      * @hide
131      */
equalsForTaskFragmentOrganizer(@ullable TaskFragmentParentInfo that)132     public boolean equalsForTaskFragmentOrganizer(@Nullable TaskFragmentParentInfo that) {
133         if (that == null) {
134             return false;
135         }
136         return getWindowingMode() == that.getWindowingMode() && mDisplayId == that.mDisplayId
137                 && mTaskId == that.mTaskId && mVisible == that.mVisible
138                 && mHasDirectActivity == that.mHasDirectActivity
139                 && mDecorSurface == that.mDecorSurface;
140     }
141 
142     /** @hide */
143     @Nullable
getDecorSurface()144     public SurfaceControl getDecorSurface() {
145         return mDecorSurface;
146     }
147 
148     @WindowConfiguration.WindowingMode
getWindowingMode()149     private int getWindowingMode() {
150         return mConfiguration.windowConfiguration.getWindowingMode();
151     }
152 
153     @Override
toString()154     public String toString() {
155         return TaskFragmentParentInfo.class.getSimpleName() + ":{"
156                 + "config=" + mConfiguration
157                 + ", displayId=" + mDisplayId
158                 + ", taskId=" + mTaskId
159                 + ", visible=" + mVisible
160                 + ", hasDirectActivity=" + mHasDirectActivity
161                 + ", decorSurface=" + mDecorSurface
162                 + "}";
163     }
164 
165     /**
166      * Indicates that whether this {@link TaskFragmentParentInfo} equals to {@code obj}.
167      * Note that {@link #equalsForTaskFragmentOrganizer(TaskFragmentParentInfo)} should be used
168      * for most cases because not all {@link Configuration} properties are interested for
169      * {@link TaskFragmentOrganizer}.
170      */
171     @Override
equals(Object obj)172     public boolean equals(Object obj) {
173         if (obj == this) {
174             return true;
175         }
176         if (!(obj instanceof TaskFragmentParentInfo)) {
177             return false;
178         }
179         final TaskFragmentParentInfo that = (TaskFragmentParentInfo) obj;
180         return mConfiguration.equals(that.mConfiguration)
181                 && mDisplayId == that.mDisplayId
182                 && mTaskId == that.mTaskId
183                 && mVisible == that.mVisible
184                 && mHasDirectActivity == that.mHasDirectActivity
185                 && mDecorSurface == that.mDecorSurface;
186     }
187 
188     @Override
hashCode()189     public int hashCode() {
190         int result = mConfiguration.hashCode();
191         result = 31 * result + mDisplayId;
192         result = 31 * result + mTaskId;
193         result = 31 * result + (mVisible ? 1 : 0);
194         result = 31 * result + (mHasDirectActivity ? 1 : 0);
195         result = 31 * result + Objects.hashCode(mDecorSurface);
196         return result;
197     }
198 
199     @SuppressLint("UnflaggedApi") // @TestApi to replace legacy usages.
200     @Override
writeToParcel(@onNull Parcel dest, int flags)201     public void writeToParcel(@NonNull Parcel dest, int flags) {
202         mConfiguration.writeToParcel(dest, flags);
203         dest.writeInt(mDisplayId);
204         dest.writeInt(mTaskId);
205         dest.writeBoolean(mVisible);
206         dest.writeBoolean(mHasDirectActivity);
207         dest.writeTypedObject(mDecorSurface, flags);
208     }
209 
TaskFragmentParentInfo(Parcel in)210     private TaskFragmentParentInfo(Parcel in) {
211         mConfiguration.readFromParcel(in);
212         mDisplayId = in.readInt();
213         mTaskId = in.readInt();
214         mVisible = in.readBoolean();
215         mHasDirectActivity = in.readBoolean();
216         mDecorSurface = in.readTypedObject(SurfaceControl.CREATOR);
217     }
218 
219     @SuppressLint("UnflaggedApi") // @TestApi to replace legacy usages.
220     @NonNull
221     public static final Creator<TaskFragmentParentInfo> CREATOR =
222             new Creator<TaskFragmentParentInfo>() {
223                 @Override
224                 public TaskFragmentParentInfo createFromParcel(Parcel in) {
225                     return new TaskFragmentParentInfo(in);
226                 }
227 
228                 @Override
229                 public TaskFragmentParentInfo[] newArray(int size) {
230                     return new TaskFragmentParentInfo[size];
231                 }
232             };
233 
234     @SuppressLint("UnflaggedApi") // @TestApi to replace legacy usages.
235     @Override
describeContents()236     public int describeContents() {
237         return 0;
238     }
239 }
240