| 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 |  | 
|  | 20 | #include <binder/Parcel.h> | 
|  | 21 | #include <input/InputWindow.h> | 
|  | 22 | #include <input/InputTransport.h> | 
|  | 23 |  | 
|  | 24 | #include <log/log.h> | 
|  | 25 |  | 
|  | 26 | #include <ui/Rect.h> | 
|  | 27 | #include <ui/Region.h> | 
|  | 28 |  | 
|  | 29 | namespace android { | 
|  | 30 |  | 
|  | 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 |  | 
| Joshua Tsuji | 466cdea | 2020-05-04 13:53:00 -0400 | [diff] [blame] | 45 | // TODO(b/155781676): Remove and replace call points with trustedOverlay when that is ready. | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 46 | bool InputWindowInfo::isTrustedOverlay() const { | 
| wilsonshih | 9499a11 | 2020-05-04 12:01:17 +0800 | [diff] [blame] | 47 | return layoutParamsType == TYPE_INPUT_METHOD || layoutParamsType == TYPE_INPUT_METHOD_DIALOG || | 
|  | 48 | layoutParamsType == TYPE_MAGNIFICATION_OVERLAY || layoutParamsType == TYPE_STATUS_BAR || | 
|  | 49 | layoutParamsType == TYPE_NOTIFICATION_SHADE || | 
|  | 50 | layoutParamsType == TYPE_NAVIGATION_BAR || | 
|  | 51 | layoutParamsType == TYPE_NAVIGATION_BAR_PANEL || | 
|  | 52 | layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY || | 
|  | 53 | layoutParamsType == TYPE_DOCK_DIVIDER || | 
|  | 54 | layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY || | 
| Joshua Tsuji | 466cdea | 2020-05-04 13:53:00 -0400 | [diff] [blame] | 55 | layoutParamsType == TYPE_INPUT_CONSUMER || | 
|  | 56 | layoutParamsType == TYPE_TRUSTED_APPLICATION_OVERLAY; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | bool InputWindowInfo::supportsSplitTouch() const { | 
|  | 60 | return layoutParamsFlags & FLAG_SPLIT_TOUCH; | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | bool InputWindowInfo::overlaps(const InputWindowInfo* other) const { | 
|  | 64 | return frameLeft < other->frameRight && frameRight > other->frameLeft | 
|  | 65 | && frameTop < other->frameBottom && frameBottom > other->frameTop; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | status_t InputWindowInfo::write(Parcel& output) const { | 
| Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 69 | if (name.empty()) { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 70 | output.writeInt32(0); | 
|  | 71 | return OK; | 
|  | 72 | } | 
|  | 73 | output.writeInt32(1); | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 74 | status_t s = output.writeStrongBinder(token); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 75 | if (s != OK) return s; | 
|  | 76 |  | 
| chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 77 | output.writeInt32(id); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 78 | output.writeString8(String8(name.c_str())); | 
|  | 79 | output.writeInt32(layoutParamsFlags); | 
|  | 80 | output.writeInt32(layoutParamsType); | 
|  | 81 | output.writeInt64(dispatchingTimeout); | 
|  | 82 | output.writeInt32(frameLeft); | 
|  | 83 | output.writeInt32(frameTop); | 
|  | 84 | output.writeInt32(frameRight); | 
|  | 85 | output.writeInt32(frameBottom); | 
| Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 86 | output.writeInt32(surfaceInset); | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 87 | output.writeFloat(globalScaleFactor); | 
|  | 88 | output.writeFloat(windowXScale); | 
|  | 89 | output.writeFloat(windowYScale); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 90 | output.writeBool(visible); | 
|  | 91 | output.writeBool(canReceiveKeys); | 
|  | 92 | output.writeBool(hasFocus); | 
|  | 93 | output.writeBool(hasWallpaper); | 
|  | 94 | output.writeBool(paused); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 95 | output.writeInt32(ownerPid); | 
|  | 96 | output.writeInt32(ownerUid); | 
|  | 97 | output.writeInt32(inputFeatures); | 
|  | 98 | output.writeInt32(displayId); | 
| Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 99 | output.writeInt32(portalToDisplayId); | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 100 | applicationInfo.write(output); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 101 | output.write(touchableRegion); | 
| Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 102 | output.writeBool(replaceTouchableRegionWithCrop); | 
| Steven Moreland | ee33b9f | 2019-07-17 15:04:02 -0700 | [diff] [blame] | 103 | output.writeStrongBinder(touchableRegionCropHandle.promote()); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 104 | return OK; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | InputWindowInfo InputWindowInfo::read(const Parcel& from) { | 
|  | 108 | InputWindowInfo ret; | 
|  | 109 |  | 
|  | 110 | if (from.readInt32() == 0) { | 
|  | 111 | return ret; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 112 | } | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 113 |  | 
| Robert Carr | 2984b7a | 2020-04-13 17:06:45 -0700 | [diff] [blame] | 114 | ret.token = from.readStrongBinder(); | 
| chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 115 | ret.id = from.readInt32(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 116 | ret.name = from.readString8().c_str(); | 
|  | 117 | ret.layoutParamsFlags = from.readInt32(); | 
|  | 118 | ret.layoutParamsType = from.readInt32(); | 
|  | 119 | ret.dispatchingTimeout = from.readInt64(); | 
|  | 120 | ret.frameLeft = from.readInt32(); | 
|  | 121 | ret.frameTop = from.readInt32(); | 
|  | 122 | ret.frameRight = from.readInt32(); | 
|  | 123 | ret.frameBottom = from.readInt32(); | 
| Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 124 | ret.surfaceInset = from.readInt32(); | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 125 | ret.globalScaleFactor = from.readFloat(); | 
|  | 126 | ret.windowXScale = from.readFloat(); | 
|  | 127 | ret.windowYScale = from.readFloat(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 128 | ret.visible = from.readBool(); | 
|  | 129 | ret.canReceiveKeys = from.readBool(); | 
|  | 130 | ret.hasFocus = from.readBool(); | 
|  | 131 | ret.hasWallpaper = from.readBool(); | 
|  | 132 | ret.paused = from.readBool(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 133 | ret.ownerPid = from.readInt32(); | 
|  | 134 | ret.ownerUid = from.readInt32(); | 
|  | 135 | ret.inputFeatures = from.readInt32(); | 
|  | 136 | ret.displayId = from.readInt32(); | 
| Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 137 | ret.portalToDisplayId = from.readInt32(); | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 138 | ret.applicationInfo = InputApplicationInfo::read(from); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 139 | from.read(ret.touchableRegion); | 
| Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 140 | ret.replaceTouchableRegionWithCrop = from.readBool(); | 
| Steven Moreland | ee33b9f | 2019-07-17 15:04:02 -0700 | [diff] [blame] | 141 | ret.touchableRegionCropHandle = from.readStrongBinder(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 142 |  | 
|  | 143 | return ret; | 
|  | 144 | } | 
|  | 145 |  | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 146 | InputWindowInfo::InputWindowInfo(const Parcel& from) { | 
|  | 147 | *this = read(from); | 
|  | 148 | } | 
|  | 149 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 150 | // --- InputWindowHandle --- | 
|  | 151 |  | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 152 | InputWindowHandle::InputWindowHandle() { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
|  | 155 | InputWindowHandle::~InputWindowHandle() { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 158 | void InputWindowHandle::releaseChannel() { | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 159 | mInfo.token.clear(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 162 | sp<IBinder> InputWindowHandle::getToken() const { | 
|  | 163 | return mInfo.token; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 164 | } | 
|  | 165 |  | 
| Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 166 | void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) { | 
|  | 167 | mInfo = handle->mInfo; | 
|  | 168 | } | 
|  | 169 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 170 | } // namespace android |