blob: 3ea3f67bd8cbac8dc9435040fd76e7a26735386d [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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
chaviw3277faf2021-05-19 16:45:23 -050017#pragma once
Michael Wrightd02c5b62014-02-10 15:10:22 -080018
chaviw3277faf2021-05-19 16:45:23 -050019#include <android/gui/TouchOcclusionMode.h>
Prabir Pradhan51e7db02022-02-07 06:02:57 -080020#include <android/os/InputConfig.h>
Chris Ye0783e992020-06-02 21:34:49 -070021#include <binder/Parcel.h>
22#include <binder/Parcelable.h>
Dominik Laskowski2f01d772022-03-23 16:01:29 -070023#include <ftl/flags.h>
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000024#include <ftl/mixins.h>
Prabir Pradhanaeebeb42023-06-13 19:53:03 +000025#include <gui/PidUid.h>
Linnan Li13bf76a2024-05-05 19:18:02 +080026#include <ui/LogicalDisplayId.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080027#include <ui/Rect.h>
28#include <ui/Region.h>
Vishnu Nair494a2e42023-11-10 17:21:19 -080029#include <ui/Size.h>
chaviwfd9c1ed2020-07-01 10:57:59 -070030#include <ui/Transform.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080031#include <utils/RefBase.h>
32#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080033
34#include "InputApplication.h"
35
chaviw3277faf2021-05-19 16:45:23 -050036namespace android::gui {
Michael Wrightd02c5b62014-02-10 15:10:22 -080037
38/*
39 * Describes the properties of a window that can receive input.
40 */
chaviw3277faf2021-05-19 16:45:23 -050041struct WindowInfo : public Parcelable {
42 WindowInfo() = default;
Robert Carr1cc78672018-07-31 14:25:57 -070043
Michael Wrightd02c5b62014-02-10 15:10:22 -080044 // Window flags from WindowManager.LayoutParams
Michael Wright44753b12020-07-08 13:48:11 +010045 enum class Flag : uint32_t {
46 ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
47 DIM_BEHIND = 0x00000002,
48 BLUR_BEHIND = 0x00000004,
49 NOT_FOCUSABLE = 0x00000008,
50 NOT_TOUCHABLE = 0x00000010,
51 NOT_TOUCH_MODAL = 0x00000020,
52 TOUCHABLE_WHEN_WAKING = 0x00000040,
53 KEEP_SCREEN_ON = 0x00000080,
54 LAYOUT_IN_SCREEN = 0x00000100,
55 LAYOUT_NO_LIMITS = 0x00000200,
56 FULLSCREEN = 0x00000400,
57 FORCE_NOT_FULLSCREEN = 0x00000800,
58 DITHER = 0x00001000,
59 SECURE = 0x00002000,
60 SCALED = 0x00004000,
61 IGNORE_CHEEK_PRESSES = 0x00008000,
62 LAYOUT_INSET_DECOR = 0x00010000,
63 ALT_FOCUSABLE_IM = 0x00020000,
64 WATCH_OUTSIDE_TOUCH = 0x00040000,
65 SHOW_WHEN_LOCKED = 0x00080000,
66 SHOW_WALLPAPER = 0x00100000,
67 TURN_SCREEN_ON = 0x00200000,
68 DISMISS_KEYGUARD = 0x00400000,
69 SPLIT_TOUCH = 0x00800000,
70 HARDWARE_ACCELERATED = 0x01000000,
71 LAYOUT_IN_OVERSCAN = 0x02000000,
72 TRANSLUCENT_STATUS = 0x04000000,
73 TRANSLUCENT_NAVIGATION = 0x08000000,
74 LOCAL_FOCUS_MODE = 0x10000000,
75 SLIPPERY = 0x20000000,
76 LAYOUT_ATTACHED_IN_DECOR = 0x40000000,
77 DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000,
Dominik Laskowski75788452021-02-09 18:51:25 -080078 };
Michael Wrightd02c5b62014-02-10 15:10:22 -080079
Dominik Laskowski75788452021-02-09 18:51:25 -080080 // Window types from WindowManager.LayoutParams
Michael Wright44753b12020-07-08 13:48:11 +010081 enum class Type : int32_t {
82 UNKNOWN = 0,
Michael Wrightd02c5b62014-02-10 15:10:22 -080083 FIRST_APPLICATION_WINDOW = 1,
Michael Wright44753b12020-07-08 13:48:11 +010084 BASE_APPLICATION = 1,
85 APPLICATION = 2,
86 APPLICATION_STARTING = 3,
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 LAST_APPLICATION_WINDOW = 99,
wilsonshih599042f2020-05-04 16:24:58 +080088 FIRST_SUB_WINDOW = 1000,
Michael Wright44753b12020-07-08 13:48:11 +010089 APPLICATION_PANEL = FIRST_SUB_WINDOW,
90 APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1,
91 APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2,
92 APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3,
93 APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4,
wilsonshih599042f2020-05-04 16:24:58 +080094 LAST_SUB_WINDOW = 1999,
Dominik Laskowski75788452021-02-09 18:51:25 -080095
96#define FIRST_SYSTEM_WINDOW_ 2000
97
98 STATUS_BAR = FIRST_SYSTEM_WINDOW_,
99 SEARCH_BAR = FIRST_SYSTEM_WINDOW_ + 1,
100 PHONE = FIRST_SYSTEM_WINDOW_ + 2,
101 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW_ + 3,
102 KEYGUARD = FIRST_SYSTEM_WINDOW_ + 4,
103 TOAST = FIRST_SYSTEM_WINDOW_ + 5,
104 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 6,
105 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW_ + 7,
106 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW_ + 8,
107 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW_ + 9,
108 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW_ + 10,
109 INPUT_METHOD = FIRST_SYSTEM_WINDOW_ + 11,
110 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW_ + 12,
111 WALLPAPER = FIRST_SYSTEM_WINDOW_ + 13,
112 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 14,
113 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 15,
114 DRAG = FIRST_SYSTEM_WINDOW_ + 16,
115 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW_ + 17,
116 POINTER = FIRST_SYSTEM_WINDOW_ + 18,
117 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW_ + 19,
118 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW_ + 20,
119 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW_ + 21,
120 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW_ + 22,
121 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 24,
122 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 27,
123 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW_ + 32,
124 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW_ + 34,
125 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 39,
126 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW_ + 40,
127
128 FIRST_SYSTEM_WINDOW = FIRST_SYSTEM_WINDOW_,
wilsonshih599042f2020-05-04 16:24:58 +0800129 LAST_SYSTEM_WINDOW = 2999,
Dominik Laskowski75788452021-02-09 18:51:25 -0800130
131#undef FIRST_SYSTEM_WINDOW_
132
133 // Small range to limit LUT size.
134 ftl_first = FIRST_SYSTEM_WINDOW,
135 ftl_last = FIRST_SYSTEM_WINDOW + 15
Michael Wrightd02c5b62014-02-10 15:10:22 -0800136 };
137
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800138 // Flags used to determine configuration of this input window.
Prabir Pradhan51e7db02022-02-07 06:02:57 -0800139 // This is a conversion of os::InputConfig to an enum backed by an unsigned
140 // type. This indicates that they are flags, so it can be used with ftl/enum.h.
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800141 enum class InputConfig : uint32_t {
142 // clang-format off
Prabir Pradhan51e7db02022-02-07 06:02:57 -0800143 DEFAULT =
144 static_cast<uint32_t>(os::InputConfig::DEFAULT),
145 NO_INPUT_CHANNEL =
146 static_cast<uint32_t>(os::InputConfig::NO_INPUT_CHANNEL),
147 NOT_VISIBLE =
148 static_cast<uint32_t>(os::InputConfig::NOT_VISIBLE),
149 NOT_FOCUSABLE =
150 static_cast<uint32_t>(os::InputConfig::NOT_FOCUSABLE),
151 NOT_TOUCHABLE =
152 static_cast<uint32_t>(os::InputConfig::NOT_TOUCHABLE),
153 PREVENT_SPLITTING =
154 static_cast<uint32_t>(os::InputConfig::PREVENT_SPLITTING),
155 DUPLICATE_TOUCH_TO_WALLPAPER =
156 static_cast<uint32_t>(os::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER),
157 IS_WALLPAPER =
158 static_cast<uint32_t>(os::InputConfig::IS_WALLPAPER),
159 PAUSE_DISPATCHING =
160 static_cast<uint32_t>(os::InputConfig::PAUSE_DISPATCHING),
161 TRUSTED_OVERLAY =
162 static_cast<uint32_t>(os::InputConfig::TRUSTED_OVERLAY),
163 WATCH_OUTSIDE_TOUCH =
164 static_cast<uint32_t>(os::InputConfig::WATCH_OUTSIDE_TOUCH),
165 SLIPPERY =
166 static_cast<uint32_t>(os::InputConfig::SLIPPERY),
167 DISABLE_USER_ACTIVITY =
168 static_cast<uint32_t>(os::InputConfig::DISABLE_USER_ACTIVITY),
169 DROP_INPUT =
170 static_cast<uint32_t>(os::InputConfig::DROP_INPUT),
171 DROP_INPUT_IF_OBSCURED =
172 static_cast<uint32_t>(os::InputConfig::DROP_INPUT_IF_OBSCURED),
173 SPY =
174 static_cast<uint32_t>(os::InputConfig::SPY),
175 INTERCEPTS_STYLUS =
176 static_cast<uint32_t>(os::InputConfig::INTERCEPTS_STYLUS),
chaviw8577ea82022-06-01 16:32:26 -0500177 CLONE =
178 static_cast<uint32_t>(os::InputConfig::CLONE),
Siarhei Vishniakouf77f60a2023-10-23 17:26:05 -0700179 GLOBAL_STYLUS_BLOCKS_TOUCH =
180 static_cast<uint32_t>(os::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH),
Arpit Singh490ccc92024-04-30 14:26:21 +0000181 SENSITIVE_FOR_PRIVACY =
182 static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_PRIVACY),
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800183 // clang-format on
184 };
185
Robert Carr5cb25782018-11-14 14:01:42 -0800186 /* These values are filled in by the WM and passed through SurfaceFlinger
187 * unless specified otherwise.
188 */
chaviwaf87b3e2019-10-01 16:59:28 -0700189 // This value should NOT be used to uniquely identify the window. There may be different
190 // input windows that have the same token.
Robert Carr5c8a0262018-10-03 16:30:44 -0700191 sp<IBinder> token;
chaviwe0ba4e92021-08-11 11:38:41 -0500192
193 // The token that identifies which client window this WindowInfo was created for.
194 sp<IBinder> windowToken;
195
chaviwaf87b3e2019-10-01 16:59:28 -0700196 // This uniquely identifies the input window.
Robert Carr7174efe2020-04-13 16:55:27 -0700197 int32_t id = -1;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800198 std::string name;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500199 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
Robert Carr5cb25782018-11-14 14:01:42 -0800200
201 /* These values are filled in by SurfaceFlinger. */
Chavi Weingarten7f019192023-08-08 20:39:01 +0000202 Rect frame = Rect::INVALID_RECT;
Robert Carr5cb25782018-11-14 14:01:42 -0800203
Vishnu Nair494a2e42023-11-10 17:21:19 -0800204 // The real size of the content, excluding any crop. If no buffer is rendered, this is 0,0
205 ui::Size contentSize = ui::Size(0, 0);
206
Robert Carr5cb25782018-11-14 14:01:42 -0800207 /*
208 * SurfaceFlinger consumes this value to shrink the computed frame. This is
209 * different from shrinking the touchable region in that it DOES shift the coordinate
210 * space where-as the touchable region does not and is more like "cropping". This
211 * is used for window shadows.
212 */
213 int32_t surfaceInset = 0;
214
Robert Carre07e1032018-11-26 12:55:53 -0800215 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
216 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
Robert Carr7174efe2020-04-13 16:55:27 -0700217 float globalScaleFactor = 1.0f;
Robert Carre07e1032018-11-26 12:55:53 -0800218
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100219 // The opacity of this window, from 0.0 to 1.0 (inclusive).
220 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent.
221 float alpha;
222
chaviwfd9c1ed2020-07-01 10:57:59 -0700223 // Transform applied to individual windows.
224 ui::Transform transform;
225
Robert Carr5cb25782018-11-14 14:01:42 -0800226 /*
227 * This is filled in by the WM relative to the frame and then translated
228 * to absolute coordinates by SurfaceFlinger once the frame is computed.
229 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800230 Region touchableRegion;
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800231
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100232 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000233 Pid ownerPid = Pid::INVALID;
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000234 Uid ownerUid = Uid::INVALID;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100235 std::string packageName;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700236 ftl::Flags<InputConfig> inputConfig;
Linnan Li13bf76a2024-05-05 19:18:02 +0800237 ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE;
Robert Carr740167f2018-10-11 19:03:41 -0700238 InputApplicationInfo applicationInfo;
Robert Carr7174efe2020-04-13 16:55:27 -0700239 bool replaceTouchableRegionWithCrop = false;
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700240 wp<IBinder> touchableRegionCropHandle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800241
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800242 // The window's layout params flags and type set by WM.
243 Type layoutParamsType = Type::UNKNOWN;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700244 ftl::Flags<Flag> layoutParamsFlags;
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800245
Chavi Weingarten847e8512023-03-29 00:26:09 +0000246 // The input token for the window to which focus should be transferred when this input window
247 // can be successfully focused. If null, this input window will not transfer its focus to
248 // any other window.
249 sp<IBinder> focusTransferTarget;
250
Vishnu Nair59a6be32024-01-29 10:26:21 -0800251 // Sets a property on this window indicating that its visible region should be considered when
252 // computing TrustedPresentation Thresholds.
253 bool canOccludePresentation = false;
254
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700255 void setInputConfig(ftl::Flags<InputConfig> config, bool value);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800256
Michael Wrightd02c5b62014-02-10 15:10:22 -0800257 void addTouchableRegion(const Rect& region);
258
Michael Wrightd02c5b62014-02-10 15:10:22 -0800259 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700260
Prabir Pradhan07e05b62021-11-19 03:57:24 -0800261 bool isSpy() const;
262
Prabir Pradhand65552b2021-10-07 11:23:50 -0700263 bool interceptsStylus() const;
264
chaviw3277faf2021-05-19 16:45:23 -0500265 bool overlaps(const WindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700266
chaviw3277faf2021-05-19 16:45:23 -0500267 bool operator==(const WindowInfo& inputChannel) const;
Chris Yefcdff3e2020-05-10 15:16:04 -0700268
Chris Ye0783e992020-06-02 21:34:49 -0700269 status_t writeToParcel(android::Parcel* parcel) const override;
270
271 status_t readFromParcel(const android::Parcel* parcel) override;
Michael Wright44753b12020-07-08 13:48:11 +0100272};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800273
Siarhei Vishniakouaeed0da2024-01-09 08:57:13 -0800274std::ostream& operator<<(std::ostream& out, const WindowInfo& window);
275
Michael Wrightd02c5b62014-02-10 15:10:22 -0800276/*
277 * Handle for a window that can receive input.
278 *
279 * Used by the native input dispatcher to indirectly refer to the window manager objects
280 * that describe a window.
281 */
chaviw3277faf2021-05-19 16:45:23 -0500282class WindowInfoHandle : public RefBase {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800283public:
chaviw3277faf2021-05-19 16:45:23 -0500284 explicit WindowInfoHandle();
285 WindowInfoHandle(const WindowInfoHandle& other);
286 WindowInfoHandle(const WindowInfo& other);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800287
chaviw3277faf2021-05-19 16:45:23 -0500288 inline const WindowInfo* getInfo() const { return &mInfo; }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000289 inline WindowInfo* editInfo() { return &mInfo; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800290
Robert Carr5c8a0262018-10-03 16:30:44 -0700291 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800292
chaviwaf87b3e2019-10-01 16:59:28 -0700293 int32_t getId() const { return mInfo.id; }
294
Chris Ye0783e992020-06-02 21:34:49 -0700295 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
Robert Carr740167f2018-10-11 19:03:41 -0700296
Chris Ye0783e992020-06-02 21:34:49 -0700297 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800298
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -0700299 inline std::chrono::nanoseconds getDispatchingTimeout(
300 std::chrono::nanoseconds defaultValue) const {
301 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
302 }
303
Michael Wrightd02c5b62014-02-10 15:10:22 -0800304 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800305 * Updates from another input window handle.
306 */
chaviw3277faf2021-05-19 16:45:23 -0500307 void updateFrom(const sp<WindowInfoHandle> handle);
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800308
309 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800310 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800311 * no longer needed.
312 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800313 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800314
Chris Ye0783e992020-06-02 21:34:49 -0700315 // Not override since this class is not derrived from Parcelable.
316 status_t readFromParcel(const android::Parcel* parcel);
317 status_t writeToParcel(android::Parcel* parcel) const;
318
Michael Wrightd02c5b62014-02-10 15:10:22 -0800319protected:
chaviw3277faf2021-05-19 16:45:23 -0500320 virtual ~WindowInfoHandle();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800321
chaviw3277faf2021-05-19 16:45:23 -0500322 WindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800323};
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -0800324
325std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window);
326
Dominik Laskowski75788452021-02-09 18:51:25 -0800327} // namespace android::gui