blob: 477e54e7081828d4a1567ea61b35607ec5c27dc2 [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 }
41 remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070042 }
Robert Carr1c4c5592018-09-24 13:18:43 -070043
44 virtual void registerInputChannel(const sp<InputChannel>& channel) {
45 Parcel data, reply;
46 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
47 channel->write(data);
48 remote()->transact(BnInputFlinger::REGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
49 }
50
51 virtual void unregisterInputChannel(const sp<InputChannel>& channel) {
52 Parcel data, reply;
53 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
54 channel->write(data);
55 remote()->transact(BnInputFlinger::UNREGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
56 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070057};
58
59IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger");
60
Jeff Brown40c9e0a2013-07-15 13:27:05 -070061status_t BnInputFlinger::onTransact(
62 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
63 switch(code) {
Robert Carr1cc78672018-07-31 14:25:57 -070064 case SET_INPUT_WINDOWS_TRANSACTION: {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070065 CHECK_INTERFACE(IInputFlinger, data, reply);
Robert Carr1cc78672018-07-31 14:25:57 -070066 size_t count = data.readUint32();
67 if (count > data.dataSize()) {
68 return BAD_VALUE;
69 }
70 Vector<InputWindowInfo> handles;
71 handles.setCapacity(count);
72 for (size_t i = 0; i < count; i++) {
73 handles.add(InputWindowInfo(data));
74 }
75 setInputWindows(handles);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070076 break;
77 }
Robert Carr1c4c5592018-09-24 13:18:43 -070078 case REGISTER_INPUT_CHANNEL_TRANSACTION: {
79 CHECK_INTERFACE(IInputFlinger, data, reply);
80 sp<InputChannel> channel = new InputChannel();
81 channel->read(data);
82 registerInputChannel(channel);
83 break;
84 }
85 case UNREGISTER_INPUT_CHANNEL_TRANSACTION: {
86 CHECK_INTERFACE(IInputFlinger, data, reply);
87 sp<InputChannel> channel = new InputChannel();
88 channel->read(data);
89 unregisterInputChannel(channel);
90 break;
91 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070092 default:
93 return BBinder::onTransact(code, data, reply, flags);
94 }
95 return NO_ERROR;
96}
97
98};