blob: d7f8ae5d12755d885564f90066968138add8e073 [file] [log] [blame]
Robert Carr3720ed02018-08-08 16:08:27 -07001/*
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#define LOG_TAG "InputWindow"
18#define LOG_NDEBUG 0
19
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070020#include <android-base/stringprintf.h>
Robert Carr3720ed02018-08-08 16:08:27 -070021#include <binder/Parcel.h>
Robert Carr3720ed02018-08-08 16:08:27 -070022#include <input/InputTransport.h>
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070023#include <input/InputWindow.h>
Robert Carr3720ed02018-08-08 16:08:27 -070024
25#include <log/log.h>
26
27#include <ui/Rect.h>
28#include <ui/Region.h>
29
30namespace android {
31
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070032const char* inputWindowFlagToString(uint32_t flag) {
33 switch (flag) {
34 case InputWindowInfo::FLAG_ALLOW_LOCK_WHILE_SCREEN_ON: {
35 return "ALLOW_LOCK_WHILE_SCREEN_ON";
36 }
37 case InputWindowInfo::FLAG_DIM_BEHIND: {
38 return "DIM_BEHIND";
39 }
40 case InputWindowInfo::FLAG_BLUR_BEHIND: {
41 return "BLUR_BEHIND";
42 }
43 case InputWindowInfo::FLAG_NOT_FOCUSABLE: {
44 return "NOT_FOCUSABLE";
45 }
46 case InputWindowInfo::FLAG_NOT_TOUCHABLE: {
47 return "NOT_TOUCHABLE";
48 }
49 case InputWindowInfo::FLAG_NOT_TOUCH_MODAL: {
50 return "NOT_TOUCH_MODAL";
51 }
52 case InputWindowInfo::FLAG_TOUCHABLE_WHEN_WAKING: {
53 return "TOUCHABLE_WHEN_WAKING";
54 }
55 case InputWindowInfo::FLAG_KEEP_SCREEN_ON: {
56 return "KEEP_SCREEN_ON";
57 }
58 case InputWindowInfo::FLAG_LAYOUT_IN_SCREEN: {
59 return "LAYOUT_IN_SCREEN";
60 }
61 case InputWindowInfo::FLAG_LAYOUT_NO_LIMITS: {
62 return "LAYOUT_NO_LIMITS";
63 }
64 case InputWindowInfo::FLAG_FULLSCREEN: {
65 return "FULLSCREEN";
66 }
67 case InputWindowInfo::FLAG_FORCE_NOT_FULLSCREEN: {
68 return "FORCE_NOT_FULLSCREEN";
69 }
70 case InputWindowInfo::FLAG_DITHER: {
71 return "DITHER";
72 }
73 case InputWindowInfo::FLAG_SECURE: {
74 return "SECURE";
75 }
76 case InputWindowInfo::FLAG_SCALED: {
77 return "SCALED";
78 }
79 case InputWindowInfo::FLAG_IGNORE_CHEEK_PRESSES: {
80 return "IGNORE_CHEEK_PRESSES";
81 }
82 case InputWindowInfo::FLAG_LAYOUT_INSET_DECOR: {
83 return "LAYOUT_INSET_DECOR";
84 }
85 case InputWindowInfo::FLAG_ALT_FOCUSABLE_IM: {
86 return "ALT_FOCUSABLE_IM";
87 }
88 case InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH: {
89 return "WATCH_OUTSIDE_TOUCH";
90 }
91 case InputWindowInfo::FLAG_SHOW_WHEN_LOCKED: {
92 return "SHOW_WHEN_LOCKED";
93 }
94 case InputWindowInfo::FLAG_SHOW_WALLPAPER: {
95 return "SHOW_WALLPAPER";
96 }
97 case InputWindowInfo::FLAG_TURN_SCREEN_ON: {
98 return "TURN_SCREEN_ON";
99 }
100 case InputWindowInfo::FLAG_DISMISS_KEYGUARD: {
101 return "DISMISS_KEYGUARD";
102 }
103 case InputWindowInfo::FLAG_SPLIT_TOUCH: {
104 return "SPLIT_TOUCH";
105 }
106 case InputWindowInfo::FLAG_HARDWARE_ACCELERATED: {
107 return "HARDWARE_ACCELERATED";
108 }
109 case InputWindowInfo::FLAG_LAYOUT_IN_OVERSCAN: {
110 return "LAYOUT_IN_OVERSCAN";
111 }
112 case InputWindowInfo::FLAG_TRANSLUCENT_STATUS: {
113 return "TRANSLUCENT_STATUS";
114 }
115 case InputWindowInfo::FLAG_TRANSLUCENT_NAVIGATION: {
116 return "TRANSLUCENT_NAVIGATION";
117 }
118 case InputWindowInfo::FLAG_LOCAL_FOCUS_MODE: {
119 return "LOCAL_FOCUS_MODE";
120 }
121 case InputWindowInfo::FLAG_SLIPPERY: {
122 return "SLIPPERY";
123 }
124 case InputWindowInfo::FLAG_LAYOUT_ATTACHED_IN_DECOR: {
125 return "LAYOUT_ATTACHED_IN_DECOR";
126 }
127 case InputWindowInfo::FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS: {
128 return "DRAWS_SYSTEM_BAR_BACKGROUNDS";
129 }
130 }
131 return "UNKNOWN";
132}
133
134std::string inputWindowFlagsToString(uint32_t flags) {
135 std::string result;
136 for (BitSet32 bits(flags); !bits.isEmpty();) {
137 uint32_t bit = bits.clearLastMarkedBit(); // counts from left
138 const uint32_t flag = 1 << (32 - bit - 1);
139 result += android::base::StringPrintf("%s | ", inputWindowFlagToString(flag));
140 }
141 return result;
142}
143
Robert Carr3720ed02018-08-08 16:08:27 -0700144// --- InputWindowInfo ---
145void InputWindowInfo::addTouchableRegion(const Rect& region) {
146 touchableRegion.orSelf(region);
147}
148
149bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
150 return touchableRegion.contains(x,y);
151}
152
153bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
154 return x >= frameLeft && x < frameRight
155 && y >= frameTop && y < frameBottom;
156}
157
158bool InputWindowInfo::isTrustedOverlay() const {
wilsonshih599042f2020-05-04 16:24:58 +0800159 return layoutParamsType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY ||
160 layoutParamsType == TYPE_INPUT_METHOD || layoutParamsType == TYPE_INPUT_METHOD_DIALOG ||
161 layoutParamsType == TYPE_MAGNIFICATION_OVERLAY || layoutParamsType == TYPE_STATUS_BAR ||
162 layoutParamsType == TYPE_NOTIFICATION_SHADE ||
163 layoutParamsType == TYPE_NAVIGATION_BAR ||
164 layoutParamsType == TYPE_NAVIGATION_BAR_PANEL ||
165 layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY ||
166 layoutParamsType == TYPE_DOCK_DIVIDER ||
167 layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY ||
168 layoutParamsType == TYPE_INPUT_CONSUMER;
Robert Carr3720ed02018-08-08 16:08:27 -0700169}
170
171bool InputWindowInfo::supportsSplitTouch() const {
172 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
173}
174
175bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
176 return frameLeft < other->frameRight && frameRight > other->frameLeft
177 && frameTop < other->frameBottom && frameBottom > other->frameTop;
178}
179
180status_t InputWindowInfo::write(Parcel& output) const {
Robert Carr2984b7a2020-04-13 17:06:45 -0700181 if (name.empty()) {
Robert Carr3720ed02018-08-08 16:08:27 -0700182 output.writeInt32(0);
183 return OK;
184 }
185 output.writeInt32(1);
Robert Carr5c8a0262018-10-03 16:30:44 -0700186 status_t s = output.writeStrongBinder(token);
Robert Carr3720ed02018-08-08 16:08:27 -0700187 if (s != OK) return s;
188
chaviwaf87b3e2019-10-01 16:59:28 -0700189 output.writeInt32(id);
Robert Carr3720ed02018-08-08 16:08:27 -0700190 output.writeString8(String8(name.c_str()));
191 output.writeInt32(layoutParamsFlags);
192 output.writeInt32(layoutParamsType);
193 output.writeInt64(dispatchingTimeout);
194 output.writeInt32(frameLeft);
195 output.writeInt32(frameTop);
196 output.writeInt32(frameRight);
197 output.writeInt32(frameBottom);
Robert Carr5cb25782018-11-14 14:01:42 -0800198 output.writeInt32(surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -0800199 output.writeFloat(globalScaleFactor);
200 output.writeFloat(windowXScale);
201 output.writeFloat(windowYScale);
Robert Carr3720ed02018-08-08 16:08:27 -0700202 output.writeBool(visible);
203 output.writeBool(canReceiveKeys);
204 output.writeBool(hasFocus);
205 output.writeBool(hasWallpaper);
206 output.writeBool(paused);
Robert Carr3720ed02018-08-08 16:08:27 -0700207 output.writeInt32(ownerPid);
208 output.writeInt32(ownerUid);
209 output.writeInt32(inputFeatures);
210 output.writeInt32(displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800211 output.writeInt32(portalToDisplayId);
Robert Carr740167f2018-10-11 19:03:41 -0700212 applicationInfo.write(output);
Robert Carr3720ed02018-08-08 16:08:27 -0700213 output.write(touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700214 output.writeBool(replaceTouchableRegionWithCrop);
Steven Morelandee33b9f2019-07-17 15:04:02 -0700215 output.writeStrongBinder(touchableRegionCropHandle.promote());
Robert Carr3720ed02018-08-08 16:08:27 -0700216 return OK;
217}
218
219InputWindowInfo InputWindowInfo::read(const Parcel& from) {
220 InputWindowInfo ret;
221
222 if (from.readInt32() == 0) {
223 return ret;
Robert Carr3720ed02018-08-08 16:08:27 -0700224 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700225
Robert Carr2984b7a2020-04-13 17:06:45 -0700226 ret.token = from.readStrongBinder();
chaviwaf87b3e2019-10-01 16:59:28 -0700227 ret.id = from.readInt32();
Robert Carr3720ed02018-08-08 16:08:27 -0700228 ret.name = from.readString8().c_str();
229 ret.layoutParamsFlags = from.readInt32();
230 ret.layoutParamsType = from.readInt32();
231 ret.dispatchingTimeout = from.readInt64();
232 ret.frameLeft = from.readInt32();
233 ret.frameTop = from.readInt32();
234 ret.frameRight = from.readInt32();
235 ret.frameBottom = from.readInt32();
Robert Carr5cb25782018-11-14 14:01:42 -0800236 ret.surfaceInset = from.readInt32();
Robert Carre07e1032018-11-26 12:55:53 -0800237 ret.globalScaleFactor = from.readFloat();
238 ret.windowXScale = from.readFloat();
239 ret.windowYScale = from.readFloat();
Robert Carr3720ed02018-08-08 16:08:27 -0700240 ret.visible = from.readBool();
241 ret.canReceiveKeys = from.readBool();
242 ret.hasFocus = from.readBool();
243 ret.hasWallpaper = from.readBool();
244 ret.paused = from.readBool();
Robert Carr3720ed02018-08-08 16:08:27 -0700245 ret.ownerPid = from.readInt32();
246 ret.ownerUid = from.readInt32();
247 ret.inputFeatures = from.readInt32();
248 ret.displayId = from.readInt32();
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800249 ret.portalToDisplayId = from.readInt32();
Robert Carr740167f2018-10-11 19:03:41 -0700250 ret.applicationInfo = InputApplicationInfo::read(from);
Robert Carr3720ed02018-08-08 16:08:27 -0700251 from.read(ret.touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700252 ret.replaceTouchableRegionWithCrop = from.readBool();
Steven Morelandee33b9f2019-07-17 15:04:02 -0700253 ret.touchableRegionCropHandle = from.readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700254
255 return ret;
256}
257
Robert Carr1cc78672018-07-31 14:25:57 -0700258InputWindowInfo::InputWindowInfo(const Parcel& from) {
259 *this = read(from);
260}
261
Robert Carr3720ed02018-08-08 16:08:27 -0700262// --- InputWindowHandle ---
263
Robert Carr740167f2018-10-11 19:03:41 -0700264InputWindowHandle::InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700265}
266
267InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700268}
269
Arthur Hung3b413f22018-10-26 18:05:34 +0800270void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700271 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700272}
273
Robert Carr5c8a0262018-10-03 16:30:44 -0700274sp<IBinder> InputWindowHandle::getToken() const {
275 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700276}
277
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800278void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
279 mInfo = handle->mInfo;
280}
281
Robert Carr3720ed02018-08-08 16:08:27 -0700282} // namespace android