blob: 2eb6bd670dd97fb7539167a88b04adb9f69b0356 [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 {
Chavi Weingarten7f019192023-08-08 20:39:01 +000046 return x >= frame.left && x < frame.right && y >= frame.top && y < frame.bottom;
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 {
Chavi Weingarten7f019192023-08-08 20:39:01 +000062 return !frame.isEmpty() && frame.left < other->frame.right && frame.right > other->frame.left &&
63 frame.top < other->frame.bottom && frame.bottom > other->frame.top;
Robert Carr3720ed02018-08-08 16:08:27 -070064}
65
chaviw3277faf2021-05-19 16:45:23 -050066bool WindowInfo::operator==(const WindowInfo& info) const {
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080067 return info.token == token && info.id == id && info.name == name &&
Chavi Weingarten7f019192023-08-08 20:39:01 +000068 info.dispatchingTimeout == dispatchingTimeout && info.frame == frame &&
69 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
70 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080071 info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid &&
72 info.ownerUid == ownerUid && info.packageName == packageName &&
Prabir Pradhan51e7db02022-02-07 06:02:57 -080073 info.inputConfig == inputConfig && info.displayId == displayId &&
Chris Ye0783e992020-06-02 21:34:49 -070074 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080075 info.applicationInfo == applicationInfo && info.layoutParamsType == layoutParamsType &&
chaviw8577ea82022-06-01 16:32:26 -050076 info.layoutParamsFlags == layoutParamsFlags;
Chris Ye0783e992020-06-02 21:34:49 -070077}
78
chaviw3277faf2021-05-19 16:45:23 -050079status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070080 if (parcel == nullptr) {
81 ALOGE("%s: Null parcel", __func__);
82 return BAD_VALUE;
83 }
Robert Carr2984b7a2020-04-13 17:06:45 -070084 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070085 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070086 return OK;
87 }
Chris Ye0783e992020-06-02 21:34:49 -070088 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070089
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000090 // Ensure that the size of custom types are what we expect for writing into the parcel.
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080091 static_assert(sizeof(inputConfig) == 4u);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +000092 static_assert(sizeof(ownerPid.val()) == 4u);
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000093 static_assert(sizeof(ownerUid.val()) == 4u);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080094
Vishnu Nair47074b82020-08-14 11:54:47 -070095 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070096 status_t status = parcel->writeStrongBinder(token) ?:
97 parcel->writeInt64(dispatchingTimeout.count()) ?:
98 parcel->writeInt32(id) ?:
99 parcel->writeUtf8AsUtf16(name) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800100 parcel->writeInt32(layoutParamsFlags.get()) ?:
101 parcel->writeInt32(
102 static_cast<std::underlying_type_t<WindowInfo::Type>>(layoutParamsType)) ?:
Chavi Weingarten7f019192023-08-08 20:39:01 +0000103 parcel->write(frame) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700104 parcel->writeInt32(surfaceInset) ?:
105 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100106 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700107 parcel->writeFloat(transform.dsdx()) ?:
108 parcel->writeFloat(transform.dtdx()) ?:
109 parcel->writeFloat(transform.tx()) ?:
110 parcel->writeFloat(transform.dtdy()) ?:
111 parcel->writeFloat(transform.dsdy()) ?:
112 parcel->writeFloat(transform.ty()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100113 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000114 parcel->writeInt32(ownerPid.val()) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000115 parcel->writeInt32(ownerUid.val()) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100116 parcel->writeUtf8AsUtf16(packageName) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800117 parcel->writeInt32(inputConfig.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700118 parcel->writeInt32(displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700119 applicationInfo.writeToParcel(parcel) ?:
120 parcel->write(touchableRegion) ?:
121 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500122 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
chaviw8577ea82022-06-01 16:32:26 -0500123 parcel->writeStrongBinder(windowToken);
Chavi Weingarten847e8512023-03-29 00:26:09 +0000124 parcel->writeStrongBinder(focusTransferTarget);
Vishnu Nair47074b82020-08-14 11:54:47 -0700125 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700126 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700127}
128
chaviw3277faf2021-05-19 16:45:23 -0500129status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700130 if (parcel == nullptr) {
131 ALOGE("%s: Null parcel", __func__);
132 return BAD_VALUE;
133 }
134 if (parcel->readInt32() == 0) {
135 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700136 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700137
Chris Ye0783e992020-06-02 21:34:49 -0700138 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100139 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
140 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
141 if (status != OK) {
142 return status;
143 }
144
chaviw1ff3d1e2020-07-01 15:53:47 -0700145 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000146 int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt;
Prabir Pradhan032141e2022-02-15 05:30:01 -0800147 sp<IBinder> touchableRegionCropHandleSp;
148
Vishnu Nair47074b82020-08-14 11:54:47 -0700149 // clang-format off
Prabir Pradhan032141e2022-02-15 05:30:01 -0800150 status = parcel->readInt32(&lpFlags) ?:
151 parcel->readInt32(&lpType) ?:
Chavi Weingarten7f019192023-08-08 20:39:01 +0000152 parcel->read(frame) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700153 parcel->readInt32(&surfaceInset) ?:
154 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100155 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700156 parcel->readFloat(&dsdx) ?:
157 parcel->readFloat(&dtdx) ?:
158 parcel->readFloat(&tx) ?:
159 parcel->readFloat(&dtdy) ?:
160 parcel->readFloat(&dsdy) ?:
161 parcel->readFloat(&ty) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100162 parcel->readInt32(&touchOcclusionModeInt) ?:
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000163 parcel->readInt32(&ownerPidInt) ?:
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000164 parcel->readInt32(&ownerUidInt) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800165 parcel->readUtf8FromUtf16(&packageName) ?:
166 parcel->readInt32(&inputConfigInt) ?:
167 parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700168 applicationInfo.readFromParcel(parcel) ?:
169 parcel->read(touchableRegion) ?:
Prabir Pradhan032141e2022-02-15 05:30:01 -0800170 parcel->readBool(&replaceTouchableRegionWithCrop) ?:
171 parcel->readNullableStrongBinder(&touchableRegionCropHandleSp) ?:
Chavi Weingarten847e8512023-03-29 00:26:09 +0000172 parcel->readNullableStrongBinder(&windowToken) ?:
173 parcel->readNullableStrongBinder(&focusTransferTarget);
174
chaviw3277faf2021-05-19 16:45:23 -0500175 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700176
Michael Wright44753b12020-07-08 13:48:11 +0100177 if (status != OK) {
178 return status;
179 }
180
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700181 layoutParamsFlags = ftl::Flags<Flag>(lpFlags);
Prabir Pradhan032141e2022-02-15 05:30:01 -0800182 layoutParamsType = static_cast<Type>(lpType);
chaviw9eaa22c2020-07-01 16:21:27 -0700183 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Prabir Pradhan032141e2022-02-15 05:30:01 -0800184 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700185 inputConfig = ftl::Flags<InputConfig>(inputConfigInt);
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000186 ownerPid = Pid{ownerPidInt};
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000187 ownerUid = Uid{static_cast<uid_t>(ownerUidInt)};
Prabir Pradhan032141e2022-02-15 05:30:01 -0800188 touchableRegionCropHandle = touchableRegionCropHandleSp;
Robert Carr3720ed02018-08-08 16:08:27 -0700189
Prabir Pradhan032141e2022-02-15 05:30:01 -0800190 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700191}
192
chaviw3277faf2021-05-19 16:45:23 -0500193WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700194
chaviw3277faf2021-05-19 16:45:23 -0500195WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700196
chaviw3277faf2021-05-19 16:45:23 -0500197WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700198
chaviw3277faf2021-05-19 16:45:23 -0500199WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700200
chaviw3277faf2021-05-19 16:45:23 -0500201status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700202 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700203}
204
chaviw3277faf2021-05-19 16:45:23 -0500205status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700206 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700207}
208
chaviw3277faf2021-05-19 16:45:23 -0500209void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700210 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700211}
212
chaviw3277faf2021-05-19 16:45:23 -0500213sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700214 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700215}
216
chaviw3277faf2021-05-19 16:45:23 -0500217void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800218 mInfo = handle->mInfo;
219}
chaviw3277faf2021-05-19 16:45:23 -0500220} // namespace android::gui