blob: acf40bcbde1ce0ad49be8b8761fb69fbb48db23d [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
chaviwfbe5d9c2018-12-26 12:23:37 -080045 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) {
46 Parcel data, reply;
47 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
48
49 data.writeStrongBinder(fromToken);
50 data.writeStrongBinder(toToken);
51 remote()->transact(BnInputFlinger::TRANSFER_TOUCH_FOCUS, data, &reply,
52 IBinder::FLAG_ONEWAY);
53 }
54
Robert Carr1c4c5592018-09-24 13:18:43 -070055 virtual void registerInputChannel(const sp<InputChannel>& channel) {
56 Parcel data, reply;
57 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
58 channel->write(data);
59 remote()->transact(BnInputFlinger::REGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
60 }
61
62 virtual void unregisterInputChannel(const sp<InputChannel>& channel) {
63 Parcel data, reply;
64 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
65 channel->write(data);
66 remote()->transact(BnInputFlinger::UNREGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
67 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070068};
69
70IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger");
71
Jeff Brown40c9e0a2013-07-15 13:27:05 -070072status_t BnInputFlinger::onTransact(
73 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
74 switch(code) {
Robert Carr1cc78672018-07-31 14:25:57 -070075 case SET_INPUT_WINDOWS_TRANSACTION: {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070076 CHECK_INTERFACE(IInputFlinger, data, reply);
Robert Carr1cc78672018-07-31 14:25:57 -070077 size_t count = data.readUint32();
78 if (count > data.dataSize()) {
79 return BAD_VALUE;
80 }
81 Vector<InputWindowInfo> handles;
82 handles.setCapacity(count);
83 for (size_t i = 0; i < count; i++) {
84 handles.add(InputWindowInfo(data));
85 }
86 setInputWindows(handles);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070087 break;
88 }
Robert Carr1c4c5592018-09-24 13:18:43 -070089 case REGISTER_INPUT_CHANNEL_TRANSACTION: {
90 CHECK_INTERFACE(IInputFlinger, data, reply);
91 sp<InputChannel> channel = new InputChannel();
92 channel->read(data);
93 registerInputChannel(channel);
94 break;
95 }
96 case UNREGISTER_INPUT_CHANNEL_TRANSACTION: {
97 CHECK_INTERFACE(IInputFlinger, data, reply);
98 sp<InputChannel> channel = new InputChannel();
99 channel->read(data);
100 unregisterInputChannel(channel);
101 break;
102 }
chaviwfbe5d9c2018-12-26 12:23:37 -0800103 case TRANSFER_TOUCH_FOCUS: {
104 CHECK_INTERFACE(IInputFlinger, data, reply);
105 sp<IBinder> fromToken = data.readStrongBinder();
106 sp<IBinder> toToken = data.readStrongBinder();
107 transferTouchFocus(fromToken, toToken);
108 break;
109 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -0700110 default:
111 return BBinder::onTransact(code, data, reply, flags);
112 }
113 return NO_ERROR;
114}
115
116};