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 | |
| 17 | #define LOG_TAG "InputWindow" |
| 18 | #define LOG_NDEBUG 0 |
| 19 | |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 20 | #include <android-base/stringprintf.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 22 | #include <input/InputTransport.h> |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 23 | #include <input/InputWindow.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 24 | |
| 25 | #include <log/log.h> |
| 26 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | |
Siarhei Vishniakou | 67d4450 | 2020-04-09 11:09:29 -0700 | [diff] [blame] | 29 | const char* inputWindowFlagToString(uint32_t flag) { |
| 30 | switch (flag) { |
| 31 | case InputWindowInfo::FLAG_ALLOW_LOCK_WHILE_SCREEN_ON: { |
| 32 | return "ALLOW_LOCK_WHILE_SCREEN_ON"; |
| 33 | } |
| 34 | case InputWindowInfo::FLAG_DIM_BEHIND: { |
| 35 | return "DIM_BEHIND"; |
| 36 | } |
| 37 | case InputWindowInfo::FLAG_BLUR_BEHIND: { |
| 38 | return "BLUR_BEHIND"; |
| 39 | } |
| 40 | case InputWindowInfo::FLAG_NOT_FOCUSABLE: { |
| 41 | return "NOT_FOCUSABLE"; |
| 42 | } |
| 43 | case InputWindowInfo::FLAG_NOT_TOUCHABLE: { |
| 44 | return "NOT_TOUCHABLE"; |
| 45 | } |
| 46 | case InputWindowInfo::FLAG_NOT_TOUCH_MODAL: { |
| 47 | return "NOT_TOUCH_MODAL"; |
| 48 | } |
| 49 | case InputWindowInfo::FLAG_TOUCHABLE_WHEN_WAKING: { |
| 50 | return "TOUCHABLE_WHEN_WAKING"; |
| 51 | } |
| 52 | case InputWindowInfo::FLAG_KEEP_SCREEN_ON: { |
| 53 | return "KEEP_SCREEN_ON"; |
| 54 | } |
| 55 | case InputWindowInfo::FLAG_LAYOUT_IN_SCREEN: { |
| 56 | return "LAYOUT_IN_SCREEN"; |
| 57 | } |
| 58 | case InputWindowInfo::FLAG_LAYOUT_NO_LIMITS: { |
| 59 | return "LAYOUT_NO_LIMITS"; |
| 60 | } |
| 61 | case InputWindowInfo::FLAG_FULLSCREEN: { |
| 62 | return "FULLSCREEN"; |
| 63 | } |
| 64 | case InputWindowInfo::FLAG_FORCE_NOT_FULLSCREEN: { |
| 65 | return "FORCE_NOT_FULLSCREEN"; |
| 66 | } |
| 67 | case InputWindowInfo::FLAG_DITHER: { |
| 68 | return "DITHER"; |
| 69 | } |
| 70 | case InputWindowInfo::FLAG_SECURE: { |
| 71 | return "SECURE"; |
| 72 | } |
| 73 | case InputWindowInfo::FLAG_SCALED: { |
| 74 | return "SCALED"; |
| 75 | } |
| 76 | case InputWindowInfo::FLAG_IGNORE_CHEEK_PRESSES: { |
| 77 | return "IGNORE_CHEEK_PRESSES"; |
| 78 | } |
| 79 | case InputWindowInfo::FLAG_LAYOUT_INSET_DECOR: { |
| 80 | return "LAYOUT_INSET_DECOR"; |
| 81 | } |
| 82 | case InputWindowInfo::FLAG_ALT_FOCUSABLE_IM: { |
| 83 | return "ALT_FOCUSABLE_IM"; |
| 84 | } |
| 85 | case InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH: { |
| 86 | return "WATCH_OUTSIDE_TOUCH"; |
| 87 | } |
| 88 | case InputWindowInfo::FLAG_SHOW_WHEN_LOCKED: { |
| 89 | return "SHOW_WHEN_LOCKED"; |
| 90 | } |
| 91 | case InputWindowInfo::FLAG_SHOW_WALLPAPER: { |
| 92 | return "SHOW_WALLPAPER"; |
| 93 | } |
| 94 | case InputWindowInfo::FLAG_TURN_SCREEN_ON: { |
| 95 | return "TURN_SCREEN_ON"; |
| 96 | } |
| 97 | case InputWindowInfo::FLAG_DISMISS_KEYGUARD: { |
| 98 | return "DISMISS_KEYGUARD"; |
| 99 | } |
| 100 | case InputWindowInfo::FLAG_SPLIT_TOUCH: { |
| 101 | return "SPLIT_TOUCH"; |
| 102 | } |
| 103 | case InputWindowInfo::FLAG_HARDWARE_ACCELERATED: { |
| 104 | return "HARDWARE_ACCELERATED"; |
| 105 | } |
| 106 | case InputWindowInfo::FLAG_LAYOUT_IN_OVERSCAN: { |
| 107 | return "LAYOUT_IN_OVERSCAN"; |
| 108 | } |
| 109 | case InputWindowInfo::FLAG_TRANSLUCENT_STATUS: { |
| 110 | return "TRANSLUCENT_STATUS"; |
| 111 | } |
| 112 | case InputWindowInfo::FLAG_TRANSLUCENT_NAVIGATION: { |
| 113 | return "TRANSLUCENT_NAVIGATION"; |
| 114 | } |
| 115 | case InputWindowInfo::FLAG_LOCAL_FOCUS_MODE: { |
| 116 | return "LOCAL_FOCUS_MODE"; |
| 117 | } |
| 118 | case InputWindowInfo::FLAG_SLIPPERY: { |
| 119 | return "SLIPPERY"; |
| 120 | } |
| 121 | case InputWindowInfo::FLAG_LAYOUT_ATTACHED_IN_DECOR: { |
| 122 | return "LAYOUT_ATTACHED_IN_DECOR"; |
| 123 | } |
| 124 | case InputWindowInfo::FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS: { |
| 125 | return "DRAWS_SYSTEM_BAR_BACKGROUNDS"; |
| 126 | } |
| 127 | } |
| 128 | return "UNKNOWN"; |
| 129 | } |
| 130 | |
| 131 | std::string inputWindowFlagsToString(uint32_t flags) { |
| 132 | std::string result; |
| 133 | for (BitSet32 bits(flags); !bits.isEmpty();) { |
| 134 | uint32_t bit = bits.clearLastMarkedBit(); // counts from left |
| 135 | const uint32_t flag = 1 << (32 - bit - 1); |
| 136 | result += android::base::StringPrintf("%s | ", inputWindowFlagToString(flag)); |
| 137 | } |
| 138 | return result; |
| 139 | } |
| 140 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 141 | // --- InputWindowInfo --- |
| 142 | void InputWindowInfo::addTouchableRegion(const Rect& region) { |
| 143 | touchableRegion.orSelf(region); |
| 144 | } |
| 145 | |
| 146 | bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const { |
| 147 | return touchableRegion.contains(x,y); |
| 148 | } |
| 149 | |
| 150 | bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const { |
| 151 | return x >= frameLeft && x < frameRight |
| 152 | && y >= frameTop && y < frameBottom; |
| 153 | } |
| 154 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 155 | bool InputWindowInfo::supportsSplitTouch() const { |
| 156 | return layoutParamsFlags & FLAG_SPLIT_TOUCH; |
| 157 | } |
| 158 | |
| 159 | bool InputWindowInfo::overlaps(const InputWindowInfo* other) const { |
| 160 | return frameLeft < other->frameRight && frameRight > other->frameLeft |
| 161 | && frameTop < other->frameBottom && frameBottom > other->frameTop; |
| 162 | } |
| 163 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 164 | bool InputWindowInfo::operator==(const InputWindowInfo& info) const { |
| 165 | return info.token == token && info.id == id && info.name == name && |
| 166 | info.layoutParamsFlags == layoutParamsFlags && |
| 167 | info.layoutParamsType == layoutParamsType && |
| 168 | info.dispatchingTimeout == dispatchingTimeout && info.frameLeft == frameLeft && |
| 169 | info.frameTop == frameTop && info.frameRight == frameRight && |
| 170 | info.frameBottom == frameBottom && info.surfaceInset == surfaceInset && |
| 171 | info.globalScaleFactor == globalScaleFactor && info.windowXScale == windowXScale && |
| 172 | info.windowYScale == windowYScale && |
| 173 | info.touchableRegion.hasSameRects(touchableRegion) && info.visible == visible && |
| 174 | info.canReceiveKeys == canReceiveKeys && info.trustedOverlay == trustedOverlay && |
| 175 | info.hasFocus == hasFocus && info.hasWallpaper == hasWallpaper && |
| 176 | info.paused == paused && info.ownerPid == ownerPid && info.ownerUid == ownerUid && |
| 177 | info.inputFeatures == inputFeatures && info.displayId == displayId && |
| 178 | info.portalToDisplayId == portalToDisplayId && |
| 179 | info.replaceTouchableRegionWithCrop == replaceTouchableRegionWithCrop && |
| 180 | info.applicationInfo.name == applicationInfo.name && |
| 181 | info.applicationInfo.token == applicationInfo.token && |
| 182 | info.applicationInfo.dispatchingTimeout == applicationInfo.dispatchingTimeout; |
| 183 | } |
| 184 | |
| 185 | status_t InputWindowInfo::writeToParcel(android::Parcel* parcel) const { |
| 186 | if (parcel == nullptr) { |
| 187 | ALOGE("%s: Null parcel", __func__); |
| 188 | return BAD_VALUE; |
| 189 | } |
Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 190 | if (name.empty()) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 191 | parcel->writeInt32(0); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 192 | return OK; |
| 193 | } |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 194 | parcel->writeInt32(1); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 195 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 196 | status_t status = parcel->writeStrongBinder(token) ?: |
| 197 | parcel->writeInt64(dispatchingTimeout.count()) ?: |
| 198 | parcel->writeInt32(id) ?: |
| 199 | parcel->writeUtf8AsUtf16(name) ?: |
| 200 | parcel->writeInt32(layoutParamsFlags) ?: |
| 201 | parcel->writeInt32(layoutParamsType) ?: |
| 202 | parcel->writeInt32(frameLeft) ?: |
| 203 | parcel->writeInt32(frameTop) ?: |
| 204 | parcel->writeInt32(frameRight) ?: |
| 205 | parcel->writeInt32(frameBottom) ?: |
| 206 | parcel->writeInt32(surfaceInset) ?: |
| 207 | parcel->writeFloat(globalScaleFactor) ?: |
| 208 | parcel->writeFloat(windowXScale) ?: |
| 209 | parcel->writeFloat(windowYScale) ?: |
| 210 | parcel->writeBool(visible) ?: |
| 211 | parcel->writeBool(canReceiveKeys) ?: |
| 212 | parcel->writeBool(hasFocus) ?: |
| 213 | parcel->writeBool(hasWallpaper) ?: |
| 214 | parcel->writeBool(paused) ?: |
| 215 | parcel->writeBool(trustedOverlay) ?: |
| 216 | parcel->writeInt32(ownerPid) ?: |
| 217 | parcel->writeInt32(ownerUid) ?: |
| 218 | parcel->writeInt32(inputFeatures) ?: |
| 219 | parcel->writeInt32(displayId) ?: |
| 220 | parcel->writeInt32(portalToDisplayId) ?: |
| 221 | applicationInfo.writeToParcel(parcel) ?: |
| 222 | parcel->write(touchableRegion) ?: |
| 223 | parcel->writeBool(replaceTouchableRegionWithCrop) ?: |
| 224 | parcel->writeStrongBinder(touchableRegionCropHandle.promote()); |
| 225 | |
| 226 | return status; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 229 | status_t InputWindowInfo::readFromParcel(const android::Parcel* parcel) { |
| 230 | if (parcel == nullptr) { |
| 231 | ALOGE("%s: Null parcel", __func__); |
| 232 | return BAD_VALUE; |
| 233 | } |
| 234 | if (parcel->readInt32() == 0) { |
| 235 | return OK; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 236 | } |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 237 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 238 | token = parcel->readStrongBinder(); |
| 239 | dispatchingTimeout = decltype(dispatchingTimeout)(parcel->readInt64()); |
| 240 | status_t status = parcel->readInt32(&id) ?: |
| 241 | parcel->readUtf8FromUtf16(&name) ?: |
| 242 | parcel->readInt32(&layoutParamsFlags) ?: |
| 243 | parcel->readInt32(&layoutParamsType) ?: |
| 244 | parcel->readInt32(&frameLeft) ?: |
| 245 | parcel->readInt32(&frameTop) ?: |
| 246 | parcel->readInt32(&frameRight) ?: |
| 247 | parcel->readInt32(&frameBottom) ?: |
| 248 | parcel->readInt32(&surfaceInset) ?: |
| 249 | parcel->readFloat(&globalScaleFactor) ?: |
| 250 | parcel->readFloat(&windowXScale) ?: |
| 251 | parcel->readFloat(&windowYScale) ?: |
| 252 | parcel->readBool(&visible) ?: |
| 253 | parcel->readBool(&canReceiveKeys) ?: |
| 254 | parcel->readBool(&hasFocus) ?: |
| 255 | parcel->readBool(&hasWallpaper) ?: |
| 256 | parcel->readBool(&paused) ?: |
| 257 | parcel->readBool(&trustedOverlay) ?: |
| 258 | parcel->readInt32(&ownerPid) ?: |
| 259 | parcel->readInt32(&ownerUid) ?: |
| 260 | parcel->readInt32(&inputFeatures) ?: |
| 261 | parcel->readInt32(&displayId) ?: |
| 262 | parcel->readInt32(&portalToDisplayId) ?: |
| 263 | applicationInfo.readFromParcel(parcel) ?: |
| 264 | parcel->read(touchableRegion) ?: |
| 265 | parcel->readBool(&replaceTouchableRegionWithCrop); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 266 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 267 | touchableRegionCropHandle = parcel->readStrongBinder(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 268 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 269 | return status; |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 272 | // --- InputWindowHandle --- |
| 273 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 274 | InputWindowHandle::InputWindowHandle() {} |
| 275 | |
| 276 | InputWindowHandle::~InputWindowHandle() {} |
| 277 | |
| 278 | InputWindowHandle::InputWindowHandle(const InputWindowHandle& other) : mInfo(other.mInfo) {} |
| 279 | |
| 280 | InputWindowHandle::InputWindowHandle(const InputWindowInfo& other) : mInfo(other) {} |
| 281 | |
| 282 | status_t InputWindowHandle::writeToParcel(android::Parcel* parcel) const { |
| 283 | return mInfo.writeToParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame^] | 286 | status_t InputWindowHandle::readFromParcel(const android::Parcel* parcel) { |
| 287 | return mInfo.readFromParcel(parcel); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 290 | void InputWindowHandle::releaseChannel() { |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 291 | mInfo.token.clear(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 294 | sp<IBinder> InputWindowHandle::getToken() const { |
| 295 | return mInfo.token; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 298 | void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) { |
| 299 | mInfo = handle->mInfo; |
| 300 | } |
| 301 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 302 | } // namespace android |