blob: 6a42ff6eb4dcad793e1edc8b3ed75166378ed135 [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
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>
chaviwfd9c1ed2020-07-01 10:57:59 -070024#include <ui/Transform.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080025#include <utils/RefBase.h>
26#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080027
28#include "InputApplication.h"
29
30namespace android {
Robert Carr3720ed02018-08-08 16:08:27 -070031class Parcel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080032
33/*
34 * Describes the properties of a window that can receive input.
35 */
36struct InputWindowInfo {
Robert Carr1cc78672018-07-31 14:25:57 -070037 InputWindowInfo() = default;
38 InputWindowInfo(const Parcel& from);
39
Michael Wrightd02c5b62014-02-10 15:10:22 -080040 // Window flags from WindowManager.LayoutParams
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070041 enum : uint32_t {
42 FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
43 FLAG_DIM_BEHIND = 0x00000002,
44 FLAG_BLUR_BEHIND = 0x00000004,
45 FLAG_NOT_FOCUSABLE = 0x00000008,
46 FLAG_NOT_TOUCHABLE = 0x00000010,
47 FLAG_NOT_TOUCH_MODAL = 0x00000020,
Michael Wrightd02c5b62014-02-10 15:10:22 -080048 FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040,
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070049 FLAG_KEEP_SCREEN_ON = 0x00000080,
50 FLAG_LAYOUT_IN_SCREEN = 0x00000100,
51 FLAG_LAYOUT_NO_LIMITS = 0x00000200,
52 FLAG_FULLSCREEN = 0x00000400,
53 FLAG_FORCE_NOT_FULLSCREEN = 0x00000800,
54 FLAG_DITHER = 0x00001000,
55 FLAG_SECURE = 0x00002000,
56 FLAG_SCALED = 0x00004000,
57 FLAG_IGNORE_CHEEK_PRESSES = 0x00008000,
Michael Wrightd02c5b62014-02-10 15:10:22 -080058 FLAG_LAYOUT_INSET_DECOR = 0x00010000,
59 FLAG_ALT_FOCUSABLE_IM = 0x00020000,
60 FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000,
61 FLAG_SHOW_WHEN_LOCKED = 0x00080000,
62 FLAG_SHOW_WALLPAPER = 0x00100000,
63 FLAG_TURN_SCREEN_ON = 0x00200000,
64 FLAG_DISMISS_KEYGUARD = 0x00400000,
65 FLAG_SPLIT_TOUCH = 0x00800000,
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070066 FLAG_HARDWARE_ACCELERATED = 0x01000000,
67 FLAG_LAYOUT_IN_OVERSCAN = 0x02000000,
68 FLAG_TRANSLUCENT_STATUS = 0x04000000,
69 FLAG_TRANSLUCENT_NAVIGATION = 0x08000000,
70 FLAG_LOCAL_FOCUS_MODE = 0x10000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -080071 FLAG_SLIPPERY = 0x20000000,
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070072 FLAG_LAYOUT_ATTACHED_IN_DECOR = 0x40000000,
73 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -080074 };
75
Michael Wrightd02c5b62014-02-10 15:10:22 -080076 // Window types from WindowManager.LayoutParams
77 enum {
78 FIRST_APPLICATION_WINDOW = 1,
wilsonshih599042f2020-05-04 16:24:58 +080079 TYPE_BASE_APPLICATION = 1,
80 TYPE_APPLICATION = 2,
Michael Wrightd02c5b62014-02-10 15:10:22 -080081 TYPE_APPLICATION_STARTING = 3,
82 LAST_APPLICATION_WINDOW = 99,
wilsonshih599042f2020-05-04 16:24:58 +080083 FIRST_SUB_WINDOW = 1000,
84 TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW,
85 TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1,
86 TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2,
87 TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3,
88 TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4,
89 LAST_SUB_WINDOW = 1999,
90 FIRST_SYSTEM_WINDOW = 2000,
91 TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW,
92 TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1,
93 TYPE_PHONE = FIRST_SYSTEM_WINDOW + 2,
94 TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3,
95 TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW + 4,
96 TYPE_TOAST = FIRST_SYSTEM_WINDOW + 5,
97 TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6,
98 TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7,
99 TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8,
100 TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9,
101 TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10,
102 TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11,
103 TYPE_INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12,
104 TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW + 13,
105 TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14,
106 TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15,
107 TYPE_DRAG = FIRST_SYSTEM_WINDOW + 16,
108 TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17,
109 TYPE_POINTER = FIRST_SYSTEM_WINDOW + 18,
110 TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19,
111 TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20,
112 TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21,
113 TYPE_INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22,
114 TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24,
115 TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27,
116 TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32,
117 TYPE_DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34,
118 TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39,
119 TYPE_NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40,
120 LAST_SYSTEM_WINDOW = 2999,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121 };
122
123 enum {
124 INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
125 INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002,
126 INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004,
127 };
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700128
Robert Carr5cb25782018-11-14 14:01:42 -0800129 /* These values are filled in by the WM and passed through SurfaceFlinger
130 * unless specified otherwise.
131 */
chaviwaf87b3e2019-10-01 16:59:28 -0700132 // This value should NOT be used to uniquely identify the window. There may be different
133 // input windows that have the same token.
Robert Carr5c8a0262018-10-03 16:30:44 -0700134 sp<IBinder> token;
chaviwaf87b3e2019-10-01 16:59:28 -0700135 // This uniquely identifies the input window.
Robert Carr7174efe2020-04-13 16:55:27 -0700136 int32_t id = -1;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800137 std::string name;
Robert Carr7174efe2020-04-13 16:55:27 -0700138 int32_t layoutParamsFlags = 0;
139 int32_t layoutParamsType = 0;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500140 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
Robert Carr5cb25782018-11-14 14:01:42 -0800141
142 /* These values are filled in by SurfaceFlinger. */
Robert Carr7174efe2020-04-13 16:55:27 -0700143 int32_t frameLeft = -1;
144 int32_t frameTop = -1;
145 int32_t frameRight = -1;
146 int32_t frameBottom = -1;
Robert Carr5cb25782018-11-14 14:01:42 -0800147
148 /*
149 * SurfaceFlinger consumes this value to shrink the computed frame. This is
150 * different from shrinking the touchable region in that it DOES shift the coordinate
151 * space where-as the touchable region does not and is more like "cropping". This
152 * is used for window shadows.
153 */
154 int32_t surfaceInset = 0;
155
Robert Carre07e1032018-11-26 12:55:53 -0800156 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
157 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
Robert Carr7174efe2020-04-13 16:55:27 -0700158 float globalScaleFactor = 1.0f;
Robert Carre07e1032018-11-26 12:55:53 -0800159
160 // Scaling factors applied to individual windows.
161 float windowXScale = 1.0f;
162 float windowYScale = 1.0f;
Robert Carr5cb25782018-11-14 14:01:42 -0800163
chaviwfd9c1ed2020-07-01 10:57:59 -0700164 // Transform applied to individual windows.
165 ui::Transform transform;
166
Robert Carr5cb25782018-11-14 14:01:42 -0800167 /*
168 * This is filled in by the WM relative to the frame and then translated
169 * to absolute coordinates by SurfaceFlinger once the frame is computed.
170 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800171 Region touchableRegion;
Robert Carr7174efe2020-04-13 16:55:27 -0700172 bool visible = false;
173 bool canReceiveKeys = false;
174 bool hasFocus = false;
175 bool hasWallpaper = false;
176 bool paused = false;
Chris Yefcdff3e2020-05-10 15:16:04 -0700177 /* This flag is set when the window is of a trusted type that is allowed to silently
178 * overlay other windows for the purpose of implementing the secure views feature.
179 * Trusted overlays, such as IME windows, can partly obscure other windows without causing
180 * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED.
181 */
182 bool trustedOverlay = false;
Robert Carr7174efe2020-04-13 16:55:27 -0700183 int32_t ownerPid = -1;
184 int32_t ownerUid = -1;
185 int32_t inputFeatures = 0;
186 int32_t displayId = ADISPLAY_ID_NONE;
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800187 int32_t portalToDisplayId = ADISPLAY_ID_NONE;
Robert Carr740167f2018-10-11 19:03:41 -0700188 InputApplicationInfo applicationInfo;
Robert Carr7174efe2020-04-13 16:55:27 -0700189 bool replaceTouchableRegionWithCrop = false;
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700190 wp<IBinder> touchableRegionCropHandle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800191
192 void addTouchableRegion(const Rect& region);
193
194 bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800195
Chris Yefcdff3e2020-05-10 15:16:04 -0700196 bool frameContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800197
198 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700199
200 bool overlaps(const InputWindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700201
202 status_t write(Parcel& output) const;
Chris Yefcdff3e2020-05-10 15:16:04 -0700203
Robert Carr3720ed02018-08-08 16:08:27 -0700204 static InputWindowInfo read(const Parcel& from);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800205};
206
Siarhei Vishniakou67d44502020-04-09 11:09:29 -0700207std::string inputWindowFlagsToString(uint32_t flags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800208
209/*
210 * Handle for a window that can receive input.
211 *
212 * Used by the native input dispatcher to indirectly refer to the window manager objects
213 * that describe a window.
214 */
215class InputWindowHandle : public RefBase {
216public:
Michael Wrightd02c5b62014-02-10 15:10:22 -0800217
218 inline const InputWindowInfo* getInfo() const {
Arthur Hung3b413f22018-10-26 18:05:34 +0800219 return &mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800220 }
221
Robert Carr5c8a0262018-10-03 16:30:44 -0700222 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800223
chaviwaf87b3e2019-10-01 16:59:28 -0700224 int32_t getId() const { return mInfo.id; }
225
Robert Carr740167f2018-10-11 19:03:41 -0700226 sp<IBinder> getApplicationToken() {
227 return mInfo.applicationInfo.token;
228 }
229
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800230 inline std::string getName() const {
Robert Carr2984b7a2020-04-13 17:06:45 -0700231 return !mInfo.name.empty() ? mInfo.name : "<invalid>";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800232 }
233
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -0700234 inline std::chrono::nanoseconds getDispatchingTimeout(
235 std::chrono::nanoseconds defaultValue) const {
236 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
237 }
238
Michael Wrightd02c5b62014-02-10 15:10:22 -0800239 /**
240 * Requests that the state of this object be updated to reflect
241 * the most current available information about the application.
242 *
243 * This method should only be called from within the input dispatcher's
244 * critical section.
245 *
246 * Returns true on success, or false if the handle is no longer valid.
247 */
248 virtual bool updateInfo() = 0;
249
250 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800251 * Updates from another input window handle.
252 */
253 void updateFrom(const sp<InputWindowHandle> handle);
254
255 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800256 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800257 * no longer needed.
258 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800259 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800260
261protected:
Robert Carr740167f2018-10-11 19:03:41 -0700262 explicit InputWindowHandle();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800263 virtual ~InputWindowHandle();
264
Arthur Hung3b413f22018-10-26 18:05:34 +0800265 InputWindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800266};
267
268} // namespace android
269
270#endif // _UI_INPUT_WINDOW_H