InputTransport: store fd in a unique_fd.
Use unique_fd to hold the file descriptor, so that it gets protected
from being closed by someone else by fdsan.
Test: atest libinput_tests inputflinger_tests
Change-Id: I08df199294f9ddd7646c7bcd637b9c035e3c1e12
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 690e0a1..28b8d80 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -42,6 +42,8 @@
#include <utils/Timers.h>
#include <utils/Vector.h>
+#include <android-base/unique_fd.h>
+
namespace android {
class Parcel;
@@ -166,8 +168,7 @@
virtual ~InputChannel();
public:
- InputChannel() = default;
- InputChannel(const std::string& name, int fd);
+ static sp<InputChannel> create(const std::string& name, android::base::unique_fd fd);
/* Creates a pair of input channels.
*
@@ -177,7 +178,7 @@
sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);
inline std::string getName() const { return mName; }
- inline int getFd() const { return mFd; }
+ inline int getFd() const { return mFd.get(); }
/* Sends a message to the other endpoint.
*
@@ -208,16 +209,15 @@
sp<InputChannel> dup() const;
status_t write(Parcel& out) const;
- status_t read(const Parcel& from);
+ static sp<InputChannel> read(const Parcel& from);
sp<IBinder> getToken() const;
void setToken(const sp<IBinder>& token);
private:
- void setFd(int fd);
-
+ InputChannel(const std::string& name, android::base::unique_fd fd);
std::string mName;
- int mFd = -1;
+ android::base::unique_fd mFd;
sp<IBinder> mToken = nullptr;
};