blob: 5f3a7263367ff1ed0c0a73a3dabdc424425e78e1 [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 &&
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070057 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
58 info.visible == visible && info.trustedOverlay == trustedOverlay &&
59 info.focusable == focusable && info.touchOcclusionMode == touchOcclusionMode &&
60 info.hasWallpaper == hasWallpaper && info.paused == paused &&
61 info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010062 info.packageName == packageName && info.inputFeatures == inputFeatures &&
63 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
Chris Ye0783e992020-06-02 21:34:49 -070064 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070065 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070066}
67
chaviw3277faf2021-05-19 16:45:23 -050068status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070069 if (parcel == nullptr) {
70 ALOGE("%s: Null parcel", __func__);
71 return BAD_VALUE;
72 }
Robert Carr2984b7a2020-04-13 17:06:45 -070073 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070074 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070075 return OK;
76 }
Chris Ye0783e992020-06-02 21:34:49 -070077 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070078
Vishnu Nair47074b82020-08-14 11:54:47 -070079 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070080 status_t status = parcel->writeStrongBinder(token) ?:
81 parcel->writeInt64(dispatchingTimeout.count()) ?:
82 parcel->writeInt32(id) ?:
83 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010084 parcel->writeInt32(flags.get()) ?:
chaviw3277faf2021-05-19 16:45:23 -050085 parcel->writeInt32(static_cast<std::underlying_type_t<WindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070086 parcel->writeInt32(frameLeft) ?:
87 parcel->writeInt32(frameTop) ?:
88 parcel->writeInt32(frameRight) ?:
89 parcel->writeInt32(frameBottom) ?:
90 parcel->writeInt32(surfaceInset) ?:
91 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +010092 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070093 parcel->writeFloat(transform.dsdx()) ?:
94 parcel->writeFloat(transform.dtdx()) ?:
95 parcel->writeFloat(transform.tx()) ?:
96 parcel->writeFloat(transform.dtdy()) ?:
97 parcel->writeFloat(transform.dsdy()) ?:
98 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -070099 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700100 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700101 parcel->writeBool(hasWallpaper) ?:
102 parcel->writeBool(paused) ?:
103 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100104 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700105 parcel->writeInt32(ownerPid) ?:
106 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100107 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100108 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700109 parcel->writeInt32(displayId) ?:
110 parcel->writeInt32(portalToDisplayId) ?:
111 applicationInfo.writeToParcel(parcel) ?:
112 parcel->write(touchableRegion) ?:
113 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500114 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
115 parcel->writeStrongBinder(windowToken);
Vishnu Nair47074b82020-08-14 11:54:47 -0700116 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700117 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700118}
119
chaviw3277faf2021-05-19 16:45:23 -0500120status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700121 if (parcel == nullptr) {
122 ALOGE("%s: Null parcel", __func__);
123 return BAD_VALUE;
124 }
125 if (parcel->readInt32() == 0) {
126 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700127 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700128
Chris Ye0783e992020-06-02 21:34:49 -0700129 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100130 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
131 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
132 if (status != OK) {
133 return status;
134 }
135
136 flags = Flags<Flag>(parcel->readInt32());
137 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700138 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100139 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700140 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100141 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700142 parcel->readInt32(&frameTop) ?:
143 parcel->readInt32(&frameRight) ?:
144 parcel->readInt32(&frameBottom) ?:
145 parcel->readInt32(&surfaceInset) ?:
146 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100147 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700148 parcel->readFloat(&dsdx) ?:
149 parcel->readFloat(&dtdx) ?:
150 parcel->readFloat(&tx) ?:
151 parcel->readFloat(&dtdy) ?:
152 parcel->readFloat(&dsdy) ?:
153 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700154 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700155 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700156 parcel->readBool(&hasWallpaper) ?:
157 parcel->readBool(&paused) ?:
158 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100159 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700160 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100161 parcel->readInt32(&ownerUid) ?:
162 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700163 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100164
165 if (status != OK) {
166 return status;
167 }
168
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100169 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
170
Michael Wright44753b12020-07-08 13:48:11 +0100171 inputFeatures = Flags<Feature>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500172 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100173 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700174 parcel->readInt32(&portalToDisplayId) ?:
175 applicationInfo.readFromParcel(parcel) ?:
176 parcel->read(touchableRegion) ?:
177 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500178 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700179
Michael Wright44753b12020-07-08 13:48:11 +0100180 if (status != OK) {
181 return status;
182 }
183
Chris Ye0783e992020-06-02 21:34:49 -0700184 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700185 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700186
chaviwe0ba4e92021-08-11 11:38:41 -0500187 status = parcel->readNullableStrongBinder(&windowToken);
188 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700189}
190
chaviw3277faf2021-05-19 16:45:23 -0500191// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700192
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