blob: 4d4c5e43940e84203c8f188345c3d8d5f4095042 [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>
chaviw3277faf2021-05-19 16:45:23 -050026#include <gui/constants.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),
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800179 // clang-format on
180 };
181
Robert Carr5cb25782018-11-14 14:01:42 -0800182 /* These values are filled in by the WM and passed through SurfaceFlinger
183 * unless specified otherwise.
184 */
chaviwaf87b3e2019-10-01 16:59:28 -0700185 // This value should NOT be used to uniquely identify the window. There may be different
186 // input windows that have the same token.
Robert Carr5c8a0262018-10-03 16:30:44 -0700187 sp<IBinder> token;
chaviwe0ba4e92021-08-11 11:38:41 -0500188
189 // The token that identifies which client window this WindowInfo was created for.
190 sp<IBinder> windowToken;
191
chaviwaf87b3e2019-10-01 16:59:28 -0700192 // This uniquely identifies the input window.
Robert Carr7174efe2020-04-13 16:55:27 -0700193 int32_t id = -1;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800194 std::string name;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500195 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
Robert Carr5cb25782018-11-14 14:01:42 -0800196
197 /* These values are filled in by SurfaceFlinger. */
Chavi Weingarten7f019192023-08-08 20:39:01 +0000198 Rect frame = Rect::INVALID_RECT;
Robert Carr5cb25782018-11-14 14:01:42 -0800199
Vishnu Nair494a2e42023-11-10 17:21:19 -0800200 // The real size of the content, excluding any crop. If no buffer is rendered, this is 0,0
201 ui::Size contentSize = ui::Size(0, 0);
202
Robert Carr5cb25782018-11-14 14:01:42 -0800203 /*
204 * SurfaceFlinger consumes this value to shrink the computed frame. This is
205 * different from shrinking the touchable region in that it DOES shift the coordinate
206 * space where-as the touchable region does not and is more like "cropping". This
207 * is used for window shadows.
208 */
209 int32_t surfaceInset = 0;
210
Robert Carre07e1032018-11-26 12:55:53 -0800211 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
212 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
Robert Carr7174efe2020-04-13 16:55:27 -0700213 float globalScaleFactor = 1.0f;
Robert Carre07e1032018-11-26 12:55:53 -0800214
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100215 // The opacity of this window, from 0.0 to 1.0 (inclusive).
216 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent.
217 float alpha;
218
chaviwfd9c1ed2020-07-01 10:57:59 -0700219 // Transform applied to individual windows.
220 ui::Transform transform;
221
Robert Carr5cb25782018-11-14 14:01:42 -0800222 /*
223 * This is filled in by the WM relative to the frame and then translated
224 * to absolute coordinates by SurfaceFlinger once the frame is computed.
225 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800226 Region touchableRegion;
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800227
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100228 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000229 Pid ownerPid = Pid::INVALID;
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000230 Uid ownerUid = Uid::INVALID;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100231 std::string packageName;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700232 ftl::Flags<InputConfig> inputConfig;
Robert Carr7174efe2020-04-13 16:55:27 -0700233 int32_t displayId = ADISPLAY_ID_NONE;
Robert Carr740167f2018-10-11 19:03:41 -0700234 InputApplicationInfo applicationInfo;
Robert Carr7174efe2020-04-13 16:55:27 -0700235 bool replaceTouchableRegionWithCrop = false;
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700236 wp<IBinder> touchableRegionCropHandle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800237
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800238 // The window's layout params flags and type set by WM.
239 Type layoutParamsType = Type::UNKNOWN;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700240 ftl::Flags<Flag> layoutParamsFlags;
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800241
Chavi Weingarten847e8512023-03-29 00:26:09 +0000242 // The input token for the window to which focus should be transferred when this input window
243 // can be successfully focused. If null, this input window will not transfer its focus to
244 // any other window.
245 sp<IBinder> focusTransferTarget;
246
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700247 void setInputConfig(ftl::Flags<InputConfig> config, bool value);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800248
Michael Wrightd02c5b62014-02-10 15:10:22 -0800249 void addTouchableRegion(const Rect& region);
250
251 bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800252
Chris Yefcdff3e2020-05-10 15:16:04 -0700253 bool frameContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800254
255 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700256
Prabir Pradhan07e05b62021-11-19 03:57:24 -0800257 bool isSpy() const;
258
Prabir Pradhand65552b2021-10-07 11:23:50 -0700259 bool interceptsStylus() const;
260
chaviw3277faf2021-05-19 16:45:23 -0500261 bool overlaps(const WindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700262
chaviw3277faf2021-05-19 16:45:23 -0500263 bool operator==(const WindowInfo& inputChannel) const;
Chris Yefcdff3e2020-05-10 15:16:04 -0700264
Chris Ye0783e992020-06-02 21:34:49 -0700265 status_t writeToParcel(android::Parcel* parcel) const override;
266
267 status_t readFromParcel(const android::Parcel* parcel) override;
Michael Wright44753b12020-07-08 13:48:11 +0100268};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800269
270/*
271 * Handle for a window that can receive input.
272 *
273 * Used by the native input dispatcher to indirectly refer to the window manager objects
274 * that describe a window.
275 */
chaviw3277faf2021-05-19 16:45:23 -0500276class WindowInfoHandle : public RefBase {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800277public:
chaviw3277faf2021-05-19 16:45:23 -0500278 explicit WindowInfoHandle();
279 WindowInfoHandle(const WindowInfoHandle& other);
280 WindowInfoHandle(const WindowInfo& other);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800281
chaviw3277faf2021-05-19 16:45:23 -0500282 inline const WindowInfo* getInfo() const { return &mInfo; }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000283 inline WindowInfo* editInfo() { return &mInfo; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800284
Robert Carr5c8a0262018-10-03 16:30:44 -0700285 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800286
chaviwaf87b3e2019-10-01 16:59:28 -0700287 int32_t getId() const { return mInfo.id; }
288
Chris Ye0783e992020-06-02 21:34:49 -0700289 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
Robert Carr740167f2018-10-11 19:03:41 -0700290
Chris Ye0783e992020-06-02 21:34:49 -0700291 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800292
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -0700293 inline std::chrono::nanoseconds getDispatchingTimeout(
294 std::chrono::nanoseconds defaultValue) const {
295 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
296 }
297
Michael Wrightd02c5b62014-02-10 15:10:22 -0800298 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800299 * Updates from another input window handle.
300 */
chaviw3277faf2021-05-19 16:45:23 -0500301 void updateFrom(const sp<WindowInfoHandle> handle);
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800302
303 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800304 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800305 * no longer needed.
306 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800307 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800308
Chris Ye0783e992020-06-02 21:34:49 -0700309 // Not override since this class is not derrived from Parcelable.
310 status_t readFromParcel(const android::Parcel* parcel);
311 status_t writeToParcel(android::Parcel* parcel) const;
312
Michael Wrightd02c5b62014-02-10 15:10:22 -0800313protected:
chaviw3277faf2021-05-19 16:45:23 -0500314 virtual ~WindowInfoHandle();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800315
chaviw3277faf2021-05-19 16:45:23 -0500316 WindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800317};
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -0800318
319std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window);
320
Dominik Laskowski75788452021-02-09 18:51:25 -0800321} // namespace android::gui