blob: 28da8b4f3b476aaf9e639e9d241cdfd2f6204be5 [file] [log] [blame]
Robert Carr3720ed02018-08-08 16:08:27 -07001/*
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
29namespace android {
30
31// --- InputWindowInfo ---
32void InputWindowInfo::addTouchableRegion(const Rect& region) {
33 touchableRegion.orSelf(region);
34}
35
36bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
37 return touchableRegion.contains(x,y);
38}
39
40bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
41 return x >= frameLeft && x < frameRight
42 && y >= frameTop && y < frameBottom;
43}
44
45bool InputWindowInfo::isTrustedOverlay() const {
mincheli9be5b332020-03-03 14:45:05 +080046 return layoutParamsType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY
47 || layoutParamsType == TYPE_INPUT_METHOD
Robert Carr3720ed02018-08-08 16:08:27 -070048 || layoutParamsType == TYPE_INPUT_METHOD_DIALOG
49 || layoutParamsType == TYPE_MAGNIFICATION_OVERLAY
50 || layoutParamsType == TYPE_STATUS_BAR
51 || layoutParamsType == TYPE_NAVIGATION_BAR
52 || layoutParamsType == TYPE_NAVIGATION_BAR_PANEL
53 || layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY
54 || layoutParamsType == TYPE_DOCK_DIVIDER
55 || layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY
56 || layoutParamsType == TYPE_INPUT_CONSUMER;
57}
58
59bool InputWindowInfo::supportsSplitTouch() const {
60 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
61}
62
63bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
64 return frameLeft < other->frameRight && frameRight > other->frameLeft
65 && frameTop < other->frameBottom && frameBottom > other->frameTop;
66}
67
68status_t InputWindowInfo::write(Parcel& output) const {
Robert Carr5c8a0262018-10-03 16:30:44 -070069 if (token == nullptr) {
Robert Carr3720ed02018-08-08 16:08:27 -070070 output.writeInt32(0);
71 return OK;
72 }
73 output.writeInt32(1);
Robert Carr5c8a0262018-10-03 16:30:44 -070074 status_t s = output.writeStrongBinder(token);
Robert Carr3720ed02018-08-08 16:08:27 -070075 if (s != OK) return s;
76
chaviwaf87b3e2019-10-01 16:59:28 -070077 output.writeInt32(id);
Robert Carr3720ed02018-08-08 16:08:27 -070078 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 Carr5cb25782018-11-14 14:01:42 -080086 output.writeInt32(surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -080087 output.writeFloat(globalScaleFactor);
88 output.writeFloat(windowXScale);
89 output.writeFloat(windowYScale);
Robert Carr3720ed02018-08-08 16:08:27 -070090 output.writeBool(visible);
91 output.writeBool(canReceiveKeys);
92 output.writeBool(hasFocus);
93 output.writeBool(hasWallpaper);
94 output.writeBool(paused);
Robert Carr3720ed02018-08-08 16:08:27 -070095 output.writeInt32(ownerPid);
96 output.writeInt32(ownerUid);
97 output.writeInt32(inputFeatures);
98 output.writeInt32(displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +080099 output.writeInt32(portalToDisplayId);
Robert Carr740167f2018-10-11 19:03:41 -0700100 applicationInfo.write(output);
Robert Carr3720ed02018-08-08 16:08:27 -0700101 output.write(touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700102 output.writeBool(replaceTouchableRegionWithCrop);
Steven Morelandee33b9f2019-07-17 15:04:02 -0700103 output.writeStrongBinder(touchableRegionCropHandle.promote());
Robert Carr3720ed02018-08-08 16:08:27 -0700104 return OK;
105}
106
107InputWindowInfo InputWindowInfo::read(const Parcel& from) {
108 InputWindowInfo ret;
109
110 if (from.readInt32() == 0) {
111 return ret;
Robert Carr3720ed02018-08-08 16:08:27 -0700112 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700113
114 sp<IBinder> token = from.readStrongBinder();
115 if (token == nullptr) {
Robert Carr3720ed02018-08-08 16:08:27 -0700116 return ret;
117 }
118
Robert Carr5c8a0262018-10-03 16:30:44 -0700119 ret.token = token;
chaviwaf87b3e2019-10-01 16:59:28 -0700120 ret.id = from.readInt32();
Robert Carr3720ed02018-08-08 16:08:27 -0700121 ret.name = from.readString8().c_str();
122 ret.layoutParamsFlags = from.readInt32();
123 ret.layoutParamsType = from.readInt32();
124 ret.dispatchingTimeout = from.readInt64();
125 ret.frameLeft = from.readInt32();
126 ret.frameTop = from.readInt32();
127 ret.frameRight = from.readInt32();
128 ret.frameBottom = from.readInt32();
Robert Carr5cb25782018-11-14 14:01:42 -0800129 ret.surfaceInset = from.readInt32();
Robert Carre07e1032018-11-26 12:55:53 -0800130 ret.globalScaleFactor = from.readFloat();
131 ret.windowXScale = from.readFloat();
132 ret.windowYScale = from.readFloat();
Robert Carr3720ed02018-08-08 16:08:27 -0700133 ret.visible = from.readBool();
134 ret.canReceiveKeys = from.readBool();
135 ret.hasFocus = from.readBool();
136 ret.hasWallpaper = from.readBool();
137 ret.paused = from.readBool();
Robert Carr3720ed02018-08-08 16:08:27 -0700138 ret.ownerPid = from.readInt32();
139 ret.ownerUid = from.readInt32();
140 ret.inputFeatures = from.readInt32();
141 ret.displayId = from.readInt32();
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800142 ret.portalToDisplayId = from.readInt32();
Robert Carr740167f2018-10-11 19:03:41 -0700143 ret.applicationInfo = InputApplicationInfo::read(from);
Robert Carr3720ed02018-08-08 16:08:27 -0700144 from.read(ret.touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700145 ret.replaceTouchableRegionWithCrop = from.readBool();
Steven Morelandee33b9f2019-07-17 15:04:02 -0700146 ret.touchableRegionCropHandle = from.readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700147
148 return ret;
149}
150
Robert Carr1cc78672018-07-31 14:25:57 -0700151InputWindowInfo::InputWindowInfo(const Parcel& from) {
152 *this = read(from);
153}
154
Robert Carr3720ed02018-08-08 16:08:27 -0700155// --- InputWindowHandle ---
156
Robert Carr740167f2018-10-11 19:03:41 -0700157InputWindowHandle::InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700158}
159
160InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700161}
162
Arthur Hung3b413f22018-10-26 18:05:34 +0800163void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700164 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700165}
166
Robert Carr5c8a0262018-10-03 16:30:44 -0700167sp<IBinder> InputWindowHandle::getToken() const {
168 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700169}
170
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800171void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
172 mInfo = handle->mInfo;
173}
174
Robert Carr3720ed02018-08-08 16:08:27 -0700175} // namespace android