| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import android.app.ActivityTaskManager; |
| 20 |
import android.graphics.Matrix; |
| 21 |
import android.graphics.Region; |
| 22 |
import android.os.IBinder; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
import android.util.Pools; |
| 26 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 27 |
|
| 28 |
import java.util.ArrayList; |
| 29 |
import java.util.List; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class WindowInfo implements Parcelable { |
| 38 |
private static final int MAX_POOL_SIZE = 10; |
| 39 |
|
| 40 |
private static final Pools.SynchronizedPool<WindowInfo> sPool = |
| 41 |
new Pools.SynchronizedPool<WindowInfo>(MAX_POOL_SIZE); |
| 42 |
|
| 43 |
public int type; |
| 44 |
public int layer; |
| 45 |
public IBinder token; |
| 46 |
public IBinder parentToken; |
| 47 |
public IBinder activityToken; |
| 48 |
public boolean focused; |
| 49 |
public Region regionInScreen = new Region(); |
| 50 |
public List<IBinder> childTokens; |
| 51 |
public CharSequence title; |
| 52 |
public long accessibilityIdOfAnchor = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
| 53 |
public boolean inPictureInPicture; |
| 54 |
public boolean hasFlagWatchOutsideTouch; |
| 55 |
public int displayId = Display.INVALID_DISPLAY; |
| 56 |
public int taskId = ActivityTaskManager.INVALID_TASK_ID; |
| 57 |
|
| 58 |
|
| 59 |
public float[] mTransformMatrix = new float[9]; |
| 60 |
|
| 61 |
public MagnificationSpec mMagnificationSpec = new MagnificationSpec(); |
| 62 |
|
| 63 |
private WindowInfo() { |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
public static WindowInfo obtain() { |
| 68 |
WindowInfo window = sPool.acquire(); |
| 69 |
if (window == null) { |
| 70 |
window = new WindowInfo(); |
| 71 |
} |
| 72 |
return window; |
| 73 |
} |
| 74 |
|
| 75 |
public static WindowInfo obtain(WindowInfo other) { |
| 76 |
WindowInfo window = obtain(); |
| 77 |
window.displayId = other.displayId; |
| 78 |
window.taskId = other.taskId; |
| 79 |
window.type = other.type; |
| 80 |
window.layer = other.layer; |
| 81 |
window.token = other.token; |
| 82 |
window.parentToken = other.parentToken; |
| 83 |
window.activityToken = other.activityToken; |
| 84 |
window.focused = other.focused; |
| 85 |
window.regionInScreen.set(other.regionInScreen); |
| 86 |
window.title = other.title; |
| 87 |
window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor; |
| 88 |
window.inPictureInPicture = other.inPictureInPicture; |
| 89 |
window.hasFlagWatchOutsideTouch = other.hasFlagWatchOutsideTouch; |
| 90 |
for (int i = 0; i < window.mTransformMatrix.length; i++) { |
| 91 |
window.mTransformMatrix[i] = other.mTransformMatrix[i]; |
| 92 |
} |
| 93 |
|
| 94 |
if (other.childTokens != null && !other.childTokens.isEmpty()) { |
| 95 |
if (window.childTokens == null) { |
| 96 |
window.childTokens = new ArrayList<IBinder>(other.childTokens); |
| 97 |
} else { |
| 98 |
window.childTokens.addAll(other.childTokens); |
| 99 |
} |
| 100 |
} |
| 101 |
window.mMagnificationSpec.setTo(other.mMagnificationSpec); |
| 102 |
return window; |
| 103 |
} |
| 104 |
|
| 105 |
public void recycle() { |
| 106 |
clear(); |
| 107 |
sPool.release(this); |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public int describeContents() { |
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
@Override |
| 116 |
public void writeToParcel(Parcel parcel, int flags) { |
| 117 |
parcel.writeInt(displayId); |
| 118 |
parcel.writeInt(taskId); |
| 119 |
parcel.writeInt(type); |
| 120 |
parcel.writeInt(layer); |
| 121 |
parcel.writeStrongBinder(token); |
| 122 |
parcel.writeStrongBinder(parentToken); |
| 123 |
parcel.writeStrongBinder(activityToken); |
| 124 |
parcel.writeInt(focused ? 1 : 0); |
| 125 |
regionInScreen.writeToParcel(parcel, flags); |
| 126 |
parcel.writeCharSequence(title); |
| 127 |
parcel.writeLong(accessibilityIdOfAnchor); |
| 128 |
parcel.writeInt(inPictureInPicture ? 1 : 0); |
| 129 |
parcel.writeInt(hasFlagWatchOutsideTouch ? 1 : 0); |
| 130 |
parcel.writeFloatArray(mTransformMatrix); |
| 131 |
|
| 132 |
if (childTokens != null && !childTokens.isEmpty()) { |
| 133 |
parcel.writeInt(1); |
| 134 |
parcel.writeBinderList(childTokens); |
| 135 |
} else { |
| 136 |
parcel.writeInt(0); |
| 137 |
} |
| 138 |
mMagnificationSpec.writeToParcel(parcel, flags); |
| 139 |
} |
| 140 |
|
| 141 |
@Override |
| 142 |
public String toString() { |
| 143 |
StringBuilder builder = new StringBuilder(); |
| 144 |
builder.append("WindowInfo["); |
| 145 |
builder.append("title=").append(title); |
| 146 |
builder.append(", displayId=").append(displayId); |
| 147 |
builder.append(", taskId=").append(taskId); |
| 148 |
builder.append(", type=").append(type); |
| 149 |
builder.append(", layer=").append(layer); |
| 150 |
builder.append(", token=").append(token); |
| 151 |
builder.append(", region=").append(regionInScreen); |
| 152 |
builder.append(", bounds=").append(regionInScreen.getBounds()); |
| 153 |
builder.append(", parent=").append(parentToken); |
| 154 |
builder.append(", focused=").append(focused); |
| 155 |
builder.append(", children=").append(childTokens); |
| 156 |
builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor); |
| 157 |
builder.append(", pictureInPicture=").append(inPictureInPicture); |
| 158 |
builder.append(", watchOutsideTouch=").append(hasFlagWatchOutsideTouch); |
| 159 |
Matrix matrix = new Matrix(); |
| 160 |
matrix.setValues(mTransformMatrix); |
| 161 |
builder.append(", mTransformMatrix=").append(matrix); |
| 162 |
builder.append(", mMagnificationSpec=").append(mMagnificationSpec); |
| 163 |
builder.append(']'); |
| 164 |
return builder.toString(); |
| 165 |
} |
| 166 |
|
| 167 |
private void initFromParcel(Parcel parcel) { |
| 168 |
displayId = parcel.readInt(); |
| 169 |
taskId = parcel.readInt(); |
| 170 |
type = parcel.readInt(); |
| 171 |
layer = parcel.readInt(); |
| 172 |
token = parcel.readStrongBinder(); |
| 173 |
parentToken = parcel.readStrongBinder(); |
| 174 |
activityToken = parcel.readStrongBinder(); |
| 175 |
focused = (parcel.readInt() == 1); |
| 176 |
regionInScreen = Region.CREATOR.createFromParcel(parcel); |
| 177 |
title = parcel.readCharSequence(); |
| 178 |
accessibilityIdOfAnchor = parcel.readLong(); |
| 179 |
inPictureInPicture = (parcel.readInt() == 1); |
| 180 |
hasFlagWatchOutsideTouch = (parcel.readInt() == 1); |
| 181 |
parcel.readFloatArray(mTransformMatrix); |
| 182 |
final boolean hasChildren = (parcel.readInt() == 1); |
| 183 |
if (hasChildren) { |
| 184 |
if (childTokens == null) { |
| 185 |
childTokens = new ArrayList<IBinder>(); |
| 186 |
} |
| 187 |
parcel.readBinderList(childTokens); |
| 188 |
} |
| 189 |
mMagnificationSpec = MagnificationSpec.CREATOR.createFromParcel(parcel); |
| 190 |
} |
| 191 |
|
| 192 |
private void clear() { |
| 193 |
displayId = Display.INVALID_DISPLAY; |
| 194 |
taskId = ActivityTaskManager.INVALID_TASK_ID; |
| 195 |
type = 0; |
| 196 |
layer = 0; |
| 197 |
token = null; |
| 198 |
parentToken = null; |
| 199 |
activityToken = null; |
| 200 |
focused = false; |
| 201 |
regionInScreen.setEmpty(); |
| 202 |
if (childTokens != null) { |
| 203 |
childTokens.clear(); |
| 204 |
} |
| 205 |
inPictureInPicture = false; |
| 206 |
hasFlagWatchOutsideTouch = false; |
| 207 |
for (int i = 0; i < mTransformMatrix.length; i++) { |
| 208 |
mTransformMatrix[i] = 0; |
| 209 |
} |
| 210 |
mMagnificationSpec.clear(); |
| 211 |
} |
| 212 |
|
| 213 |
public static final @android.annotation.NonNull Parcelable.Creator<WindowInfo> CREATOR = |
| 214 |
new Creator<WindowInfo>() { |
| 215 |
@Override |
| 216 |
public WindowInfo createFromParcel(Parcel parcel) { |
| 217 |
WindowInfo window = obtain(); |
| 218 |
window.initFromParcel(parcel); |
| 219 |
return window; |
| 220 |
} |
| 221 |
|
| 222 |
@Override |
| 223 |
public WindowInfo[] newArray(int size) { |
| 224 |
return new WindowInfo[size]; |
| 225 |
} |
| 226 |
}; |
| 227 |
} |