blob: e92be01e15f749a4a3c66e9637eb513dc58bc2ae [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
chaviw3277faf2021-05-19 16:45:23 -050050bool WindowInfo::overlaps(const WindowInfo* other) const {
51 return frameLeft < other->frameRight && frameRight > other->frameLeft &&
52 frameTop < other->frameBottom && frameBottom > other->frameTop;
Robert Carr3720ed02018-08-08 16:08:27 -070053}
54
chaviw3277faf2021-05-19 16:45:23 -050055bool WindowInfo::operator==(const WindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010056 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
57 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
58 info.frameLeft == frameLeft && info.frameTop == frameTop &&
59 info.frameRight == frameRight && info.frameBottom == frameBottom &&
60 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070061 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
62 info.visible == visible && info.trustedOverlay == trustedOverlay &&
63 info.focusable == focusable && info.touchOcclusionMode == touchOcclusionMode &&
64 info.hasWallpaper == hasWallpaper && info.paused == paused &&
65 info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010066 info.packageName == packageName && info.inputFeatures == inputFeatures &&
67 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
Chris Ye0783e992020-06-02 21:34:49 -070068 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070069 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070070}
71
chaviw3277faf2021-05-19 16:45:23 -050072status_t WindowInfo::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -070073 if (parcel == nullptr) {
74 ALOGE("%s: Null parcel", __func__);
75 return BAD_VALUE;
76 }
Robert Carr2984b7a2020-04-13 17:06:45 -070077 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070078 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070079 return OK;
80 }
Chris Ye0783e992020-06-02 21:34:49 -070081 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070082
Vishnu Nair47074b82020-08-14 11:54:47 -070083 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070084 status_t status = parcel->writeStrongBinder(token) ?:
85 parcel->writeInt64(dispatchingTimeout.count()) ?:
86 parcel->writeInt32(id) ?:
87 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010088 parcel->writeInt32(flags.get()) ?:
chaviw3277faf2021-05-19 16:45:23 -050089 parcel->writeInt32(static_cast<std::underlying_type_t<WindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070090 parcel->writeInt32(frameLeft) ?:
91 parcel->writeInt32(frameTop) ?:
92 parcel->writeInt32(frameRight) ?:
93 parcel->writeInt32(frameBottom) ?:
94 parcel->writeInt32(surfaceInset) ?:
95 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +010096 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070097 parcel->writeFloat(transform.dsdx()) ?:
98 parcel->writeFloat(transform.dtdx()) ?:
99 parcel->writeFloat(transform.tx()) ?:
100 parcel->writeFloat(transform.dtdy()) ?:
101 parcel->writeFloat(transform.dsdy()) ?:
102 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700103 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700104 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700105 parcel->writeBool(hasWallpaper) ?:
106 parcel->writeBool(paused) ?:
107 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100108 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700109 parcel->writeInt32(ownerPid) ?:
110 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100111 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100112 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700113 parcel->writeInt32(displayId) ?:
114 parcel->writeInt32(portalToDisplayId) ?:
115 applicationInfo.writeToParcel(parcel) ?:
116 parcel->write(touchableRegion) ?:
117 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
chaviwe0ba4e92021-08-11 11:38:41 -0500118 parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?:
119 parcel->writeStrongBinder(windowToken);
Vishnu Nair47074b82020-08-14 11:54:47 -0700120 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700121 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700122}
123
chaviw3277faf2021-05-19 16:45:23 -0500124status_t WindowInfo::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700125 if (parcel == nullptr) {
126 ALOGE("%s: Null parcel", __func__);
127 return BAD_VALUE;
128 }
129 if (parcel->readInt32() == 0) {
130 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700131 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700132
Chris Ye0783e992020-06-02 21:34:49 -0700133 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100134 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
135 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
136 if (status != OK) {
137 return status;
138 }
139
140 flags = Flags<Flag>(parcel->readInt32());
141 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700142 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100143 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700144 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100145 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700146 parcel->readInt32(&frameTop) ?:
147 parcel->readInt32(&frameRight) ?:
148 parcel->readInt32(&frameBottom) ?:
149 parcel->readInt32(&surfaceInset) ?:
150 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100151 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700152 parcel->readFloat(&dsdx) ?:
153 parcel->readFloat(&dtdx) ?:
154 parcel->readFloat(&tx) ?:
155 parcel->readFloat(&dtdy) ?:
156 parcel->readFloat(&dsdy) ?:
157 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700158 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700159 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700160 parcel->readBool(&hasWallpaper) ?:
161 parcel->readBool(&paused) ?:
162 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100163 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700164 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100165 parcel->readInt32(&ownerUid) ?:
166 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700167 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100168
169 if (status != OK) {
170 return status;
171 }
172
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100173 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
174
Michael Wright44753b12020-07-08 13:48:11 +0100175 inputFeatures = Flags<Feature>(parcel->readInt32());
chaviw3277faf2021-05-19 16:45:23 -0500176 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100177 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700178 parcel->readInt32(&portalToDisplayId) ?:
179 applicationInfo.readFromParcel(parcel) ?:
180 parcel->read(touchableRegion) ?:
181 parcel->readBool(&replaceTouchableRegionWithCrop);
chaviw3277faf2021-05-19 16:45:23 -0500182 // clang-format on
Robert Carr3720ed02018-08-08 16:08:27 -0700183
Michael Wright44753b12020-07-08 13:48:11 +0100184 if (status != OK) {
185 return status;
186 }
187
Chris Ye0783e992020-06-02 21:34:49 -0700188 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700189 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700190
chaviwe0ba4e92021-08-11 11:38:41 -0500191 status = parcel->readNullableStrongBinder(&windowToken);
192 return status;
Robert Carr1cc78672018-07-31 14:25:57 -0700193}
194
chaviw3277faf2021-05-19 16:45:23 -0500195// --- WindowInfoHandle ---
Robert Carr3720ed02018-08-08 16:08:27 -0700196
chaviw3277faf2021-05-19 16:45:23 -0500197WindowInfoHandle::WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700198
chaviw3277faf2021-05-19 16:45:23 -0500199WindowInfoHandle::~WindowInfoHandle() {}
Chris Ye0783e992020-06-02 21:34:49 -0700200
chaviw3277faf2021-05-19 16:45:23 -0500201WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {}
Chris Ye0783e992020-06-02 21:34:49 -0700202
chaviw3277faf2021-05-19 16:45:23 -0500203WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {}
Chris Ye0783e992020-06-02 21:34:49 -0700204
chaviw3277faf2021-05-19 16:45:23 -0500205status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const {
Chris Ye0783e992020-06-02 21:34:49 -0700206 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700207}
208
chaviw3277faf2021-05-19 16:45:23 -0500209status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) {
Chris Ye0783e992020-06-02 21:34:49 -0700210 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700211}
212
chaviw3277faf2021-05-19 16:45:23 -0500213void WindowInfoHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700214 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700215}
216
chaviw3277faf2021-05-19 16:45:23 -0500217sp<IBinder> WindowInfoHandle::getToken() const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700218 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700219}
220
chaviw3277faf2021-05-19 16:45:23 -0500221void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) {
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800222 mInfo = handle->mInfo;
223}
chaviw3277faf2021-05-19 16:45:23 -0500224} // namespace android::gui