blob: 52af9d5114d548133488c1d1f3aeb73b029d3f56 [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
Dominik Laskowski2f01d772022-03-23 16:01:29 -070029void WindowInfo::setInputConfig(ftl::Flags<InputConfig> config, bool value) {
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080030 if (value) {
31 inputConfig |= config;
32 return;
33 }
34 inputConfig &= ~config;
35}
36
chaviw3277faf2021-05-19 16:45:23 -050037void WindowInfo::addTouchableRegion(const Rect& region) {
Robert Carr3720ed02018-08-08 16:08:27 -070038 touchableRegion.orSelf(region);
39}
40
chaviw3277faf2021-05-19 16:45:23 -050041bool WindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
42 return touchableRegion.contains(x, y);
Robert Carr3720ed02018-08-08 16:08:27 -070043}
44
chaviw3277faf2021-05-19 16:45:23 -050045bool WindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
46 return x >= frameLeft && x < frameRight && y >= frameTop && y < frameBottom;
Robert Carr3720ed02018-08-08 16:08:27 -070047}
48
chaviw3277faf2021-05-19 16:45:23 -050049bool WindowInfo::supportsSplitTouch() const {
Prabir Pradhan76bdecb2022-01-31 11:14:15 -080050 return !inputConfig.test(InputConfig::PREVENT_SPLITTING);
Robert Carr3720ed02018-08-08 16:08:27 -070051}
52
Prabir Pradhan07e05b62021-11-19 03:57:24 -080053bool WindowInfo::isSpy() const {
Prabir Pradhan51e7db02022-02-07 06:02:57 -080054 return inputConfig.test(InputConfig::SPY);
Prabir Pradhan07e05b62021-11-19 03:57:24 -080055}
56
Prabir Pradhand65552b2021-10-07 11:23:50 -070057bool WindowInfo::interceptsStylus() const {
Prabir Pradhan51e7db02022-02-07 06:02:57 -080058 return inputConfig.test(InputConfig::INTERCEPTS_STYLUS);
Prabir Pradhand65552b2021-10-07 11:23:50 -070059}
60
chaviw3277faf2021-05-19 16:45:23 -050061bool WindowInfo::overlaps(const WindowInfo* other) const {
Prabir Pradhan6fa425a2021-12-16 07:16:04 -080062 const bool nonEmpty = (frameRight - frameLeft > 0) || (frameBottom - frameTop > 0);
63 return nonEmpty && frameLeft < other->frameRight && frameRight > other->frameLeft &&
chaviw3277faf2021-05-19 16:45:23 -050064 frameTop < other->frameBottom && frameBottom > other->frameTop;
Robert Carr3720ed02018-08-08 16:08:27 -070065}
66
chaviw3277faf2021-05-19 16:45:23 -050067bool WindowInfo::operator==(const WindowInfo& info) const {
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080068 return info.token == token && info.id == id && info.name == name &&
69 info.dispatchingTimeout == dispatchingTimeout && info.frameLeft == frameLeft &&
70 info.frameTop == frameTop && info.frameRight == frameRight &&
71 info.frameBottom == frameBottom && info.surfaceInset == surfaceInset &&
72 info.globalScaleFactor == globalScaleFactor && info.transform == transform &&
73 info.touchableRegion.hasSameRects(touchableRegion) &&
74 info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid &&
75 info.ownerUid == ownerUid && info.packageName == packageName &&
Prabir Pradhan51e7db02022-02-07 06:02:57 -080076 info.inputConfig == inputConfig && info.displayId == displayId &&
Chris Ye0783e992020-06-02 21:34:49 -070077 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080078 info.applicationInfo == applicationInfo && info.layoutParamsType == layoutParamsType &&
chaviw8577ea82022-06-01 16:32:26 -050079 info.layoutParamsFlags == layoutParamsFlags;
Chris Ye0783e992020-06-02 21:34:49 -070080}
81
chaviw3277faf2021-05-19 16:45:23 -050082status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070083 if (parcel == nullptr) {
84 ALOGE("%s: Null parcel", __func__);
85 return BAD_VALUE;
86 }
Robert Carr2984b7a2020-04-13 17:06:45 -070087 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070088 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070089 return OK;
90 }
Chris Ye0783e992020-06-02 21:34:49 -070091 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070092
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000093 // Ensure that the size of custom types are what we expect for writing into the parcel.
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080094 static_assert(sizeof(inputConfig) == 4u);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +000095 static_assert(sizeof(ownerPid.val()) == 4u);
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000096 static_assert(sizeof(ownerUid.val()) == 4u);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080097
Vishnu Nair47074b82020-08-14 11:54:47 -070098 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070099 status_t status = parcel->writeStrongBinder(token) ?:
100 parcel->writeInt64(dispatchingTimeout.count()) ?:
101 parcel->writeInt32(id) ?:
102 parcel->writeUtf8AsUtf16(name) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800103 parcel->writeInt32(layoutParamsFlags.get()) ?:
104 parcel->writeInt32(
105 static_cast<std::underlying_type_t<WindowInfo::Type>>(layoutParamsType)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700106 parcel->writeInt32(frameLeft) ?:
107 parcel->writeInt32(frameTop) ?:
108 parcel->writeInt32(frameRight) ?:
109 parcel->writeInt32(frameBottom) ?:
110 parcel->writeInt32(surfaceInset) ?:
111 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100112 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700113 parcel->writeFloat(transform.dsdx()) ?:
114 parcel->writeFloat(transform.dtdx()) ?:
115 parcel->writeFloat(transform.tx()) ?:
116 parcel->writeFloat(transform.dtdy()) ?:
117 parcel->writeFloat(transform.dsdy()) ?:
118 parcel->writeFloat(transform.ty()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100119 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000120 parcel->writeInt32(ownerPid.val()) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000121 parcel->writeInt32(ownerUid.val()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100122 parcel->writeUtf8AsUtf16(packageName) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800123 parcel->writeInt32(inputConfig.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700124 parcel->writeInt32(displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700125 applicationInfo.writeToParcel(parcel) ?:
126 parcel->write(touchableRegion) ?:
127 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500128 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
chaviw8577ea82022-06-01 16:32:26 -0500129 parcel->writeStrongBinder(windowToken);
Chavi Weingarten847e8512023-03-29 00:26:09 +0000130 parcel->writeStrongBinder(focusTransferTarget);
Vishnu Nair47074b82020-08-14 11:54:47 -0700131 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700132 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700133}
134
chaviw3277faf2021-05-19 16:45:23 -0500135status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700136 if (parcel == nullptr) {
137 ALOGE("%s: Null parcel", __func__);
138 return BAD_VALUE;
139 }
140 if (parcel->readInt32() == 0) {
141 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700142 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700143
Chris Ye0783e992020-06-02 21:34:49 -0700144 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100145 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
146 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
147 if (status != OK) {
148 return status;
149 }
150
chaviw1ff3d1e2020-07-01 15:53:47 -0700151 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000152 int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt;
Prabir Pradhan032141e2022-02-15 05:30:01 -0800153 sp<IBinder> touchableRegionCropHandleSp;
154
Vishnu Nair47074b82020-08-14 11:54:47 -0700155 // clang-format off
Prabir Pradhan032141e2022-02-15 05:30:01 -0800156 status = parcel->readInt32(&lpFlags) ?:
157 parcel->readInt32(&lpType) ?:
158 parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700159 parcel->readInt32(&frameTop) ?:
160 parcel->readInt32(&frameRight) ?:
161 parcel->readInt32(&frameBottom) ?:
162 parcel->readInt32(&surfaceInset) ?:
163 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100164 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700165 parcel->readFloat(&dsdx) ?:
166 parcel->readFloat(&dtdx) ?:
167 parcel->readFloat(&tx) ?:
168 parcel->readFloat(&dtdy) ?:
169 parcel->readFloat(&dsdy) ?:
170 parcel->readFloat(&ty) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100171 parcel->readInt32(&touchOcclusionModeInt) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000172 parcel->readInt32(&ownerPidInt) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000173 parcel->readInt32(&ownerUidInt) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800174 parcel->readUtf8FromUtf16(&packageName) ?:
175 parcel->readInt32(&inputConfigInt) ?:
176 parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700177 applicationInfo.readFromParcel(parcel) ?:
178 parcel->read(touchableRegion) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800179 parcel->readBool(&replaceTouchableRegionWithCrop) ?:
180 parcel->readNullableStrongBinder(&touchableRegionCropHandleSp) ?:
Chavi Weingarten847e8512023-03-29 00:26:09 +0000181 parcel->readNullableStrongBinder(&windowToken) ?:
182 parcel->readNullableStrongBinder(&focusTransferTarget);
183
chaviw3277faf2021-05-19 16:45:23 -0500184 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700185
Michael Wright44753b12020-07-08 13:48:11 +0100186 if (status != OK) {
187 return status;
188 }
189
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700190 layoutParamsFlags = ftl::Flags<Flag>(lpFlags);
Prabir Pradhan032141e2022-02-15 05:30:01 -0800191 layoutParamsType = static_cast<Type>(lpType);
chaviw9eaa22c2020-07-01 16:21:27 -0700192 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Prabir Pradhan032141e2022-02-15 05:30:01 -0800193 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700194 inputConfig = ftl::Flags<InputConfig>(inputConfigInt);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000195 ownerPid = Pid{ownerPidInt};
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000196 ownerUid = Uid{static_cast<uid_t>(ownerUidInt)};
Prabir Pradhan032141e2022-02-15 05:30:01 -0800197 touchableRegionCropHandle = touchableRegionCropHandleSp;
Robert Carr3720ed02018-08-08 16:08:27 -0700198
Prabir Pradhan032141e2022-02-15 05:30:01 -0800199 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700200}
201
chaviw3277faf2021-05-19 16:45:23 -0500202WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700203
chaviw3277faf2021-05-19 16:45:23 -0500204WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700205
chaviw3277faf2021-05-19 16:45:23 -0500206WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700207
chaviw3277faf2021-05-19 16:45:23 -0500208WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700209
chaviw3277faf2021-05-19 16:45:23 -0500210status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700211 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700212}
213
chaviw3277faf2021-05-19 16:45:23 -0500214status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700215 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700216}
217
chaviw3277faf2021-05-19 16:45:23 -0500218void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700219 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700220}
221
chaviw3277faf2021-05-19 16:45:23 -0500222sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700223 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700224}
225
chaviw3277faf2021-05-19 16:45:23 -0500226void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800227 mInfo = handle->mInfo;
228}
chaviw3277faf2021-05-19 16:45:23 -0500229} // namespace android::gui