| 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 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 33 |     virtual void setInputWindows(const std::vector<InputWindowInfo>& inputInfo, | 
| chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 34 |             const sp<ISetInputWindowsListener>& setInputWindowsListener) { | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 35 |         Parcel data, reply; | 
 | 36 |         data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor()); | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 37 |  | 
 | 38 |         data.writeUint32(static_cast<uint32_t>(inputInfo.size())); | 
 | 39 |         for (const auto& info : inputInfo) { | 
 | 40 |             info.write(data); | 
 | 41 |         } | 
| chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 42 |         data.writeStrongBinder(IInterface::asBinder(setInputWindowsListener)); | 
 | 43 |  | 
| Rob Carr | 2ccbd6e | 2018-11-29 13:08:54 -0800 | [diff] [blame] | 44 |         remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply, | 
 | 45 |                 IBinder::FLAG_ONEWAY); | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 46 |     } | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 47 |  | 
 | 48 |     virtual void registerInputChannel(const sp<InputChannel>& channel) { | 
 | 49 |         Parcel data, reply; | 
 | 50 |         data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor()); | 
 | 51 |         channel->write(data); | 
 | 52 |         remote()->transact(BnInputFlinger::REGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply); | 
 | 53 |     } | 
 | 54 |  | 
 | 55 |     virtual void unregisterInputChannel(const sp<InputChannel>& channel) { | 
 | 56 |         Parcel data, reply; | 
 | 57 |         data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor()); | 
 | 58 |         channel->write(data); | 
 | 59 |         remote()->transact(BnInputFlinger::UNREGISTER_INPUT_CHANNEL_TRANSACTION, data, &reply); | 
 | 60 |     } | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 61 | }; | 
 | 62 |  | 
 | 63 | IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger"); | 
 | 64 |  | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 65 | status_t BnInputFlinger::onTransact( | 
 | 66 |         uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { | 
 | 67 |     switch(code) { | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 68 |     case SET_INPUT_WINDOWS_TRANSACTION: { | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 69 |         CHECK_INTERFACE(IInputFlinger, data, reply); | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 70 |         size_t count = data.readUint32(); | 
 | 71 |         if (count > data.dataSize()) { | 
 | 72 |             return BAD_VALUE; | 
 | 73 |         } | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 74 |         std::vector<InputWindowInfo> handles; | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 75 |         for (size_t i = 0; i < count; i++) { | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 76 |             handles.push_back(InputWindowInfo::read(data)); | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 77 |         } | 
| chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 78 |         const sp<ISetInputWindowsListener> setInputWindowsListener = | 
 | 79 |                 ISetInputWindowsListener::asInterface(data.readStrongBinder()); | 
 | 80 |         setInputWindows(handles, setInputWindowsListener); | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 81 |         break; | 
 | 82 |     } | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 83 |     case REGISTER_INPUT_CHANNEL_TRANSACTION: { | 
 | 84 |         CHECK_INTERFACE(IInputFlinger, data, reply); | 
| Josh Gao | 2ccbe3a | 2019-08-09 14:35:36 -0700 | [diff] [blame] | 85 |         sp<InputChannel> channel = InputChannel::read(data); | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 86 |         registerInputChannel(channel); | 
 | 87 |         break; | 
 | 88 |     } | 
 | 89 |     case UNREGISTER_INPUT_CHANNEL_TRANSACTION: { | 
 | 90 |         CHECK_INTERFACE(IInputFlinger, data, reply); | 
| Josh Gao | 2ccbe3a | 2019-08-09 14:35:36 -0700 | [diff] [blame] | 91 |         sp<InputChannel> channel = InputChannel::read(data); | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 92 |         unregisterInputChannel(channel); | 
 | 93 |         break; | 
 | 94 |     } | 
| Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 95 |     default: | 
 | 96 |         return BBinder::onTransact(code, data, reply, flags); | 
 | 97 |     } | 
 | 98 |     return NO_ERROR; | 
 | 99 | } | 
 | 100 |  | 
 | 101 | }; |