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 | |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 45 | 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 Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 55 | 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger"); |
| 71 | |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 72 | status_t BnInputFlinger::onTransact( |
| 73 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 74 | switch(code) { |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 75 | case SET_INPUT_WINDOWS_TRANSACTION: { |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 76 | CHECK_INTERFACE(IInputFlinger, data, reply); |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 77 | 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 87 | break; |
| 88 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 89 | 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 | } |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 103 | 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 Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 110 | default: |
| 111 | return BBinder::onTransact(code, data, reply, flags); |
| 112 | } |
| 113 | return NO_ERROR; |
| 114 | } |
| 115 | |
| 116 | }; |