blob: 74fc15acf3eabd4eb890a65227a9b440e9cea992 [file] [log] [blame]
Svetoslav8e3feb12014-02-24 13:46:47 -08001/*
2 * Copyright (C) 2014 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
17package android.view;
18
19import android.graphics.Rect;
20import android.os.IBinder;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.util.Pools;
Phil Weaver8583ae82018-02-13 11:01:24 -080024import android.view.accessibility.AccessibilityNodeInfo;
Svetoslav8e3feb12014-02-24 13:46:47 -080025
26import java.util.ArrayList;
27import java.util.List;
28
29/**
30 * This class represents information about a window from the
31 * window manager to another part of the system.
32 *
33 * @hide
34 */
35public class WindowInfo implements Parcelable {
36 private static final int MAX_POOL_SIZE = 10;
37
38 private static final Pools.SynchronizedPool<WindowInfo> sPool =
39 new Pools.SynchronizedPool<WindowInfo>(MAX_POOL_SIZE);
40
41 public int type;
42 public int layer;
43 public IBinder token;
44 public IBinder parentToken;
Phil Weaver5dc3ebc2017-08-16 13:04:20 -070045 public IBinder activityToken;
Svetoslav8e3feb12014-02-24 13:46:47 -080046 public boolean focused;
47 public final Rect boundsInScreen = new Rect();
48 public List<IBinder> childTokens;
Phil Weaver396d5492016-03-22 17:53:50 -070049 public CharSequence title;
Phil Weaver8583ae82018-02-13 11:01:24 -080050 public long accessibilityIdOfAnchor = AccessibilityNodeInfo.UNDEFINED_NODE_ID;
Phil Weaverf00cd142017-03-03 13:44:00 -080051 public boolean inPictureInPicture;
Jackal Guoac2b62e2018-08-22 18:28:46 +080052 public boolean hasFlagWatchOutsideTouch;
Svetoslav8e3feb12014-02-24 13:46:47 -080053
54 private WindowInfo() {
55 /* do nothing - hide constructor */
56 }
57
58 public static WindowInfo obtain() {
59 WindowInfo window = sPool.acquire();
60 if (window == null) {
61 window = new WindowInfo();
62 }
63 return window;
64 }
65
66 public static WindowInfo obtain(WindowInfo other) {
67 WindowInfo window = obtain();
68 window.type = other.type;
69 window.layer = other.layer;
70 window.token = other.token;
71 window.parentToken = other.parentToken;
Phil Weaver5dc3ebc2017-08-16 13:04:20 -070072 window.activityToken = other.activityToken;
Svetoslav8e3feb12014-02-24 13:46:47 -080073 window.focused = other.focused;
74 window.boundsInScreen.set(other.boundsInScreen);
Phil Weaver396d5492016-03-22 17:53:50 -070075 window.title = other.title;
76 window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor;
Phil Weaverf00cd142017-03-03 13:44:00 -080077 window.inPictureInPicture = other.inPictureInPicture;
Jackal Guoac2b62e2018-08-22 18:28:46 +080078 window.hasFlagWatchOutsideTouch = other.hasFlagWatchOutsideTouch;
Svetoslav8e3feb12014-02-24 13:46:47 -080079
80 if (other.childTokens != null && !other.childTokens.isEmpty()) {
81 if (window.childTokens == null) {
82 window.childTokens = new ArrayList<IBinder>(other.childTokens);
83 } else {
84 window.childTokens.addAll(other.childTokens);
85 }
86 }
87
88 return window;
89 }
90
91 public void recycle() {
92 clear();
93 sPool.release(this);
94 }
95
96 @Override
97 public int describeContents() {
98 return 0;
99 }
100
101 @Override
102 public void writeToParcel(Parcel parcel, int flags) {
103 parcel.writeInt(type);
104 parcel.writeInt(layer);
105 parcel.writeStrongBinder(token);
106 parcel.writeStrongBinder(parentToken);
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700107 parcel.writeStrongBinder(activityToken);
Svetoslav8e3feb12014-02-24 13:46:47 -0800108 parcel.writeInt(focused ? 1 : 0);
109 boundsInScreen.writeToParcel(parcel, flags);
Phil Weaver396d5492016-03-22 17:53:50 -0700110 parcel.writeCharSequence(title);
Phil Weaver8583ae82018-02-13 11:01:24 -0800111 parcel.writeLong(accessibilityIdOfAnchor);
Phil Weaverf00cd142017-03-03 13:44:00 -0800112 parcel.writeInt(inPictureInPicture ? 1 : 0);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800113 parcel.writeInt(hasFlagWatchOutsideTouch ? 1 : 0);
Svetoslav8e3feb12014-02-24 13:46:47 -0800114
115 if (childTokens != null && !childTokens.isEmpty()) {
116 parcel.writeInt(1);
117 parcel.writeBinderList(childTokens);
118 } else {
119 parcel.writeInt(0);
120 }
121 }
122
123 @Override
124 public String toString() {
125 StringBuilder builder = new StringBuilder();
126 builder.append("WindowInfo[");
Phil Weaver396d5492016-03-22 17:53:50 -0700127 builder.append("title=").append(title);
128 builder.append(", type=").append(type);
Svetoslav8e3feb12014-02-24 13:46:47 -0800129 builder.append(", layer=").append(layer);
130 builder.append(", token=").append(token);
Svetoslavf7174e82014-06-12 11:29:35 -0700131 builder.append(", bounds=").append(boundsInScreen);
Svetoslav8e3feb12014-02-24 13:46:47 -0800132 builder.append(", parent=").append(parentToken);
133 builder.append(", focused=").append(focused);
134 builder.append(", children=").append(childTokens);
Phil Weaver396d5492016-03-22 17:53:50 -0700135 builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800136 builder.append(", pictureInPicture=").append(inPictureInPicture);
137 builder.append(", watchOutsideTouch=").append(hasFlagWatchOutsideTouch);
Svetoslav8e3feb12014-02-24 13:46:47 -0800138 builder.append(']');
139 return builder.toString();
140 }
141
142 private void initFromParcel(Parcel parcel) {
143 type = parcel.readInt();
144 layer = parcel.readInt();
145 token = parcel.readStrongBinder();
146 parentToken = parcel.readStrongBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700147 activityToken = parcel.readStrongBinder();
Svetoslav8e3feb12014-02-24 13:46:47 -0800148 focused = (parcel.readInt() == 1);
149 boundsInScreen.readFromParcel(parcel);
Phil Weaver396d5492016-03-22 17:53:50 -0700150 title = parcel.readCharSequence();
Phil Weaver8583ae82018-02-13 11:01:24 -0800151 accessibilityIdOfAnchor = parcel.readLong();
Phil Weaverf00cd142017-03-03 13:44:00 -0800152 inPictureInPicture = (parcel.readInt() == 1);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800153 hasFlagWatchOutsideTouch = (parcel.readInt() == 1);
Svetoslav8e3feb12014-02-24 13:46:47 -0800154
155 final boolean hasChildren = (parcel.readInt() == 1);
156 if (hasChildren) {
157 if (childTokens == null) {
158 childTokens = new ArrayList<IBinder>();
159 }
160 parcel.readBinderList(childTokens);
161 }
162 }
163
164 private void clear() {
165 type = 0;
166 layer = 0;
167 token = null;
168 parentToken = null;
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700169 activityToken = null;
Svetoslav8e3feb12014-02-24 13:46:47 -0800170 focused = false;
171 boundsInScreen.setEmpty();
172 if (childTokens != null) {
173 childTokens.clear();
174 }
Phil Weaverf00cd142017-03-03 13:44:00 -0800175 inPictureInPicture = false;
Jackal Guoac2b62e2018-08-22 18:28:46 +0800176 hasFlagWatchOutsideTouch = false;
Svetoslav8e3feb12014-02-24 13:46:47 -0800177 }
178
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700179 public static final @android.annotation.NonNull Parcelable.Creator<WindowInfo> CREATOR =
Svetoslav8e3feb12014-02-24 13:46:47 -0800180 new Creator<WindowInfo>() {
181 @Override
182 public WindowInfo createFromParcel(Parcel parcel) {
183 WindowInfo window = obtain();
184 window.initFromParcel(parcel);
185 return window;
186 }
187
188 @Override
189 public WindowInfo[] newArray(int size) {
190 return new WindowInfo[size];
191 }
192 };
193}