blob: 6b68e1a93b3e937e764a514c33db8517bc8bb59a [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
chaviw3277faf2021-05-19 16:45:23 -050046bool WindowInfo::overlaps(const WindowInfo* other) const {
47 return frameLeft < other->frameRight && frameRight > other->frameLeft &&
48 frameTop < other->frameBottom && frameBottom > other->frameTop;
Robert Carr3720ed02018-08-08 16:08:27 -070049}
50
chaviw3277faf2021-05-19 16:45:23 -050051bool WindowInfo::operator==(const WindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010052 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
53 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
54 info.frameLeft == frameLeft && info.frameTop == frameTop &&
55 info.frameRight == frameRight && info.frameBottom == frameBottom &&
56 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
Evan Rosky44edce92021-05-14 18:09:55 -070057 info.transform == transform && info.displayWidth == displayWidth &&
58 info.displayHeight == displayHeight &&
59 info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible &&
60 info.trustedOverlay == trustedOverlay && info.focusable == focusable &&
61 info.touchOcclusionMode == touchOcclusionMode && info.hasWallpaper == hasWallpaper &&
62 info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010063 info.packageName == packageName && info.inputFeatures == inputFeatures &&
64 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
Chris Ye0783e992020-06-02 21:34:49 -070065 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070066 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070067}
68
chaviw3277faf2021-05-19 16:45:23 -050069status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070070 if (parcel == nullptr) {
71 ALOGE("%s: Null parcel", __func__);
72 return BAD_VALUE;
73 }
Robert Carr2984b7a2020-04-13 17:06:45 -070074 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070075 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070076 return OK;
77 }
Chris Ye0783e992020-06-02 21:34:49 -070078 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070079
Vishnu Nair47074b82020-08-14 11:54:47 -070080 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070081 status_t status = parcel->writeStrongBinder(token) ?:
82 parcel->writeInt64(dispatchingTimeout.count()) ?:
83 parcel->writeInt32(id) ?:
84 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010085 parcel->writeInt32(flags.get()) ?:
chaviw3277faf2021-05-19 16:45:23 -050086 parcel->writeInt32(static_cast<std::underlying_type_t<WindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070087 parcel->writeInt32(frameLeft) ?:
88 parcel->writeInt32(frameTop) ?:
89 parcel->writeInt32(frameRight) ?:
90 parcel->writeInt32(frameBottom) ?:
91 parcel->writeInt32(surfaceInset) ?:
92 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +010093 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070094 parcel->writeFloat(transform.dsdx()) ?:
95 parcel->writeFloat(transform.dtdx()) ?:
96 parcel->writeFloat(transform.tx()) ?:
97 parcel->writeFloat(transform.dtdy()) ?:
98 parcel->writeFloat(transform.dsdy()) ?:
99 parcel->writeFloat(transform.ty()) ?:
Evan Rosky44edce92021-05-14 18:09:55 -0700100 parcel->writeInt32(displayWidth) ?:
101 parcel->writeInt32(displayHeight) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700102 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700103 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700104 parcel->writeBool(hasWallpaper) ?:
105 parcel->writeBool(paused) ?:
106 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100107 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700108 parcel->writeInt32(ownerPid) ?:
109 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100110 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100111 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700112 parcel->writeInt32(displayId) ?:
113 parcel->writeInt32(portalToDisplayId) ?:
114 applicationInfo.writeToParcel(parcel) ?:
115 parcel->write(touchableRegion) ?:
116 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500117 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
118 parcel->writeStrongBinder(windowToken);
Vishnu Nair47074b82020-08-14 11:54:47 -0700119 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700120 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700121}
122
chaviw3277faf2021-05-19 16:45:23 -0500123status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700124 if (parcel == nullptr) {
125 ALOGE("%s: Null parcel", __func__);
126 return BAD_VALUE;
127 }
128 if (parcel->readInt32() == 0) {
129 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700130 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700131
Chris Ye0783e992020-06-02 21:34:49 -0700132 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100133 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
134 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
135 if (status != OK) {
136 return status;
137 }
138
139 flags = Flags<Flag>(parcel->readInt32());
140 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700141 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100142 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700143 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100144 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700145 parcel->readInt32(&frameTop) ?:
146 parcel->readInt32(&frameRight) ?:
147 parcel->readInt32(&frameBottom) ?:
148 parcel->readInt32(&surfaceInset) ?:
149 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100150 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700151 parcel->readFloat(&dsdx) ?:
152 parcel->readFloat(&dtdx) ?:
153 parcel->readFloat(&tx) ?:
154 parcel->readFloat(&dtdy) ?:
155 parcel->readFloat(&dsdy) ?:
156 parcel->readFloat(&ty) ?:
Evan Rosky44edce92021-05-14 18:09:55 -0700157 parcel->readInt32(&displayWidth) ?:
158 parcel->readInt32(&displayHeight) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700159 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700160 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700161 parcel->readBool(&hasWallpaper) ?:
162 parcel->readBool(&paused) ?:
163 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100164 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700165 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100166 parcel->readInt32(&ownerUid) ?:
167 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700168 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100169
170 if (status != OK) {
171 return status;
172 }
173
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100174 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
175
Michael Wright44753b12020-07-08 13:48:11 +0100176 inputFeatures = Flags<Feature>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500177 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100178 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700179 parcel->readInt32(&portalToDisplayId) ?:
180 applicationInfo.readFromParcel(parcel) ?:
181 parcel->read(touchableRegion) ?:
182 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500183 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700184
Michael Wright44753b12020-07-08 13:48:11 +0100185 if (status != OK) {
186 return status;
187 }
188
Chris Ye0783e992020-06-02 21:34:49 -0700189 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700190 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700191
chaviwe0ba4e92021-08-11 11:38:41 -0500192 status = parcel->readNullableStrongBinder(&windowToken);
193 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700194}
195
chaviw3277faf2021-05-19 16:45:23 -0500196// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700197
chaviw3277faf2021-05-19 16:45:23 -0500198WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -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(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700203
chaviw3277faf2021-05-19 16:45:23 -0500204WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700205
chaviw3277faf2021-05-19 16:45:23 -0500206status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700207 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700208}
209
chaviw3277faf2021-05-19 16:45:23 -0500210status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700211 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700212}
213
chaviw3277faf2021-05-19 16:45:23 -0500214void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700215 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700216}
217
chaviw3277faf2021-05-19 16:45:23 -0500218sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700219 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700220}
221
chaviw3277faf2021-05-19 16:45:23 -0500222void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800223 mInfo = handle->mInfo;
224}
chaviw3277faf2021-05-19 16:45:23 -0500225} // namespace android::gui