blob: 3d3bec8ba4c72e87e8381ff8d6b49b6d343e5913 [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
Joshua Tsuji466cdea2020-05-04 13:53:00 -0400158// TODO(b/155781676): Remove and replace call points with trustedOverlay when that is ready.
Robert Carr3720ed02018-08-08 16:08:27 -0700159bool InputWindowInfo::isTrustedOverlay() const {
wilsonshih599042f2020-05-04 16:24:58 +0800160 return layoutParamsType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY ||
161 layoutParamsType == TYPE_INPUT_METHOD || layoutParamsType == TYPE_INPUT_METHOD_DIALOG ||
162 layoutParamsType == TYPE_MAGNIFICATION_OVERLAY || layoutParamsType == TYPE_STATUS_BAR ||
163 layoutParamsType == TYPE_NOTIFICATION_SHADE ||
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 ||
Joshua Tsuji466cdea2020-05-04 13:53:00 -0400169 layoutParamsType == TYPE_INPUT_CONSUMER ||
170 layoutParamsType == TYPE_TRUSTED_APPLICATION_OVERLAY;
Robert Carr3720ed02018-08-08 16:08:27 -0700171}
172
173bool InputWindowInfo::supportsSplitTouch() const {
174 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
175}
176
177bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
178 return frameLeft < other->frameRight && frameRight > other->frameLeft
179 && frameTop < other->frameBottom && frameBottom > other->frameTop;
180}
181
182status_t InputWindowInfo::write(Parcel& output) const {
Robert Carr2984b7a2020-04-13 17:06:45 -0700183 if (name.empty()) {
Robert Carr3720ed02018-08-08 16:08:27 -0700184 output.writeInt32(0);
185 return OK;
186 }
187 output.writeInt32(1);
Robert Carr5c8a0262018-10-03 16:30:44 -0700188 status_t s = output.writeStrongBinder(token);
Robert Carr3720ed02018-08-08 16:08:27 -0700189 if (s != OK) return s;
190
chaviwaf87b3e2019-10-01 16:59:28 -0700191 output.writeInt32(id);
Robert Carr3720ed02018-08-08 16:08:27 -0700192 output.writeString8(String8(name.c_str()));
193 output.writeInt32(layoutParamsFlags);
194 output.writeInt32(layoutParamsType);
195 output.writeInt64(dispatchingTimeout);
196 output.writeInt32(frameLeft);
197 output.writeInt32(frameTop);
198 output.writeInt32(frameRight);
199 output.writeInt32(frameBottom);
Robert Carr5cb25782018-11-14 14:01:42 -0800200 output.writeInt32(surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -0800201 output.writeFloat(globalScaleFactor);
202 output.writeFloat(windowXScale);
203 output.writeFloat(windowYScale);
Robert Carr3720ed02018-08-08 16:08:27 -0700204 output.writeBool(visible);
205 output.writeBool(canReceiveKeys);
206 output.writeBool(hasFocus);
207 output.writeBool(hasWallpaper);
208 output.writeBool(paused);
Robert Carr3720ed02018-08-08 16:08:27 -0700209 output.writeInt32(ownerPid);
210 output.writeInt32(ownerUid);
211 output.writeInt32(inputFeatures);
212 output.writeInt32(displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800213 output.writeInt32(portalToDisplayId);
Robert Carr740167f2018-10-11 19:03:41 -0700214 applicationInfo.write(output);
Robert Carr3720ed02018-08-08 16:08:27 -0700215 output.write(touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700216 output.writeBool(replaceTouchableRegionWithCrop);
Steven Morelandee33b9f2019-07-17 15:04:02 -0700217 output.writeStrongBinder(touchableRegionCropHandle.promote());
Robert Carr3720ed02018-08-08 16:08:27 -0700218 return OK;
219}
220
221InputWindowInfo InputWindowInfo::read(const Parcel& from) {
222 InputWindowInfo ret;
223
224 if (from.readInt32() == 0) {
225 return ret;
Robert Carr3720ed02018-08-08 16:08:27 -0700226 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700227
Robert Carr2984b7a2020-04-13 17:06:45 -0700228 ret.token = from.readStrongBinder();
chaviwaf87b3e2019-10-01 16:59:28 -0700229 ret.id = from.readInt32();
Robert Carr3720ed02018-08-08 16:08:27 -0700230 ret.name = from.readString8().c_str();
231 ret.layoutParamsFlags = from.readInt32();
232 ret.layoutParamsType = from.readInt32();
233 ret.dispatchingTimeout = from.readInt64();
234 ret.frameLeft = from.readInt32();
235 ret.frameTop = from.readInt32();
236 ret.frameRight = from.readInt32();
237 ret.frameBottom = from.readInt32();
Robert Carr5cb25782018-11-14 14:01:42 -0800238 ret.surfaceInset = from.readInt32();
Robert Carre07e1032018-11-26 12:55:53 -0800239 ret.globalScaleFactor = from.readFloat();
240 ret.windowXScale = from.readFloat();
241 ret.windowYScale = from.readFloat();
Robert Carr3720ed02018-08-08 16:08:27 -0700242 ret.visible = from.readBool();
243 ret.canReceiveKeys = from.readBool();
244 ret.hasFocus = from.readBool();
245 ret.hasWallpaper = from.readBool();
246 ret.paused = from.readBool();
Robert Carr3720ed02018-08-08 16:08:27 -0700247 ret.ownerPid = from.readInt32();
248 ret.ownerUid = from.readInt32();
249 ret.inputFeatures = from.readInt32();
250 ret.displayId = from.readInt32();
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800251 ret.portalToDisplayId = from.readInt32();
Robert Carr740167f2018-10-11 19:03:41 -0700252 ret.applicationInfo = InputApplicationInfo::read(from);
Robert Carr3720ed02018-08-08 16:08:27 -0700253 from.read(ret.touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700254 ret.replaceTouchableRegionWithCrop = from.readBool();
Steven Morelandee33b9f2019-07-17 15:04:02 -0700255 ret.touchableRegionCropHandle = from.readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700256
257 return ret;
258}
259
Robert Carr1cc78672018-07-31 14:25:57 -0700260InputWindowInfo::InputWindowInfo(const Parcel& from) {
261 *this = read(from);
262}
263
Robert Carr3720ed02018-08-08 16:08:27 -0700264// --- InputWindowHandle ---
265
Robert Carr740167f2018-10-11 19:03:41 -0700266InputWindowHandle::InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700267}
268
269InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700270}
271
Arthur Hung3b413f22018-10-26 18:05:34 +0800272void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700273 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700274}
275
Robert Carr5c8a0262018-10-03 16:30:44 -0700276sp<IBinder> InputWindowHandle::getToken() const {
277 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700278}
279
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800280void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
281 mInfo = handle->mInfo;
282}
283
Robert Carr3720ed02018-08-08 16:08:27 -0700284} // namespace android