blob: 139570a5fd2592303d5cd14ea3d6bcd0e26c85c6 [file] [log] [blame]
Jeff Brown40c9e0a2013-07-15 13:27:05 -07001/*
2 * Copyright (C) 2013 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#include <stdint.h>
18#include <sys/types.h>
19
20#include <binder/Parcel.h>
21#include <binder/IPCThreadState.h>
22#include <binder/IServiceManager.h>
23
24#include <input/IInputFlinger.h>
25
Jeff Brown40c9e0a2013-07-15 13:27:05 -070026namespace android {
27
28class BpInputFlinger : public BpInterface<IInputFlinger> {
29public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070030 explicit BpInputFlinger(const sp<IBinder>& impl) :
Jeff Brown40c9e0a2013-07-15 13:27:05 -070031 BpInterface<IInputFlinger>(impl) { }
32
Robert Carr1cc78672018-07-31 14:25:57 -070033 virtual void setInputWindows(const Vector<InputWindowInfo>& inputInfo) {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070034 Parcel data, reply;
35 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
Robert Carr1cc78672018-07-31 14:25:57 -070036
37 data.writeUint32(static_cast<uint32_t>(inputInfo.size()));
38 for (const auto& info : inputInfo) {
39 info.write(data);
40 }
Rob Carr2ccbd6e2018-11-29 13:08:54 -080041 remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply,
42 IBinder::FLAG_ONEWAY);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070043 }
Robert Carr1c4c5592018-09-24 13:18:43 -070044
45 virtual void registerInputChannel(const sp<InputChannel>& channel) {
46 Parcel data, reply;
47 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
48 channel->write(data);
49 remote()->transact(BnInputFlinger::REGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
50 }
51
52 virtual void unregisterInputChannel(const sp<InputChannel>& channel) {
53 Parcel data, reply;
54 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
55 channel->write(data);
56 remote()->transact(BnInputFlinger::UNREGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
57 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070058};
59
60IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger");
61
Jeff Brown40c9e0a2013-07-15 13:27:05 -070062status_t BnInputFlinger::onTransact(
63 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
64 switch(code) {
Robert Carr1cc78672018-07-31 14:25:57 -070065 case SET_INPUT_WINDOWS_TRANSACTION: {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070066 CHECK_INTERFACE(IInputFlinger, data, reply);
Robert Carr1cc78672018-07-31 14:25:57 -070067 size_t count = data.readUint32();
68 if (count > data.dataSize()) {
69 return BAD_VALUE;
70 }
71 Vector<InputWindowInfo> handles;
72 handles.setCapacity(count);
73 for (size_t i = 0; i < count; i++) {
74 handles.add(InputWindowInfo(data));
75 }
76 setInputWindows(handles);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070077 break;
78 }
Robert Carr1c4c5592018-09-24 13:18:43 -070079 case REGISTER_INPUT_CHANNEL_TRANSACTION: {
80 CHECK_INTERFACE(IInputFlinger, data, reply);
81 sp<InputChannel> channel = new InputChannel();
82 channel->read(data);
83 registerInputChannel(channel);
84 break;
85 }
86 case UNREGISTER_INPUT_CHANNEL_TRANSACTION: {
87 CHECK_INTERFACE(IInputFlinger, data, reply);
88 sp<InputChannel> channel = new InputChannel();
89 channel->read(data);
90 unregisterInputChannel(channel);
91 break;
92 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070093 default:
94 return BBinder::onTransact(code, data, reply, flags);
95 }
96 return NO_ERROR;
97}
98
99};