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