Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -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 | |
| 17 | #ifndef _UI_INPUT_WINDOW_H |
| 18 | #define _UI_INPUT_WINDOW_H |
| 19 | |
| 20 | #include <input/Input.h> |
| 21 | #include <input/InputTransport.h> |
| 22 | #include <ui/Rect.h> |
| 23 | #include <ui/Region.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Timers.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 26 | |
| 27 | #include "InputApplication.h" |
| 28 | |
| 29 | namespace android { |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 30 | class Parcel; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Describes the properties of a window that can receive input. |
| 34 | */ |
| 35 | struct InputWindowInfo { |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 36 | InputWindowInfo() = default; |
| 37 | InputWindowInfo(const Parcel& from); |
| 38 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | // Window flags from WindowManager.LayoutParams |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame^] | 40 | enum : uint32_t { |
| 41 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, |
| 42 | FLAG_DIM_BEHIND = 0x00000002, |
| 43 | FLAG_BLUR_BEHIND = 0x00000004, |
| 44 | FLAG_NOT_FOCUSABLE = 0x00000008, |
| 45 | FLAG_NOT_TOUCHABLE = 0x00000010, |
| 46 | FLAG_NOT_TOUCH_MODAL = 0x00000020, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 47 | FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040, |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame^] | 48 | FLAG_KEEP_SCREEN_ON = 0x00000080, |
| 49 | FLAG_LAYOUT_IN_SCREEN = 0x00000100, |
| 50 | FLAG_LAYOUT_NO_LIMITS = 0x00000200, |
| 51 | FLAG_FULLSCREEN = 0x00000400, |
| 52 | FLAG_FORCE_NOT_FULLSCREEN = 0x00000800, |
| 53 | FLAG_DITHER = 0x00001000, |
| 54 | FLAG_SECURE = 0x00002000, |
| 55 | FLAG_SCALED = 0x00004000, |
| 56 | FLAG_IGNORE_CHEEK_PRESSES = 0x00008000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 57 | FLAG_LAYOUT_INSET_DECOR = 0x00010000, |
| 58 | FLAG_ALT_FOCUSABLE_IM = 0x00020000, |
| 59 | FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000, |
| 60 | FLAG_SHOW_WHEN_LOCKED = 0x00080000, |
| 61 | FLAG_SHOW_WALLPAPER = 0x00100000, |
| 62 | FLAG_TURN_SCREEN_ON = 0x00200000, |
| 63 | FLAG_DISMISS_KEYGUARD = 0x00400000, |
| 64 | FLAG_SPLIT_TOUCH = 0x00800000, |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame^] | 65 | FLAG_HARDWARE_ACCELERATED = 0x01000000, |
| 66 | FLAG_LAYOUT_IN_OVERSCAN = 0x02000000, |
| 67 | FLAG_TRANSLUCENT_STATUS = 0x04000000, |
| 68 | FLAG_TRANSLUCENT_NAVIGATION = 0x08000000, |
| 69 | FLAG_LOCAL_FOCUS_MODE = 0x10000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 70 | FLAG_SLIPPERY = 0x20000000, |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame^] | 71 | FLAG_LAYOUT_ATTACHED_IN_DECOR = 0x40000000, |
| 72 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 75 | // Window types from WindowManager.LayoutParams |
| 76 | enum { |
| 77 | FIRST_APPLICATION_WINDOW = 1, |
| 78 | TYPE_BASE_APPLICATION = 1, |
| 79 | TYPE_APPLICATION = 2, |
| 80 | TYPE_APPLICATION_STARTING = 3, |
| 81 | LAST_APPLICATION_WINDOW = 99, |
| 82 | FIRST_SUB_WINDOW = 1000, |
| 83 | TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW, |
| 84 | TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1, |
| 85 | TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2, |
| 86 | TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3, |
| 87 | TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4, |
| 88 | LAST_SUB_WINDOW = 1999, |
| 89 | FIRST_SYSTEM_WINDOW = 2000, |
| 90 | TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW, |
| 91 | TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1, |
| 92 | TYPE_PHONE = FIRST_SYSTEM_WINDOW+2, |
| 93 | TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3, |
| 94 | TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4, |
| 95 | TYPE_TOAST = FIRST_SYSTEM_WINDOW+5, |
| 96 | TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6, |
| 97 | TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7, |
| 98 | TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8, |
| 99 | TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9, |
| 100 | TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10, |
| 101 | TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11, |
| 102 | TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12, |
| 103 | TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13, |
| 104 | TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14, |
| 105 | TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15, |
| 106 | TYPE_DRAG = FIRST_SYSTEM_WINDOW+16, |
| 107 | TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17, |
| 108 | TYPE_POINTER = FIRST_SYSTEM_WINDOW+18, |
| 109 | TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19, |
| 110 | TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20, |
| 111 | TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21, |
Michael Wright | afe7a5c | 2017-09-19 20:19:39 +0100 | [diff] [blame] | 112 | TYPE_INPUT_CONSUMER = FIRST_SYSTEM_WINDOW+22, |
Phil Weaver | 5a07198 | 2017-06-26 16:22:26 -0700 | [diff] [blame] | 113 | TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24, |
kenzyun_chen | 7942ad7 | 2017-06-02 13:36:21 +0800 | [diff] [blame] | 114 | TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27, |
Phil Weaver | 5a07198 | 2017-06-26 16:22:26 -0700 | [diff] [blame] | 115 | TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32, |
Michael Wright | b9be0cf | 2016-05-26 13:49:53 +0100 | [diff] [blame] | 116 | TYPE_DOCK_DIVIDER = FIRST_SYSTEM_WINDOW+34, |
mincheli | 9be5b33 | 2020-03-03 14:45:05 +0800 | [diff] [blame] | 117 | TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+39, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 118 | LAST_SYSTEM_WINDOW = 2999, |
| 119 | }; |
| 120 | |
| 121 | enum { |
| 122 | INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001, |
| 123 | INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002, |
| 124 | INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004, |
| 125 | }; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 126 | |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 127 | /* These values are filled in by the WM and passed through SurfaceFlinger |
| 128 | * unless specified otherwise. |
| 129 | */ |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 130 | // This value should NOT be used to uniquely identify the window. There may be different |
| 131 | // input windows that have the same token. |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 132 | sp<IBinder> token; |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 133 | // This uniquely identifies the input window. |
| 134 | int32_t id = 0; |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 135 | std::string name; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 136 | int32_t layoutParamsFlags; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 137 | int32_t layoutParamsType; |
| 138 | nsecs_t dispatchingTimeout; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 139 | |
| 140 | /* These values are filled in by SurfaceFlinger. */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 141 | int32_t frameLeft; |
| 142 | int32_t frameTop; |
| 143 | int32_t frameRight; |
| 144 | int32_t frameBottom; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * SurfaceFlinger consumes this value to shrink the computed frame. This is |
| 148 | * different from shrinking the touchable region in that it DOES shift the coordinate |
| 149 | * space where-as the touchable region does not and is more like "cropping". This |
| 150 | * is used for window shadows. |
| 151 | */ |
| 152 | int32_t surfaceInset = 0; |
| 153 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 154 | // A global scaling factor for all windows. Unlike windowScaleX/Y this results |
| 155 | // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis. |
| 156 | float globalScaleFactor; |
| 157 | |
| 158 | // Scaling factors applied to individual windows. |
| 159 | float windowXScale = 1.0f; |
| 160 | float windowYScale = 1.0f; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | * This is filled in by the WM relative to the frame and then translated |
| 164 | * to absolute coordinates by SurfaceFlinger once the frame is computed. |
| 165 | */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 166 | Region touchableRegion; |
| 167 | bool visible; |
| 168 | bool canReceiveKeys; |
| 169 | bool hasFocus; |
| 170 | bool hasWallpaper; |
| 171 | bool paused; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 172 | int32_t ownerPid; |
| 173 | int32_t ownerUid; |
| 174 | int32_t inputFeatures; |
| 175 | int32_t displayId; |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 176 | int32_t portalToDisplayId = ADISPLAY_ID_NONE; |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 177 | InputApplicationInfo applicationInfo; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 178 | bool replaceTouchableRegionWithCrop; |
| 179 | wp<IBinder> touchableRegionCropHandle; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 180 | |
| 181 | void addTouchableRegion(const Rect& region); |
| 182 | |
| 183 | bool touchableRegionContainsPoint(int32_t x, int32_t y) const; |
| 184 | bool frameContainsPoint(int32_t x, int32_t y) const; |
| 185 | |
| 186 | /* Returns true if the window is of a trusted type that is allowed to silently |
| 187 | * overlay other windows for the purpose of implementing the secure views feature. |
| 188 | * Trusted overlays, such as IME windows, can partly obscure other windows without causing |
| 189 | * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. |
| 190 | */ |
| 191 | bool isTrustedOverlay() const; |
| 192 | |
| 193 | bool supportsSplitTouch() const; |
Michael Wright | cdcd8f2 | 2016-03-22 16:52:13 -0700 | [diff] [blame] | 194 | |
| 195 | bool overlaps(const InputWindowInfo* other) const; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 196 | |
| 197 | status_t write(Parcel& output) const; |
| 198 | static InputWindowInfo read(const Parcel& from); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame^] | 201 | std::string inputWindowFlagsToString(uint32_t flags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Handle for a window that can receive input. |
| 205 | * |
| 206 | * Used by the native input dispatcher to indirectly refer to the window manager objects |
| 207 | * that describe a window. |
| 208 | */ |
| 209 | class InputWindowHandle : public RefBase { |
| 210 | public: |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 211 | |
| 212 | inline const InputWindowInfo* getInfo() const { |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 213 | return &mInfo; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 216 | sp<IBinder> getToken() const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 217 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 218 | int32_t getId() const { return mInfo.id; } |
| 219 | |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 220 | sp<IBinder> getApplicationToken() { |
| 221 | return mInfo.applicationInfo.token; |
| 222 | } |
| 223 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 224 | inline std::string getName() const { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 225 | return mInfo.token ? mInfo.name : "<invalid>"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 229 | return mInfo.token ? mInfo.dispatchingTimeout : defaultValue; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Requests that the state of this object be updated to reflect |
| 234 | * the most current available information about the application. |
| 235 | * |
| 236 | * This method should only be called from within the input dispatcher's |
| 237 | * critical section. |
| 238 | * |
| 239 | * Returns true on success, or false if the handle is no longer valid. |
| 240 | */ |
| 241 | virtual bool updateInfo() = 0; |
| 242 | |
| 243 | /** |
Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 244 | * Updates from another input window handle. |
| 245 | */ |
| 246 | void updateFrom(const sp<InputWindowHandle> handle); |
| 247 | |
| 248 | /** |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 249 | * Releases the channel used by the associated information when it is |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 250 | * no longer needed. |
| 251 | */ |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 252 | void releaseChannel(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 253 | |
| 254 | protected: |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 255 | explicit InputWindowHandle(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 256 | virtual ~InputWindowHandle(); |
| 257 | |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 258 | InputWindowInfo mInfo; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | } // namespace android |
| 262 | |
| 263 | #endif // _UI_INPUT_WINDOW_H |