| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 17 | #include <type_traits> | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 18 | #define LOG_TAG "InputWindow" | 
|  | 19 | #define LOG_NDEBUG 0 | 
|  | 20 |  | 
| Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 23 | #include <input/InputTransport.h> | 
| Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 24 | #include <input/InputWindow.h> | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | #include <log/log.h> | 
|  | 27 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 28 | namespace android { | 
|  | 29 |  | 
| Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 30 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 31 | // --- InputWindowInfo --- | 
|  | 32 | void InputWindowInfo::addTouchableRegion(const Rect& region) { | 
|  | 33 | touchableRegion.orSelf(region); | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const { | 
|  | 37 | return touchableRegion.contains(x,y); | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const { | 
|  | 41 | return x >= frameLeft && x < frameRight | 
|  | 42 | && y >= frameTop && y < frameBottom; | 
|  | 43 | } | 
|  | 44 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 45 | bool InputWindowInfo::supportsSplitTouch() const { | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 46 | return flags.test(Flag::SPLIT_TOUCH); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
|  | 49 | bool InputWindowInfo::overlaps(const InputWindowInfo* other) const { | 
|  | 50 | return frameLeft < other->frameRight && frameRight > other->frameLeft | 
|  | 51 | && frameTop < other->frameBottom && frameBottom > other->frameTop; | 
|  | 52 | } | 
|  | 53 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 54 | bool InputWindowInfo::operator==(const InputWindowInfo& info) const { | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 55 | 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 Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 60 | info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) && | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 61 | info.visible == visible && info.trustedOverlay == trustedOverlay && | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 62 | 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 Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 67 | info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop && | 
| Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 68 | info.applicationInfo == applicationInfo; | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 69 | } | 
|  | 70 |  | 
|  | 71 | status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const { | 
|  | 72 | if (parcel == nullptr) { | 
|  | 73 | ALOGE("%s: Null parcel", __func__); | 
|  | 74 | return BAD_VALUE; | 
|  | 75 | } | 
| Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 76 | if (name.empty()) { | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 77 | parcel->writeInt32(0); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 78 | return OK; | 
|  | 79 | } | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 80 | parcel->writeInt32(1); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 81 |  | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 82 | // clang-format off | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 83 | status_t status = parcel->writeStrongBinder(token) ?: | 
|  | 84 | parcel->writeInt64(dispatchingTimeout.count()) ?: | 
|  | 85 | parcel->writeInt32(id) ?: | 
|  | 86 | parcel->writeUtf8AsUtf16(name) ?: | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 87 | parcel->writeInt32(flags.get()) ?: | 
|  | 88 | parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::Type>>(type)) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 89 | parcel->writeInt32(frameLeft) ?: | 
|  | 90 | parcel->writeInt32(frameTop) ?: | 
|  | 91 | parcel->writeInt32(frameRight) ?: | 
|  | 92 | parcel->writeInt32(frameBottom) ?: | 
|  | 93 | parcel->writeInt32(surfaceInset) ?: | 
|  | 94 | parcel->writeFloat(globalScaleFactor) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 95 | parcel->writeFloat(alpha) ?: | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 96 | 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 Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 102 | parcel->writeBool(visible) ?: | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 103 | parcel->writeBool(focusable) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 104 | parcel->writeBool(hasWallpaper) ?: | 
|  | 105 | parcel->writeBool(paused) ?: | 
|  | 106 | parcel->writeBool(trustedOverlay) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 107 | parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 108 | parcel->writeInt32(ownerPid) ?: | 
|  | 109 | parcel->writeInt32(ownerUid) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 110 | parcel->writeUtf8AsUtf16(packageName) ?: | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 111 | parcel->writeInt32(inputFeatures.get()) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 112 | 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 Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 118 | // clang-format on | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 119 | return status; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 122 | status_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 Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 129 | } | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 130 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 131 | token = parcel->readStrongBinder(); | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 132 | 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()); | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 140 | float dsdx, dtdx, tx, dtdy, dsdy, ty; | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 141 | int32_t touchOcclusionModeInt; | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 142 | // clang-format off | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 143 | status = parcel->readInt32(&frameLeft) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 144 | parcel->readInt32(&frameTop) ?: | 
|  | 145 | parcel->readInt32(&frameRight) ?: | 
|  | 146 | parcel->readInt32(&frameBottom) ?: | 
|  | 147 | parcel->readInt32(&surfaceInset) ?: | 
|  | 148 | parcel->readFloat(&globalScaleFactor) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 149 | parcel->readFloat(&alpha) ?: | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 150 | parcel->readFloat(&dsdx) ?: | 
|  | 151 | parcel->readFloat(&dtdx) ?: | 
|  | 152 | parcel->readFloat(&tx) ?: | 
|  | 153 | parcel->readFloat(&dtdy) ?: | 
|  | 154 | parcel->readFloat(&dsdy) ?: | 
|  | 155 | parcel->readFloat(&ty) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 156 | parcel->readBool(&visible) ?: | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 157 | parcel->readBool(&focusable) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 158 | parcel->readBool(&hasWallpaper) ?: | 
|  | 159 | parcel->readBool(&paused) ?: | 
|  | 160 | parcel->readBool(&trustedOverlay) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 161 | parcel->readInt32(&touchOcclusionModeInt) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 162 | parcel->readInt32(&ownerPid) ?: | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 163 | parcel->readInt32(&ownerUid) ?: | 
|  | 164 | parcel->readUtf8FromUtf16(&packageName); | 
| Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 165 | // clang-format on | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 166 |  | 
|  | 167 | if (status != OK) { | 
|  | 168 | return status; | 
|  | 169 | } | 
|  | 170 |  | 
| Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 171 | touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt); | 
|  | 172 |  | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 173 | inputFeatures = Flags<Feature>(parcel->readInt32()); | 
|  | 174 | status = parcel->readInt32(&displayId) ?: | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 175 | parcel->readInt32(&portalToDisplayId) ?: | 
|  | 176 | applicationInfo.readFromParcel(parcel) ?: | 
|  | 177 | parcel->read(touchableRegion) ?: | 
|  | 178 | parcel->readBool(&replaceTouchableRegionWithCrop); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 179 |  | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 180 | if (status != OK) { | 
|  | 181 | return status; | 
|  | 182 | } | 
|  | 183 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 184 | touchableRegionCropHandle = parcel->readStrongBinder(); | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 185 | transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 186 |  | 
| Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 187 | return OK; | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 190 | // --- InputWindowHandle --- | 
|  | 191 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 192 | InputWindowHandle::InputWindowHandle() {} | 
|  | 193 |  | 
|  | 194 | InputWindowHandle::~InputWindowHandle() {} | 
|  | 195 |  | 
|  | 196 | InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {} | 
|  | 197 |  | 
|  | 198 | InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {} | 
|  | 199 |  | 
|  | 200 | status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const { | 
|  | 201 | return mInfo.writeToParcel(parcel); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 202 | } | 
|  | 203 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 204 | status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) { | 
|  | 205 | return mInfo.readFromParcel(parcel); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 208 | void InputWindowHandle::releaseChannel() { | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 209 | mInfo.token.clear(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 210 | } | 
|  | 211 |  | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 212 | sp<IBinder> InputWindowHandle::getToken() const { | 
|  | 213 | return mInfo.token; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
| Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 216 | void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) { | 
|  | 217 | mInfo = handle->mInfo; | 
|  | 218 | } | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 219 | } // namespace android |