blob: 99b718bae3e3b55e77c2a029d5d22b4ac3bad75b [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
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070020#include <android-base/stringprintf.h>
Robert Carr3720ed02018-08-08 16:08:27 -070021#include <binder/Parcel.h>
Robert Carr3720ed02018-08-08 16:08:27 -070022#include <input/InputTransport.h>
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070023#include <input/InputWindow.h>
Robert Carr3720ed02018-08-08 16:08:27 -070024
25#include <log/log.h>
26
27#include <ui/Rect.h>
28#include <ui/Region.h>
29
30namespace android {
31
Siarhei Vishniakou67d44502020-04-09 11:09:29 -070032const 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
134std::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 Carr3720ed02018-08-08 16:08:27 -0700144// --- InputWindowInfo ---
145void InputWindowInfo::addTouchableRegion(const Rect& region) {
146 touchableRegion.orSelf(region);
147}
148
149bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
150 return touchableRegion.contains(x,y);
151}
152
153bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
154 return x >= frameLeft && x < frameRight
155 && y >= frameTop && y < frameBottom;
156}
157
158bool InputWindowInfo::isTrustedOverlay() const {
mincheli9be5b332020-03-03 14:45:05 +0800159 return layoutParamsType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY
160 || layoutParamsType == TYPE_INPUT_METHOD
Robert Carr3720ed02018-08-08 16:08:27 -0700161 || 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
172bool InputWindowInfo::supportsSplitTouch() const {
173 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
174}
175
176bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
177 return frameLeft < other->frameRight && frameRight > other->frameLeft
178 && frameTop < other->frameBottom && frameBottom > other->frameTop;
179}
180
181status_t InputWindowInfo::write(Parcel& output) const {
Robert Carr5c8a0262018-10-03 16:30:44 -0700182 if (token == nullptr) {
Robert Carr3720ed02018-08-08 16:08:27 -0700183 output.writeInt32(0);
184 return OK;
185 }
186 output.writeInt32(1);
Robert Carr5c8a0262018-10-03 16:30:44 -0700187 status_t s = output.writeStrongBinder(token);
Robert Carr3720ed02018-08-08 16:08:27 -0700188 if (s != OK) return s;
189
chaviwaf87b3e2019-10-01 16:59:28 -0700190 output.writeInt32(id);
Robert Carr3720ed02018-08-08 16:08:27 -0700191 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 Carr5cb25782018-11-14 14:01:42 -0800199 output.writeInt32(surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -0800200 output.writeFloat(globalScaleFactor);
201 output.writeFloat(windowXScale);
202 output.writeFloat(windowYScale);
Robert Carr3720ed02018-08-08 16:08:27 -0700203 output.writeBool(visible);
204 output.writeBool(canReceiveKeys);
205 output.writeBool(hasFocus);
206 output.writeBool(hasWallpaper);
207 output.writeBool(paused);
Robert Carr3720ed02018-08-08 16:08:27 -0700208 output.writeInt32(ownerPid);
209 output.writeInt32(ownerUid);
210 output.writeInt32(inputFeatures);
211 output.writeInt32(displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800212 output.writeInt32(portalToDisplayId);
Robert Carr740167f2018-10-11 19:03:41 -0700213 applicationInfo.write(output);
Robert Carr3720ed02018-08-08 16:08:27 -0700214 output.write(touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700215 output.writeBool(replaceTouchableRegionWithCrop);
Steven Morelandee33b9f2019-07-17 15:04:02 -0700216 output.writeStrongBinder(touchableRegionCropHandle.promote());
Robert Carr3720ed02018-08-08 16:08:27 -0700217 return OK;
218}
219
220InputWindowInfo InputWindowInfo::read(const Parcel& from) {
221 InputWindowInfo ret;
222
223 if (from.readInt32() == 0) {
224 return ret;
Robert Carr3720ed02018-08-08 16:08:27 -0700225 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700226
227 sp<IBinder> token = from.readStrongBinder();
228 if (token == nullptr) {
Robert Carr3720ed02018-08-08 16:08:27 -0700229 return ret;
230 }
231
Robert Carr5c8a0262018-10-03 16:30:44 -0700232 ret.token = token;
chaviwaf87b3e2019-10-01 16:59:28 -0700233 ret.id = from.readInt32();
Robert Carr3720ed02018-08-08 16:08:27 -0700234 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 Carr5cb25782018-11-14 14:01:42 -0800242 ret.surfaceInset = from.readInt32();
Robert Carre07e1032018-11-26 12:55:53 -0800243 ret.globalScaleFactor = from.readFloat();
244 ret.windowXScale = from.readFloat();
245 ret.windowYScale = from.readFloat();
Robert Carr3720ed02018-08-08 16:08:27 -0700246 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 Carr3720ed02018-08-08 16:08:27 -0700251 ret.ownerPid = from.readInt32();
252 ret.ownerUid = from.readInt32();
253 ret.inputFeatures = from.readInt32();
254 ret.displayId = from.readInt32();
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800255 ret.portalToDisplayId = from.readInt32();
Robert Carr740167f2018-10-11 19:03:41 -0700256 ret.applicationInfo = InputApplicationInfo::read(from);
Robert Carr3720ed02018-08-08 16:08:27 -0700257 from.read(ret.touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700258 ret.replaceTouchableRegionWithCrop = from.readBool();
Steven Morelandee33b9f2019-07-17 15:04:02 -0700259 ret.touchableRegionCropHandle = from.readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700260
261 return ret;
262}
263
Robert Carr1cc78672018-07-31 14:25:57 -0700264InputWindowInfo::InputWindowInfo(const Parcel& from) {
265 *this = read(from);
266}
267
Robert Carr3720ed02018-08-08 16:08:27 -0700268// --- InputWindowHandle ---
269
Robert Carr740167f2018-10-11 19:03:41 -0700270InputWindowHandle::InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700271}
272
273InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700274}
275
Arthur Hung3b413f22018-10-26 18:05:34 +0800276void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700277 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700278}
279
Robert Carr5c8a0262018-10-03 16:30:44 -0700280sp<IBinder> InputWindowHandle::getToken() const {
281 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700282}
283
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800284void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
285 mInfo = handle->mInfo;
286}
287
Robert Carr3720ed02018-08-08 16:08:27 -0700288} // namespace android