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> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 18 | #define LOG_TAG "WindowInfo" |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 19 | #define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include <binder/Parcel.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 22 | #include <gui/WindowInfo.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 23 | |
| 24 | #include <log/log.h> |
| 25 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 26 | namespace android::gui { |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 27 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 28 | // --- WindowInfo --- |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 29 | void WindowInfo::setInputConfig(Flags<InputConfig> config, bool value) { |
| 30 | if (value) { |
| 31 | inputConfig |= config; |
| 32 | return; |
| 33 | } |
| 34 | inputConfig &= ~config; |
| 35 | } |
| 36 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 37 | void WindowInfo::addTouchableRegion(const Rect& region) { |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 38 | touchableRegion.orSelf(region); |
| 39 | } |
| 40 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 41 | bool WindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const { |
| 42 | return touchableRegion.contains(x, y); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 43 | } |
| 44 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 45 | bool WindowInfo::frameContainsPoint(int32_t x, int32_t y) const { |
| 46 | return x >= frameLeft && x < frameRight && y >= frameTop && y < frameBottom; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 47 | } |
| 48 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 49 | bool WindowInfo::supportsSplitTouch() const { |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame^] | 50 | return !inputConfig.test(InputConfig::PREVENT_SPLITTING); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 53 | bool WindowInfo::isSpy() const { |
| 54 | return inputFeatures.test(Feature::SPY); |
| 55 | } |
| 56 | |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 57 | bool WindowInfo::interceptsStylus() const { |
| 58 | return inputFeatures.test(Feature::INTERCEPTS_STYLUS); |
| 59 | } |
| 60 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 61 | bool WindowInfo::overlaps(const WindowInfo* other) const { |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 62 | const bool nonEmpty = (frameRight - frameLeft > 0) || (frameBottom - frameTop > 0); |
| 63 | return nonEmpty && frameLeft < other->frameRight && frameRight > other->frameLeft && |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 64 | frameTop < other->frameBottom && frameBottom > other->frameTop; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 65 | } |
| 66 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 67 | bool WindowInfo::operator==(const WindowInfo& info) const { |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 68 | return info.token == token && info.id == id && info.name == name && |
| 69 | info.dispatchingTimeout == dispatchingTimeout && info.frameLeft == frameLeft && |
| 70 | info.frameTop == frameTop && info.frameRight == frameRight && |
| 71 | info.frameBottom == frameBottom && info.surfaceInset == surfaceInset && |
| 72 | info.globalScaleFactor == globalScaleFactor && info.transform == transform && |
| 73 | info.touchableRegion.hasSameRects(touchableRegion) && |
| 74 | info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid && |
| 75 | info.ownerUid == ownerUid && info.packageName == packageName && |
| 76 | info.inputFeatures == inputFeatures && info.inputConfig == inputConfig && |
Prabir Pradhan | 1c58c0d | 2021-12-29 02:10:29 -0800 | [diff] [blame] | 77 | info.displayId == displayId && |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 78 | info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop && |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 79 | info.applicationInfo == applicationInfo && info.layoutParamsType == layoutParamsType && |
| 80 | info.layoutParamsFlags == layoutParamsFlags; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 81 | } |
| 82 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 83 | status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 84 | if (parcel == nullptr) { |
| 85 | ALOGE("%s: Null parcel", __func__); |
| 86 | return BAD_VALUE; |
| 87 | } |
Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 88 | if (name.empty()) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 89 | parcel->writeInt32(0); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 90 | return OK; |
| 91 | } |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 92 | parcel->writeInt32(1); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 93 | |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 94 | // Ensure that the size of the flags that we use is 32 bits for writing into the parcel. |
| 95 | static_assert(sizeof(inputFeatures) == 4u); |
| 96 | static_assert(sizeof(inputConfig) == 4u); |
| 97 | |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 98 | // clang-format off |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 99 | status_t status = parcel->writeStrongBinder(token) ?: |
| 100 | parcel->writeInt64(dispatchingTimeout.count()) ?: |
| 101 | parcel->writeInt32(id) ?: |
| 102 | parcel->writeUtf8AsUtf16(name) ?: |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 103 | parcel->writeInt32(layoutParamsFlags.get()) ?: |
| 104 | parcel->writeInt32( |
| 105 | static_cast<std::underlying_type_t<WindowInfo::Type>>(layoutParamsType)) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 106 | parcel->writeInt32(frameLeft) ?: |
| 107 | parcel->writeInt32(frameTop) ?: |
| 108 | parcel->writeInt32(frameRight) ?: |
| 109 | parcel->writeInt32(frameBottom) ?: |
| 110 | parcel->writeInt32(surfaceInset) ?: |
| 111 | parcel->writeFloat(globalScaleFactor) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 112 | parcel->writeFloat(alpha) ?: |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 113 | parcel->writeFloat(transform.dsdx()) ?: |
| 114 | parcel->writeFloat(transform.dtdx()) ?: |
| 115 | parcel->writeFloat(transform.tx()) ?: |
| 116 | parcel->writeFloat(transform.dtdy()) ?: |
| 117 | parcel->writeFloat(transform.dsdy()) ?: |
| 118 | parcel->writeFloat(transform.ty()) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 119 | parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 120 | parcel->writeInt32(ownerPid) ?: |
| 121 | parcel->writeInt32(ownerUid) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 122 | parcel->writeUtf8AsUtf16(packageName) ?: |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 123 | parcel->writeInt32(inputFeatures.get()) ?: |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 124 | parcel->writeInt32(inputConfig.get()) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 125 | parcel->writeInt32(displayId) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 126 | applicationInfo.writeToParcel(parcel) ?: |
| 127 | parcel->write(touchableRegion) ?: |
| 128 | parcel->writeBool(replaceTouchableRegionWithCrop) ?: |
chaviw | e0ba4e9 | 2021-08-11 11:38:41 -0500 | [diff] [blame] | 129 | parcel->writeStrongBinder(touchableRegionCropHandle.promote()) ?: |
| 130 | parcel->writeStrongBinder(windowToken); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 131 | // clang-format on |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 132 | return status; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 133 | } |
| 134 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 135 | status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 136 | if (parcel == nullptr) { |
| 137 | ALOGE("%s: Null parcel", __func__); |
| 138 | return BAD_VALUE; |
| 139 | } |
| 140 | if (parcel->readInt32() == 0) { |
| 141 | return OK; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 142 | } |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 143 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 144 | token = parcel->readStrongBinder(); |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 145 | dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64()); |
| 146 | status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name); |
| 147 | if (status != OK) { |
| 148 | return status; |
| 149 | } |
| 150 | |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 151 | layoutParamsFlags = Flags<Flag>(parcel->readInt32()); |
| 152 | layoutParamsType = static_cast<Type>(parcel->readInt32()); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 153 | float dsdx, dtdx, tx, dtdy, dsdy, ty; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 154 | int32_t touchOcclusionModeInt; |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 155 | // clang-format off |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 156 | status = parcel->readInt32(&frameLeft) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 157 | parcel->readInt32(&frameTop) ?: |
| 158 | parcel->readInt32(&frameRight) ?: |
| 159 | parcel->readInt32(&frameBottom) ?: |
| 160 | parcel->readInt32(&surfaceInset) ?: |
| 161 | parcel->readFloat(&globalScaleFactor) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 162 | parcel->readFloat(&alpha) ?: |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 163 | parcel->readFloat(&dsdx) ?: |
| 164 | parcel->readFloat(&dtdx) ?: |
| 165 | parcel->readFloat(&tx) ?: |
| 166 | parcel->readFloat(&dtdy) ?: |
| 167 | parcel->readFloat(&dsdy) ?: |
| 168 | parcel->readFloat(&ty) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 169 | parcel->readInt32(&touchOcclusionModeInt) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 170 | parcel->readInt32(&ownerPid) ?: |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 171 | parcel->readInt32(&ownerUid) ?: |
| 172 | parcel->readUtf8FromUtf16(&packageName); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 173 | // clang-format on |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 174 | |
| 175 | if (status != OK) { |
| 176 | return status; |
| 177 | } |
| 178 | |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 179 | touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt); |
| 180 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 181 | inputFeatures = Flags<Feature>(parcel->readInt32()); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 182 | inputConfig = Flags<InputConfig>(parcel->readInt32()); |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 183 | // clang-format off |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 184 | status = parcel->readInt32(&displayId) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 185 | applicationInfo.readFromParcel(parcel) ?: |
| 186 | parcel->read(touchableRegion) ?: |
| 187 | parcel->readBool(&replaceTouchableRegionWithCrop); |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 188 | // clang-format on |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 189 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 190 | if (status != OK) { |
| 191 | return status; |
| 192 | } |
| 193 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 194 | touchableRegionCropHandle = parcel->readStrongBinder(); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 195 | transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 196 | |
chaviw | e0ba4e9 | 2021-08-11 11:38:41 -0500 | [diff] [blame] | 197 | status = parcel->readNullableStrongBinder(&windowToken); |
| 198 | return status; |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 199 | } |
| 200 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 201 | // --- WindowInfoHandle --- |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 202 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 203 | WindowInfoHandle::WindowInfoHandle() {} |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 204 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 205 | WindowInfoHandle::~WindowInfoHandle() {} |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 206 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 207 | WindowInfoHandle::WindowInfoHandle(const WindowInfoHandle& other) : mInfo(other.mInfo) {} |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 208 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 209 | WindowInfoHandle::WindowInfoHandle(const WindowInfo& other) : mInfo(other) {} |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 210 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 211 | status_t WindowInfoHandle::writeToParcel(android::Parcel* parcel) const { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 212 | return mInfo.writeToParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 213 | } |
| 214 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 215 | status_t WindowInfoHandle::readFromParcel(const android::Parcel* parcel) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 216 | return mInfo.readFromParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 217 | } |
| 218 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 219 | void WindowInfoHandle::releaseChannel() { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 220 | mInfo.token.clear(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 221 | } |
| 222 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 223 | sp<IBinder> WindowInfoHandle::getToken() const { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 224 | return mInfo.token; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 225 | } |
| 226 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 227 | void WindowInfoHandle::updateFrom(sp<WindowInfoHandle> handle) { |
Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 228 | mInfo = handle->mInfo; |
| 229 | } |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 230 | } // namespace android::gui |