• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <android/gui/TouchOcclusionMode.h>
20 #include <android/os/InputConfig.h>
21 #include <binder/Parcel.h>
22 #include <binder/Parcelable.h>
23 #include <ftl/flags.h>
24 #include <ftl/mixins.h>
25 #include <gui/PidUid.h>
26 #include <ui/LogicalDisplayId.h>
27 #include <ui/Rect.h>
28 #include <ui/Region.h>
29 #include <ui/Size.h>
30 #include <ui/Transform.h>
31 #include <utils/RefBase.h>
32 #include <utils/Timers.h>
33 
34 #include "InputApplication.h"
35 
36 namespace android::gui {
37 
38 /*
39  * Describes the properties of a window that can receive input.
40  */
41 struct WindowInfo : public Parcelable {
42     WindowInfo() = default;
43 
44     // Window flags from WindowManager.LayoutParams
45     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,
78     };
79 
80     // Window types from WindowManager.LayoutParams
81     enum class Type : int32_t {
82         UNKNOWN = 0,
83         FIRST_APPLICATION_WINDOW = 1,
84         BASE_APPLICATION = 1,
85         APPLICATION = 2,
86         APPLICATION_STARTING = 3,
87         LAST_APPLICATION_WINDOW = 99,
88         FIRST_SUB_WINDOW = 1000,
89         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,
94         LAST_SUB_WINDOW = 1999,
95 
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_,
129         LAST_SYSTEM_WINDOW = 2999,
130 
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
136     };
137 
138     // Flags used to determine configuration of this input window.
139     // 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.
141     enum class InputConfig : uint32_t {
142         // clang-format off
143         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         DUPLICATE_TOUCH_TO_WALLPAPER =
154                 static_cast<uint32_t>(os::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER),
155         IS_WALLPAPER =
156                 static_cast<uint32_t>(os::InputConfig::IS_WALLPAPER),
157         PAUSE_DISPATCHING =
158                 static_cast<uint32_t>(os::InputConfig::PAUSE_DISPATCHING),
159         TRUSTED_OVERLAY =
160                 static_cast<uint32_t>(os::InputConfig::TRUSTED_OVERLAY),
161         WATCH_OUTSIDE_TOUCH =
162                 static_cast<uint32_t>(os::InputConfig::WATCH_OUTSIDE_TOUCH),
163         SLIPPERY =
164                 static_cast<uint32_t>(os::InputConfig::SLIPPERY),
165         DISABLE_USER_ACTIVITY =
166                 static_cast<uint32_t>(os::InputConfig::DISABLE_USER_ACTIVITY),
167         DROP_INPUT =
168                 static_cast<uint32_t>(os::InputConfig::DROP_INPUT),
169         DROP_INPUT_IF_OBSCURED =
170                 static_cast<uint32_t>(os::InputConfig::DROP_INPUT_IF_OBSCURED),
171         SPY =
172                 static_cast<uint32_t>(os::InputConfig::SPY),
173         INTERCEPTS_STYLUS =
174                 static_cast<uint32_t>(os::InputConfig::INTERCEPTS_STYLUS),
175         CLONE =
176                 static_cast<uint32_t>(os::InputConfig::CLONE),
177         GLOBAL_STYLUS_BLOCKS_TOUCH =
178                 static_cast<uint32_t>(os::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH),
179         SENSITIVE_FOR_PRIVACY =
180                 static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_PRIVACY),
181         // clang-format on
182     };
183 
184     /* These values are filled in by the WM and passed through SurfaceFlinger
185      * unless specified otherwise.
186      */
187     // This value should NOT be used to uniquely identify the window. There may be different
188     // input windows that have the same token.
189     sp<IBinder> token;
190 
191     // The token that identifies which client window this WindowInfo was created for.
192     sp<IBinder> windowToken;
193 
194     // This uniquely identifies the input window.
195     int32_t id = -1;
196     std::string name;
197     std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
198 
199     /* These values are filled in by SurfaceFlinger. */
200     Rect frame = Rect::INVALID_RECT;
201 
202     // The real size of the content, excluding any crop. If no buffer is rendered, this is 0,0
203     ui::Size contentSize = ui::Size(0, 0);
204 
205     /*
206      * SurfaceFlinger consumes this value to shrink the computed frame. This is
207      * different from shrinking the touchable region in that it DOES shift the coordinate
208      * space where-as the touchable region does not and is more like "cropping". This
209      * is used for window shadows.
210      */
211     int32_t surfaceInset = 0;
212 
213     // A global scaling factor for all windows. Unlike windowScaleX/Y this results
214     // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
215     float globalScaleFactor = 1.0f;
216 
217     // The opacity of this window, from 0.0 to 1.0 (inclusive).
218     // An alpha of 1.0 means fully opaque and 0.0 means fully transparent.
219     float alpha;
220 
221     // Transform applied to individual windows for input.
222     // Maps display coordinates to the window's input coordinate space.
223     ui::Transform transform;
224 
225     // Transform applied to get to the layer stack space of the cloned window for input.
226     // Maps display coordinates of the clone window to the layer stack space of the cloned window.
227     std::optional<ui::Transform> cloneLayerStackTransform;
228 
229     /*
230      * This is filled in by the WM relative to the frame and then translated
231      * to absolute coordinates by SurfaceFlinger once the frame is computed.
232      */
233     Region touchableRegion;
234 
235     TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED;
236     Pid ownerPid = Pid::INVALID;
237     Uid ownerUid = Uid::INVALID;
238     std::string packageName;
239     ftl::Flags<InputConfig> inputConfig;
240     ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID;
241     InputApplicationInfo applicationInfo;
242     bool replaceTouchableRegionWithCrop = false;
243     wp<IBinder> touchableRegionCropHandle;
244 
245     // The window's layout params flags and type set by WM.
246     Type layoutParamsType = Type::UNKNOWN;
247     ftl::Flags<Flag> layoutParamsFlags;
248 
249     // The input token for the window to which focus should be transferred when this input window
250     // can be successfully focused. If null, this input window will not transfer its focus to
251     // any other window.
252     sp<IBinder> focusTransferTarget;
253 
254     // Sets a property on this window indicating that its visible region should be considered when
255     // computing TrustedPresentation Thresholds.
256     bool canOccludePresentation = false;
257 
258     void setInputConfig(ftl::Flags<InputConfig> config, bool value);
259 
260     void addTouchableRegion(const Rect& region);
261 
262     bool supportsSplitTouch() const;
263 
264     bool isSpy() const;
265 
266     bool interceptsStylus() const;
267 
268     bool overlaps(const WindowInfo* other) const;
269 
270     bool operator==(const WindowInfo& inputChannel) const;
271     bool operator!=(const WindowInfo&) const = default;
272 
273     status_t writeToParcel(android::Parcel* parcel) const override;
274 
275     status_t readFromParcel(const android::Parcel* parcel) override;
276 };
277 
278 std::ostream& operator<<(std::ostream& out, const WindowInfo& window);
279 
280 /*
281  * Handle for a window that can receive input.
282  *
283  * Used by the native input dispatcher to indirectly refer to the window manager objects
284  * that describe a window.
285  */
286 class WindowInfoHandle : public RefBase {
287 public:
288     explicit WindowInfoHandle();
289     WindowInfoHandle(const WindowInfoHandle& other);
290     WindowInfoHandle(const WindowInfo& other);
291 
getInfo()292     inline const WindowInfo* getInfo() const { return &mInfo; }
editInfo()293     inline WindowInfo* editInfo() { return &mInfo; }
294 
295     sp<IBinder> getToken() const;
296 
getId()297     int32_t getId() const { return mInfo.id; }
298 
getApplicationToken()299     sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
300 
getName()301     inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
302 
getDispatchingTimeout(std::chrono::nanoseconds defaultValue)303     inline std::chrono::nanoseconds getDispatchingTimeout(
304             std::chrono::nanoseconds defaultValue) const {
305         return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
306     }
307 
308     /**
309      * Updates from another input window handle.
310      */
311     void updateFrom(const sp<WindowInfoHandle> handle);
312 
313     /**
314      * Releases the channel used by the associated information when it is
315      * no longer needed.
316      */
317     void releaseChannel();
318 
319     // Not override since this class is not derrived from Parcelable.
320     status_t readFromParcel(const android::Parcel* parcel);
321     status_t writeToParcel(android::Parcel* parcel) const;
322 
323     bool operator==(const WindowInfoHandle& rhs) const { return mInfo == rhs.mInfo; }
324     bool operator!=(const WindowInfoHandle&) const = default;
325 
326 protected:
327     virtual ~WindowInfoHandle();
328 
329     WindowInfo mInfo;
330 };
331 
332 std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window);
333 
334 } // namespace android::gui
335