blob: 885dc9b51e85beebd6ade29b7488844f32b5ca86 [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 &&
62 info.focusable == focusable && info.hasWallpaper == hasWallpaper &&
63 info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid &&
Chris Ye0783e992020-06-02 21:34:49 -070064 info.inputFeatures == inputFeatures && info.displayId == displayId &&
65 info.portalToDisplayId == portalToDisplayId &&
66 info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop &&
Chris Ye6c4243b2020-07-22 12:07:12 -070067 info.applicationInfo == applicationInfo;
Chris Ye0783e992020-06-02 21:34:49 -070068}
69
70status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const {
71 if (parcel == nullptr) {
72 ALOGE("%s: Null parcel", __func__);
73 return BAD_VALUE;
74 }
Robert Carr2984b7a2020-04-13 17:06:45 -070075 if (name.empty()) {
Chris Ye0783e992020-06-02 21:34:49 -070076 parcel->writeInt32(0);
Robert Carr3720ed02018-08-08 16:08:27 -070077 return OK;
78 }
Chris Ye0783e992020-06-02 21:34:49 -070079 parcel->writeInt32(1);
Robert Carr3720ed02018-08-08 16:08:27 -070080
Vishnu Nair47074b82020-08-14 11:54:47 -070081 // clang-format off
Chris Ye0783e992020-06-02 21:34:49 -070082 status_t status = parcel->writeStrongBinder(token) ?:
83 parcel->writeInt64(dispatchingTimeout.count()) ?:
84 parcel->writeInt32(id) ?:
85 parcel->writeUtf8AsUtf16(name) ?:
Michael Wright44753b12020-07-08 13:48:11 +010086 parcel->writeInt32(flags.get()) ?:
87 parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::Type>>(type)) ?:
Chris Ye0783e992020-06-02 21:34:49 -070088 parcel->writeInt32(frameLeft) ?:
89 parcel->writeInt32(frameTop) ?:
90 parcel->writeInt32(frameRight) ?:
91 parcel->writeInt32(frameBottom) ?:
92 parcel->writeInt32(surfaceInset) ?:
93 parcel->writeFloat(globalScaleFactor) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -070094 parcel->writeFloat(transform.dsdx()) ?:
95 parcel->writeFloat(transform.dtdx()) ?:
96 parcel->writeFloat(transform.tx()) ?:
97 parcel->writeFloat(transform.dtdy()) ?:
98 parcel->writeFloat(transform.dsdy()) ?:
99 parcel->writeFloat(transform.ty()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700100 parcel->writeBool(visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700101 parcel->writeBool(focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700102 parcel->writeBool(hasWallpaper) ?:
103 parcel->writeBool(paused) ?:
104 parcel->writeBool(trustedOverlay) ?:
105 parcel->writeInt32(ownerPid) ?:
106 parcel->writeInt32(ownerUid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100107 parcel->writeInt32(inputFeatures.get()) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700108 parcel->writeInt32(displayId) ?:
109 parcel->writeInt32(portalToDisplayId) ?:
110 applicationInfo.writeToParcel(parcel) ?:
111 parcel->write(touchableRegion) ?:
112 parcel->writeBool(replaceTouchableRegionWithCrop) ?:
113 parcel->writeStrongBinder(touchableRegionCropHandle.promote());
Vishnu Nair47074b82020-08-14 11:54:47 -0700114 // clang-format on
Chris Ye0783e992020-06-02 21:34:49 -0700115 return status;
Robert Carr3720ed02018-08-08 16:08:27 -0700116}
117
Chris Ye0783e992020-06-02 21:34:49 -0700118status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) {
119 if (parcel == nullptr) {
120 ALOGE("%s: Null parcel", __func__);
121 return BAD_VALUE;
122 }
123 if (parcel->readInt32() == 0) {
124 return OK;
Robert Carr3720ed02018-08-08 16:08:27 -0700125 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700126
Chris Ye0783e992020-06-02 21:34:49 -0700127 token = parcel->readStrongBinder();
Michael Wright44753b12020-07-08 13:48:11 +0100128 dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64());
129 status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name);
130 if (status != OK) {
131 return status;
132 }
133
134 flags = Flags<Flag>(parcel->readInt32());
135 type = static_cast<Type>(parcel->readInt32());
chaviw1ff3d1e2020-07-01 15:53:47 -0700136 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Vishnu Nair47074b82020-08-14 11:54:47 -0700137 // clang-format off
Michael Wright44753b12020-07-08 13:48:11 +0100138 status = parcel->readInt32(&frameLeft) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700139 parcel->readInt32(&frameTop) ?:
140 parcel->readInt32(&frameRight) ?:
141 parcel->readInt32(&frameBottom) ?:
142 parcel->readInt32(&surfaceInset) ?:
143 parcel->readFloat(&globalScaleFactor) ?:
chaviw1ff3d1e2020-07-01 15:53:47 -0700144 parcel->readFloat(&dsdx) ?:
145 parcel->readFloat(&dtdx) ?:
146 parcel->readFloat(&tx) ?:
147 parcel->readFloat(&dtdy) ?:
148 parcel->readFloat(&dsdy) ?:
149 parcel->readFloat(&ty) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700150 parcel->readBool(&visible) ?:
Vishnu Nair47074b82020-08-14 11:54:47 -0700151 parcel->readBool(&focusable) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700152 parcel->readBool(&hasWallpaper) ?:
153 parcel->readBool(&paused) ?:
154 parcel->readBool(&trustedOverlay) ?:
155 parcel->readInt32(&ownerPid) ?:
Michael Wright44753b12020-07-08 13:48:11 +0100156 parcel->readInt32(&ownerUid);
Vishnu Nair47074b82020-08-14 11:54:47 -0700157 // clang-format on
Michael Wright44753b12020-07-08 13:48:11 +0100158
159 if (status != OK) {
160 return status;
161 }
162
163 inputFeatures = Flags<Feature>(parcel->readInt32());
164 status = parcel->readInt32(&displayId) ?:
Chris Ye0783e992020-06-02 21:34:49 -0700165 parcel->readInt32(&portalToDisplayId) ?:
166 applicationInfo.readFromParcel(parcel) ?:
167 parcel->read(touchableRegion) ?:
168 parcel->readBool(&replaceTouchableRegionWithCrop);
Robert Carr3720ed02018-08-08 16:08:27 -0700169
Michael Wright44753b12020-07-08 13:48:11 +0100170 if (status != OK) {
171 return status;
172 }
173
Chris Ye0783e992020-06-02 21:34:49 -0700174 touchableRegionCropHandle = parcel->readStrongBinder();
chaviw9eaa22c2020-07-01 16:21:27 -0700175 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -0700176
Michael Wright44753b12020-07-08 13:48:11 +0100177 return OK;
Robert Carr1cc78672018-07-31 14:25:57 -0700178}
179
Robert Carr3720ed02018-08-08 16:08:27 -0700180// --- InputWindowHandle ---
181
Chris Ye0783e992020-06-02 21:34:49 -0700182InputWindowHandle::InputWindowHandle() {}
183
184InputWindowHandle::~InputWindowHandle() {}
185
186InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {}
187
188InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {}
189
190status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const {
191 return mInfo.writeToParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700192}
193
Chris Ye0783e992020-06-02 21:34:49 -0700194status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) {
195 return mInfo.readFromParcel(parcel);
Robert Carr3720ed02018-08-08 16:08:27 -0700196}
197
Arthur Hung3b413f22018-10-26 18:05:34 +0800198void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700199 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700200}
201
Robert Carr5c8a0262018-10-03 16:30:44 -0700202sp<IBinder> InputWindowHandle::getToken() const {
203 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700204}
205
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800206void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
207 mInfo = handle->mInfo;
208}
Robert Carr3720ed02018-08-08 16:08:27 -0700209} // namespace android