| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.graphics.Matrix; |
| 22 |
import android.graphics.Region; |
| 23 |
import android.gui.TouchOcclusionMode; |
| 24 |
import android.os.IBinder; |
| 25 |
import android.os.InputConfig; |
| 26 |
|
| 27 |
import java.lang.annotation.Retention; |
| 28 |
import java.lang.annotation.RetentionPolicy; |
| 29 |
import java.lang.ref.WeakReference; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public final class InputWindowHandle { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
@Retention(RetentionPolicy.SOURCE) |
| 52 |
@IntDef(flag = true, value = { |
| 53 |
InputConfig.DEFAULT, |
| 54 |
InputConfig.NO_INPUT_CHANNEL, |
| 55 |
InputConfig.NOT_FOCUSABLE, |
| 56 |
InputConfig.NOT_TOUCHABLE, |
| 57 |
InputConfig.PREVENT_SPLITTING, |
| 58 |
InputConfig.DUPLICATE_TOUCH_TO_WALLPAPER, |
| 59 |
InputConfig.IS_WALLPAPER, |
| 60 |
InputConfig.PAUSE_DISPATCHING, |
| 61 |
InputConfig.TRUSTED_OVERLAY, |
| 62 |
InputConfig.WATCH_OUTSIDE_TOUCH, |
| 63 |
InputConfig.SLIPPERY, |
| 64 |
InputConfig.DISABLE_USER_ACTIVITY, |
| 65 |
InputConfig.SPY, |
| 66 |
InputConfig.INTERCEPTS_STYLUS, |
| 67 |
}) |
| 68 |
public @interface InputConfigFlags {} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@SuppressWarnings("unused") |
| 73 |
private long ptr; |
| 74 |
|
| 75 |
|
| 76 |
public InputApplicationHandle inputApplicationHandle; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public IBinder token; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@Nullable |
| 86 |
private IBinder windowToken; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
private IWindow window; |
| 92 |
|
| 93 |
|
| 94 |
public String name; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public int layoutParamsFlags; |
| 99 |
public int layoutParamsType; |
| 100 |
|
| 101 |
|
| 102 |
public long dispatchingTimeoutMillis; |
| 103 |
|
| 104 |
|
| 105 |
public int frameLeft; |
| 106 |
public int frameTop; |
| 107 |
public int frameRight; |
| 108 |
public int frameBottom; |
| 109 |
|
| 110 |
public int surfaceInset; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public float scaleFactor; |
| 115 |
|
| 116 |
|
| 117 |
public final Region touchableRegion = new Region(); |
| 118 |
|
| 119 |
|
| 120 |
@InputConfigFlags |
| 121 |
public int inputConfig; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public int touchOcclusionMode = TouchOcclusionMode.BLOCK_UNTRUSTED; |
| 127 |
|
| 128 |
|
| 129 |
public int ownerPid; |
| 130 |
public int ownerUid; |
| 131 |
|
| 132 |
|
| 133 |
public String packageName; |
| 134 |
|
| 135 |
|
| 136 |
public int displayId; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public boolean replaceTouchableRegionWithCrop; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public Matrix transform; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public boolean isClone; |
| 164 |
|
| 165 |
private native void nativeDispose(); |
| 166 |
|
| 167 |
public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) { |
| 168 |
this.inputApplicationHandle = inputApplicationHandle; |
| 169 |
this.displayId = displayId; |
| 170 |
} |
| 171 |
|
| 172 |
public InputWindowHandle(InputWindowHandle other) { |
| 173 |
|
| 174 |
ptr = 0; |
| 175 |
inputApplicationHandle = new InputApplicationHandle(other.inputApplicationHandle); |
| 176 |
token = other.token; |
| 177 |
windowToken = other.windowToken; |
| 178 |
window = other.window; |
| 179 |
name = other.name; |
| 180 |
layoutParamsFlags = other.layoutParamsFlags; |
| 181 |
layoutParamsType = other.layoutParamsType; |
| 182 |
dispatchingTimeoutMillis = other.dispatchingTimeoutMillis; |
| 183 |
frameLeft = other.frameLeft; |
| 184 |
frameTop = other.frameTop; |
| 185 |
frameRight = other.frameRight; |
| 186 |
frameBottom = other.frameBottom; |
| 187 |
surfaceInset = other.surfaceInset; |
| 188 |
scaleFactor = other.scaleFactor; |
| 189 |
touchableRegion.set(other.touchableRegion); |
| 190 |
inputConfig = other.inputConfig; |
| 191 |
touchOcclusionMode = other.touchOcclusionMode; |
| 192 |
ownerPid = other.ownerPid; |
| 193 |
ownerUid = other.ownerUid; |
| 194 |
packageName = other.packageName; |
| 195 |
displayId = other.displayId; |
| 196 |
touchableRegionSurfaceControl = other.touchableRegionSurfaceControl; |
| 197 |
replaceTouchableRegionWithCrop = other.replaceTouchableRegionWithCrop; |
| 198 |
if (other.transform != null) { |
| 199 |
transform = new Matrix(); |
| 200 |
transform.set(other.transform); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
@Override |
| 205 |
public String toString() { |
| 206 |
return new StringBuilder(name != null ? name : "") |
| 207 |
.append(", frame=[").append(frameLeft).append(",").append(frameTop).append(",") |
| 208 |
.append(frameRight).append(",").append(frameBottom).append("]") |
| 209 |
.append(", touchableRegion=").append(touchableRegion) |
| 210 |
.append(", scaleFactor=").append(scaleFactor) |
| 211 |
.append(", transform=").append(transform) |
| 212 |
.append(", windowToken=").append(windowToken) |
| 213 |
.append(", isClone=").append(isClone) |
| 214 |
.toString(); |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
@Override |
| 219 |
protected void finalize() throws Throwable { |
| 220 |
try { |
| 221 |
nativeDispose(); |
| 222 |
} finally { |
| 223 |
super.finalize(); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
public void replaceTouchableRegionWithCrop(@Nullable SurfaceControl bounds) { |
| 235 |
setTouchableRegionCrop(bounds); |
| 236 |
replaceTouchableRegionWithCrop = true; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) { |
| 243 |
touchableRegionSurfaceControl = new WeakReference<>(bounds); |
| 244 |
} |
| 245 |
|
| 246 |
public void setWindowToken(IWindow iwindow) { |
| 247 |
windowToken = iwindow.asBinder(); |
| 248 |
window = iwindow; |
| 249 |
} |
| 250 |
|
| 251 |
public IWindow getWindow() { |
| 252 |
if (window != null) { |
| 253 |
return window; |
| 254 |
} |
| 255 |
window = IWindow.Stub.asInterface(windowToken); |
| 256 |
return window; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public void setInputConfig(@InputConfigFlags int inputConfig, boolean value) { |
| 265 |
if (value) { |
| 266 |
this.inputConfig |= inputConfig; |
| 267 |
return; |
| 268 |
} |
| 269 |
this.inputConfig &= ~inputConfig; |
| 270 |
} |
| 271 |
} |