Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 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 | |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 17 | package android.view; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 18 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
| 20 | |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 22 | import android.graphics.Region; |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 23 | import android.os.IBinder; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 24 | |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 25 | import java.lang.ref.WeakReference; |
| 26 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 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") |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 36 | private long ptr; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 37 | |
| 38 | // The input application handle. |
Riddle Hsu | a68473c | 2020-12-03 15:57:36 +0800 | [diff] [blame] | 39 | public InputApplicationHandle inputApplicationHandle; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 40 | |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 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. |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 43 | public IBinder token; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 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 | |
Robert Carr | fcc0852 | 2018-11-14 14:02:52 -0800 | [diff] [blame] | 61 | public int surfaceInset; |
| 62 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 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 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 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 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 92 | // Display this input is on. |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 93 | public int displayId; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 94 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 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 | |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 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 | */ |
Vishnu Nair | bc9beab | 2019-06-25 17:28:58 -0700 | [diff] [blame] | 107 | public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null); |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Vishnu Nair | bc9beab | 2019-06-25 17:28:58 -0700 | [diff] [blame] | 110 | * Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 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 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 116 | private native void nativeDispose(); |
| 117 | |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 118 | public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 119 | this.inputApplicationHandle = inputApplicationHandle; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 120 | this.displayId = displayId; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 124 | public String toString() { |
Arthur Hung | 39134b2 | 2018-08-14 11:58:28 +0800 | [diff] [blame] | 125 | return new StringBuilder(name != null ? name : "") |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 126 | .append(", frame=[").append(frameLeft).append(",").append(frameTop).append(",") |
| 127 | .append(frameRight).append(",").append(frameBottom).append("]") |
| 128 | .append(", touchableRegion=").append(touchableRegion) |
Filip Gruszczynski | 5514930 | 2015-11-25 10:51:25 -0800 | [diff] [blame] | 129 | .append(", visible=").append(visible) |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 130 | .toString(); |
| 131 | |
| 132 | } |
| 133 | |
| 134 | @Override |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 135 | protected void finalize() throws Throwable { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 136 | try { |
| 137 | nativeDispose(); |
| 138 | } finally { |
| 139 | super.finalize(); |
| 140 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 141 | } |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 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 | */ |
| 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 | */ |
| 158 | public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) { |
Vishnu Nair | bc9beab | 2019-06-25 17:28:58 -0700 | [diff] [blame] | 159 | touchableRegionSurfaceControl = new WeakReference<>(bounds); |
Vishnu Nair | 40efb71 | 2019-03-12 13:37:51 -0700 | [diff] [blame] | 160 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 161 | } |