blob: 57dfc62b4f8fbbdac75ab5f719ecd3ab100edfb3 [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
Jackal Guof3823712019-05-20 10:16:06 +080019import android.graphics.Region;
Svetoslav8e3feb12014-02-24 13:46:47 -080020import 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;
Jackal Guof3823712019-05-20 10:16:06 +080047 public Region regionInScreen = new Region();
Svetoslav8e3feb12014-02-24 13:46:47 -080048 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;
RyanlwLin25a36512019-05-28 21:01:52 +080053 public int displayId = Display.INVALID_DISPLAY;
Svetoslav8e3feb12014-02-24 13:46:47 -080054
55 private WindowInfo() {
56 /* do nothing - hide constructor */
57 }
58
59 public static WindowInfo obtain() {
60 WindowInfo window = sPool.acquire();
61 if (window == null) {
62 window = new WindowInfo();
63 }
64 return window;
65 }
66
67 public static WindowInfo obtain(WindowInfo other) {
68 WindowInfo window = obtain();
RyanlwLin25a36512019-05-28 21:01:52 +080069 window.displayId = other.displayId;
Svetoslav8e3feb12014-02-24 13:46:47 -080070 window.type = other.type;
71 window.layer = other.layer;
72 window.token = other.token;
73 window.parentToken = other.parentToken;
Phil Weaver5dc3ebc2017-08-16 13:04:20 -070074 window.activityToken = other.activityToken;
Svetoslav8e3feb12014-02-24 13:46:47 -080075 window.focused = other.focused;
Jackal Guof3823712019-05-20 10:16:06 +080076 window.regionInScreen.set(other.regionInScreen);
Phil Weaver396d5492016-03-22 17:53:50 -070077 window.title = other.title;
78 window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor;
Phil Weaverf00cd142017-03-03 13:44:00 -080079 window.inPictureInPicture = other.inPictureInPicture;
Jackal Guoac2b62e2018-08-22 18:28:46 +080080 window.hasFlagWatchOutsideTouch = other.hasFlagWatchOutsideTouch;
Svetoslav8e3feb12014-02-24 13:46:47 -080081
82 if (other.childTokens != null && !other.childTokens.isEmpty()) {
83 if (window.childTokens == null) {
84 window.childTokens = new ArrayList<IBinder>(other.childTokens);
85 } else {
86 window.childTokens.addAll(other.childTokens);
87 }
88 }
89
90 return window;
91 }
92
93 public void recycle() {
94 clear();
95 sPool.release(this);
96 }
97
98 @Override
99 public int describeContents() {
100 return 0;
101 }
102
103 @Override
104 public void writeToParcel(Parcel parcel, int flags) {
RyanlwLin25a36512019-05-28 21:01:52 +0800105 parcel.writeInt(displayId);
Svetoslav8e3feb12014-02-24 13:46:47 -0800106 parcel.writeInt(type);
107 parcel.writeInt(layer);
108 parcel.writeStrongBinder(token);
109 parcel.writeStrongBinder(parentToken);
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700110 parcel.writeStrongBinder(activityToken);
Svetoslav8e3feb12014-02-24 13:46:47 -0800111 parcel.writeInt(focused ? 1 : 0);
Jackal Guof3823712019-05-20 10:16:06 +0800112 regionInScreen.writeToParcel(parcel, flags);
Phil Weaver396d5492016-03-22 17:53:50 -0700113 parcel.writeCharSequence(title);
Phil Weaver8583ae82018-02-13 11:01:24 -0800114 parcel.writeLong(accessibilityIdOfAnchor);
Phil Weaverf00cd142017-03-03 13:44:00 -0800115 parcel.writeInt(inPictureInPicture ? 1 : 0);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800116 parcel.writeInt(hasFlagWatchOutsideTouch ? 1 : 0);
Svetoslav8e3feb12014-02-24 13:46:47 -0800117
118 if (childTokens != null && !childTokens.isEmpty()) {
119 parcel.writeInt(1);
120 parcel.writeBinderList(childTokens);
121 } else {
122 parcel.writeInt(0);
123 }
124 }
125
126 @Override
127 public String toString() {
128 StringBuilder builder = new StringBuilder();
129 builder.append("WindowInfo[");
Phil Weaver396d5492016-03-22 17:53:50 -0700130 builder.append("title=").append(title);
RyanlwLin25a36512019-05-28 21:01:52 +0800131 builder.append(", displayId=").append(displayId);
Phil Weaver396d5492016-03-22 17:53:50 -0700132 builder.append(", type=").append(type);
Svetoslav8e3feb12014-02-24 13:46:47 -0800133 builder.append(", layer=").append(layer);
134 builder.append(", token=").append(token);
Jackal Guof3823712019-05-20 10:16:06 +0800135 builder.append(", region=").append(regionInScreen);
136 builder.append(", bounds=").append(regionInScreen.getBounds());
Svetoslav8e3feb12014-02-24 13:46:47 -0800137 builder.append(", parent=").append(parentToken);
138 builder.append(", focused=").append(focused);
139 builder.append(", children=").append(childTokens);
Phil Weaver396d5492016-03-22 17:53:50 -0700140 builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800141 builder.append(", pictureInPicture=").append(inPictureInPicture);
142 builder.append(", watchOutsideTouch=").append(hasFlagWatchOutsideTouch);
Svetoslav8e3feb12014-02-24 13:46:47 -0800143 builder.append(']');
144 return builder.toString();
145 }
146
147 private void initFromParcel(Parcel parcel) {
RyanlwLin25a36512019-05-28 21:01:52 +0800148 displayId = parcel.readInt();
Svetoslav8e3feb12014-02-24 13:46:47 -0800149 type = parcel.readInt();
150 layer = parcel.readInt();
151 token = parcel.readStrongBinder();
152 parentToken = parcel.readStrongBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700153 activityToken = parcel.readStrongBinder();
Svetoslav8e3feb12014-02-24 13:46:47 -0800154 focused = (parcel.readInt() == 1);
Jackal Guof3823712019-05-20 10:16:06 +0800155 regionInScreen = Region.CREATOR.createFromParcel(parcel);
Phil Weaver396d5492016-03-22 17:53:50 -0700156 title = parcel.readCharSequence();
Phil Weaver8583ae82018-02-13 11:01:24 -0800157 accessibilityIdOfAnchor = parcel.readLong();
Phil Weaverf00cd142017-03-03 13:44:00 -0800158 inPictureInPicture = (parcel.readInt() == 1);
Jackal Guoac2b62e2018-08-22 18:28:46 +0800159 hasFlagWatchOutsideTouch = (parcel.readInt() == 1);
Svetoslav8e3feb12014-02-24 13:46:47 -0800160
161 final boolean hasChildren = (parcel.readInt() == 1);
162 if (hasChildren) {
163 if (childTokens == null) {
164 childTokens = new ArrayList<IBinder>();
165 }
166 parcel.readBinderList(childTokens);
167 }
168 }
169
170 private void clear() {
RyanlwLin25a36512019-05-28 21:01:52 +0800171 displayId = Display.INVALID_DISPLAY;
Svetoslav8e3feb12014-02-24 13:46:47 -0800172 type = 0;
173 layer = 0;
174 token = null;
175 parentToken = null;
Phil Weaver5dc3ebc2017-08-16 13:04:20 -0700176 activityToken = null;
Svetoslav8e3feb12014-02-24 13:46:47 -0800177 focused = false;
Jackal Guof3823712019-05-20 10:16:06 +0800178 regionInScreen.setEmpty();
Svetoslav8e3feb12014-02-24 13:46:47 -0800179 if (childTokens != null) {
180 childTokens.clear();
181 }
Phil Weaverf00cd142017-03-03 13:44:00 -0800182 inPictureInPicture = false;
Jackal Guoac2b62e2018-08-22 18:28:46 +0800183 hasFlagWatchOutsideTouch = false;
Svetoslav8e3feb12014-02-24 13:46:47 -0800184 }
185
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700186 public static final @android.annotation.NonNull Parcelable.Creator<WindowInfo> CREATOR =
Svetoslav8e3feb12014-02-24 13:46:47 -0800187 new Creator<WindowInfo>() {
188 @Override
189 public WindowInfo createFromParcel(Parcel parcel) {
190 WindowInfo window = obtain();
191 window.initFromParcel(parcel);
192 return window;
193 }
194
195 @Override
196 public WindowInfo[] newArray(int size) {
197 return new WindowInfo[size];
198 }
199 };
200}