blob: 8546bbbb4357ddbd776346d96b86eafb8f88cc72 [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 &&
Chris Ye6c4243b2020-07-22 12:07:12 -070060 info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) &&
Vishnu Nair47074b82020-08-14 11:54:47 -070061 info.visible == visible && info.trustedOverlay == trustedOverlay &&
Bernardo Rufinoea97d182020-08-19 14:43:14 +010062 info.focusable == focusable && info.touchOcclusionMode == touchOcclusionMode &&
63 info.hasWallpaper == hasWallpaper && info.paused == paused &&
64 info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
65 info.packageName == packageName && info.inputFeatures == inputFeatures &&
66 info.displayId == displayId && info.portalToDisplayId == portalToDisplayId &&
Chris Ye0783e992020-06-02 21:34:49 -070067 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070068 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070069}
70
71status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const {
72 if (parcel == nullptr) {
73 ALOGE("%s: Null parcel", __func__);
74 return BAD_VALUE;
75 }
Robert Carr2984b7a2020-04-13 17:06:45 -070076 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070077 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070078 return OK;
79 }
Chris Ye0783e992020-06-02 21:34:49 -070080 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070081
Vishnu Nair47074b82020-08-14 11:54:47 -070082 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070083 status_t status = parcel->writeStrongBinder(token) ?:
84 parcel->writeInt64(dispatchingTimeout.count()) ?:
85 parcel->writeInt32(id) ?:
86 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010087 parcel->writeInt32(flags.get()) ?:
88 parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070089 parcel->writeInt32(frameLeft) ?:
90 parcel->writeInt32(frameTop) ?:
91 parcel->writeInt32(frameRight) ?:
92 parcel->writeInt32(frameBottom) ?:
93 parcel->writeInt32(surfaceInset) ?:
94 parcel->writeFloat(globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +010095 parcel->writeFloat(alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070096 parcel->writeFloat(transform.dsdx()) ?:
97 parcel->writeFloat(transform.dtdx()) ?:
98 parcel->writeFloat(transform.tx()) ?:
99 parcel->writeFloat(transform.dtdy()) ?:
100 parcel->writeFloat(transform.dsdy()) ?:
101 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700102 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700103 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700104 parcel->writeBool(hasWallpaper) ?:
105 parcel->writeBool(paused) ?:
106 parcel->writeBool(trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100107 parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700108 parcel->writeInt32(ownerPid) ?:
109 parcel->writeInt32(ownerUid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100110 parcel->writeUtf8AsUtf16(packageName) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100111 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700112 parcel->writeInt32(displayId) ?:
113 parcel->writeInt32(portalToDisplayId) ?:
114 applicationInfo.writeToParcel(parcel) ?:
115 parcel->write(touchableRegion) ?:
116 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
117 parcel->writeStrongBinder(touchableRegionCropHandle.promote());
Vishnu Nair47074b82020-08-14 11:54:47 -0700118 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700119 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700120}
121
Chris Ye0783e992020-06-02 21:34:49 -0700122status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) {
123 if (parcel == nullptr) {
124 ALOGE("%s: Null parcel", __func__);
125 return BAD_VALUE;
126 }
127 if (parcel->readInt32() == 0) {
128 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700129 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700130
Chris Ye0783e992020-06-02 21:34:49 -0700131 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100132 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
133 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
134 if (status != OK) {
135 return status;
136 }
137
138 flags = Flags<Flag>(parcel->readInt32());
139 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700140 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100141 int32_t touchOcclusionModeInt;
Vishnu Nair47074b82020-08-14 11:54:47 -0700142 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100143 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700144 parcel->readInt32(&frameTop) ?:
145 parcel->readInt32(&frameRight) ?:
146 parcel->readInt32(&frameBottom) ?:
147 parcel->readInt32(&surfaceInset) ?:
148 parcel->readFloat(&globalScaleFactor) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100149 parcel->readFloat(&alpha) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700150 parcel->readFloat(&dsdx) ?:
151 parcel->readFloat(&dtdx) ?:
152 parcel->readFloat(&tx) ?:
153 parcel->readFloat(&dtdy) ?:
154 parcel->readFloat(&dsdy) ?:
155 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700156 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700157 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700158 parcel->readBool(&hasWallpaper) ?:
159 parcel->readBool(&paused) ?:
160 parcel->readBool(&trustedOverlay) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100161 parcel->readInt32(&touchOcclusionModeInt) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700162 parcel->readInt32(&ownerPid) ?:
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100163 parcel->readInt32(&ownerUid) ?:
164 parcel->readUtf8FromUtf16(&packageName);
Vishnu Nair47074b82020-08-14 11:54:47 -0700165 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100166
167 if (status != OK) {
168 return status;
169 }
170
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100171 touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt);
172
Michael Wright44753b12020-07-08 13:48:11 +0100173 inputFeatures = Flags<Feature>(parcel->readInt32());
174 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700175 parcel->readInt32(&portalToDisplayId) ?:
176 applicationInfo.readFromParcel(parcel) ?:
177 parcel->read(touchableRegion) ?:
178 parcel->readBool(&replaceTouchableRegionWithCrop);
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
Michael Wright44753b12020-07-08 13:48:11 +0100187 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700188}
189
Robert Carr3720ed02018-08-08 16:08:27 -0700190// --- InputWindowHandle ---
191
Chris Ye0783e992020-06-02 21:34:49 -0700192InputWindowHandle::InputWindowHandle() {}
193
194InputWindowHandle::~InputWindowHandle() {}
195
196InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {}
197
198InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {}
199
200status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const {
201 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700202}
203
Chris Ye0783e992020-06-02 21:34:49 -0700204status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) {
205 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700206}
207
Arthur Hung3b413f22018-10-26 18:05:34 +0800208void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700209 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700210}
211
Robert Carr5c8a0262018-10-03 16:30:44 -0700212sp<IBinder> InputWindowHandle::getToken() const {
213 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700214}
215
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800216void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
217 mInfo = handle->mInfo;
218}
Robert Carr3720ed02018-08-08 16:08:27 -0700219} // namespace android