blob: 9429d2cc15e8b34b84a8bfe414a3f90c6e16d378 [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
chaviw3277faf2021-05-19 16:45:23 -050017#define LOG_TAG "WindowInfo"
Robert Carr3720ed02018-08-08 16:08:27 -070018#define LOG_NDEBUG 0
19
Dominik Laskowski2f01d772022-03-23 16:01:29 -070020#include <type_traits>
21
Robert Carr3720ed02018-08-08 16:08:27 -070022#include <binder/Parcel.h>
chaviw3277faf2021-05-19 16:45:23 -050023#include <gui/WindowInfo.h>
Robert Carr3720ed02018-08-08 16:08:27 -070024
25#include <log/log.h>
26
chaviw3277faf2021-05-19 16:45:23 -050027namespace android::gui {
Robert Carr3720ed02018-08-08 16:08:27 -070028
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -080029namespace {
30
31std::ostream& operator<<(std::ostream& out, const sp<IBinder>& binder) {
32 if (binder == nullptr) {
33 out << "<null>";
34 } else {
35 out << binder.get();
36 }
37 return out;
38}
39
40std::ostream& operator<<(std::ostream& out, const Region& region) {
41 if (region.isEmpty()) {
42 out << "<empty>";
43 return out;
44 }
45
46 bool first = true;
47 Region::const_iterator cur = region.begin();
48 Region::const_iterator const tail = region.end();
49 while (cur != tail) {
50 if (first) {
51 first = false;
52 } else {
53 out << "|";
54 }
55 out << "[" << cur->left << "," << cur->top << "][" << cur->right << "," << cur->bottom
56 << "]";
57 cur++;
58 }
59 return out;
60}
61
62} // namespace
63
Dominik Laskowski2f01d772022-03-23 16:01:29 -070064void WindowInfo::setInputConfig(ftl::Flags<InputConfig> config, bool value) {
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080065 if (value) {
66 inputConfig |= config;
67 return;
68 }
69 inputConfig &= ~config;
70}
71
chaviw3277faf2021-05-19 16:45:23 -050072void WindowInfo::addTouchableRegion(const Rect& region) {
Robert Carr3720ed02018-08-08 16:08:27 -070073 touchableRegion.orSelf(region);
74}
75
chaviw3277faf2021-05-19 16:45:23 -050076bool WindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
77 return touchableRegion.contains(x, y);
Robert Carr3720ed02018-08-08 16:08:27 -070078}
79
chaviw3277faf2021-05-19 16:45:23 -050080bool WindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
Chavi Weingarten7f019192023-08-08 20:39:01 +000081 return x >= frame.left && x < frame.right && y >= frame.top && y < frame.bottom;
Robert Carr3720ed02018-08-08 16:08:27 -070082}
83
chaviw3277faf2021-05-19 16:45:23 -050084bool WindowInfo::supportsSplitTouch() const {
Prabir Pradhan76bdecb2022-01-31 11:14:15 -080085 return !inputConfig.test(InputConfig::PREVENT_SPLITTING);
Robert Carr3720ed02018-08-08 16:08:27 -070086}
87
Prabir Pradhan07e05b62021-11-19 03:57:24 -080088bool WindowInfo::isSpy() const {
Prabir Pradhan51e7db02022-02-07 06:02:57 -080089 return inputConfig.test(InputConfig::SPY);
Prabir Pradhan07e05b62021-11-19 03:57:24 -080090}
91
Prabir Pradhand65552b2021-10-07 11:23:50 -070092bool WindowInfo::interceptsStylus() const {
Prabir Pradhan51e7db02022-02-07 06:02:57 -080093 return inputConfig.test(InputConfig::INTERCEPTS_STYLUS);
Prabir Pradhand65552b2021-10-07 11:23:50 -070094}
95
chaviw3277faf2021-05-19 16:45:23 -050096bool WindowInfo::overlaps(const WindowInfo* other) const {
Chavi Weingarten7f019192023-08-08 20:39:01 +000097 return !frame.isEmpty() && frame.left < other->frame.right && frame.right > other->frame.left &&
98 frame.top < other->frame.bottom && frame.bottom > other->frame.top;
Robert Carr3720ed02018-08-08 16:08:27 -070099}
100
chaviw3277faf2021-05-19 16:45:23 -0500101bool WindowInfo::operator==(const WindowInfo& info) const {
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800102 return info.token == token && info.id == id && info.name == name &&
Chavi Weingarten7f019192023-08-08 20:39:01 +0000103 info.dispatchingTimeout == dispatchingTimeout && info.frame == frame &&
Vishnu Nair494a2e42023-11-10 17:21:19 -0800104 info.contentSize == contentSize && info.surfaceInset == surfaceInset &&
105 info.globalScaleFactor == globalScaleFactor && info.transform == transform &&
106 info.touchableRegion.hasSameRects(touchableRegion) &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800107 info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid &&
108 info.ownerUid == ownerUid && info.packageName == packageName &&
Prabir Pradhan51e7db02022-02-07 06:02:57 -0800109 info.inputConfig == inputConfig && info.displayId == displayId &&
Chris Ye0783e992020-06-02 21:34:49 -0700110 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800111 info.applicationInfo == applicationInfo && info.layoutParamsType == layoutParamsType &&
Vishnu Nair59a6be32024-01-29 10:26:21 -0800112 info.layoutParamsFlags == layoutParamsFlags &&
113 info.canOccludePresentation == canOccludePresentation;
Chris Ye0783e992020-06-02 21:34:49 -0700114}
115
chaviw3277faf2021-05-19 16:45:23 -0500116status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700117 if (parcel == nullptr) {
118 ALOGE("%s: Null parcel", __func__);
119 return BAD_VALUE;
120 }
Robert Carr2984b7a2020-04-13 17:06:45 -0700121 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -0700122 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -0700123 return OK;
124 }
Chris Ye0783e992020-06-02 21:34:49 -0700125 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -0700126
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000127 // Ensure that the size of custom types are what we expect for writing into the parcel.
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800128 static_assert(sizeof(inputConfig) == 4u);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000129 static_assert(sizeof(ownerPid.val()) == 4u);
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000130 static_assert(sizeof(ownerUid.val()) == 4u);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800131
Vishnu Nair47074b82020-08-14 11:54:47 -0700132 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -0700133 status_t status = parcel->writeStrongBinder(token) ?:
134 parcel->writeInt64(dispatchingTimeout.count()) ?:
135 parcel->writeInt32(id) ?:
136 parcel->writeUtf8AsUtf16(name) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800137 parcel->writeInt32(layoutParamsFlags.get()) ?:
138 parcel->writeInt32(
139 static_cast<std::underlying_type_t<WindowInfo::Type>>(layoutParamsType)) ?:
Chavi Weingarten7f019192023-08-08 20:39:01 +0000140 parcel->write(frame) ?:
Vishnu Nair494a2e42023-11-10 17:21:19 -0800141 parcel->writeInt32(contentSize.width) ?:
142 parcel->writeInt32(contentSize.height) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700143 parcel->writeInt32(surfaceInset) ?:
144 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100145 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700146 parcel->writeFloat(transform.dsdx()) ?:
147 parcel->writeFloat(transform.dtdx()) ?:
148 parcel->writeFloat(transform.tx()) ?:
149 parcel->writeFloat(transform.dtdy()) ?:
150 parcel->writeFloat(transform.dsdy()) ?:
151 parcel->writeFloat(transform.ty()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100152 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000153 parcel->writeInt32(ownerPid.val()) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000154 parcel->writeInt32(ownerUid.val()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100155 parcel->writeUtf8AsUtf16(packageName) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800156 parcel->writeInt32(inputConfig.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700157 parcel->writeInt32(displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700158 applicationInfo.writeToParcel(parcel) ?:
159 parcel->write(touchableRegion) ?:
160 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500161 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
Vishnu Nair59a6be32024-01-29 10:26:21 -0800162 parcel->writeStrongBinder(windowToken) ?:
163 parcel->writeStrongBinder(focusTransferTarget) ?:
164 parcel->writeBool(canOccludePresentation);
Vishnu Nair47074b82020-08-14 11:54:47 -0700165 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700166 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700167}
168
chaviw3277faf2021-05-19 16:45:23 -0500169status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700170 if (parcel == nullptr) {
171 ALOGE("%s: Null parcel", __func__);
172 return BAD_VALUE;
173 }
174 if (parcel->readInt32() == 0) {
175 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700176 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700177
Chris Ye0783e992020-06-02 21:34:49 -0700178 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100179 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
180 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
181 if (status != OK) {
182 return status;
183 }
184
chaviw1ff3d1e2020-07-01 15:53:47 -0700185 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000186 int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt;
Prabir Pradhan032141e2022-02-15 05:30:01 -0800187 sp<IBinder> touchableRegionCropHandleSp;
188
Vishnu Nair47074b82020-08-14 11:54:47 -0700189 // clang-format off
Prabir Pradhan032141e2022-02-15 05:30:01 -0800190 status = parcel->readInt32(&lpFlags) ?:
191 parcel->readInt32(&lpType) ?:
Chavi Weingarten7f019192023-08-08 20:39:01 +0000192 parcel->read(frame) ?:
Vishnu Nair494a2e42023-11-10 17:21:19 -0800193 parcel->readInt32(&contentSize.width) ?:
194 parcel->readInt32(&contentSize.height) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700195 parcel->readInt32(&surfaceInset) ?:
196 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100197 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700198 parcel->readFloat(&dsdx) ?:
199 parcel->readFloat(&dtdx) ?:
200 parcel->readFloat(&tx) ?:
201 parcel->readFloat(&dtdy) ?:
202 parcel->readFloat(&dsdy) ?:
203 parcel->readFloat(&ty) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100204 parcel->readInt32(&touchOcclusionModeInt) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000205 parcel->readInt32(&ownerPidInt) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000206 parcel->readInt32(&ownerUidInt) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800207 parcel->readUtf8FromUtf16(&packageName) ?:
208 parcel->readInt32(&inputConfigInt) ?:
209 parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700210 applicationInfo.readFromParcel(parcel) ?:
211 parcel->read(touchableRegion) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800212 parcel->readBool(&replaceTouchableRegionWithCrop) ?:
213 parcel->readNullableStrongBinder(&touchableRegionCropHandleSp) ?:
Chavi Weingarten847e8512023-03-29 00:26:09 +0000214 parcel->readNullableStrongBinder(&windowToken) ?:
Vishnu Nair59a6be32024-01-29 10:26:21 -0800215 parcel->readNullableStrongBinder(&focusTransferTarget) ?:
216 parcel->readBool(&canOccludePresentation);
Chavi Weingarten847e8512023-03-29 00:26:09 +0000217
chaviw3277faf2021-05-19 16:45:23 -0500218 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700219
Michael Wright44753b12020-07-08 13:48:11 +0100220 if (status != OK) {
221 return status;
222 }
223
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700224 layoutParamsFlags = ftl::Flags<Flag>(lpFlags);
Prabir Pradhan032141e2022-02-15 05:30:01 -0800225 layoutParamsType = static_cast<Type>(lpType);
chaviw9eaa22c2020-07-01 16:21:27 -0700226 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Prabir Pradhan032141e2022-02-15 05:30:01 -0800227 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700228 inputConfig = ftl::Flags<InputConfig>(inputConfigInt);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000229 ownerPid = Pid{ownerPidInt};
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000230 ownerUid = Uid{static_cast<uid_t>(ownerUidInt)};
Prabir Pradhan032141e2022-02-15 05:30:01 -0800231 touchableRegionCropHandle = touchableRegionCropHandleSp;
Robert Carr3720ed02018-08-08 16:08:27 -0700232
Prabir Pradhan032141e2022-02-15 05:30:01 -0800233 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700234}
235
chaviw3277faf2021-05-19 16:45:23 -0500236WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700237
chaviw3277faf2021-05-19 16:45:23 -0500238WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700239
chaviw3277faf2021-05-19 16:45:23 -0500240WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700241
chaviw3277faf2021-05-19 16:45:23 -0500242WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700243
chaviw3277faf2021-05-19 16:45:23 -0500244status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700245 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700246}
247
chaviw3277faf2021-05-19 16:45:23 -0500248status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700249 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700250}
251
chaviw3277faf2021-05-19 16:45:23 -0500252void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700253 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700254}
255
chaviw3277faf2021-05-19 16:45:23 -0500256sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700257 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700258}
259
chaviw3277faf2021-05-19 16:45:23 -0500260void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800261 mInfo = handle->mInfo;
262}
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -0800263
Siarhei Vishniakouaeed0da2024-01-09 08:57:13 -0800264std::ostream& operator<<(std::ostream& out, const WindowInfo& info) {
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -0800265 std::string transform;
266 info.transform.dump(transform, "transform", " ");
267 out << "name=" << info.name << ", id=" << info.id << ", displayId=" << info.displayId
268 << ", inputConfig=" << info.inputConfig.string() << ", alpha=" << info.alpha << ", frame=["
269 << info.frame.left << "," << info.frame.top << "][" << info.frame.right << ","
270 << info.frame.bottom << "], globalScale=" << info.globalScaleFactor
271 << ", applicationInfo.name=" << info.applicationInfo.name
272 << ", applicationInfo.token=" << info.applicationInfo.token
273 << ", touchableRegion=" << info.touchableRegion << ", ownerPid=" << info.ownerPid.toString()
274 << ", ownerUid=" << info.ownerUid.toString() << ", dispatchingTimeout="
275 << std::chrono::duration_cast<std::chrono::milliseconds>(info.dispatchingTimeout).count()
276 << "ms, token=" << info.token.get()
277 << ", touchOcclusionMode=" << ftl::enum_string(info.touchOcclusionMode) << "\n"
278 << transform;
Vishnu Nair59a6be32024-01-29 10:26:21 -0800279 if (info.canOccludePresentation) out << " canOccludePresentation";
Siarhei Vishniakou366fb5b2023-12-06 11:23:41 -0800280 return out;
281}
282
Siarhei Vishniakouaeed0da2024-01-09 08:57:13 -0800283std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window) {
284 const WindowInfo& info = *window.getInfo();
285 out << info;
286 return out;
287}
288
chaviw3277faf2021-05-19 16:45:23 -0500289} // namespace android::gui