blob: 80bd6389a075fdefd0f40500337f3c950ec20a6c [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>
chaviw3277faf2021-05-19 16:45:23 -050018#define LOG_TAG "WindowInfo"
Robert Carr3720ed02018-08-08 16:08:27 -070019#define LOG_NDEBUG 0
20
21#include <binder/Parcel.h>
chaviw3277faf2021-05-19 16:45:23 -050022#include <gui/WindowInfo.h>
Robert Carr3720ed02018-08-08 16:08:27 -070023
24#include <log/log.h>
25
chaviw3277faf2021-05-19 16:45:23 -050026namespace android::gui {
Robert Carr3720ed02018-08-08 16:08:27 -070027
chaviw3277faf2021-05-19 16:45:23 -050028// --- WindowInfo ---
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080029void WindowInfo::setInputConfig(Flags<InputConfig> config, bool value) {
30 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 {
54 return inputFeatures.test(Feature::SPY);
55}
56
Prabir Pradhand65552b2021-10-07 11:23:50 -070057bool WindowInfo::interceptsStylus() const {
58 return inputFeatures.test(Feature::INTERCEPTS_STYLUS);
59}
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 &&
76 info.inputFeatures == inputFeatures && info.inputConfig == inputConfig &&
Prabir Pradhan1c58c0d2021-12-29 02:10:29 -080077 info.displayId == displayId &&
Chris Ye0783e992020-06-02 21:34:49 -070078 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080079 info.applicationInfo == applicationInfo && info.layoutParamsType == layoutParamsType &&
80 info.layoutParamsFlags == layoutParamsFlags;
Chris Ye0783e992020-06-02 21:34:49 -070081}
82
chaviw3277faf2021-05-19 16:45:23 -050083status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070084 if (parcel == nullptr) {
85 ALOGE("%s: Null parcel", __func__);
86 return BAD_VALUE;
87 }
Robert Carr2984b7a2020-04-13 17:06:45 -070088 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070089 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070090 return OK;
91 }
Chris Ye0783e992020-06-02 21:34:49 -070092 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070093
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080094 // Ensure that the size of the flags that we use is 32 bits for writing into the parcel.
95 static_assert(sizeof(inputFeatures) == 4u);
96 static_assert(sizeof(inputConfig) == 4u);
97
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)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700120 parcel->writeInt32(ownerPid) ?:
121 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100122 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100123 parcel->writeInt32(inputFeatures.get()) ?:
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800124 parcel->writeInt32(inputConfig.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700125 parcel->writeInt32(displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700126 applicationInfo.writeToParcel(parcel) ?:
127 parcel->write(touchableRegion) ?:
128 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500129 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
130 parcel->writeStrongBinder(windowToken);
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
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800151 layoutParamsFlags = Flags<Flag>(parcel->readInt32());
152 layoutParamsType = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700153 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100154 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700155 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100156 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700157 parcel->readInt32(&frameTop) ?:
158 parcel->readInt32(&frameRight) ?:
159 parcel->readInt32(&frameBottom) ?:
160 parcel->readInt32(&surfaceInset) ?:
161 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100162 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700163 parcel->readFloat(&dsdx) ?:
164 parcel->readFloat(&dtdx) ?:
165 parcel->readFloat(&tx) ?:
166 parcel->readFloat(&dtdy) ?:
167 parcel->readFloat(&dsdy) ?:
168 parcel->readFloat(&ty) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100169 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700170 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100171 parcel->readInt32(&ownerUid) ?:
172 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700173 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100174
175 if (status != OK) {
176 return status;
177 }
178
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100179 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
180
Michael Wright44753b12020-07-08 13:48:11 +0100181 inputFeatures = Flags<Feature>(parcel->readInt32());
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800182 inputConfig = Flags<InputConfig>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500183 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100184 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700185 applicationInfo.readFromParcel(parcel) ?:
186 parcel->read(touchableRegion) ?:
187 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500188 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700189
Michael Wright44753b12020-07-08 13:48:11 +0100190 if (status != OK) {
191 return status;
192 }
193
Chris Ye0783e992020-06-02 21:34:49 -0700194 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700195 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700196
chaviwe0ba4e92021-08-11 11:38:41 -0500197 status = parcel->readNullableStrongBinder(&windowToken);
198 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700199}
200
chaviw3277faf2021-05-19 16:45:23 -0500201// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700202
chaviw3277faf2021-05-19 16:45:23 -0500203WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700204
chaviw3277faf2021-05-19 16:45:23 -0500205WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700206
chaviw3277faf2021-05-19 16:45:23 -0500207WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700208
chaviw3277faf2021-05-19 16:45:23 -0500209WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700210
chaviw3277faf2021-05-19 16:45:23 -0500211status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700212 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700213}
214
chaviw3277faf2021-05-19 16:45:23 -0500215status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700216 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700217}
218
chaviw3277faf2021-05-19 16:45:23 -0500219void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700220 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700221}
222
chaviw3277faf2021-05-19 16:45:23 -0500223sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700224 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700225}
226
chaviw3277faf2021-05-19 16:45:23 -0500227void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800228 mInfo = handle->mInfo;
229}
chaviw3277faf2021-05-19 16:45:23 -0500230} // namespace android::gui