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