blob: 3700e8f0f80e08b754955bd33be7d7cd9c43aa34 [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
Robert Carr3720ed02018-08-08 16:08:27 -0700158bool InputWindowInfo::supportsSplitTouch() const {
159 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
160}
161
162bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
163 return frameLeft < other->frameRight && frameRight > other->frameLeft
164 && frameTop < other->frameBottom && frameBottom > other->frameTop;
165}
166
167status_t InputWindowInfo::write(Parcel& output) const {
Robert Carr2984b7a2020-04-13 17:06:45 -0700168 if (name.empty()) {
Robert Carr3720ed02018-08-08 16:08:27 -0700169 output.writeInt32(0);
170 return OK;
171 }
172 output.writeInt32(1);
Robert Carr5c8a0262018-10-03 16:30:44 -0700173 status_t s = output.writeStrongBinder(token);
Robert Carr3720ed02018-08-08 16:08:27 -0700174 if (s != OK) return s;
175
chaviwaf87b3e2019-10-01 16:59:28 -0700176 output.writeInt32(id);
Robert Carr3720ed02018-08-08 16:08:27 -0700177 output.writeString8(String8(name.c_str()));
178 output.writeInt32(layoutParamsFlags);
179 output.writeInt32(layoutParamsType);
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500180 output.writeInt64(dispatchingTimeout.count());
Robert Carr3720ed02018-08-08 16:08:27 -0700181 output.writeInt32(frameLeft);
182 output.writeInt32(frameTop);
183 output.writeInt32(frameRight);
184 output.writeInt32(frameBottom);
Robert Carr5cb25782018-11-14 14:01:42 -0800185 output.writeInt32(surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -0800186 output.writeFloat(globalScaleFactor);
187 output.writeFloat(windowXScale);
188 output.writeFloat(windowYScale);
Robert Carr3720ed02018-08-08 16:08:27 -0700189 output.writeBool(visible);
190 output.writeBool(canReceiveKeys);
191 output.writeBool(hasFocus);
192 output.writeBool(hasWallpaper);
193 output.writeBool(paused);
Chris Yefcdff3e2020-05-10 15:16:04 -0700194 output.writeBool(trustedOverlay);
Robert Carr3720ed02018-08-08 16:08:27 -0700195 output.writeInt32(ownerPid);
196 output.writeInt32(ownerUid);
197 output.writeInt32(inputFeatures);
198 output.writeInt32(displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800199 output.writeInt32(portalToDisplayId);
Robert Carr740167f2018-10-11 19:03:41 -0700200 applicationInfo.write(output);
Robert Carr3720ed02018-08-08 16:08:27 -0700201 output.write(touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700202 output.writeBool(replaceTouchableRegionWithCrop);
Steven Morelandee33b9f2019-07-17 15:04:02 -0700203 output.writeStrongBinder(touchableRegionCropHandle.promote());
Robert Carr3720ed02018-08-08 16:08:27 -0700204 return OK;
205}
206
207InputWindowInfo InputWindowInfo::read(const Parcel& from) {
208 InputWindowInfo ret;
209
210 if (from.readInt32() == 0) {
211 return ret;
Robert Carr3720ed02018-08-08 16:08:27 -0700212 }
Robert Carr5c8a0262018-10-03 16:30:44 -0700213
Robert Carr2984b7a2020-04-13 17:06:45 -0700214 ret.token = from.readStrongBinder();
chaviwaf87b3e2019-10-01 16:59:28 -0700215 ret.id = from.readInt32();
Robert Carr3720ed02018-08-08 16:08:27 -0700216 ret.name = from.readString8().c_str();
217 ret.layoutParamsFlags = from.readInt32();
218 ret.layoutParamsType = from.readInt32();
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500219 ret.dispatchingTimeout = decltype(ret.dispatchingTimeout)(from.readInt64());
Robert Carr3720ed02018-08-08 16:08:27 -0700220 ret.frameLeft = from.readInt32();
221 ret.frameTop = from.readInt32();
222 ret.frameRight = from.readInt32();
223 ret.frameBottom = from.readInt32();
Robert Carr5cb25782018-11-14 14:01:42 -0800224 ret.surfaceInset = from.readInt32();
Robert Carre07e1032018-11-26 12:55:53 -0800225 ret.globalScaleFactor = from.readFloat();
226 ret.windowXScale = from.readFloat();
227 ret.windowYScale = from.readFloat();
Robert Carr3720ed02018-08-08 16:08:27 -0700228 ret.visible = from.readBool();
229 ret.canReceiveKeys = from.readBool();
230 ret.hasFocus = from.readBool();
231 ret.hasWallpaper = from.readBool();
232 ret.paused = from.readBool();
Chris Yefcdff3e2020-05-10 15:16:04 -0700233 ret.trustedOverlay = from.readBool();
Robert Carr3720ed02018-08-08 16:08:27 -0700234 ret.ownerPid = from.readInt32();
235 ret.ownerUid = from.readInt32();
236 ret.inputFeatures = from.readInt32();
237 ret.displayId = from.readInt32();
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800238 ret.portalToDisplayId = from.readInt32();
Robert Carr740167f2018-10-11 19:03:41 -0700239 ret.applicationInfo = InputApplicationInfo::read(from);
Robert Carr3720ed02018-08-08 16:08:27 -0700240 from.read(ret.touchableRegion);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700241 ret.replaceTouchableRegionWithCrop = from.readBool();
Steven Morelandee33b9f2019-07-17 15:04:02 -0700242 ret.touchableRegionCropHandle = from.readStrongBinder();
Robert Carr3720ed02018-08-08 16:08:27 -0700243
244 return ret;
245}
246
Robert Carr1cc78672018-07-31 14:25:57 -0700247InputWindowInfo::InputWindowInfo(const Parcel& from) {
248 *this = read(from);
249}
250
Robert Carr3720ed02018-08-08 16:08:27 -0700251// --- InputWindowHandle ---
252
Robert Carr740167f2018-10-11 19:03:41 -0700253InputWindowHandle::InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700254}
255
256InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700257}
258
Arthur Hung3b413f22018-10-26 18:05:34 +0800259void InputWindowHandle::releaseChannel() {
Robert Carr5c8a0262018-10-03 16:30:44 -0700260 mInfo.token.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700261}
262
Robert Carr5c8a0262018-10-03 16:30:44 -0700263sp<IBinder> InputWindowHandle::getToken() const {
264 return mInfo.token;
Robert Carr3720ed02018-08-08 16:08:27 -0700265}
266
Garfield Tanbd0fbcd2018-11-30 12:45:03 -0800267void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
268 mInfo = handle->mInfo;
269}
270
Robert Carr3720ed02018-08-08 16:08:27 -0700271} // namespace android