Use unique_ptr when creating InputChannel
InputChannel api will return unique_ptr, and it is up to the caller to
decide how to use that.
In most cases, the caller will proceed with making is a shared_ptr.
Bug: 142581626
Test: atest libinput_tests inputflinger_tests
Change-Id: Ice473a4c85241c63e3f4d6cdd30f8258ed7485e7
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index f337d00..24f8e77 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -193,7 +193,7 @@
*/
class InputChannel : public Parcelable {
public:
- static std::shared_ptr<InputChannel> create(const std::string& name,
+ static std::unique_ptr<InputChannel> create(const std::string& name,
android::base::unique_fd fd, sp<IBinder> token);
InputChannel() = default;
InputChannel(const InputChannel& other)
@@ -208,8 +208,8 @@
* Return OK on success.
*/
static status_t openInputChannelPair(const std::string& name,
- std::shared_ptr<InputChannel>& outServerChannel,
- std::shared_ptr<InputChannel>& outClientChannel);
+ std::unique_ptr<InputChannel>& outServerChannel,
+ std::unique_ptr<InputChannel>& outClientChannel);
inline std::string getName() const { return mName; }
inline const android::base::unique_fd& getFd() const { return mFd; }
@@ -241,7 +241,7 @@
status_t receiveMessage(InputMessage* msg);
/* Return a new object that has a duplicate of this channel's fd. */
- std::shared_ptr<InputChannel> dup() const;
+ std::unique_ptr<InputChannel> dup() const;
status_t readFromParcel(const android::Parcel* parcel) override;
status_t writeToParcel(android::Parcel* parcel) const override;