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 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 20 | #include <binder/Parcel.h> |
| 21 | #include <binder/Parcelable.h> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 22 | #include <input/Flags.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 23 | #include <input/Input.h> |
| 24 | #include <input/InputTransport.h> |
| 25 | #include <ui/Rect.h> |
| 26 | #include <ui/Region.h> |
chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 27 | #include <ui/Transform.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/Timers.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 30 | |
| 31 | #include "InputApplication.h" |
| 32 | |
| 33 | namespace android { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Describes the properties of a window that can receive input. |
| 37 | */ |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 38 | struct InputWindowInfo : public Parcelable { |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 39 | InputWindowInfo() = default; |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 40 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | // Window flags from WindowManager.LayoutParams |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 42 | enum class Flag : uint32_t { |
| 43 | ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, |
| 44 | DIM_BEHIND = 0x00000002, |
| 45 | BLUR_BEHIND = 0x00000004, |
| 46 | NOT_FOCUSABLE = 0x00000008, |
| 47 | NOT_TOUCHABLE = 0x00000010, |
| 48 | NOT_TOUCH_MODAL = 0x00000020, |
| 49 | TOUCHABLE_WHEN_WAKING = 0x00000040, |
| 50 | KEEP_SCREEN_ON = 0x00000080, |
| 51 | LAYOUT_IN_SCREEN = 0x00000100, |
| 52 | LAYOUT_NO_LIMITS = 0x00000200, |
| 53 | FULLSCREEN = 0x00000400, |
| 54 | FORCE_NOT_FULLSCREEN = 0x00000800, |
| 55 | DITHER = 0x00001000, |
| 56 | SECURE = 0x00002000, |
| 57 | SCALED = 0x00004000, |
| 58 | IGNORE_CHEEK_PRESSES = 0x00008000, |
| 59 | LAYOUT_INSET_DECOR = 0x00010000, |
| 60 | ALT_FOCUSABLE_IM = 0x00020000, |
| 61 | WATCH_OUTSIDE_TOUCH = 0x00040000, |
| 62 | SHOW_WHEN_LOCKED = 0x00080000, |
| 63 | SHOW_WALLPAPER = 0x00100000, |
| 64 | TURN_SCREEN_ON = 0x00200000, |
| 65 | DISMISS_KEYGUARD = 0x00400000, |
| 66 | SPLIT_TOUCH = 0x00800000, |
| 67 | HARDWARE_ACCELERATED = 0x01000000, |
| 68 | LAYOUT_IN_OVERSCAN = 0x02000000, |
| 69 | TRANSLUCENT_STATUS = 0x04000000, |
| 70 | TRANSLUCENT_NAVIGATION = 0x08000000, |
| 71 | LOCAL_FOCUS_MODE = 0x10000000, |
| 72 | SLIPPERY = 0x20000000, |
| 73 | LAYOUT_ATTACHED_IN_DECOR = 0x40000000, |
| 74 | DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000, |
| 75 | }; // Window types from WindowManager.LayoutParams |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 76 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 77 | enum class Type : int32_t { |
| 78 | UNKNOWN = 0, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 79 | FIRST_APPLICATION_WINDOW = 1, |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 80 | BASE_APPLICATION = 1, |
| 81 | APPLICATION = 2, |
| 82 | APPLICATION_STARTING = 3, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 83 | LAST_APPLICATION_WINDOW = 99, |
wilsonshih | 599042f | 2020-05-04 16:24:58 +0800 | [diff] [blame] | 84 | FIRST_SUB_WINDOW = 1000, |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 85 | APPLICATION_PANEL = FIRST_SUB_WINDOW, |
| 86 | APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1, |
| 87 | APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2, |
| 88 | APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3, |
| 89 | APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4, |
wilsonshih | 599042f | 2020-05-04 16:24:58 +0800 | [diff] [blame] | 90 | LAST_SUB_WINDOW = 1999, |
| 91 | FIRST_SYSTEM_WINDOW = 2000, |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 92 | STATUS_BAR = FIRST_SYSTEM_WINDOW, |
| 93 | SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1, |
| 94 | PHONE = FIRST_SYSTEM_WINDOW + 2, |
| 95 | SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3, |
| 96 | KEYGUARD = FIRST_SYSTEM_WINDOW + 4, |
| 97 | TOAST = FIRST_SYSTEM_WINDOW + 5, |
| 98 | SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6, |
| 99 | PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7, |
| 100 | SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8, |
| 101 | KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9, |
| 102 | SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10, |
| 103 | INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11, |
| 104 | INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12, |
| 105 | WALLPAPER = FIRST_SYSTEM_WINDOW + 13, |
| 106 | STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14, |
| 107 | SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15, |
| 108 | DRAG = FIRST_SYSTEM_WINDOW + 16, |
| 109 | STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17, |
| 110 | POINTER = FIRST_SYSTEM_WINDOW + 18, |
| 111 | NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19, |
| 112 | VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20, |
| 113 | BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21, |
| 114 | INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22, |
| 115 | NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24, |
| 116 | MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27, |
| 117 | ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32, |
| 118 | DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34, |
| 119 | ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39, |
| 120 | NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40, |
wilsonshih | 599042f | 2020-05-04 16:24:58 +0800 | [diff] [blame] | 121 | LAST_SYSTEM_WINDOW = 2999, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 124 | enum class Feature { |
| 125 | DISABLE_TOUCH_PAD_GESTURES = 0x00000001, |
| 126 | NO_INPUT_CHANNEL = 0x00000002, |
| 127 | DISABLE_USER_ACTIVITY = 0x00000004, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 128 | }; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 129 | |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 130 | /* These values are filled in by the WM and passed through SurfaceFlinger |
| 131 | * unless specified otherwise. |
| 132 | */ |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 133 | // This value should NOT be used to uniquely identify the window. There may be different |
| 134 | // input windows that have the same token. |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 135 | sp<IBinder> token; |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 136 | // This uniquely identifies the input window. |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 137 | int32_t id = -1; |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 138 | std::string name; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 139 | Flags<Flag> flags; |
| 140 | Type type = Type::UNKNOWN; |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 141 | std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5); |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 142 | |
| 143 | /* These values are filled in by SurfaceFlinger. */ |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 144 | int32_t frameLeft = -1; |
| 145 | int32_t frameTop = -1; |
| 146 | int32_t frameRight = -1; |
| 147 | int32_t frameBottom = -1; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * SurfaceFlinger consumes this value to shrink the computed frame. This is |
| 151 | * different from shrinking the touchable region in that it DOES shift the coordinate |
| 152 | * space where-as the touchable region does not and is more like "cropping". This |
| 153 | * is used for window shadows. |
| 154 | */ |
| 155 | int32_t surfaceInset = 0; |
| 156 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 157 | // A global scaling factor for all windows. Unlike windowScaleX/Y this results |
| 158 | // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis. |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 159 | float globalScaleFactor = 1.0f; |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 160 | |
chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 161 | // Transform applied to individual windows. |
| 162 | ui::Transform transform; |
| 163 | |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 164 | /* |
| 165 | * This is filled in by the WM relative to the frame and then translated |
| 166 | * to absolute coordinates by SurfaceFlinger once the frame is computed. |
| 167 | */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 168 | Region touchableRegion; |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 169 | bool visible = false; |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 170 | bool focusable = false; |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 171 | bool hasWallpaper = false; |
| 172 | bool paused = false; |
Chris Ye | fcdff3e | 2020-05-10 15:16:04 -0700 | [diff] [blame] | 173 | /* This flag is set when the window is of a trusted type that is allowed to silently |
| 174 | * overlay other windows for the purpose of implementing the secure views feature. |
| 175 | * Trusted overlays, such as IME windows, can partly obscure other windows without causing |
| 176 | * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. |
| 177 | */ |
| 178 | bool trustedOverlay = false; |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 179 | int32_t ownerPid = -1; |
| 180 | int32_t ownerUid = -1; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 181 | Flags<Feature> inputFeatures; |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 182 | int32_t displayId = ADISPLAY_ID_NONE; |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 183 | int32_t portalToDisplayId = ADISPLAY_ID_NONE; |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 184 | InputApplicationInfo applicationInfo; |
Robert Carr | 7174efe | 2020-04-13 16:55:27 -0700 | [diff] [blame] | 185 | bool replaceTouchableRegionWithCrop = false; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 186 | wp<IBinder> touchableRegionCropHandle; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 187 | |
| 188 | void addTouchableRegion(const Rect& region); |
| 189 | |
| 190 | bool touchableRegionContainsPoint(int32_t x, int32_t y) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 191 | |
Chris Ye | fcdff3e | 2020-05-10 15:16:04 -0700 | [diff] [blame] | 192 | bool frameContainsPoint(int32_t x, int32_t y) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 193 | |
| 194 | bool supportsSplitTouch() const; |
Michael Wright | cdcd8f2 | 2016-03-22 16:52:13 -0700 | [diff] [blame] | 195 | |
| 196 | bool overlaps(const InputWindowInfo* other) const; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 197 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 198 | bool operator==(const InputWindowInfo& inputChannel) const; |
Chris Ye | fcdff3e | 2020-05-10 15:16:04 -0700 | [diff] [blame] | 199 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 200 | status_t writeToParcel(android::Parcel* parcel) const override; |
| 201 | |
| 202 | status_t readFromParcel(const android::Parcel* parcel) override; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 203 | }; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Handle for a window that can receive input. |
| 207 | * |
| 208 | * Used by the native input dispatcher to indirectly refer to the window manager objects |
| 209 | * that describe a window. |
| 210 | */ |
| 211 | class InputWindowHandle : public RefBase { |
| 212 | public: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 213 | explicit InputWindowHandle(); |
| 214 | InputWindowHandle(const InputWindowHandle& other); |
| 215 | InputWindowHandle(const InputWindowInfo& other); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 216 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 217 | inline const InputWindowInfo* getInfo() const { return &mInfo; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 218 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 219 | sp<IBinder> getToken() const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 220 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 221 | int32_t getId() const { return mInfo.id; } |
| 222 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 223 | sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; } |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 224 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 225 | inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 226 | |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 227 | inline std::chrono::nanoseconds getDispatchingTimeout( |
| 228 | std::chrono::nanoseconds defaultValue) const { |
| 229 | return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; |
| 230 | } |
| 231 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 232 | /** |
| 233 | * Requests that the state of this object be updated to reflect |
| 234 | * the most current available information about the application. |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 235 | * As this class is created as RefBase object, no pure virtual function is allowed. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 236 | * |
| 237 | * This method should only be called from within the input dispatcher's |
| 238 | * critical section. |
| 239 | * |
| 240 | * Returns true on success, or false if the handle is no longer valid. |
| 241 | */ |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 242 | virtual bool updateInfo() { return false; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 243 | |
| 244 | /** |
Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 245 | * Updates from another input window handle. |
| 246 | */ |
| 247 | void updateFrom(const sp<InputWindowHandle> handle); |
| 248 | |
| 249 | /** |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 250 | * Releases the channel used by the associated information when it is |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 251 | * no longer needed. |
| 252 | */ |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 253 | void releaseChannel(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 254 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 255 | // Not override since this class is not derrived from Parcelable. |
| 256 | status_t readFromParcel(const android::Parcel* parcel); |
| 257 | status_t writeToParcel(android::Parcel* parcel) const; |
| 258 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 259 | protected: |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 260 | virtual ~InputWindowHandle(); |
| 261 | |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 262 | InputWindowInfo mInfo; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 263 | }; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 264 | } // namespace android |
| 265 | |
| 266 | #endif // _UI_INPUT_WINDOW_H |