blob: 36c1f8068d54eced5608e8b2e668d045ce01ec29 [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 &&
60 info.windowXScale == windowXScale && info.windowYScale == windowYScale &&
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) ?:
96 parcel->writeFloat(windowXScale) ?:
97 parcel->writeFloat(windowYScale) ?:
98 parcel->writeBool(visible) ?:
99 parcel->writeBool(canReceiveKeys) ?:
100 parcel->writeBool(hasFocus) ?:
101 parcel->writeBool(hasWallpaper) ?:
102 parcel->writeBool(paused) ?:
103 parcel->writeBool(trustedOverlay) ?:
104 parcel->writeInt32(ownerPid) ?:
105 parcel->writeInt32(ownerUid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100106 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700107 parcel->writeInt32(displayId) ?:
108 parcel->writeInt32(portalToDisplayId) ?:
109 applicationInfo.writeToParcel(parcel) ?:
110 parcel->write(touchableRegion) ?:
111 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
112 parcel->writeStrongBinder(touchableRegionCropHandle.promote());
113
114 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700115}
116
Chris Ye0783e992020-06-02 21:34:49 -0700117status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) {
118 if (parcel == nullptr) {
119 ALOGE("%s: Null parcel", __func__);
120 return BAD_VALUE;
121 }
122 if (parcel->readInt32() == 0) {
123 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700124 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700125
Chris Ye0783e992020-06-02 21:34:49 -0700126 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100127 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
128 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
129 if (status != OK) {
130 return status;
131 }
132
133 flags = Flags<Flag>(parcel->readInt32());
134 type = static_cast<Type>(parcel->readInt32());
135 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700136 parcel->readInt32(&frameTop) ?:
137 parcel->readInt32(&frameRight) ?:
138 parcel->readInt32(&frameBottom) ?:
139 parcel->readInt32(&surfaceInset) ?:
140 parcel->readFloat(&globalScaleFactor) ?:
141 parcel->readFloat(&windowXScale) ?:
142 parcel->readFloat(&windowYScale) ?:
143 parcel->readBool(&visible) ?:
144 parcel->readBool(&canReceiveKeys) ?:
145 parcel->readBool(&hasFocus) ?:
146 parcel->readBool(&hasWallpaper) ?:
147 parcel->readBool(&paused) ?:
148 parcel->readBool(&trustedOverlay) ?:
149 parcel->readInt32(&ownerPid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100150 parcel->readInt32(&ownerUid);
151
152 if (status != OK) {
153 return status;
154 }
155
156 inputFeatures = Flags<Feature>(parcel->readInt32());
157 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700158 parcel->readInt32(&portalToDisplayId) ?:
159 applicationInfo.readFromParcel(parcel) ?:
160 parcel->read(touchableRegion) ?:
161 parcel->readBool(&replaceTouchableRegionWithCrop);
Robert Carr3720ed02018-08-08 16:08:27 -0700162
Michael Wright44753b12020-07-08 13:48:11 +0100163 if (status != OK) {
164 return status;
165 }
166
Chris Ye0783e992020-06-02 21:34:49 -0700167 touchableRegionCropHandle = parcel->readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700168
Michael Wright44753b12020-07-08 13:48:11 +0100169 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700170}
171
Robert Carr3720ed02018-08-08 16:08:27 -0700172// --- InputWindowHandle ---
173
Chris Ye0783e992020-06-02 21:34:49 -0700174InputWindowHandle::InputWindowHandle() {}
175
176InputWindowHandle::~InputWindowHandle() {}
177
178InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {}
179
180InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {}
181
182status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const {
183 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700184}
185
Chris Ye0783e992020-06-02 21:34:49 -0700186status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) {
187 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700188}
189
Arthur Hung3b413f22018-10-26 18:05:34 +0800190void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700191 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700192}
193
Robert Carr5c8a0262018-10-03 16:30:44 -0700194sp<IBinder> InputWindowHandle::getToken() const {
195 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700196}
197
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800198void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
199 mInfo = handle->mInfo;
200}
201
Michael Wright44753b12020-07-08 13:48:11 +0100202std::optional<std::string> InputWindowInfo::flagToString(Flag flag) {
203 switch (flag) {
204 case InputWindowInfo::Flag::ALLOW_LOCK_WHILE_SCREEN_ON: {
205 return "ALLOW_LOCK_WHILE_SCREEN_ON";
206 }
207 case InputWindowInfo::Flag::DIM_BEHIND: {
208 return "DIM_BEHIND";
209 }
210 case InputWindowInfo::Flag::BLUR_BEHIND: {
211 return "BLUR_BEHIND";
212 }
213 case InputWindowInfo::Flag::NOT_FOCUSABLE: {
214 return "NOT_FOCUSABLE";
215 }
216 case InputWindowInfo::Flag::NOT_TOUCHABLE: {
217 return "NOT_TOUCHABLE";
218 }
219 case InputWindowInfo::Flag::NOT_TOUCH_MODAL: {
220 return "NOT_TOUCH_MODAL";
221 }
222 case InputWindowInfo::Flag::TOUCHABLE_WHEN_WAKING: {
223 return "TOUCHABLE_WHEN_WAKING";
224 }
225 case InputWindowInfo::Flag::KEEP_SCREEN_ON: {
226 return "KEEP_SCREEN_ON";
227 }
228 case InputWindowInfo::Flag::LAYOUT_IN_SCREEN: {
229 return "LAYOUT_IN_SCREEN";
230 }
231 case InputWindowInfo::Flag::LAYOUT_NO_LIMITS: {
232 return "LAYOUT_NO_LIMITS";
233 }
234 case InputWindowInfo::Flag::FULLSCREEN: {
235 return "FULLSCREEN";
236 }
237 case InputWindowInfo::Flag::FORCE_NOT_FULLSCREEN: {
238 return "FORCE_NOT_FULLSCREEN";
239 }
240 case InputWindowInfo::Flag::DITHER: {
241 return "DITHER";
242 }
243 case InputWindowInfo::Flag::SECURE: {
244 return "SECURE";
245 }
246 case InputWindowInfo::Flag::SCALED: {
247 return "SCALED";
248 }
249 case InputWindowInfo::Flag::IGNORE_CHEEK_PRESSES: {
250 return "IGNORE_CHEEK_PRESSES";
251 }
252 case InputWindowInfo::Flag::LAYOUT_INSET_DECOR: {
253 return "LAYOUT_INSET_DECOR";
254 }
255 case InputWindowInfo::Flag::ALT_FOCUSABLE_IM: {
256 return "ALT_FOCUSABLE_IM";
257 }
258 case InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH: {
259 return "WATCH_OUTSIDE_TOUCH";
260 }
261 case InputWindowInfo::Flag::SHOW_WHEN_LOCKED: {
262 return "SHOW_WHEN_LOCKED";
263 }
264 case InputWindowInfo::Flag::SHOW_WALLPAPER: {
265 return "SHOW_WALLPAPER";
266 }
267 case InputWindowInfo::Flag::TURN_SCREEN_ON: {
268 return "TURN_SCREEN_ON";
269 }
270 case InputWindowInfo::Flag::DISMISS_KEYGUARD: {
271 return "DISMISS_KEYGUARD";
272 }
273 case InputWindowInfo::Flag::SPLIT_TOUCH: {
274 return "SPLIT_TOUCH";
275 }
276 case InputWindowInfo::Flag::HARDWARE_ACCELERATED: {
277 return "HARDWARE_ACCELERATED";
278 }
279 case InputWindowInfo::Flag::LAYOUT_IN_OVERSCAN: {
280 return "LAYOUT_IN_OVERSCAN";
281 }
282 case InputWindowInfo::Flag::TRANSLUCENT_STATUS: {
283 return "TRANSLUCENT_STATUS";
284 }
285 case InputWindowInfo::Flag::TRANSLUCENT_NAVIGATION: {
286 return "TRANSLUCENT_NAVIGATION";
287 }
288 case InputWindowInfo::Flag::LOCAL_FOCUS_MODE: {
289 return "LOCAL_FOCUS_MODE";
290 }
291 case InputWindowInfo::Flag::SLIPPERY: {
292 return "SLIPPERY";
293 }
294 case InputWindowInfo::Flag::LAYOUT_ATTACHED_IN_DECOR: {
295 return "LAYOUT_ATTACHED_IN_DECOR";
296 }
297 case InputWindowInfo::Flag::DRAWS_SYSTEM_BAR_BACKGROUNDS: {
298 return "DRAWS_SYSTEM_BAR_BACKGROUNDS";
299 }
300 }
301 return std::nullopt;
302}
303
Robert Carr3720ed02018-08-08 16:08:27 -0700304} // namespace android