Debian Codegraph @

core/java/android/window/TaskFragmentParentInfo.java

raw symbols SCIP
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.app.WindowConfiguration;
22 import android.content.res.Configuration;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25
26 /**
27 * The information about the parent Task of a particular TaskFragment
28 * @hide
29 */
30 public class TaskFragmentParentInfo implements Parcelable {
31 @NonNull
32 private final Configuration mConfiguration = new Configuration();
33
34 private final int mDisplayId;
35
36 private final boolean mVisible;
37
38 public TaskFragmentParentInfo(@NonNull Configuration configuration, int displayId,
39 boolean visible) {
40 mConfiguration.setTo(configuration);
41 mDisplayId = displayId;
42 mVisible = visible;
43 }
44
45 public TaskFragmentParentInfo(@NonNull TaskFragmentParentInfo info) {
46 mConfiguration.setTo(info.getConfiguration());
47 mDisplayId = info.mDisplayId;
48 mVisible = info.mVisible;
49 }
50
51 /** The {@link Configuration} of the parent Task */
52 @NonNull
53 public Configuration getConfiguration() {
54 return mConfiguration;
55 }
56
57 /**
58 * The display ID of the parent Task. {@link android.view.Display#INVALID_DISPLAY} means the
59 * Task is detached from previously associated display.
60 */
61 public int getDisplayId() {
62 return mDisplayId;
63 }
64
65 /** Whether the parent Task is visible or not */
66 public boolean isVisible() {
67 return mVisible;
68 }
69
70 /**
71 * Returns {@code true} if the parameters which are important for task fragment
72 * organizers are equal between this {@link TaskFragmentParentInfo} and {@code that}.
73 * Note that this method is usually called with
74 * {@link com.android.server.wm.WindowOrganizerController#configurationsAreEqualForOrganizer(
75 * Configuration, Configuration)} to determine if this {@link TaskFragmentParentInfo} should
76 * be dispatched to the client.
77 */
78 public boolean equalsForTaskFragmentOrganizer(@Nullable TaskFragmentParentInfo that) {
79 if (that == null) {
80 return false;
81 }
82 return getWindowingMode() == that.getWindowingMode() && mDisplayId == that.mDisplayId
83 && mVisible == that.mVisible;
84 }
85
86 @WindowConfiguration.WindowingMode
87 private int getWindowingMode() {
88 return mConfiguration.windowConfiguration.getWindowingMode();
89 }
90
91 @Override
92 public String toString() {
93 return TaskFragmentParentInfo.class.getSimpleName() + ":{"
94 + "config=" + mConfiguration
95 + ", displayId=" + mDisplayId
96 + ", visible=" + mVisible
97 + "}";
98 }
99
100 /**
101 * Indicates that whether this {@link TaskFragmentParentInfo} equals to {@code obj}.
102 * Note that {@link #equalsForTaskFragmentOrganizer(TaskFragmentParentInfo)} should be used
103 * for most cases because not all {@link Configuration} properties are interested for
104 * {@link TaskFragmentOrganizer}.
105 */
106 @Override
107 public boolean equals(Object obj) {
108 if (obj == this) {
109 return true;
110 }
111 if (!(obj instanceof TaskFragmentParentInfo)) {
112 return false;
113 }
114 final TaskFragmentParentInfo that = (TaskFragmentParentInfo) obj;
115 return mConfiguration.equals(that.mConfiguration)
116 && mDisplayId == that.mDisplayId
117 && mVisible == that.mVisible;
118 }
119
120 @Override
121 public int hashCode() {
122 int result = mConfiguration.hashCode();
123 result = 31 * result + mDisplayId;
124 result = 31 * result + (mVisible ? 1 : 0);
125 return result;
126 }
127
128 @Override
129 public void writeToParcel(@NonNull Parcel dest, int flags) {
130 mConfiguration.writeToParcel(dest, flags);
131 dest.writeInt(mDisplayId);
132 dest.writeBoolean(mVisible);
133 }
134
135 private TaskFragmentParentInfo(Parcel in) {
136 mConfiguration.readFromParcel(in);
137 mDisplayId = in.readInt();
138 mVisible = in.readBoolean();
139 }
140
141 public static final Creator<TaskFragmentParentInfo> CREATOR =
142 new Creator<TaskFragmentParentInfo>() {
143 @Override
144 public TaskFragmentParentInfo createFromParcel(Parcel in) {
145 return new TaskFragmentParentInfo(in);
146 }
147
148 @Override
149 public TaskFragmentParentInfo[] newArray(int size) {
150 return new TaskFragmentParentInfo[size];
151 }
152 };
153
154 @Override
155 public int describeContents() {
156 return 0;
157 }
158 }