1 /* 2 * Copyright (C) 2011 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 static android.view.Display.INVALID_DISPLAY; 20 21 import android.annotation.Nullable; 22 import android.graphics.Region; 23 import android.os.IBinder; 24 import android.os.TouchOcclusionMode; 25 26 import java.lang.ref.WeakReference; 27 28 /** 29 * Functions as a handle for a window that can receive input. 30 * Enables the native input dispatcher to refer indirectly to the window manager's window state. 31 * @hide 32 */ 33 public final class InputWindowHandle { 34 // Pointer to the native input window handle. 35 // This field is lazily initialized via JNI. 36 @SuppressWarnings("unused") 37 private long ptr; 38 39 // The input application handle. 40 public InputApplicationHandle inputApplicationHandle; 41 42 // The token associates input data with a window and its input channel. The client input 43 // channel and the server input channel will both contain this token. 44 public IBinder token; 45 46 // The window name. 47 public String name; 48 49 // Window layout params attributes. (WindowManager.LayoutParams) 50 public int layoutParamsFlags; 51 public int layoutParamsType; 52 53 // Dispatching timeout. 54 public long dispatchingTimeoutMillis; 55 56 // Window frame. 57 public int frameLeft; 58 public int frameTop; 59 public int frameRight; 60 public int frameBottom; 61 62 public int surfaceInset; 63 64 // Global scaling factor applied to touch events when they are dispatched 65 // to the window 66 public float scaleFactor; 67 68 // Window touchable region. 69 public final Region touchableRegion = new Region(); 70 71 // Window is visible. 72 public boolean visible; 73 74 // Window can be focused. 75 public boolean focusable; 76 77 // Window has wallpaper. (window is the current wallpaper target) 78 public boolean hasWallpaper; 79 80 // Input event dispatching is paused. 81 public boolean paused; 82 83 // Window is trusted overlay. 84 public boolean trustedOverlay; 85 86 // What effect this window has on touch occlusion if it lets touches pass through 87 // By default windows will block touches if they are untrusted and from a different UID due to 88 // security concerns 89 public int touchOcclusionMode = TouchOcclusionMode.BLOCK_UNTRUSTED; 90 91 // Id of process and user that owns the window. 92 public int ownerPid; 93 public int ownerUid; 94 95 // Owner package of the window 96 public String packageName; 97 98 // Window input features. 99 public int inputFeatures; 100 101 // Display this input is on. 102 public int displayId; 103 104 // If this value is set to a valid display ID, it indicates this window is a portal which 105 // transports the touch of this window to the display indicated by portalToDisplayId. 106 public int portalToDisplayId = INVALID_DISPLAY; 107 108 /** 109 * Crops the touchable region to the bounds of the surface provided. 110 * 111 * This can be used in cases where the window is not 112 * {@link android.view.WindowManager#FLAG_NOT_TOUCH_MODAL} but should be constrained to the 113 * bounds of a parent window. That is the window should receive touch events outside its 114 * window but be limited to its stack bounds, such as in the case of split screen. 115 */ 116 public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null); 117 118 /** 119 * Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If 120 * the handle is {@code null}, the bounds of the surface associated with this window is used 121 * as the touchable region. 122 */ 123 public boolean replaceTouchableRegionWithCrop; 124 nativeDispose()125 private native void nativeDispose(); 126 InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId)127 public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) { 128 this.inputApplicationHandle = inputApplicationHandle; 129 this.displayId = displayId; 130 } 131 132 @Override toString()133 public String toString() { 134 return new StringBuilder(name != null ? name : "") 135 .append(", frame=[").append(frameLeft).append(",").append(frameTop).append(",") 136 .append(frameRight).append(",").append(frameBottom).append("]") 137 .append(", touchableRegion=").append(touchableRegion) 138 .append(", visible=").append(visible) 139 .toString(); 140 141 } 142 143 @Override finalize()144 protected void finalize() throws Throwable { 145 try { 146 nativeDispose(); 147 } finally { 148 super.finalize(); 149 } 150 } 151 152 /** 153 * Set the window touchable region to the bounds of {@link touchableRegionBounds} ignoring any 154 * touchable region provided. 155 * 156 * @param bounds surface to set the touchable region to. Set to {@code null} to set the bounds 157 * to the current surface. 158 */ replaceTouchableRegionWithCrop(@ullable SurfaceControl bounds)159 public void replaceTouchableRegionWithCrop(@Nullable SurfaceControl bounds) { 160 setTouchableRegionCrop(bounds); 161 replaceTouchableRegionWithCrop = true; 162 } 163 164 /** 165 * Crop the window touchable region to the bounds of the surface provided. 166 */ setTouchableRegionCrop(@ullable SurfaceControl bounds)167 public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) { 168 touchableRegionSurfaceControl = new WeakReference<>(bounds); 169 } 170 } 171