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