blob: a8667867b26bdedfcc1ed8ff0a037de5595e7753 [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
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>
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
chaviw3277faf2021-05-19 16:45:23 -050029// --- WindowInfo ---
30void WindowInfo::addTouchableRegion(const Rect& region) {
Robert Carr3720ed02018-08-08 16:08:27 -070031 touchableRegion.orSelf(region);
32}
33
chaviw3277faf2021-05-19 16:45:23 -050034bool WindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
35 return touchableRegion.contains(x, y);
Robert Carr3720ed02018-08-08 16:08:27 -070036}
37
chaviw3277faf2021-05-19 16:45:23 -050038bool WindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
39 return x >= frameLeft && x < frameRight && y >= frameTop && y < frameBottom;
Robert Carr3720ed02018-08-08 16:08:27 -070040}
41
chaviw3277faf2021-05-19 16:45:23 -050042bool WindowInfo::supportsSplitTouch() const {
Michael Wright44753b12020-07-08 13:48:11 +010043 return flags.test(Flag::SPLIT_TOUCH);
Robert Carr3720ed02018-08-08 16:08:27 -070044}
45
Prabir Pradhan07e05b62021-11-19 03:57:24 -080046bool WindowInfo::isSpy() const {
47 return inputFeatures.test(Feature::SPY);
48}
49
Prabir Pradhand65552b2021-10-07 11:23:50 -070050bool WindowInfo::interceptsStylus() const {
51 return inputFeatures.test(Feature::INTERCEPTS_STYLUS);
52}
53
chaviw3277faf2021-05-19 16:45:23 -050054bool WindowInfo::overlaps(const WindowInfo* other) const {
Prabir Pradhan6fa425a2021-12-16 07:16:04 -080055 const bool nonEmpty = (frameRight - frameLeft > 0) || (frameBottom - frameTop > 0);
56 return nonEmpty && frameLeft < other->frameRight && frameRight > other->frameLeft &&
chaviw3277faf2021-05-19 16:45:23 -050057 frameTop < other->frameBottom && frameBottom > other->frameTop;
Robert Carr3720ed02018-08-08 16:08:27 -070058}
59
chaviw3277faf2021-05-19 16:45:23 -050060bool WindowInfo::operator==(const WindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010061 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
62 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
63 info.frameLeft == frameLeft && info.frameTop == frameTop &&
64 info.frameRight == frameRight && info.frameBottom == frameBottom &&
65 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070066 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
67 info.visible == visible && info.trustedOverlay == trustedOverlay &&
68 info.focusable == focusable && info.touchOcclusionMode == touchOcclusionMode &&
69 info.hasWallpaper == hasWallpaper && info.paused == paused &&
70 info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010071 info.packageName == packageName && info.inputFeatures == inputFeatures &&
Prabir Pradhan1c58c0d2021-12-29 02:10:29 -080072 info.displayId == displayId &&
Chris Ye0783e992020-06-02 21:34:49 -070073 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070074 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070075}
76
chaviw3277faf2021-05-19 16:45:23 -050077status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070078 if (parcel == nullptr) {
79 ALOGE("%s: Null parcel", __func__);
80 return BAD_VALUE;
81 }
Robert Carr2984b7a2020-04-13 17:06:45 -070082 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070083 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070084 return OK;
85 }
Chris Ye0783e992020-06-02 21:34:49 -070086 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070087
Vishnu Nair47074b82020-08-14 11:54:47 -070088 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070089 status_t status = parcel->writeStrongBinder(token) ?:
90 parcel->writeInt64(dispatchingTimeout.count()) ?:
91 parcel->writeInt32(id) ?:
92 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010093 parcel->writeInt32(flags.get()) ?:
chaviw3277faf2021-05-19 16:45:23 -050094 parcel->writeInt32(static_cast<std::underlying_type_t<WindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070095 parcel->writeInt32(frameLeft) ?:
96 parcel->writeInt32(frameTop) ?:
97 parcel->writeInt32(frameRight) ?:
98 parcel->writeInt32(frameBottom) ?:
99 parcel->writeInt32(surfaceInset) ?:
100 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100101 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700102 parcel->writeFloat(transform.dsdx()) ?:
103 parcel->writeFloat(transform.dtdx()) ?:
104 parcel->writeFloat(transform.tx()) ?:
105 parcel->writeFloat(transform.dtdy()) ?:
106 parcel->writeFloat(transform.dsdy()) ?:
107 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700108 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700109 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700110 parcel->writeBool(hasWallpaper) ?:
111 parcel->writeBool(paused) ?:
112 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100113 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700114 parcel->writeInt32(ownerPid) ?:
115 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100116 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100117 parcel->writeInt32(inputFeatures.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()) ?:
123 parcel->writeStrongBinder(windowToken);
Vishnu Nair47074b82020-08-14 11:54:47 -0700124 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700125 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700126}
127
chaviw3277faf2021-05-19 16:45:23 -0500128status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700129 if (parcel == nullptr) {
130 ALOGE("%s: Null parcel", __func__);
131 return BAD_VALUE;
132 }
133 if (parcel->readInt32() == 0) {
134 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700135 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700136
Chris Ye0783e992020-06-02 21:34:49 -0700137 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100138 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
139 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
140 if (status != OK) {
141 return status;
142 }
143
144 flags = Flags<Flag>(parcel->readInt32());
145 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700146 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100147 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700148 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100149 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700150 parcel->readInt32(&frameTop) ?:
151 parcel->readInt32(&frameRight) ?:
152 parcel->readInt32(&frameBottom) ?:
153 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) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700162 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700163 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700164 parcel->readBool(&hasWallpaper) ?:
165 parcel->readBool(&paused) ?:
166 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100167 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700168 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100169 parcel->readInt32(&ownerUid) ?:
170 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700171 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100172
173 if (status != OK) {
174 return status;
175 }
176
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100177 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
178
Michael Wright44753b12020-07-08 13:48:11 +0100179 inputFeatures = Flags<Feature>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500180 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100181 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700182 applicationInfo.readFromParcel(parcel) ?:
183 parcel->read(touchableRegion) ?:
184 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500185 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700186
Michael Wright44753b12020-07-08 13:48:11 +0100187 if (status != OK) {
188 return status;
189 }
190
Chris Ye0783e992020-06-02 21:34:49 -0700191 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700192 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700193
chaviwe0ba4e92021-08-11 11:38:41 -0500194 status = parcel->readNullableStrongBinder(&windowToken);
195 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700196}
197
chaviw3277faf2021-05-19 16:45:23 -0500198// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700199
chaviw3277faf2021-05-19 16:45:23 -0500200WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700201
chaviw3277faf2021-05-19 16:45:23 -0500202WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700203
chaviw3277faf2021-05-19 16:45:23 -0500204WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700205
chaviw3277faf2021-05-19 16:45:23 -0500206WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700207
chaviw3277faf2021-05-19 16:45:23 -0500208status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700209 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700210}
211
chaviw3277faf2021-05-19 16:45:23 -0500212status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700213 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700214}
215
chaviw3277faf2021-05-19 16:45:23 -0500216void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700217 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700218}
219
chaviw3277faf2021-05-19 16:45:23 -0500220sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700221 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700222}
223
chaviw3277faf2021-05-19 16:45:23 -0500224void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800225 mInfo = handle->mInfo;
226}
chaviw3277faf2021-05-19 16:45:23 -0500227} // namespace android::gui