Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.graphics.Rect; |
| 20 | import android.os.IBinder; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.util.Pools; |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 24 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import 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 | */ |
| 35 | public 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 Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 45 | public IBinder activityToken; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 46 | public boolean focused; |
| 47 | public final Rect boundsInScreen = new Rect(); |
| 48 | public List<IBinder> childTokens; |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 49 | public CharSequence title; |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 50 | public long accessibilityIdOfAnchor = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 51 | public boolean inPictureInPicture; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 52 | public boolean hasFlagWatchOutsideTouch; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 53 | |
| 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 Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 72 | window.activityToken = other.activityToken; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 73 | window.focused = other.focused; |
| 74 | window.boundsInScreen.set(other.boundsInScreen); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 75 | window.title = other.title; |
| 76 | window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 77 | window.inPictureInPicture = other.inPictureInPicture; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 78 | window.hasFlagWatchOutsideTouch = other.hasFlagWatchOutsideTouch; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 79 | |
| 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 Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 107 | parcel.writeStrongBinder(activityToken); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 108 | parcel.writeInt(focused ? 1 : 0); |
| 109 | boundsInScreen.writeToParcel(parcel, flags); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 110 | parcel.writeCharSequence(title); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 111 | parcel.writeLong(accessibilityIdOfAnchor); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 112 | parcel.writeInt(inPictureInPicture ? 1 : 0); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 113 | parcel.writeInt(hasFlagWatchOutsideTouch ? 1 : 0); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 114 | |
| 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 Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 127 | builder.append("title=").append(title); |
| 128 | builder.append(", type=").append(type); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 129 | builder.append(", layer=").append(layer); |
| 130 | builder.append(", token=").append(token); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 131 | builder.append(", bounds=").append(boundsInScreen); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 132 | builder.append(", parent=").append(parentToken); |
| 133 | builder.append(", focused=").append(focused); |
| 134 | builder.append(", children=").append(childTokens); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 135 | builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 136 | builder.append(", pictureInPicture=").append(inPictureInPicture); |
| 137 | builder.append(", watchOutsideTouch=").append(hasFlagWatchOutsideTouch); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 138 | 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 Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 147 | activityToken = parcel.readStrongBinder(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 148 | focused = (parcel.readInt() == 1); |
| 149 | boundsInScreen.readFromParcel(parcel); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 150 | title = parcel.readCharSequence(); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 151 | accessibilityIdOfAnchor = parcel.readLong(); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 152 | inPictureInPicture = (parcel.readInt() == 1); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 153 | hasFlagWatchOutsideTouch = (parcel.readInt() == 1); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 154 | |
| 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 Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 169 | activityToken = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 170 | focused = false; |
| 171 | boundsInScreen.setEmpty(); |
| 172 | if (childTokens != null) { |
| 173 | childTokens.clear(); |
| 174 | } |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 175 | inPictureInPicture = false; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 176 | hasFlagWatchOutsideTouch = false; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | public static final Parcelable.Creator<WindowInfo> CREATOR = |
| 180 | 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 | } |