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 26 namespace android { 27 28 class BpInputFlinger : public BpInterface<IInputFlinger> { 29 public: 30 explicit BpInputFlinger(const sp<IBinder>& impl) : 31 BpInterface<IInputFlinger>(impl) { } 32 33 virtual void setInputWindows(const std::vector<InputWindowInfo>& inputInfo, 34 const sp<ISetInputWindowsListener>& setInputWindowsListener) { 35 Parcel data, reply; 36 data.writeInterfaceToken(IInputFlinger::getInterfaceDescriptor()); 37 38 data.writeUint32(static_cast<uint32_t>(inputInfo.size())); 39 for (const auto& info : inputInfo) { 40 info.write(data); 41 } 42 data.writeStrongBinder(IInterface::asBinder(setInputWindowsListener)); 43 44 remote()->transact(BnInputFlinger::SET_INPUT_WINDOWS_TRANSACTION, data, &reply, 45 IBinder::FLAG_ONEWAY); 46 } 47 48 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 58 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 } 71 }; 72 73 IMPLEMENT_META_INTERFACE(InputFlinger, "android.input.IInputFlinger"); 74 75 status_t BnInputFlinger::onTransact( 76 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { 77 switch(code) { 78 case SET_INPUT_WINDOWS_TRANSACTION: { 79 CHECK_INTERFACE(IInputFlinger, data, reply); 80 size_t count = data.readUint32(); 81 if (count > data.dataSize()) { 82 return BAD_VALUE; 83 } 84 std::vector<InputWindowInfo> handles; 85 for (size_t i = 0; i < count; i++) { 86 handles.push_back(InputWindowInfo::read(data)); 87 } 88 const sp<ISetInputWindowsListener> setInputWindowsListener = 89 ISetInputWindowsListener::asInterface(data.readStrongBinder()); 90 setInputWindows(handles, setInputWindowsListener); 91 break; 92 } 93 case REGISTER_INPUT_CHANNEL_TRANSACTION: { 94 CHECK_INTERFACE(IInputFlinger, data, reply); 95 sp<InputChannel> channel = new InputChannel(); 96 channel->read(data); 97 registerInputChannel(channel); 98 break; 99 } 100 case UNREGISTER_INPUT_CHANNEL_TRANSACTION: { 101 CHECK_INTERFACE(IInputFlinger, data, reply); 102 sp<InputChannel> channel = new InputChannel(); 103 channel->read(data); 104 unregisterInputChannel(channel); 105 break; 106 } 107 case TRANSFER_TOUCH_FOCUS: { 108 CHECK_INTERFACE(IInputFlinger, data, reply); 109 sp<IBinder> fromToken = data.readStrongBinder(); 110 sp<IBinder> toToken = data.readStrongBinder(); 111 transferTouchFocus(fromToken, toToken); 112 break; 113 } 114 default: 115 return BBinder::onTransact(code, data, reply, flags); 116 } 117 return NO_ERROR; 118 } 119 120 }; 121