| 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 |  | 
|  | 45 | bool InputWindowInfo::isTrustedOverlay() const { | 
|  | 46 | return layoutParamsType == TYPE_INPUT_METHOD | 
|  | 47 | || layoutParamsType == TYPE_INPUT_METHOD_DIALOG | 
|  | 48 | || layoutParamsType == TYPE_MAGNIFICATION_OVERLAY | 
|  | 49 | || layoutParamsType == TYPE_STATUS_BAR | 
|  | 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 | 
|  | 55 | || layoutParamsType == TYPE_INPUT_CONSUMER; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | bool InputWindowInfo::supportsSplitTouch() const { | 
|  | 59 | return layoutParamsFlags & FLAG_SPLIT_TOUCH; | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | bool InputWindowInfo::overlaps(const InputWindowInfo* other) const { | 
|  | 63 | return frameLeft < other->frameRight && frameRight > other->frameLeft | 
|  | 64 | && frameTop < other->frameBottom && frameBottom > other->frameTop; | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | status_t InputWindowInfo::write(Parcel& output) const { | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 68 | if (token == nullptr) { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 69 | output.writeInt32(0); | 
|  | 70 | return OK; | 
|  | 71 | } | 
|  | 72 | output.writeInt32(1); | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 73 | status_t s = output.writeStrongBinder(token); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 74 | if (s != OK) return s; | 
|  | 75 |  | 
|  | 76 | output.writeString8(String8(name.c_str())); | 
|  | 77 | output.writeInt32(layoutParamsFlags); | 
|  | 78 | output.writeInt32(layoutParamsType); | 
|  | 79 | output.writeInt64(dispatchingTimeout); | 
|  | 80 | output.writeInt32(frameLeft); | 
|  | 81 | output.writeInt32(frameTop); | 
|  | 82 | output.writeInt32(frameRight); | 
|  | 83 | output.writeInt32(frameBottom); | 
| Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 84 | output.writeInt32(surfaceInset); | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 85 | output.writeFloat(globalScaleFactor); | 
|  | 86 | output.writeFloat(windowXScale); | 
|  | 87 | output.writeFloat(windowYScale); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 88 | output.writeBool(visible); | 
|  | 89 | output.writeBool(canReceiveKeys); | 
|  | 90 | output.writeBool(hasFocus); | 
|  | 91 | output.writeBool(hasWallpaper); | 
|  | 92 | output.writeBool(paused); | 
|  | 93 | output.writeInt32(layer); | 
|  | 94 | output.writeInt32(ownerPid); | 
|  | 95 | output.writeInt32(ownerUid); | 
|  | 96 | output.writeInt32(inputFeatures); | 
|  | 97 | output.writeInt32(displayId); | 
| Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 98 | output.writeInt32(portalToDisplayId); | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 99 | applicationInfo.write(output); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 100 | output.write(touchableRegion); | 
|  | 101 |  | 
|  | 102 | return OK; | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | InputWindowInfo InputWindowInfo::read(const Parcel& from) { | 
|  | 106 | InputWindowInfo ret; | 
|  | 107 |  | 
|  | 108 | if (from.readInt32() == 0) { | 
|  | 109 | return ret; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 110 | } | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | sp<IBinder> token = from.readStrongBinder(); | 
|  | 113 | if (token == nullptr) { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 114 | return ret; | 
|  | 115 | } | 
|  | 116 |  | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 117 | ret.token = token; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 118 | ret.name = from.readString8().c_str(); | 
|  | 119 | ret.layoutParamsFlags = from.readInt32(); | 
|  | 120 | ret.layoutParamsType = from.readInt32(); | 
|  | 121 | ret.dispatchingTimeout = from.readInt64(); | 
|  | 122 | ret.frameLeft = from.readInt32(); | 
|  | 123 | ret.frameTop = from.readInt32(); | 
|  | 124 | ret.frameRight = from.readInt32(); | 
|  | 125 | ret.frameBottom = from.readInt32(); | 
| Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 126 | ret.surfaceInset = from.readInt32(); | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 127 | ret.globalScaleFactor = from.readFloat(); | 
|  | 128 | ret.windowXScale = from.readFloat(); | 
|  | 129 | ret.windowYScale = from.readFloat(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 130 | ret.visible = from.readBool(); | 
|  | 131 | ret.canReceiveKeys = from.readBool(); | 
|  | 132 | ret.hasFocus = from.readBool(); | 
|  | 133 | ret.hasWallpaper = from.readBool(); | 
|  | 134 | ret.paused = from.readBool(); | 
|  | 135 | ret.layer = from.readInt32(); | 
|  | 136 | ret.ownerPid = from.readInt32(); | 
|  | 137 | ret.ownerUid = from.readInt32(); | 
|  | 138 | ret.inputFeatures = from.readInt32(); | 
|  | 139 | ret.displayId = from.readInt32(); | 
| Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 140 | ret.portalToDisplayId = from.readInt32(); | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 141 | ret.applicationInfo = InputApplicationInfo::read(from); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 142 | from.read(ret.touchableRegion); | 
|  | 143 |  | 
|  | 144 | return ret; | 
|  | 145 | } | 
|  | 146 |  | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 147 | InputWindowInfo::InputWindowInfo(const Parcel& from) { | 
|  | 148 | *this = read(from); | 
|  | 149 | } | 
|  | 150 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 151 | // --- InputWindowHandle --- | 
|  | 152 |  | 
| Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 153 | InputWindowHandle::InputWindowHandle() { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
|  | 156 | InputWindowHandle::~InputWindowHandle() { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 157 | } | 
|  | 158 |  | 
| Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 159 | void InputWindowHandle::releaseChannel() { | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 160 | mInfo.token.clear(); | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 161 | } | 
|  | 162 |  | 
| Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 163 | sp<IBinder> InputWindowHandle::getToken() const { | 
|  | 164 | return mInfo.token; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 165 | } | 
|  | 166 |  | 
| Garfield Tan | bd0fbcd | 2018-11-30 12:45:03 -0800 | [diff] [blame] | 167 | void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) { | 
|  | 168 | mInfo = handle->mInfo; | 
|  | 169 | } | 
|  | 170 |  | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 171 | } // namespace android |