blob: 8d356aaaa15d43970aa6ab23a14fefe12f1cf2fc [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 {
55 return frameLeft < other->frameRight && frameRight > other->frameLeft &&
56 frameTop < other->frameBottom && frameBottom > other->frameTop;
Robert Carr3720ed02018-08-08 16:08:27 -070057}
58
chaviw3277faf2021-05-19 16:45:23 -050059bool WindowInfo::operator==(const WindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010060 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
61 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
62 info.frameLeft == frameLeft && info.frameTop == frameTop &&
63 info.frameRight == frameRight && info.frameBottom == frameBottom &&
64 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070065 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
66 info.visible == visible && info.trustedOverlay == trustedOverlay &&
67 info.focusable == focusable && info.touchOcclusionMode == touchOcclusionMode &&
68 info.hasWallpaper == hasWallpaper && info.paused == paused &&
69 info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010070 info.packageName == packageName && info.inputFeatures == inputFeatures &&
71 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
Chris Ye0783e992020-06-02 21:34:49 -070072 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070073 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070074}
75
chaviw3277faf2021-05-19 16:45:23 -050076status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070077 if (parcel == nullptr) {
78 ALOGE("%s: Null parcel", __func__);
79 return BAD_VALUE;
80 }
Robert Carr2984b7a2020-04-13 17:06:45 -070081 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070082 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070083 return OK;
84 }
Chris Ye0783e992020-06-02 21:34:49 -070085 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070086
Vishnu Nair47074b82020-08-14 11:54:47 -070087 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070088 status_t status = parcel->writeStrongBinder(token) ?:
89 parcel->writeInt64(dispatchingTimeout.count()) ?:
90 parcel->writeInt32(id) ?:
91 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010092 parcel->writeInt32(flags.get()) ?:
chaviw3277faf2021-05-19 16:45:23 -050093 parcel->writeInt32(static_cast<std::underlying_type_t<WindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070094 parcel->writeInt32(frameLeft) ?:
95 parcel->writeInt32(frameTop) ?:
96 parcel->writeInt32(frameRight) ?:
97 parcel->writeInt32(frameBottom) ?:
98 parcel->writeInt32(surfaceInset) ?:
99 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100100 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700101 parcel->writeFloat(transform.dsdx()) ?:
102 parcel->writeFloat(transform.dtdx()) ?:
103 parcel->writeFloat(transform.tx()) ?:
104 parcel->writeFloat(transform.dtdy()) ?:
105 parcel->writeFloat(transform.dsdy()) ?:
106 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700107 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700108 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700109 parcel->writeBool(hasWallpaper) ?:
110 parcel->writeBool(paused) ?:
111 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100112 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700113 parcel->writeInt32(ownerPid) ?:
114 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100115 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100116 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700117 parcel->writeInt32(displayId) ?:
118 parcel->writeInt32(portalToDisplayId) ?:
119 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 parcel->readInt32(&portalToDisplayId) ?:
183 applicationInfo.readFromParcel(parcel) ?:
184 parcel->read(touchableRegion) ?:
185 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500186 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700187
Michael Wright44753b12020-07-08 13:48:11 +0100188 if (status != OK) {
189 return status;
190 }
191
Chris Ye0783e992020-06-02 21:34:49 -0700192 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700193 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700194
chaviwe0ba4e92021-08-11 11:38:41 -0500195 status = parcel->readNullableStrongBinder(&windowToken);
196 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700197}
198
chaviw3277faf2021-05-19 16:45:23 -0500199// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700200
chaviw3277faf2021-05-19 16:45:23 -0500201WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -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(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700206
chaviw3277faf2021-05-19 16:45:23 -0500207WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700208
chaviw3277faf2021-05-19 16:45:23 -0500209status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700210 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700211}
212
chaviw3277faf2021-05-19 16:45:23 -0500213status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700214 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700215}
216
chaviw3277faf2021-05-19 16:45:23 -0500217void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700218 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700219}
220
chaviw3277faf2021-05-19 16:45:23 -0500221sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700222 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700223}
224
chaviw3277faf2021-05-19 16:45:23 -0500225void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800226 mInfo = handle->mInfo;
227}
chaviw3277faf2021-05-19 16:45:23 -0500228} // namespace android::gui