blob: 2b8cc57c05132a6312ecbe656d341bad4ce2a57e [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>
24#include <utils/RefBase.h>
25#include <utils/Timers.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080026
27#include "InputApplication.h"
28
29namespace android {
Robert Carr3720ed02018-08-08 16:08:27 -070030class Parcel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080031
32/*
33 * Describes the properties of a window that can receive input.
34 */
35struct InputWindowInfo {
Robert Carr1cc78672018-07-31 14:25:57 -070036 InputWindowInfo() = default;
37 InputWindowInfo(const Parcel& from);
38
Michael Wrightd02c5b62014-02-10 15:10:22 -080039 // Window flags from WindowManager.LayoutParams
40 enum {
41 FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
42 FLAG_DIM_BEHIND = 0x00000002,
43 FLAG_BLUR_BEHIND = 0x00000004,
44 FLAG_NOT_FOCUSABLE = 0x00000008,
45 FLAG_NOT_TOUCHABLE = 0x00000010,
46 FLAG_NOT_TOUCH_MODAL = 0x00000020,
47 FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040,
48 FLAG_KEEP_SCREEN_ON = 0x00000080,
49 FLAG_LAYOUT_IN_SCREEN = 0x00000100,
50 FLAG_LAYOUT_NO_LIMITS = 0x00000200,
51 FLAG_FULLSCREEN = 0x00000400,
52 FLAG_FORCE_NOT_FULLSCREEN = 0x00000800,
53 FLAG_DITHER = 0x00001000,
54 FLAG_SECURE = 0x00002000,
55 FLAG_SCALED = 0x00004000,
56 FLAG_IGNORE_CHEEK_PRESSES = 0x00008000,
57 FLAG_LAYOUT_INSET_DECOR = 0x00010000,
58 FLAG_ALT_FOCUSABLE_IM = 0x00020000,
59 FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000,
60 FLAG_SHOW_WHEN_LOCKED = 0x00080000,
61 FLAG_SHOW_WALLPAPER = 0x00100000,
62 FLAG_TURN_SCREEN_ON = 0x00200000,
63 FLAG_DISMISS_KEYGUARD = 0x00400000,
64 FLAG_SPLIT_TOUCH = 0x00800000,
65 FLAG_SLIPPERY = 0x20000000,
66 FLAG_NEEDS_MENU_KEY = 0x40000000,
67 };
68
Michael Wrightd02c5b62014-02-10 15:10:22 -080069 // Window types from WindowManager.LayoutParams
70 enum {
71 FIRST_APPLICATION_WINDOW = 1,
72 TYPE_BASE_APPLICATION = 1,
73 TYPE_APPLICATION = 2,
74 TYPE_APPLICATION_STARTING = 3,
75 LAST_APPLICATION_WINDOW = 99,
76 FIRST_SUB_WINDOW = 1000,
77 TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW,
78 TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1,
79 TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2,
80 TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3,
81 TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4,
82 LAST_SUB_WINDOW = 1999,
83 FIRST_SYSTEM_WINDOW = 2000,
84 TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW,
85 TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1,
86 TYPE_PHONE = FIRST_SYSTEM_WINDOW+2,
87 TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3,
88 TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4,
89 TYPE_TOAST = FIRST_SYSTEM_WINDOW+5,
90 TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6,
91 TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7,
92 TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8,
93 TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9,
94 TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10,
95 TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11,
96 TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12,
97 TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13,
98 TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14,
99 TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15,
100 TYPE_DRAG = FIRST_SYSTEM_WINDOW+16,
101 TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17,
102 TYPE_POINTER = FIRST_SYSTEM_WINDOW+18,
103 TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19,
104 TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20,
105 TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21,
Michael Wrightafe7a5c2017-09-19 20:19:39 +0100106 TYPE_INPUT_CONSUMER = FIRST_SYSTEM_WINDOW+22,
Phil Weaver5a071982017-06-26 16:22:26 -0700107 TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24,
kenzyun_chen7942ad72017-06-02 13:36:21 +0800108 TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27,
Phil Weaver5a071982017-06-26 16:22:26 -0700109 TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32,
Michael Wrightb9be0cf2016-05-26 13:49:53 +0100110 TYPE_DOCK_DIVIDER = FIRST_SYSTEM_WINDOW+34,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800111 LAST_SYSTEM_WINDOW = 2999,
112 };
113
114 enum {
115 INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
116 INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002,
117 INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004,
118 };
Robert Carr5cb25782018-11-14 14:01:42 -0800119
120 /* These values are filled in by the WM and passed through SurfaceFlinger
121 * unless specified otherwise.
122 */
Robert Carr5c8a0262018-10-03 16:30:44 -0700123 sp<IBinder> token;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800124 std::string name;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800125 int32_t layoutParamsFlags;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800126 int32_t layoutParamsType;
127 nsecs_t dispatchingTimeout;
Robert Carr5cb25782018-11-14 14:01:42 -0800128
129 /* These values are filled in by SurfaceFlinger. */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800130 int32_t frameLeft;
131 int32_t frameTop;
132 int32_t frameRight;
133 int32_t frameBottom;
Robert Carr5cb25782018-11-14 14:01:42 -0800134
135 /*
136 * SurfaceFlinger consumes this value to shrink the computed frame. This is
137 * different from shrinking the touchable region in that it DOES shift the coordinate
138 * space where-as the touchable region does not and is more like "cropping". This
139 * is used for window shadows.
140 */
141 int32_t surfaceInset = 0;
142
Robert Carre07e1032018-11-26 12:55:53 -0800143 // A global scaling factor for all windows. Unlike windowScaleX/Y this results
144 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
145 float globalScaleFactor;
146
147 // Scaling factors applied to individual windows.
148 float windowXScale = 1.0f;
149 float windowYScale = 1.0f;
Robert Carr5cb25782018-11-14 14:01:42 -0800150
151 /*
152 * This is filled in by the WM relative to the frame and then translated
153 * to absolute coordinates by SurfaceFlinger once the frame is computed.
154 */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800155 Region touchableRegion;
156 bool visible;
157 bool canReceiveKeys;
158 bool hasFocus;
159 bool hasWallpaper;
160 bool paused;
161 int32_t layer;
162 int32_t ownerPid;
163 int32_t ownerUid;
164 int32_t inputFeatures;
165 int32_t displayId;
Robert Carr740167f2018-10-11 19:03:41 -0700166 InputApplicationInfo applicationInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800167
168 void addTouchableRegion(const Rect& region);
169
170 bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
171 bool frameContainsPoint(int32_t x, int32_t y) const;
172
173 /* Returns true if 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 isTrustedOverlay() const;
179
180 bool supportsSplitTouch() const;
Michael Wrightcdcd8f22016-03-22 16:52:13 -0700181
182 bool overlaps(const InputWindowInfo* other) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700183
184 status_t write(Parcel& output) const;
185 static InputWindowInfo read(const Parcel& from);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800186};
187
188
189/*
190 * Handle for a window that can receive input.
191 *
192 * Used by the native input dispatcher to indirectly refer to the window manager objects
193 * that describe a window.
194 */
195class InputWindowHandle : public RefBase {
196public:
Michael Wrightd02c5b62014-02-10 15:10:22 -0800197
198 inline const InputWindowInfo* getInfo() const {
Arthur Hung3b413f22018-10-26 18:05:34 +0800199 return &mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800200 }
201
Robert Carr5c8a0262018-10-03 16:30:44 -0700202 sp<IBinder> getToken() const;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800203
Robert Carr740167f2018-10-11 19:03:41 -0700204 sp<IBinder> getApplicationToken() {
205 return mInfo.applicationInfo.token;
206 }
207
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800208 inline std::string getName() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700209 return mInfo.token ? mInfo.name : "<invalid>";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800210 }
211
212 inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700213 return mInfo.token ? mInfo.dispatchingTimeout : defaultValue;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800214 }
215
216 /**
217 * Requests that the state of this object be updated to reflect
218 * the most current available information about the application.
219 *
220 * This method should only be called from within the input dispatcher's
221 * critical section.
222 *
223 * Returns true on success, or false if the handle is no longer valid.
224 */
225 virtual bool updateInfo() = 0;
226
227 /**
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800228 * Updates from another input window handle.
229 */
230 void updateFrom(const sp<InputWindowHandle> handle);
231
232 /**
Arthur Hung3b413f22018-10-26 18:05:34 +0800233 * Releases the channel used by the associated information when it is
Michael Wrightd02c5b62014-02-10 15:10:22 -0800234 * no longer needed.
235 */
Arthur Hung3b413f22018-10-26 18:05:34 +0800236 void releaseChannel();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800237
238protected:
Robert Carr740167f2018-10-11 19:03:41 -0700239 explicit InputWindowHandle();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800240 virtual ~InputWindowHandle();
241
Arthur Hung3b413f22018-10-26 18:05:34 +0800242 InputWindowInfo mInfo;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800243};
244
245} // namespace android
246
247#endif // _UI_INPUT_WINDOW_H