blob: 99477200db82750aaff93c39b0328e82408b957c [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>
Robert Carr3720ed02018-08-08 16:08:27 -070018#define LOG_TAG "InputWindow"
19#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>
Robert Carr3720ed02018-08-08 16:08:27 -070023#include <input/InputTransport.h>
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070024#include <input/InputWindow.h>
Robert Carr3720ed02018-08-08 16:08:27 -070025
26#include <log/log.h>
27
Robert Carr3720ed02018-08-08 16:08:27 -070028namespace android {
29
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070030
Robert Carr3720ed02018-08-08 16:08:27 -070031// --- InputWindowInfo ---
32void InputWindowInfo::addTouchableRegion(const Rect& region) {
33 touchableRegion.orSelf(region);
34}
35
36bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
37 return touchableRegion.contains(x,y);
38}
39
40bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
41 return x >= frameLeft && x < frameRight
42 && y >= frameTop && y < frameBottom;
43}
44
Robert Carr3720ed02018-08-08 16:08:27 -070045bool InputWindowInfo::supportsSplitTouch() const {
Michael Wright44753b12020-07-08 13:48:11 +010046 return flags.test(Flag::SPLIT_TOUCH);
Robert Carr3720ed02018-08-08 16:08:27 -070047}
48
49bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
50 return frameLeft < other->frameRight && frameRight > other->frameLeft
51 && frameTop < other->frameBottom && frameBottom > other->frameTop;
52}
53
Chris Ye0783e992020-06-02 21:34:49 -070054bool InputWindowInfo::operator==(const InputWindowInfo& info) const {
Michael Wright44753b12020-07-08 13:48:11 +010055 return info.token == token && info.id == id && info.name == name && info.flags == flags &&
56 info.type == type && info.dispatchingTimeout == dispatchingTimeout &&
57 info.frameLeft == frameLeft && info.frameTop == frameTop &&
58 info.frameRight == frameRight && info.frameBottom == frameBottom &&
59 info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor &&
Evan Rosky44edce92021-05-14 18:09:55 -070060 info.transform == transform && info.displayWidth == displayWidth &&
61 info.displayHeight == displayHeight &&
62 info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible &&
63 info.trustedOverlay == trustedOverlay && info.focusable == focusable &&
64 info.touchOcclusionMode == touchOcclusionMode && info.hasWallpaper == hasWallpaper &&
65 info.paused == paused && 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
72status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const {
73 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()) ?:
89 parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::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()) ?:
Evan Rosky44edce92021-05-14 18:09:55 -0700103 parcel->writeInt32(displayWidth) ?:
104 parcel->writeInt32(displayHeight) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700105 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700106 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700107 parcel->writeBool(hasWallpaper) ?:
108 parcel->writeBool(paused) ?:
109 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100110 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700111 parcel->writeInt32(ownerPid) ?:
112 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100113 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100114 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700115 parcel->writeInt32(displayId) ?:
116 parcel->writeInt32(portalToDisplayId) ?:
117 applicationInfo.writeToParcel(parcel) ?:
118 parcel->write(touchableRegion) ?:
119 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
120 parcel->writeStrongBinder(touchableRegionCropHandle.promote());
Vishnu Nair47074b82020-08-14 11:54:47 -0700121 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700122 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700123}
124
Chris Ye0783e992020-06-02 21:34:49 -0700125status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) {
126 if (parcel == nullptr) {
127 ALOGE("%s: Null parcel", __func__);
128 return BAD_VALUE;
129 }
130 if (parcel->readInt32() == 0) {
131 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700132 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700133
Chris Ye0783e992020-06-02 21:34:49 -0700134 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100135 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
136 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
137 if (status != OK) {
138 return status;
139 }
140
141 flags = Flags<Flag>(parcel->readInt32());
142 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700143 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100144 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700145 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100146 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700147 parcel->readInt32(&frameTop) ?:
148 parcel->readInt32(&frameRight) ?:
149 parcel->readInt32(&frameBottom) ?:
150 parcel->readInt32(&surfaceInset) ?:
151 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100152 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700153 parcel->readFloat(&dsdx) ?:
154 parcel->readFloat(&dtdx) ?:
155 parcel->readFloat(&tx) ?:
156 parcel->readFloat(&dtdy) ?:
157 parcel->readFloat(&dsdy) ?:
158 parcel->readFloat(&ty) ?:
Evan Rosky44edce92021-05-14 18:09:55 -0700159 parcel->readInt32(&displayWidth) ?:
160 parcel->readInt32(&displayHeight) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700161 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700162 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700163 parcel->readBool(&hasWallpaper) ?:
164 parcel->readBool(&paused) ?:
165 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100166 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700167 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100168 parcel->readInt32(&ownerUid) ?:
169 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700170 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100171
172 if (status != OK) {
173 return status;
174 }
175
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100176 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
177
Michael Wright44753b12020-07-08 13:48:11 +0100178 inputFeatures = Flags<Feature>(parcel->readInt32());
179 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700180 parcel->readInt32(&portalToDisplayId) ?:
181 applicationInfo.readFromParcel(parcel) ?:
182 parcel->read(touchableRegion) ?:
183 parcel->readBool(&replaceTouchableRegionWithCrop);
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
Michael Wright44753b12020-07-08 13:48:11 +0100192 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700193}
194
Robert Carr3720ed02018-08-08 16:08:27 -0700195// --- InputWindowHandle ---
196
Chris Ye0783e992020-06-02 21:34:49 -0700197InputWindowHandle::InputWindowHandle() {}
198
199InputWindowHandle::~InputWindowHandle() {}
200
201InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {}
202
203InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {}
204
205status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const {
206 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700207}
208
Chris Ye0783e992020-06-02 21:34:49 -0700209status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) {
210 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700211}
212
Arthur Hung3b413f22018-10-26 18:05:34 +0800213void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700214 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700215}
216
Robert Carr5c8a0262018-10-03 16:30:44 -0700217sp<IBinder> InputWindowHandle::getToken() const {
218 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700219}
220
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800221void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
222 mInfo = handle->mInfo;
223}
Robert Carr3720ed02018-08-08 16:08:27 -0700224} // namespace android