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 | |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 19 | import android.graphics.Region; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 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; |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 47 | public Region regionInScreen = new Region(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 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; |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 53 | public int displayId = Display.INVALID_DISPLAY; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 54 | |
| 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(); |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 69 | window.displayId = other.displayId; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 70 | window.type = other.type; |
| 71 | window.layer = other.layer; |
| 72 | window.token = other.token; |
| 73 | window.parentToken = other.parentToken; |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 74 | window.activityToken = other.activityToken; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 75 | window.focused = other.focused; |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 76 | window.regionInScreen.set(other.regionInScreen); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 77 | window.title = other.title; |
| 78 | window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 79 | window.inPictureInPicture = other.inPictureInPicture; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 80 | window.hasFlagWatchOutsideTouch = other.hasFlagWatchOutsideTouch; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 81 | |
| 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) { |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 105 | parcel.writeInt(displayId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 106 | parcel.writeInt(type); |
| 107 | parcel.writeInt(layer); |
| 108 | parcel.writeStrongBinder(token); |
| 109 | parcel.writeStrongBinder(parentToken); |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 110 | parcel.writeStrongBinder(activityToken); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 111 | parcel.writeInt(focused ? 1 : 0); |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 112 | regionInScreen.writeToParcel(parcel, flags); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 113 | parcel.writeCharSequence(title); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 114 | parcel.writeLong(accessibilityIdOfAnchor); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 115 | parcel.writeInt(inPictureInPicture ? 1 : 0); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 116 | parcel.writeInt(hasFlagWatchOutsideTouch ? 1 : 0); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 117 | |
| 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 Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 130 | builder.append("title=").append(title); |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 131 | builder.append(", displayId=").append(displayId); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 132 | builder.append(", type=").append(type); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 133 | builder.append(", layer=").append(layer); |
| 134 | builder.append(", token=").append(token); |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 135 | builder.append(", region=").append(regionInScreen); |
| 136 | builder.append(", bounds=").append(regionInScreen.getBounds()); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 137 | builder.append(", parent=").append(parentToken); |
| 138 | builder.append(", focused=").append(focused); |
| 139 | builder.append(", children=").append(childTokens); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 140 | builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 141 | builder.append(", pictureInPicture=").append(inPictureInPicture); |
| 142 | builder.append(", watchOutsideTouch=").append(hasFlagWatchOutsideTouch); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 143 | builder.append(']'); |
| 144 | return builder.toString(); |
| 145 | } |
| 146 | |
| 147 | private void initFromParcel(Parcel parcel) { |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 148 | displayId = parcel.readInt(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 149 | type = parcel.readInt(); |
| 150 | layer = parcel.readInt(); |
| 151 | token = parcel.readStrongBinder(); |
| 152 | parentToken = parcel.readStrongBinder(); |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 153 | activityToken = parcel.readStrongBinder(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 154 | focused = (parcel.readInt() == 1); |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 155 | regionInScreen = Region.CREATOR.createFromParcel(parcel); |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 156 | title = parcel.readCharSequence(); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 157 | accessibilityIdOfAnchor = parcel.readLong(); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 158 | inPictureInPicture = (parcel.readInt() == 1); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 159 | hasFlagWatchOutsideTouch = (parcel.readInt() == 1); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 160 | |
| 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() { |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 171 | displayId = Display.INVALID_DISPLAY; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 172 | type = 0; |
| 173 | layer = 0; |
| 174 | token = null; |
| 175 | parentToken = null; |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 176 | activityToken = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 177 | focused = false; |
Jackal Guo | f382371 | 2019-05-20 10:16:06 +0800 | [diff] [blame] | 178 | regionInScreen.setEmpty(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 179 | if (childTokens != null) { |
| 180 | childTokens.clear(); |
| 181 | } |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 182 | inPictureInPicture = false; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 183 | hasFlagWatchOutsideTouch = false; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 186 | public static final @android.annotation.NonNull Parcelable.Creator<WindowInfo> CREATOR = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 187 | 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 | } |