blob: 36097d6d65b430b51269985d71f4d0d81eb1fcfe [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
Bernardo Rufinoea97d182020-08-19 14:43:14 +010020#include <android/os/TouchOcclusionMode.h>
Chris Ye0783e992020-06-02 21:34:49 -070021#include <binder/Parcel.h>
22#include <binder/Parcelable.h>
Michael Wright44753b12020-07-08 13:48:11 +010023#include <input/Flags.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080024#include <input/Input.h>
25#include <input/InputTransport.h>
26#include <ui/Rect.h>
27#include <ui/Region.h>
chaviwfd9c1ed2020-07-01 10:57:59 -070028#include <ui/Transform.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080029#include <utils/RefBase.h>
30#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080031
32#include "InputApplication.h"
33
Bernardo Rufinoea97d182020-08-19 14:43:14 +010034using android::os::TouchOcclusionMode;
35
Michael Wrightd02c5b62014-02-10 15:10:22 -080036namespace android {
Michael Wrightd02c5b62014-02-10 15:10:22 -080037
38/*
39 * Describes the properties of a window that can receive input.
40 */
Chris Ye0783e992020-06-02 21:34:49 -070041struct InputWindowInfo : public Parcelable {
Robert Carr1cc78672018-07-31 14:25:57 -070042 InputWindowInfo() = 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,
78 }; // Window types from WindowManager.LayoutParams
Michael Wrightd02c5b62014-02-10 15:10:22 -080079
Michael Wright44753b12020-07-08 13:48:11 +010080 enum class Type : int32_t {
81 UNKNOWN = 0,
Michael Wrightd02c5b62014-02-10 15:10:22 -080082 FIRST_APPLICATION_WINDOW = 1,
Michael Wright44753b12020-07-08 13:48:11 +010083 BASE_APPLICATION = 1,
84 APPLICATION = 2,
85 APPLICATION_STARTING = 3,
Michael Wrightd02c5b62014-02-10 15:10:22 -080086 LAST_APPLICATION_WINDOW = 99,
wilsonshih599042f2020-05-04 16:24:58 +080087 FIRST_SUB_WINDOW = 1000,
Michael Wright44753b12020-07-08 13:48:11 +010088 APPLICATION_PANEL = FIRST_SUB_WINDOW,
89 APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1,
90 APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2,
91 APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3,
92 APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4,
wilsonshih599042f2020-05-04 16:24:58 +080093 LAST_SUB_WINDOW = 1999,
94 FIRST_SYSTEM_WINDOW = 2000,
Michael Wright44753b12020-07-08 13:48:11 +010095 STATUS_BAR = FIRST_SYSTEM_WINDOW,
96 SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1,
97 PHONE = FIRST_SYSTEM_WINDOW + 2,
98 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3,
99 KEYGUARD = FIRST_SYSTEM_WINDOW + 4,
100 TOAST = FIRST_SYSTEM_WINDOW + 5,
101 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6,
102 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7,
103 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8,
104 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9,
105 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10,
106 INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11,
107 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12,
108 WALLPAPER = FIRST_SYSTEM_WINDOW + 13,
109 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14,
110 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15,
111 DRAG = FIRST_SYSTEM_WINDOW + 16,
112 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17,
113 POINTER = FIRST_SYSTEM_WINDOW + 18,
114 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19,
115 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20,
116 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21,
117 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22,
118 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24,
119 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27,
120 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32,
121 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34,
122 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39,
123 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40,
wilsonshih599042f2020-05-04 16:24:58 +0800124 LAST_SYSTEM_WINDOW = 2999,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800125 };
126
Michael Wright44753b12020-07-08 13:48:11 +0100127 enum class Feature {
128 DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
129 NO_INPUT_CHANNEL = 0x00000002,
130 DISABLE_USER_ACTIVITY = 0x00000004,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800131 };
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700132
Robert Carr5cb25782018-11-14 14:01:42 -0800133 /* These values are filled in by the WM and passed through SurfaceFlinger
134 * unless specified otherwise.
135 */
chaviwaf87b3e2019-10-01 16:59:28 -0700136 // This value should NOT be used to uniquely identify the window. There may be different
137 // input windows that have the same token.
Robert Carr5c8a0262018-10-03 16:30:44 -0700138 sp<IBinder> token;
chaviwaf87b3e2019-10-01 16:59:28 -0700139 // This uniquely identifies the input window.
Robert Carr7174efe2020-04-13 16:55:27 -0700140 int32_t id = -1;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800141 std::string name;
Michael Wright44753b12020-07-08 13:48:11 +0100142 Flags<Flag> flags;
143 Type type = Type::UNKNOWN;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500144 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
Robert Carr5cb25782018-11-14 14:01:42 -0800145
146 /* These values are filled in by SurfaceFlinger. */
Robert Carr7174efe2020-04-13 16:55:27 -0700147 int32_t frameLeft = -1;
148 int32_t frameTop = -1;
149 int32_t frameRight = -1;
150 int32_t frameBottom = -1;
Robert Carr5cb25782018-11-14 14:01:42 -0800151
152 /*
153 * SurfaceFlinger consumes this value to shrink the computed frame. This is
154 * different from shrinking the touchable region in that it DOES shift the coordinate
155 * space where-as the touchable region does not and is more like "cropping". This
156 * is used for window shadows.
157 */
158 int32_t surfaceInset = 0;
159
Robert Carre07e1032018-11-26 12:55:53 -0800160 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
161 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
Robert Carr7174efe2020-04-13 16:55:27 -0700162 float globalScaleFactor = 1.0f;
Robert Carre07e1032018-11-26 12:55:53 -0800163
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100164 // The opacity of this window, from 0.0 to 1.0 (inclusive).
165 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent.
166 float alpha;
167
chaviwfd9c1ed2020-07-01 10:57:59 -0700168 // Transform applied to individual windows.
169 ui::Transform transform;
170
Robert Carr5cb25782018-11-14 14:01:42 -0800171 /*
172 * This is filled in by the WM relative to the frame and then translated
173 * to absolute coordinates by SurfaceFlinger once the frame is computed.
174 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800175 Region touchableRegion;
Robert Carr7174efe2020-04-13 16:55:27 -0700176 bool visible = false;
Vishnu Nair47074b82020-08-14 11:54:47 -0700177 bool focusable = false;
Robert Carr7174efe2020-04-13 16:55:27 -0700178 bool hasWallpaper = false;
179 bool paused = false;
Chris Yefcdff3e2020-05-10 15:16:04 -0700180 /* This flag is set when 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 trustedOverlay = false;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100186 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED;
Robert Carr7174efe2020-04-13 16:55:27 -0700187 int32_t ownerPid = -1;
188 int32_t ownerUid = -1;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100189 std::string packageName;
Michael Wright44753b12020-07-08 13:48:11 +0100190 Flags<Feature> inputFeatures;
Robert Carr7174efe2020-04-13 16:55:27 -0700191 int32_t displayId = ADISPLAY_ID_NONE;
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800192 int32_t portalToDisplayId = ADISPLAY_ID_NONE;
Robert Carr740167f2018-10-11 19:03:41 -0700193 InputApplicationInfo applicationInfo;
Robert Carr7174efe2020-04-13 16:55:27 -0700194 bool replaceTouchableRegionWithCrop = false;
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700195 wp<IBinder> touchableRegionCropHandle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800196
197 void addTouchableRegion(const Rect& region);
198
199 bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800200
Chris Yefcdff3e2020-05-10 15:16:04 -0700201 bool frameContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800202
203 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700204
205 bool overlaps(const InputWindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700206
Chris Ye0783e992020-06-02 21:34:49 -0700207 bool operator==(const InputWindowInfo& inputChannel) const;
Chris Yefcdff3e2020-05-10 15:16:04 -0700208
Chris Ye0783e992020-06-02 21:34:49 -0700209 status_t writeToParcel(android::Parcel* parcel) const override;
210
211 status_t readFromParcel(const android::Parcel* parcel) override;
Michael Wright44753b12020-07-08 13:48:11 +0100212};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800213
214/*
215 * Handle for a window that can receive input.
216 *
217 * Used by the native input dispatcher to indirectly refer to the window manager objects
218 * that describe a window.
219 */
220class InputWindowHandle : public RefBase {
221public:
Chris Ye0783e992020-06-02 21:34:49 -0700222 explicit InputWindowHandle();
223 InputWindowHandle(const InputWindowHandle& other);
224 InputWindowHandle(const InputWindowInfo& other);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800225
Chris Ye0783e992020-06-02 21:34:49 -0700226 inline const InputWindowInfo* getInfo() const { return &mInfo; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800227
Robert Carr5c8a0262018-10-03 16:30:44 -0700228 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800229
chaviwaf87b3e2019-10-01 16:59:28 -0700230 int32_t getId() const { return mInfo.id; }
231
Chris Ye0783e992020-06-02 21:34:49 -0700232 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
Robert Carr740167f2018-10-11 19:03:41 -0700233
Chris Ye0783e992020-06-02 21:34:49 -0700234 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800235
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -0700236 inline std::chrono::nanoseconds getDispatchingTimeout(
237 std::chrono::nanoseconds defaultValue) const {
238 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
239 }
240
Michael Wrightd02c5b62014-02-10 15:10:22 -0800241 /**
242 * Requests that the state of this object be updated to reflect
243 * the most current available information about the application.
Chris Ye0783e992020-06-02 21:34:49 -0700244 * As this class is created as RefBase object, no pure virtual function is allowed.
Michael Wrightd02c5b62014-02-10 15:10:22 -0800245 *
246 * This method should only be called from within the input dispatcher's
247 * critical section.
248 *
249 * Returns true on success, or false if the handle is no longer valid.
250 */
Chris Ye0783e992020-06-02 21:34:49 -0700251 virtual bool updateInfo() { return false; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800252
253 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800254 * Updates from another input window handle.
255 */
256 void updateFrom(const sp<InputWindowHandle> handle);
257
258 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800259 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800260 * no longer needed.
261 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800262 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800263
Chris Ye0783e992020-06-02 21:34:49 -0700264 // Not override since this class is not derrived from Parcelable.
265 status_t readFromParcel(const android::Parcel* parcel);
266 status_t writeToParcel(android::Parcel* parcel) const;
267
Michael Wrightd02c5b62014-02-10 15:10:22 -0800268protected:
Michael Wrightd02c5b62014-02-10 15:10:22 -0800269 virtual ~InputWindowHandle();
270
Arthur Hung3b413f22018-10-26 18:05:34 +0800271 InputWindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800272};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800273} // namespace android
274
275#endif // _UI_INPUT_WINDOW_H