blob: d5d35e6a96f4d401135e6d4acfe42ea1cf8fe719 [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
Michael Wright44753b12020-07-08 13:48:11 +010017#include <type_traits>
Robert Carr3720ed02018-08-08 16:08:27 -070018#define LOG_TAG "InputWindow"
19#define LOG_NDEBUG 0
20
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070021#include <android-base/stringprintf.h>
Robert Carr3720ed02018-08-08 16:08:27 -070022#include <binder/Parcel.h>
Robert Carr3720ed02018-08-08 16:08:27 -070023#include <input/InputTransport.h>
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070024#include <input/InputWindow.h>
Robert Carr3720ed02018-08-08 16:08:27 -070025
26#include <log/log.h>
27
Robert Carr3720ed02018-08-08 16:08:27 -070028namespace android {
29
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070030
Robert Carr3720ed02018-08-08 16:08:27 -070031// --- InputWindowInfo ---
32void InputWindowInfo::addTouchableRegion(const Rect& region) {
33 touchableRegion.orSelf(region);
34}
35
36bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
37 return touchableRegion.contains(x,y);
38}
39
40bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
41 return x >= frameLeft && x < frameRight
42 && y >= frameTop && y < frameBottom;
43}
44
Robert Carr3720ed02018-08-08 16:08:27 -070045bool InputWindowInfo::supportsSplitTouch() const {
Michael Wright44753b12020-07-08 13:48:11 +010046 return flags.test(Flag::SPLIT_TOUCH);
Robert Carr3720ed02018-08-08 16:08:27 -070047}
48
49bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
50 return frameLeft < other->frameRight && frameRight > other->frameLeft
51 && frameTop < other->frameBottom && frameBottom > other->frameTop;
52}
53
Chris Ye0783e992020-06-02 21:34:49 -070054bool InputWindowInfo::operator==(const InputWindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010055 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
56 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
57 info.frameLeft == frameLeft && info.frameTop == frameTop &&
58 info.frameRight == frameRight && info.frameBottom == frameBottom &&
59 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
chaviw1ff3d1e2020-07-01 15:53:47 -070060 info.transform == transform &&
Chris Ye0783e992020-06-02 21:34:49 -070061 info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible &&
62 info.canReceiveKeys == canReceiveKeys && info.trustedOverlay == trustedOverlay &&
63 info.hasFocus == hasFocus && info.hasWallpaper == hasWallpaper &&
64 info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
65 info.inputFeatures == inputFeatures && info.displayId == displayId &&
66 info.portalToDisplayId == portalToDisplayId &&
67 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
68 info.applicationInfo.name == applicationInfo.name &&
69 info.applicationInfo.token == applicationInfo.token &&
70 info.applicationInfo.dispatchingTimeout == applicationInfo.dispatchingTimeout;
71}
72
73status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const {
74 if (parcel == nullptr) {
75 ALOGE("%s: Null parcel", __func__);
76 return BAD_VALUE;
77 }
Robert Carr2984b7a2020-04-13 17:06:45 -070078 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070079 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070080 return OK;
81 }
Chris Ye0783e992020-06-02 21:34:49 -070082 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070083
Chris Ye0783e992020-06-02 21:34:49 -070084 status_t status = parcel->writeStrongBinder(token) ?:
85 parcel->writeInt64(dispatchingTimeout.count()) ?:
86 parcel->writeInt32(id) ?:
87 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010088 parcel->writeInt32(flags.get()) ?:
89 parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070090 parcel->writeInt32(frameLeft) ?:
91 parcel->writeInt32(frameTop) ?:
92 parcel->writeInt32(frameRight) ?:
93 parcel->writeInt32(frameBottom) ?:
94 parcel->writeInt32(surfaceInset) ?:
95 parcel->writeFloat(globalScaleFactor) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070096 parcel->writeFloat(transform.dsdx()) ?:
97 parcel->writeFloat(transform.dtdx()) ?:
98 parcel->writeFloat(transform.tx()) ?:
99 parcel->writeFloat(transform.dtdy()) ?:
100 parcel->writeFloat(transform.dsdy()) ?:
101 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700102 parcel->writeBool(visible) ?:
103 parcel->writeBool(canReceiveKeys) ?:
104 parcel->writeBool(hasFocus) ?:
105 parcel->writeBool(hasWallpaper) ?:
106 parcel->writeBool(paused) ?:
107 parcel->writeBool(trustedOverlay) ?:
108 parcel->writeInt32(ownerPid) ?:
109 parcel->writeInt32(ownerUid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100110 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700111 parcel->writeInt32(displayId) ?:
112 parcel->writeInt32(portalToDisplayId) ?:
113 applicationInfo.writeToParcel(parcel) ?:
114 parcel->write(touchableRegion) ?:
115 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
116 parcel->writeStrongBinder(touchableRegionCropHandle.promote());
117
118 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700119}
120
Chris Ye0783e992020-06-02 21:34:49 -0700121status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) {
122 if (parcel == nullptr) {
123 ALOGE("%s: Null parcel", __func__);
124 return BAD_VALUE;
125 }
126 if (parcel->readInt32() == 0) {
127 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700128 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700129
Chris Ye0783e992020-06-02 21:34:49 -0700130 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100131 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
132 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
133 if (status != OK) {
134 return status;
135 }
136
137 flags = Flags<Flag>(parcel->readInt32());
138 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700139 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Michael Wright44753b12020-07-08 13:48:11 +0100140 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700141 parcel->readInt32(&frameTop) ?:
142 parcel->readInt32(&frameRight) ?:
143 parcel->readInt32(&frameBottom) ?:
144 parcel->readInt32(&surfaceInset) ?:
145 parcel->readFloat(&globalScaleFactor) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700146 parcel->readFloat(&dsdx) ?:
147 parcel->readFloat(&dtdx) ?:
148 parcel->readFloat(&tx) ?:
149 parcel->readFloat(&dtdy) ?:
150 parcel->readFloat(&dsdy) ?:
151 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700152 parcel->readBool(&visible) ?:
153 parcel->readBool(&canReceiveKeys) ?:
154 parcel->readBool(&hasFocus) ?:
155 parcel->readBool(&hasWallpaper) ?:
156 parcel->readBool(&paused) ?:
157 parcel->readBool(&trustedOverlay) ?:
158 parcel->readInt32(&ownerPid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100159 parcel->readInt32(&ownerUid);
160
161 if (status != OK) {
162 return status;
163 }
164
165 inputFeatures = Flags<Feature>(parcel->readInt32());
166 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700167 parcel->readInt32(&portalToDisplayId) ?:
168 applicationInfo.readFromParcel(parcel) ?:
169 parcel->read(touchableRegion) ?:
170 parcel->readBool(&replaceTouchableRegionWithCrop);
Robert Carr3720ed02018-08-08 16:08:27 -0700171
Michael Wright44753b12020-07-08 13:48:11 +0100172 if (status != OK) {
173 return status;
174 }
175
Chris Ye0783e992020-06-02 21:34:49 -0700176 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw1ff3d1e2020-07-01 15:53:47 -0700177 transform.set(std::array<float, 9>{dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700178
Michael Wright44753b12020-07-08 13:48:11 +0100179 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700180}
181
Robert Carr3720ed02018-08-08 16:08:27 -0700182// --- InputWindowHandle ---
183
Chris Ye0783e992020-06-02 21:34:49 -0700184InputWindowHandle::InputWindowHandle() {}
185
186InputWindowHandle::~InputWindowHandle() {}
187
188InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {}
189
190InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {}
191
192status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const {
193 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700194}
195
Chris Ye0783e992020-06-02 21:34:49 -0700196status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) {
197 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700198}
199
Arthur Hung3b413f22018-10-26 18:05:34 +0800200void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700201 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700202}
203
Robert Carr5c8a0262018-10-03 16:30:44 -0700204sp<IBinder> InputWindowHandle::getToken() const {
205 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700206}
207
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800208void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
209 mInfo = handle->mInfo;
210}
211
Michael Wright44753b12020-07-08 13:48:11 +0100212std::optional<std::string> InputWindowInfo::flagToString(Flag flag) {
213 switch (flag) {
214 case InputWindowInfo::Flag::ALLOW_LOCK_WHILE_SCREEN_ON: {
215 return "ALLOW_LOCK_WHILE_SCREEN_ON";
216 }
217 case InputWindowInfo::Flag::DIM_BEHIND: {
218 return "DIM_BEHIND";
219 }
220 case InputWindowInfo::Flag::BLUR_BEHIND: {
221 return "BLUR_BEHIND";
222 }
223 case InputWindowInfo::Flag::NOT_FOCUSABLE: {
224 return "NOT_FOCUSABLE";
225 }
226 case InputWindowInfo::Flag::NOT_TOUCHABLE: {
227 return "NOT_TOUCHABLE";
228 }
229 case InputWindowInfo::Flag::NOT_TOUCH_MODAL: {
230 return "NOT_TOUCH_MODAL";
231 }
232 case InputWindowInfo::Flag::TOUCHABLE_WHEN_WAKING: {
233 return "TOUCHABLE_WHEN_WAKING";
234 }
235 case InputWindowInfo::Flag::KEEP_SCREEN_ON: {
236 return "KEEP_SCREEN_ON";
237 }
238 case InputWindowInfo::Flag::LAYOUT_IN_SCREEN: {
239 return "LAYOUT_IN_SCREEN";
240 }
241 case InputWindowInfo::Flag::LAYOUT_NO_LIMITS: {
242 return "LAYOUT_NO_LIMITS";
243 }
244 case InputWindowInfo::Flag::FULLSCREEN: {
245 return "FULLSCREEN";
246 }
247 case InputWindowInfo::Flag::FORCE_NOT_FULLSCREEN: {
248 return "FORCE_NOT_FULLSCREEN";
249 }
250 case InputWindowInfo::Flag::DITHER: {
251 return "DITHER";
252 }
253 case InputWindowInfo::Flag::SECURE: {
254 return "SECURE";
255 }
256 case InputWindowInfo::Flag::SCALED: {
257 return "SCALED";
258 }
259 case InputWindowInfo::Flag::IGNORE_CHEEK_PRESSES: {
260 return "IGNORE_CHEEK_PRESSES";
261 }
262 case InputWindowInfo::Flag::LAYOUT_INSET_DECOR: {
263 return "LAYOUT_INSET_DECOR";
264 }
265 case InputWindowInfo::Flag::ALT_FOCUSABLE_IM: {
266 return "ALT_FOCUSABLE_IM";
267 }
268 case InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH: {
269 return "WATCH_OUTSIDE_TOUCH";
270 }
271 case InputWindowInfo::Flag::SHOW_WHEN_LOCKED: {
272 return "SHOW_WHEN_LOCKED";
273 }
274 case InputWindowInfo::Flag::SHOW_WALLPAPER: {
275 return "SHOW_WALLPAPER";
276 }
277 case InputWindowInfo::Flag::TURN_SCREEN_ON: {
278 return "TURN_SCREEN_ON";
279 }
280 case InputWindowInfo::Flag::DISMISS_KEYGUARD: {
281 return "DISMISS_KEYGUARD";
282 }
283 case InputWindowInfo::Flag::SPLIT_TOUCH: {
284 return "SPLIT_TOUCH";
285 }
286 case InputWindowInfo::Flag::HARDWARE_ACCELERATED: {
287 return "HARDWARE_ACCELERATED";
288 }
289 case InputWindowInfo::Flag::LAYOUT_IN_OVERSCAN: {
290 return "LAYOUT_IN_OVERSCAN";
291 }
292 case InputWindowInfo::Flag::TRANSLUCENT_STATUS: {
293 return "TRANSLUCENT_STATUS";
294 }
295 case InputWindowInfo::Flag::TRANSLUCENT_NAVIGATION: {
296 return "TRANSLUCENT_NAVIGATION";
297 }
298 case InputWindowInfo::Flag::LOCAL_FOCUS_MODE: {
299 return "LOCAL_FOCUS_MODE";
300 }
301 case InputWindowInfo::Flag::SLIPPERY: {
302 return "SLIPPERY";
303 }
304 case InputWindowInfo::Flag::LAYOUT_ATTACHED_IN_DECOR: {
305 return "LAYOUT_ATTACHED_IN_DECOR";
306 }
307 case InputWindowInfo::Flag::DRAWS_SYSTEM_BAR_BACKGROUNDS: {
308 return "DRAWS_SYSTEM_BAR_BACKGROUNDS";
309 }
310 }
311 return std::nullopt;
312}
313
Robert Carr3720ed02018-08-08 16:08:27 -0700314} // namespace android