blob: 7372022078d9426c1d4bce8efbff0400de9204b4 [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
Chris Ye0783e992020-06-02 21:34:49 -070020#include <binder/Parcel.h>
21#include <binder/Parcelable.h>
Michael Wright44753b12020-07-08 13:48:11 +010022#include <input/Flags.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080023#include <input/Input.h>
24#include <input/InputTransport.h>
25#include <ui/Rect.h>
26#include <ui/Region.h>
chaviwfd9c1ed2020-07-01 10:57:59 -070027#include <ui/Transform.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080028#include <utils/RefBase.h>
29#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080030
31#include "InputApplication.h"
32
33namespace android {
Michael Wrightd02c5b62014-02-10 15:10:22 -080034
35/*
36 * Describes the properties of a window that can receive input.
37 */
Chris Ye0783e992020-06-02 21:34:49 -070038struct InputWindowInfo : public Parcelable {
Robert Carr1cc78672018-07-31 14:25:57 -070039 InputWindowInfo() = default;
Robert Carr1cc78672018-07-31 14:25:57 -070040
Michael Wrightd02c5b62014-02-10 15:10:22 -080041 // Window flags from WindowManager.LayoutParams
Michael Wright44753b12020-07-08 13:48:11 +010042 enum class Flag : uint32_t {
43 ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
44 DIM_BEHIND = 0x00000002,
45 BLUR_BEHIND = 0x00000004,
46 NOT_FOCUSABLE = 0x00000008,
47 NOT_TOUCHABLE = 0x00000010,
48 NOT_TOUCH_MODAL = 0x00000020,
49 TOUCHABLE_WHEN_WAKING = 0x00000040,
50 KEEP_SCREEN_ON = 0x00000080,
51 LAYOUT_IN_SCREEN = 0x00000100,
52 LAYOUT_NO_LIMITS = 0x00000200,
53 FULLSCREEN = 0x00000400,
54 FORCE_NOT_FULLSCREEN = 0x00000800,
55 DITHER = 0x00001000,
56 SECURE = 0x00002000,
57 SCALED = 0x00004000,
58 IGNORE_CHEEK_PRESSES = 0x00008000,
59 LAYOUT_INSET_DECOR = 0x00010000,
60 ALT_FOCUSABLE_IM = 0x00020000,
61 WATCH_OUTSIDE_TOUCH = 0x00040000,
62 SHOW_WHEN_LOCKED = 0x00080000,
63 SHOW_WALLPAPER = 0x00100000,
64 TURN_SCREEN_ON = 0x00200000,
65 DISMISS_KEYGUARD = 0x00400000,
66 SPLIT_TOUCH = 0x00800000,
67 HARDWARE_ACCELERATED = 0x01000000,
68 LAYOUT_IN_OVERSCAN = 0x02000000,
69 TRANSLUCENT_STATUS = 0x04000000,
70 TRANSLUCENT_NAVIGATION = 0x08000000,
71 LOCAL_FOCUS_MODE = 0x10000000,
72 SLIPPERY = 0x20000000,
73 LAYOUT_ATTACHED_IN_DECOR = 0x40000000,
74 DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000,
75 }; // Window types from WindowManager.LayoutParams
Michael Wrightd02c5b62014-02-10 15:10:22 -080076
Michael Wright44753b12020-07-08 13:48:11 +010077 enum class Type : int32_t {
78 UNKNOWN = 0,
Michael Wrightd02c5b62014-02-10 15:10:22 -080079 FIRST_APPLICATION_WINDOW = 1,
Michael Wright44753b12020-07-08 13:48:11 +010080 BASE_APPLICATION = 1,
81 APPLICATION = 2,
82 APPLICATION_STARTING = 3,
Michael Wrightd02c5b62014-02-10 15:10:22 -080083 LAST_APPLICATION_WINDOW = 99,
wilsonshih599042f2020-05-04 16:24:58 +080084 FIRST_SUB_WINDOW = 1000,
Michael Wright44753b12020-07-08 13:48:11 +010085 APPLICATION_PANEL = FIRST_SUB_WINDOW,
86 APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1,
87 APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2,
88 APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3,
89 APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4,
wilsonshih599042f2020-05-04 16:24:58 +080090 LAST_SUB_WINDOW = 1999,
91 FIRST_SYSTEM_WINDOW = 2000,
Michael Wright44753b12020-07-08 13:48:11 +010092 STATUS_BAR = FIRST_SYSTEM_WINDOW,
93 SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1,
94 PHONE = FIRST_SYSTEM_WINDOW + 2,
95 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3,
96 KEYGUARD = FIRST_SYSTEM_WINDOW + 4,
97 TOAST = FIRST_SYSTEM_WINDOW + 5,
98 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6,
99 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7,
100 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8,
101 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9,
102 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10,
103 INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11,
104 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12,
105 WALLPAPER = FIRST_SYSTEM_WINDOW + 13,
106 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14,
107 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15,
108 DRAG = FIRST_SYSTEM_WINDOW + 16,
109 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17,
110 POINTER = FIRST_SYSTEM_WINDOW + 18,
111 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19,
112 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20,
113 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21,
114 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22,
115 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24,
116 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27,
117 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32,
118 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34,
119 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39,
120 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40,
wilsonshih599042f2020-05-04 16:24:58 +0800121 LAST_SYSTEM_WINDOW = 2999,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800122 };
123
Michael Wright44753b12020-07-08 13:48:11 +0100124 enum class Feature {
125 DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
126 NO_INPUT_CHANNEL = 0x00000002,
127 DISABLE_USER_ACTIVITY = 0x00000004,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800128 };
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700129
Robert Carr5cb25782018-11-14 14:01:42 -0800130 /* These values are filled in by the WM and passed through SurfaceFlinger
131 * unless specified otherwise.
132 */
chaviwaf87b3e2019-10-01 16:59:28 -0700133 // This value should NOT be used to uniquely identify the window. There may be different
134 // input windows that have the same token.
Robert Carr5c8a0262018-10-03 16:30:44 -0700135 sp<IBinder> token;
chaviwaf87b3e2019-10-01 16:59:28 -0700136 // This uniquely identifies the input window.
Robert Carr7174efe2020-04-13 16:55:27 -0700137 int32_t id = -1;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800138 std::string name;
Michael Wright44753b12020-07-08 13:48:11 +0100139 Flags<Flag> flags;
140 Type type = Type::UNKNOWN;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500141 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);
Robert Carr5cb25782018-11-14 14:01:42 -0800142
143 /* These values are filled in by SurfaceFlinger. */
Robert Carr7174efe2020-04-13 16:55:27 -0700144 int32_t frameLeft = -1;
145 int32_t frameTop = -1;
146 int32_t frameRight = -1;
147 int32_t frameBottom = -1;
Robert Carr5cb25782018-11-14 14:01:42 -0800148
149 /*
150 * SurfaceFlinger consumes this value to shrink the computed frame. This is
151 * different from shrinking the touchable region in that it DOES shift the coordinate
152 * space where-as the touchable region does not and is more like "cropping". This
153 * is used for window shadows.
154 */
155 int32_t surfaceInset = 0;
156
Robert Carre07e1032018-11-26 12:55:53 -0800157 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
158 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
Robert Carr7174efe2020-04-13 16:55:27 -0700159 float globalScaleFactor = 1.0f;
Robert Carre07e1032018-11-26 12:55:53 -0800160
chaviwfd9c1ed2020-07-01 10:57:59 -0700161 // Transform applied to individual windows.
162 ui::Transform transform;
163
Robert Carr5cb25782018-11-14 14:01:42 -0800164 /*
165 * This is filled in by the WM relative to the frame and then translated
166 * to absolute coordinates by SurfaceFlinger once the frame is computed.
167 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800168 Region touchableRegion;
Robert Carr7174efe2020-04-13 16:55:27 -0700169 bool visible = false;
Vishnu Nair47074b82020-08-14 11:54:47 -0700170 bool focusable = false;
Robert Carr7174efe2020-04-13 16:55:27 -0700171 bool hasWallpaper = false;
172 bool paused = false;
Chris Yefcdff3e2020-05-10 15:16:04 -0700173 /* This flag is set when the window is of a trusted type that is allowed to silently
174 * overlay other windows for the purpose of implementing the secure views feature.
175 * Trusted overlays, such as IME windows, can partly obscure other windows without causing
176 * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED.
177 */
178 bool trustedOverlay = false;
Robert Carr7174efe2020-04-13 16:55:27 -0700179 int32_t ownerPid = -1;
180 int32_t ownerUid = -1;
Michael Wright44753b12020-07-08 13:48:11 +0100181 Flags<Feature> inputFeatures;
Robert Carr7174efe2020-04-13 16:55:27 -0700182 int32_t displayId = ADISPLAY_ID_NONE;
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800183 int32_t portalToDisplayId = ADISPLAY_ID_NONE;
Robert Carr740167f2018-10-11 19:03:41 -0700184 InputApplicationInfo applicationInfo;
Robert Carr7174efe2020-04-13 16:55:27 -0700185 bool replaceTouchableRegionWithCrop = false;
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700186 wp<IBinder> touchableRegionCropHandle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800187
188 void addTouchableRegion(const Rect& region);
189
190 bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800191
Chris Yefcdff3e2020-05-10 15:16:04 -0700192 bool frameContainsPoint(int32_t x, int32_t y) const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800193
194 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700195
196 bool overlaps(const InputWindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700197
Chris Ye0783e992020-06-02 21:34:49 -0700198 bool operator==(const InputWindowInfo& inputChannel) const;
Chris Yefcdff3e2020-05-10 15:16:04 -0700199
Chris Ye0783e992020-06-02 21:34:49 -0700200 status_t writeToParcel(android::Parcel* parcel) const override;
201
202 status_t readFromParcel(const android::Parcel* parcel) override;
Michael Wright44753b12020-07-08 13:48:11 +0100203};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800204
205/*
206 * Handle for a window that can receive input.
207 *
208 * Used by the native input dispatcher to indirectly refer to the window manager objects
209 * that describe a window.
210 */
211class InputWindowHandle : public RefBase {
212public:
Chris Ye0783e992020-06-02 21:34:49 -0700213 explicit InputWindowHandle();
214 InputWindowHandle(const InputWindowHandle& other);
215 InputWindowHandle(const InputWindowInfo& other);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800216
Chris Ye0783e992020-06-02 21:34:49 -0700217 inline const InputWindowInfo* getInfo() const { return &mInfo; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800218
Robert Carr5c8a0262018-10-03 16:30:44 -0700219 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800220
chaviwaf87b3e2019-10-01 16:59:28 -0700221 int32_t getId() const { return mInfo.id; }
222
Chris Ye0783e992020-06-02 21:34:49 -0700223 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
Robert Carr740167f2018-10-11 19:03:41 -0700224
Chris Ye0783e992020-06-02 21:34:49 -0700225 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800226
Siarhei Vishniakou4cb50ca2020-05-26 21:43:02 -0700227 inline std::chrono::nanoseconds getDispatchingTimeout(
228 std::chrono::nanoseconds defaultValue) const {
229 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
230 }
231
Michael Wrightd02c5b62014-02-10 15:10:22 -0800232 /**
233 * Requests that the state of this object be updated to reflect
234 * the most current available information about the application.
Chris Ye0783e992020-06-02 21:34:49 -0700235 * As this class is created as RefBase object, no pure virtual function is allowed.
Michael Wrightd02c5b62014-02-10 15:10:22 -0800236 *
237 * This method should only be called from within the input dispatcher's
238 * critical section.
239 *
240 * Returns true on success, or false if the handle is no longer valid.
241 */
Chris Ye0783e992020-06-02 21:34:49 -0700242 virtual bool updateInfo() { return false; }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800243
244 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800245 * Updates from another input window handle.
246 */
247 void updateFrom(const sp<InputWindowHandle> handle);
248
249 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800250 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800251 * no longer needed.
252 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800253 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800254
Chris Ye0783e992020-06-02 21:34:49 -0700255 // Not override since this class is not derrived from Parcelable.
256 status_t readFromParcel(const android::Parcel* parcel);
257 status_t writeToParcel(android::Parcel* parcel) const;
258
Michael Wrightd02c5b62014-02-10 15:10:22 -0800259protected:
Michael Wrightd02c5b62014-02-10 15:10:22 -0800260 virtual ~InputWindowHandle();
261
Arthur Hung3b413f22018-10-26 18:05:34 +0800262 InputWindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800263};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800264} // namespace android
265
266#endif // _UI_INPUT_WINDOW_H