blob: 1c7b2705277bbc6a7f2208933c2707227e3f823f [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 &&
72 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
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) ?:
119 parcel->writeInt32(portalToDisplayId) ?:
120 applicationInfo.writeToParcel(parcel) ?:
121 parcel->write(touchableRegion) ?:
122 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500123 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
124 parcel->writeStrongBinder(windowToken);
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
145 flags = Flags<Flag>(parcel->readInt32());
146 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700147 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100148 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700149 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100150 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700151 parcel->readInt32(&frameTop) ?:
152 parcel->readInt32(&frameRight) ?:
153 parcel->readInt32(&frameBottom) ?:
154 parcel->readInt32(&surfaceInset) ?:
155 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100156 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700157 parcel->readFloat(&dsdx) ?:
158 parcel->readFloat(&dtdx) ?:
159 parcel->readFloat(&tx) ?:
160 parcel->readFloat(&dtdy) ?:
161 parcel->readFloat(&dsdy) ?:
162 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700163 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700164 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700165 parcel->readBool(&hasWallpaper) ?:
166 parcel->readBool(&paused) ?:
167 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100168 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700169 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100170 parcel->readInt32(&ownerUid) ?:
171 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700172 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100173
174 if (status != OK) {
175 return status;
176 }
177
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100178 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
179
Michael Wright44753b12020-07-08 13:48:11 +0100180 inputFeatures = Flags<Feature>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500181 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100182 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700183 parcel->readInt32(&portalToDisplayId) ?:
184 applicationInfo.readFromParcel(parcel) ?:
185 parcel->read(touchableRegion) ?:
186 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500187 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700188
Michael Wright44753b12020-07-08 13:48:11 +0100189 if (status != OK) {
190 return status;
191 }
192
Chris Ye0783e992020-06-02 21:34:49 -0700193 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700194 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700195
chaviwe0ba4e92021-08-11 11:38:41 -0500196 status = parcel->readNullableStrongBinder(&windowToken);
197 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700198}
199
chaviw3277faf2021-05-19 16:45:23 -0500200// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -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() {}
Chris Ye0783e992020-06-02 21:34:49 -0700205
chaviw3277faf2021-05-19 16:45:23 -0500206WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700207
chaviw3277faf2021-05-19 16:45:23 -0500208WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700209
chaviw3277faf2021-05-19 16:45:23 -0500210status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700211 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700212}
213
chaviw3277faf2021-05-19 16:45:23 -0500214status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700215 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700216}
217
chaviw3277faf2021-05-19 16:45:23 -0500218void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700219 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700220}
221
chaviw3277faf2021-05-19 16:45:23 -0500222sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700223 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700224}
225
chaviw3277faf2021-05-19 16:45:23 -0500226void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800227 mInfo = handle->mInfo;
228}
chaviw3277faf2021-05-19 16:45:23 -0500229} // namespace android::gui