Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 1 | /* |
| 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | class BpInputFlinger : public BpInterface<IInputFlinger> { |
| 29 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 30 | explicit BpInputFlinger(const sp<IBinder>& impl) : |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 31 | BpInterface<IInputFlinger>(impl) { } |
| 32 | |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 33 | virtual void setInputWindows(const Vector<InputWindowInfo>& inputInfo) { |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 34 | Parcel data, reply; |
| 35 | data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor()); |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 36 | |
| 37 | data.writeUint32(static_cast<uint32_t>(inputInfo.size())); |
| 38 | for (const auto& info : inputInfo) { |
| 39 | info.write(data); |
| 40 | } |
Rob Carr | 2ccbd6e | 2018-11-29 13:08:54 -0800 | [diff] [blame^] | 41 | remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply, |
| 42 | IBinder::FLAG_ONEWAY); |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 43 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 44 | |
| 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger"); |
| 61 | |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 62 | status_t BnInputFlinger::onTransact( |
| 63 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 64 | switch(code) { |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 65 | case SET_INPUT_WINDOWS_TRANSACTION: { |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 66 | CHECK_INTERFACE(IInputFlinger, data, reply); |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 67 | 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 77 | break; |
| 78 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 79 | 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 93 | default: |
| 94 | return BBinder::onTransact(code, data, reply, flags); |
| 95 | } |
| 96 | return NO_ERROR; |
| 97 | } |
| 98 | |
| 99 | }; |