blob: 6968661a16675eaa9b609151c59e759ac258255b [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 {
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
58bool InputWindowInfo::supportsSplitTouch() const {
59 return layoutParamsFlags & FLAG_SPLIT_TOUCH;
60}
61
62bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
63 return frameLeft < other->frameRight && frameRight > other->frameLeft
64 && frameTop < other->frameBottom && frameBottom > other->frameTop;
65}
66
67status_t InputWindowInfo::write(Parcel& output) const {
68 if (inputChannel == nullptr) {
69 output.writeInt32(0);
70 return OK;
71 }
72 output.writeInt32(1);
73 status_t s = inputChannel->write(output);
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);
84 output.writeFloat(scaleFactor);
85 output.writeBool(visible);
86 output.writeBool(canReceiveKeys);
87 output.writeBool(hasFocus);
88 output.writeBool(hasWallpaper);
89 output.writeBool(paused);
90 output.writeInt32(layer);
91 output.writeInt32(ownerPid);
92 output.writeInt32(ownerUid);
93 output.writeInt32(inputFeatures);
94 output.writeInt32(displayId);
95 output.write(touchableRegion);
96
97 return OK;
98}
99
100InputWindowInfo InputWindowInfo::read(const Parcel& from) {
101 InputWindowInfo ret;
102
103 if (from.readInt32() == 0) {
104 return ret;
105
106 }
107 sp<InputChannel> inputChannel = new InputChannel();
108 status_t s = inputChannel->read(from);
109 if (s != OK) {
110 return ret;
111 }
112
113 ret.inputChannel = inputChannel;
114 ret.name = from.readString8().c_str();
115 ret.layoutParamsFlags = from.readInt32();
116 ret.layoutParamsType = from.readInt32();
117 ret.dispatchingTimeout = from.readInt64();
118 ret.frameLeft = from.readInt32();
119 ret.frameTop = from.readInt32();
120 ret.frameRight = from.readInt32();
121 ret.frameBottom = from.readInt32();
122 ret.scaleFactor = from.readFloat();
123 ret.visible = from.readBool();
124 ret.canReceiveKeys = from.readBool();
125 ret.hasFocus = from.readBool();
126 ret.hasWallpaper = from.readBool();
127 ret.paused = from.readBool();
128 ret.layer = from.readInt32();
129 ret.ownerPid = from.readInt32();
130 ret.ownerUid = from.readInt32();
131 ret.inputFeatures = from.readInt32();
132 ret.displayId = from.readInt32();
133 from.read(ret.touchableRegion);
134
135 return ret;
136}
137
138// --- InputWindowHandle ---
139
140InputWindowHandle::InputWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle) :
Arthur Hung3b413f22018-10-26 18:05:34 +0800141 inputApplicationHandle(inputApplicationHandle) {
Robert Carr3720ed02018-08-08 16:08:27 -0700142}
143
144InputWindowHandle::~InputWindowHandle() {
Robert Carr3720ed02018-08-08 16:08:27 -0700145}
146
Arthur Hung3b413f22018-10-26 18:05:34 +0800147void InputWindowHandle::releaseChannel() {
148 mInfo.inputChannel.clear();
Robert Carr3720ed02018-08-08 16:08:27 -0700149}
150
151sp<InputChannel> InputWindowHandle::getInputChannel() const {
Arthur Hung3b413f22018-10-26 18:05:34 +0800152 return mInfo.inputChannel;
Robert Carr3720ed02018-08-08 16:08:27 -0700153}
154
155} // namespace android