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 && |
| 60 | info.windowXScale == windowXScale && info.windowYScale == windowYScale && |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 61 | info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible && |
| 62 | info.canReceiveKeys == canReceiveKeys && info.trustedOverlay == trustedOverlay && |
| 63 | info.hasFocus == hasFocus && info.hasWallpaper == hasWallpaper && |
| 64 | info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid && |
| 65 | info.inputFeatures == inputFeatures && info.displayId == displayId && |
| 66 | info.portalToDisplayId == portalToDisplayId && |
| 67 | info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop && |
| 68 | info.applicationInfo.name == applicationInfo.name && |
| 69 | info.applicationInfo.token == applicationInfo.token && |
| 70 | info.applicationInfo.dispatchingTimeout == applicationInfo.dispatchingTimeout; |
| 71 | } |
| 72 | |
| 73 | status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const { |
| 74 | if (parcel == nullptr) { |
| 75 | ALOGE("%s: Null parcel", __func__); |
| 76 | return BAD_VALUE; |
| 77 | } |
Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 78 | if (name.empty()) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 79 | parcel->writeInt32(0); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 80 | return OK; |
| 81 | } |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 82 | parcel->writeInt32(1); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 83 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 84 | status_t status = parcel->writeStrongBinder(token) ?: |
| 85 | parcel->writeInt64(dispatchingTimeout.count()) ?: |
| 86 | parcel->writeInt32(id) ?: |
| 87 | parcel->writeUtf8AsUtf16(name) ?: |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 88 | parcel->writeInt32(flags.get()) ?: |
| 89 | parcel->writeInt32(static_cast<std::underlying_type_t<InputWindowInfo::Type>>(type)) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 90 | parcel->writeInt32(frameLeft) ?: |
| 91 | parcel->writeInt32(frameTop) ?: |
| 92 | parcel->writeInt32(frameRight) ?: |
| 93 | parcel->writeInt32(frameBottom) ?: |
| 94 | parcel->writeInt32(surfaceInset) ?: |
| 95 | parcel->writeFloat(globalScaleFactor) ?: |
| 96 | parcel->writeFloat(windowXScale) ?: |
| 97 | parcel->writeFloat(windowYScale) ?: |
| 98 | parcel->writeBool(visible) ?: |
| 99 | parcel->writeBool(canReceiveKeys) ?: |
| 100 | parcel->writeBool(hasFocus) ?: |
| 101 | parcel->writeBool(hasWallpaper) ?: |
| 102 | parcel->writeBool(paused) ?: |
| 103 | parcel->writeBool(trustedOverlay) ?: |
| 104 | parcel->writeInt32(ownerPid) ?: |
| 105 | parcel->writeInt32(ownerUid) ?: |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 106 | parcel->writeInt32(inputFeatures.get()) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 107 | parcel->writeInt32(displayId) ?: |
| 108 | parcel->writeInt32(portalToDisplayId) ?: |
| 109 | applicationInfo.writeToParcel(parcel) ?: |
| 110 | parcel->write(touchableRegion) ?: |
| 111 | parcel->writeBool(replaceTouchableRegionWithCrop) ?: |
| 112 | parcel->writeStrongBinder(touchableRegionCropHandle.promote()); |
| 113 | |
| 114 | return status; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 117 | status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) { |
| 118 | if (parcel == nullptr) { |
| 119 | ALOGE("%s: Null parcel", __func__); |
| 120 | return BAD_VALUE; |
| 121 | } |
| 122 | if (parcel->readInt32() == 0) { |
| 123 | return OK; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 124 | } |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 125 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 126 | token = parcel->readStrongBinder(); |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 127 | dispatchingTimeout = static_cast<decltype(dispatchingTimeout)>(parcel->readInt64()); |
| 128 | status_t status = parcel->readInt32(&id) ?: parcel->readUtf8FromUtf16(&name); |
| 129 | if (status != OK) { |
| 130 | return status; |
| 131 | } |
| 132 | |
| 133 | flags = Flags<Flag>(parcel->readInt32()); |
| 134 | type = static_cast<Type>(parcel->readInt32()); |
| 135 | status = parcel->readInt32(&frameLeft) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 136 | parcel->readInt32(&frameTop) ?: |
| 137 | parcel->readInt32(&frameRight) ?: |
| 138 | parcel->readInt32(&frameBottom) ?: |
| 139 | parcel->readInt32(&surfaceInset) ?: |
| 140 | parcel->readFloat(&globalScaleFactor) ?: |
| 141 | parcel->readFloat(&windowXScale) ?: |
| 142 | parcel->readFloat(&windowYScale) ?: |
| 143 | parcel->readBool(&visible) ?: |
| 144 | parcel->readBool(&canReceiveKeys) ?: |
| 145 | parcel->readBool(&hasFocus) ?: |
| 146 | parcel->readBool(&hasWallpaper) ?: |
| 147 | parcel->readBool(&paused) ?: |
| 148 | parcel->readBool(&trustedOverlay) ?: |
| 149 | parcel->readInt32(&ownerPid) ?: |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 150 | parcel->readInt32(&ownerUid); |
| 151 | |
| 152 | if (status != OK) { |
| 153 | return status; |
| 154 | } |
| 155 | |
| 156 | inputFeatures = Flags<Feature>(parcel->readInt32()); |
| 157 | status = parcel->readInt32(&displayId) ?: |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 158 | parcel->readInt32(&portalToDisplayId) ?: |
| 159 | applicationInfo.readFromParcel(parcel) ?: |
| 160 | parcel->read(touchableRegion) ?: |
| 161 | parcel->readBool(&replaceTouchableRegionWithCrop); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 162 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 163 | if (status != OK) { |
| 164 | return status; |
| 165 | } |
| 166 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 167 | touchableRegionCropHandle = parcel->readStrongBinder(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 168 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 169 | return OK; |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 172 | // --- InputWindowHandle --- |
| 173 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 174 | InputWindowHandle::InputWindowHandle() {} |
| 175 | |
| 176 | InputWindowHandle::~InputWindowHandle() {} |
| 177 | |
| 178 | InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {} |
| 179 | |
| 180 | InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {} |
| 181 | |
| 182 | status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const { |
| 183 | return mInfo.writeToParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 186 | status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) { |
| 187 | return mInfo.readFromParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 190 | void InputWindowHandle::releaseChannel() { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 191 | mInfo.token.clear(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 194 | sp<IBinder> InputWindowHandle::getToken() const { |
| 195 | return mInfo.token; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 198 | void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) { |
| 199 | mInfo = handle->mInfo; |
| 200 | } |
| 201 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame^] | 202 | std::optional<std::string> InputWindowInfo::flagToString(Flag flag) { |
| 203 | switch (flag) { |
| 204 | case InputWindowInfo::Flag::ALLOW_LOCK_WHILE_SCREEN_ON: { |
| 205 | return "ALLOW_LOCK_WHILE_SCREEN_ON"; |
| 206 | } |
| 207 | case InputWindowInfo::Flag::DIM_BEHIND: { |
| 208 | return "DIM_BEHIND"; |
| 209 | } |
| 210 | case InputWindowInfo::Flag::BLUR_BEHIND: { |
| 211 | return "BLUR_BEHIND"; |
| 212 | } |
| 213 | case InputWindowInfo::Flag::NOT_FOCUSABLE: { |
| 214 | return "NOT_FOCUSABLE"; |
| 215 | } |
| 216 | case InputWindowInfo::Flag::NOT_TOUCHABLE: { |
| 217 | return "NOT_TOUCHABLE"; |
| 218 | } |
| 219 | case InputWindowInfo::Flag::NOT_TOUCH_MODAL: { |
| 220 | return "NOT_TOUCH_MODAL"; |
| 221 | } |
| 222 | case InputWindowInfo::Flag::TOUCHABLE_WHEN_WAKING: { |
| 223 | return "TOUCHABLE_WHEN_WAKING"; |
| 224 | } |
| 225 | case InputWindowInfo::Flag::KEEP_SCREEN_ON: { |
| 226 | return "KEEP_SCREEN_ON"; |
| 227 | } |
| 228 | case InputWindowInfo::Flag::LAYOUT_IN_SCREEN: { |
| 229 | return "LAYOUT_IN_SCREEN"; |
| 230 | } |
| 231 | case InputWindowInfo::Flag::LAYOUT_NO_LIMITS: { |
| 232 | return "LAYOUT_NO_LIMITS"; |
| 233 | } |
| 234 | case InputWindowInfo::Flag::FULLSCREEN: { |
| 235 | return "FULLSCREEN"; |
| 236 | } |
| 237 | case InputWindowInfo::Flag::FORCE_NOT_FULLSCREEN: { |
| 238 | return "FORCE_NOT_FULLSCREEN"; |
| 239 | } |
| 240 | case InputWindowInfo::Flag::DITHER: { |
| 241 | return "DITHER"; |
| 242 | } |
| 243 | case InputWindowInfo::Flag::SECURE: { |
| 244 | return "SECURE"; |
| 245 | } |
| 246 | case InputWindowInfo::Flag::SCALED: { |
| 247 | return "SCALED"; |
| 248 | } |
| 249 | case InputWindowInfo::Flag::IGNORE_CHEEK_PRESSES: { |
| 250 | return "IGNORE_CHEEK_PRESSES"; |
| 251 | } |
| 252 | case InputWindowInfo::Flag::LAYOUT_INSET_DECOR: { |
| 253 | return "LAYOUT_INSET_DECOR"; |
| 254 | } |
| 255 | case InputWindowInfo::Flag::ALT_FOCUSABLE_IM: { |
| 256 | return "ALT_FOCUSABLE_IM"; |
| 257 | } |
| 258 | case InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH: { |
| 259 | return "WATCH_OUTSIDE_TOUCH"; |
| 260 | } |
| 261 | case InputWindowInfo::Flag::SHOW_WHEN_LOCKED: { |
| 262 | return "SHOW_WHEN_LOCKED"; |
| 263 | } |
| 264 | case InputWindowInfo::Flag::SHOW_WALLPAPER: { |
| 265 | return "SHOW_WALLPAPER"; |
| 266 | } |
| 267 | case InputWindowInfo::Flag::TURN_SCREEN_ON: { |
| 268 | return "TURN_SCREEN_ON"; |
| 269 | } |
| 270 | case InputWindowInfo::Flag::DISMISS_KEYGUARD: { |
| 271 | return "DISMISS_KEYGUARD"; |
| 272 | } |
| 273 | case InputWindowInfo::Flag::SPLIT_TOUCH: { |
| 274 | return "SPLIT_TOUCH"; |
| 275 | } |
| 276 | case InputWindowInfo::Flag::HARDWARE_ACCELERATED: { |
| 277 | return "HARDWARE_ACCELERATED"; |
| 278 | } |
| 279 | case InputWindowInfo::Flag::LAYOUT_IN_OVERSCAN: { |
| 280 | return "LAYOUT_IN_OVERSCAN"; |
| 281 | } |
| 282 | case InputWindowInfo::Flag::TRANSLUCENT_STATUS: { |
| 283 | return "TRANSLUCENT_STATUS"; |
| 284 | } |
| 285 | case InputWindowInfo::Flag::TRANSLUCENT_NAVIGATION: { |
| 286 | return "TRANSLUCENT_NAVIGATION"; |
| 287 | } |
| 288 | case InputWindowInfo::Flag::LOCAL_FOCUS_MODE: { |
| 289 | return "LOCAL_FOCUS_MODE"; |
| 290 | } |
| 291 | case InputWindowInfo::Flag::SLIPPERY: { |
| 292 | return "SLIPPERY"; |
| 293 | } |
| 294 | case InputWindowInfo::Flag::LAYOUT_ATTACHED_IN_DECOR: { |
| 295 | return "LAYOUT_ATTACHED_IN_DECOR"; |
| 296 | } |
| 297 | case InputWindowInfo::Flag::DRAWS_SYSTEM_BAR_BACKGROUNDS: { |
| 298 | return "DRAWS_SYSTEM_BAR_BACKGROUNDS"; |
| 299 | } |
| 300 | } |
| 301 | return std::nullopt; |
| 302 | } |
| 303 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 304 | } // namespace android |