AIDL-ize InputManager IInputFlinger interface.
Use AIDL interface to define the IInputFlinger interface and replace
the manual interface.
Bug:155425003
Test: atest libgui_test, atest libinput_test.
Change-Id: Ibad036b8ceb3a3f5c6d58f8de4ea8c79379d29b5
diff --git a/include/input/IInputFlinger.h b/include/input/IInputFlinger.h
deleted file mode 100644
index d23e3b7..0000000
--- a/include/input/IInputFlinger.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _LIBINPUT_IINPUT_FLINGER_H
-#define _LIBINPUT_IINPUT_FLINGER_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/IInterface.h>
-
-#include <input/InputWindow.h>
-#include <input/ISetInputWindowsListener.h>
-
-namespace android {
-
-/*
- * This class defines the Binder IPC interface for accessing various
- * InputFlinger features.
- */
-class IInputFlinger : public IInterface {
-public:
- DECLARE_META_INTERFACE(InputFlinger)
-
- virtual void setInputWindows(const std::vector<InputWindowInfo>& inputHandles,
- const sp<ISetInputWindowsListener>& setInputWindowsListener) = 0;
- virtual void registerInputChannel(const sp<InputChannel>& channel) = 0;
- virtual void unregisterInputChannel(const sp<InputChannel>& channel) = 0;
-};
-
-
-/**
- * Binder implementation.
- */
-class BnInputFlinger : public BnInterface<IInputFlinger> {
-public:
- enum {
- SET_INPUT_WINDOWS_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- REGISTER_INPUT_CHANNEL_TRANSACTION,
- UNREGISTER_INPUT_CHANNEL_TRANSACTION
- };
-
- virtual status_t onTransact(uint32_t code, const Parcel& data,
- Parcel* reply, uint32_t flags = 0);
-};
-
-} // namespace android
-
-#endif // _LIBINPUT_IINPUT_FLINGER_H
diff --git a/include/input/ISetInputWindowsListener.h b/include/input/ISetInputWindowsListener.h
deleted file mode 100644
index 15d31b2..0000000
--- a/include/input/ISetInputWindowsListener.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-
-namespace android {
-
-class ISetInputWindowsListener : public IInterface {
-public:
- DECLARE_META_INTERFACE(SetInputWindowsListener)
- virtual void onSetInputWindowsFinished() = 0;
-};
-
-class BnSetInputWindowsListener: public BnInterface<ISetInputWindowsListener> {
-public:
- enum SetInputWindowsTag : uint32_t {
- ON_SET_INPUT_WINDOWS_FINISHED
- };
-
- virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags = 0) override;
-};
-
-}; // namespace android
diff --git a/include/input/InputApplication.h b/include/input/InputApplication.h
index ccffeb1..b6b9353 100644
--- a/include/input/InputApplication.h
+++ b/include/input/InputApplication.h
@@ -21,6 +21,7 @@
#include <binder/IBinder.h>
#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
#include <input/Input.h>
#include <utils/RefBase.h>
@@ -31,15 +32,17 @@
/*
* Describes the properties of an application that can receive input.
*/
-struct InputApplicationInfo {
+struct InputApplicationInfo : public Parcelable {
sp<IBinder> token;
std::string name;
std::chrono::nanoseconds dispatchingTimeout;
- status_t write(Parcel& output) const;
- static InputApplicationInfo read(const Parcel& from);
-};
+ InputApplicationInfo() = default;
+ status_t readFromParcel(const android::Parcel* parcel) override;
+
+ status_t writeToParcel(android::Parcel* parcel) const override;
+};
/*
* Handle for an application that can receive input.
@@ -76,6 +79,7 @@
* Returns true on success, or false if the handle is no longer valid.
*/
virtual bool updateInfo() = 0;
+
protected:
InputApplicationHandle();
virtual ~InputApplicationHandle();
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 7ca9031..0219cf7 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -34,7 +34,9 @@
#include <android-base/chrono_utils.h>
#include <binder/IBinder.h>
+#include <binder/Parcelable.h>
#include <input/Input.h>
+#include <sys/stat.h>
#include <utils/BitSet.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -174,6 +176,18 @@
void getSanitizedCopy(InputMessage* msg) const;
};
+struct InputChannelInfo : public Parcelable {
+ std::string mName;
+ android::base::unique_fd mFd;
+ sp<IBinder> mToken;
+
+ InputChannelInfo() = default;
+ InputChannelInfo(const std::string& name, android::base::unique_fd fd, sp<IBinder> token)
+ : mName(name), mFd(std::move(fd)), mToken(token){};
+ status_t readFromParcel(const android::Parcel* parcel) override;
+ status_t writeToParcel(android::Parcel* parcel) const override;
+};
+
/*
* An input channel consists of a local unix domain socket used to send and receive
* input messages across processes. Each channel has a descriptive name for debugging purposes.
@@ -183,10 +197,10 @@
* The input channel is closed when all references to it are released.
*/
class InputChannel : public RefBase {
-protected:
+public:
+ InputChannel();
virtual ~InputChannel();
-public:
static sp<InputChannel> create(const std::string& name, android::base::unique_fd fd,
sp<IBinder> token);
@@ -200,8 +214,10 @@
static status_t openInputChannelPair(const std::string& name,
sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);
- inline std::string getName() const { return mName; }
- inline int getFd() const { return mFd.get(); }
+ inline std::string getName() const { return mInfo.mName; }
+ inline int getFd() const { return mInfo.mFd.get(); }
+ inline sp<IBinder> getToken() const { return mInfo.mToken; }
+ inline InputChannelInfo& getInfo() { return mInfo; }
/* Send a message to the other endpoint.
*
@@ -231,8 +247,9 @@
/* Return a new object that has a duplicate of this channel's fd. */
sp<InputChannel> dup() const;
- status_t write(Parcel& out) const;
- static sp<InputChannel> read(const Parcel& from);
+ status_t readFromParcel(const android::Parcel* parcel);
+
+ status_t writeToParcel(android::Parcel* parcel) const;
/**
* The connection token is used to identify the input connection, i.e.
@@ -248,12 +265,23 @@
*/
sp<IBinder> getConnectionToken() const;
+ bool operator==(const InputChannel& inputChannel) const {
+ struct stat lhsInfo, rhsInfo;
+ if (fstat(mInfo.mFd.get(), &lhsInfo) != 0) {
+ return false;
+ }
+ if (fstat(inputChannel.getFd(), &rhsInfo) != 0) {
+ return false;
+ }
+ // If file descriptors are pointing to same inode they are duplicated fds.
+ return inputChannel.getName() == getName() &&
+ inputChannel.getConnectionToken() == mInfo.mToken &&
+ lhsInfo.st_ino == rhsInfo.st_ino;
+ }
+
private:
InputChannel(const std::string& name, android::base::unique_fd fd, sp<IBinder> token);
- std::string mName;
- android::base::unique_fd mFd;
-
- sp<IBinder> mToken;
+ InputChannelInfo mInfo;
};
/*
@@ -325,7 +353,6 @@
status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);
private:
-
sp<InputChannel> mChannel;
};
diff --git a/include/input/InputWindow.h b/include/input/InputWindow.h
index f8c759c..582e73d 100644
--- a/include/input/InputWindow.h
+++ b/include/input/InputWindow.h
@@ -17,6 +17,8 @@
#ifndef _UI_INPUT_WINDOW_H
#define _UI_INPUT_WINDOW_H
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
#include <input/Input.h>
#include <input/InputTransport.h>
#include <ui/Rect.h>
@@ -27,14 +29,12 @@
#include "InputApplication.h"
namespace android {
-class Parcel;
/*
* Describes the properties of a window that can receive input.
*/
-struct InputWindowInfo {
+struct InputWindowInfo : public Parcelable {
InputWindowInfo() = default;
- InputWindowInfo(const Parcel& from);
// Window flags from WindowManager.LayoutParams
enum : uint32_t {
@@ -195,9 +195,11 @@
bool overlaps(const InputWindowInfo* other) const;
- status_t write(Parcel& output) const;
+ bool operator==(const InputWindowInfo& inputChannel) const;
- static InputWindowInfo read(const Parcel& from);
+ status_t writeToParcel(android::Parcel* parcel) const override;
+
+ status_t readFromParcel(const android::Parcel* parcel) override;
};
std::string inputWindowFlagsToString(uint32_t flags);
@@ -210,22 +212,19 @@
*/
class InputWindowHandle : public RefBase {
public:
+ explicit InputWindowHandle();
+ InputWindowHandle(const InputWindowHandle& other);
+ InputWindowHandle(const InputWindowInfo& other);
- inline const InputWindowInfo* getInfo() const {
- return &mInfo;
- }
+ inline const InputWindowInfo* getInfo() const { return &mInfo; }
sp<IBinder> getToken() const;
int32_t getId() const { return mInfo.id; }
- sp<IBinder> getApplicationToken() {
- return mInfo.applicationInfo.token;
- }
+ sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }
- inline std::string getName() const {
- return !mInfo.name.empty() ? mInfo.name : "<invalid>";
- }
+ inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }
inline std::chrono::nanoseconds getDispatchingTimeout(
std::chrono::nanoseconds defaultValue) const {
@@ -235,13 +234,14 @@
/**
* Requests that the state of this object be updated to reflect
* the most current available information about the application.
+ * As this class is created as RefBase object, no pure virtual function is allowed.
*
* This method should only be called from within the input dispatcher's
* critical section.
*
* Returns true on success, or false if the handle is no longer valid.
*/
- virtual bool updateInfo() = 0;
+ virtual bool updateInfo() { return false; }
/**
* Updates from another input window handle.
@@ -254,8 +254,11 @@
*/
void releaseChannel();
+ // Not override since this class is not derrived from Parcelable.
+ status_t readFromParcel(const android::Parcel* parcel);
+ status_t writeToParcel(android::Parcel* parcel) const;
+
protected:
- explicit InputWindowHandle();
virtual ~InputWindowHandle();
InputWindowInfo mInfo;