blob: 4ce5a10e5cfae185691d5cb25e03bc59f87b6fab [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
chaviw291d88a2019-02-14 10:33:58 -080033 virtual void setInputWindows(const Vector<InputWindowInfo>& inputInfo,
34 const sp<ISetInputWindowsListener>& setInputWindowsListener) {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070035 Parcel data, reply;
36 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
Robert Carr1cc78672018-07-31 14:25:57 -070037
38 data.writeUint32(static_cast<uint32_t>(inputInfo.size()));
39 for (const auto& info : inputInfo) {
40 info.write(data);
41 }
chaviw291d88a2019-02-14 10:33:58 -080042 data.writeStrongBinder(IInterface::asBinder(setInputWindowsListener));
43
Rob Carr2ccbd6e2018-11-29 13:08:54 -080044 remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply,
45 IBinder::FLAG_ONEWAY);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070046 }
Robert Carr1c4c5592018-09-24 13:18:43 -070047
chaviwfbe5d9c2018-12-26 12:23:37 -080048 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) {
49 Parcel data, reply;
50 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
51
52 data.writeStrongBinder(fromToken);
53 data.writeStrongBinder(toToken);
54 remote()->transact(BnInputFlinger::TRANSFER_TOUCH_FOCUS, data, &reply,
55 IBinder::FLAG_ONEWAY);
56 }
57
Robert Carr1c4c5592018-09-24 13:18:43 -070058 virtual void registerInputChannel(const sp<InputChannel>& channel) {
59 Parcel data, reply;
60 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
61 channel->write(data);
62 remote()->transact(BnInputFlinger::REGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
63 }
64
65 virtual void unregisterInputChannel(const sp<InputChannel>& channel) {
66 Parcel data, reply;
67 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor());
68 channel->write(data);
69 remote()->transact(BnInputFlinger::UNREGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply);
70 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -070071};
72
73IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger");
74
Jeff Brown40c9e0a2013-07-15 13:27:05 -070075status_t BnInputFlinger::onTransact(
76 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
77 switch(code) {
Robert Carr1cc78672018-07-31 14:25:57 -070078 case SET_INPUT_WINDOWS_TRANSACTION: {
Jeff Brown40c9e0a2013-07-15 13:27:05 -070079 CHECK_INTERFACE(IInputFlinger, data, reply);
Robert Carr1cc78672018-07-31 14:25:57 -070080 size_t count = data.readUint32();
81 if (count > data.dataSize()) {
82 return BAD_VALUE;
83 }
84 Vector<InputWindowInfo> handles;
85 handles.setCapacity(count);
86 for (size_t i = 0; i < count; i++) {
87 handles.add(InputWindowInfo(data));
88 }
chaviw291d88a2019-02-14 10:33:58 -080089 const sp<ISetInputWindowsListener> setInputWindowsListener =
90 ISetInputWindowsListener::asInterface(data.readStrongBinder());
91 setInputWindows(handles, setInputWindowsListener);
Jeff Brown40c9e0a2013-07-15 13:27:05 -070092 break;
93 }
Robert Carr1c4c5592018-09-24 13:18:43 -070094 case REGISTER_INPUT_CHANNEL_TRANSACTION: {
95 CHECK_INTERFACE(IInputFlinger, data, reply);
96 sp<InputChannel> channel = new InputChannel();
97 channel->read(data);
98 registerInputChannel(channel);
99 break;
100 }
101 case UNREGISTER_INPUT_CHANNEL_TRANSACTION: {
102 CHECK_INTERFACE(IInputFlinger, data, reply);
103 sp<InputChannel> channel = new InputChannel();
104 channel->read(data);
105 unregisterInputChannel(channel);
106 break;
107 }
chaviwfbe5d9c2018-12-26 12:23:37 -0800108 case TRANSFER_TOUCH_FOCUS: {
109 CHECK_INTERFACE(IInputFlinger, data, reply);
110 sp<IBinder> fromToken = data.readStrongBinder();
111 sp<IBinder> toToken = data.readStrongBinder();
112 transferTouchFocus(fromToken, toToken);
113 break;
114 }
Jeff Brown40c9e0a2013-07-15 13:27:05 -0700115 default:
116 return BBinder::onTransact(code, data, reply, flags);
117 }
118 return NO_ERROR;
119}
120
121};