Replace ScopedFd with unique_fd

aidl-cpp will generate code using unique_fd in the near future.

While here, also make the binder intermediates library depend on
libbinder in order to obtain proper header include paths.

Bug: 27804373
Test: Compiles with accompanying changes.

Change-Id: I6098e63f179ac81096fa4775cc11e59e87a962c9
diff --git a/client/gpio_impl.cc b/client/gpio_impl.cc
index cf57613..dfe5f83 100644
--- a/client/gpio_impl.cc
+++ b/client/gpio_impl.cc
@@ -16,6 +16,7 @@
 
 #include "gpio_impl.h"
 
+#include <android-base/unique_fd.h>
 #include <binder/Status.h>
 
 #include "peripheralmanager/constants.h"
@@ -105,7 +106,7 @@
 }
 
 int GpioImpl::GetPollingFd(int* fd) {
-  ScopedFd scoped_fd;
+  android::base::unique_fd scoped_fd;
   Status ret = client_->GetGpioPollingFd(name_, &scoped_fd);
   if (ret.isOk()) {
     uint8_t buf[2];
diff --git a/daemon/gpio_driver.h b/daemon/gpio_driver.h
index f157ffc..20dcbb1 100644
--- a/daemon/gpio_driver.h
+++ b/daemon/gpio_driver.h
@@ -22,8 +22,8 @@
 #include <memory>
 #include <string>
 
+#include <android-base/unique_fd.h>
 #include <base/macros.h>
-#include <nativehelper/ScopedFd.h>
 #include <peripheralmanager/constants.h>
 
 namespace android {
@@ -43,7 +43,7 @@
   virtual bool SetActiveType(GpioActiveType type) = 0;
   virtual bool SetDirection(GpioDirection direction) = 0;
   virtual bool SetEdgeType(GpioEdgeType type) = 0;
-  virtual bool GetPollingFd(ScopedFd* fd) = 0;
+  virtual bool GetPollingFd(::android::base::unique_fd* fd) = 0;
 };
 
 // The following is driver boilerplate.
diff --git a/daemon/gpio_driver_mock.h b/daemon/gpio_driver_mock.h
index 0025325..4c52f4c 100644
--- a/daemon/gpio_driver_mock.h
+++ b/daemon/gpio_driver_mock.h
@@ -40,7 +40,7 @@
   bool SetActiveType(GpioActiveType type) { return true; };
   bool SetDirection(GpioDirection direction) { return true; };
   bool SetEdgeType(GpioEdgeType type) { return true; };
-  bool GetPollingFd(ScopedFd* fd) { return true; };
+  bool GetPollingFd(::android::base::unique_fd* fd) { return true; };
 
  private:
   DISALLOW_COPY_AND_ASSIGN(GpioDriverMock);
diff --git a/daemon/gpio_driver_sysfs.cc b/daemon/gpio_driver_sysfs.cc
index 683cb94..f1b75b0 100644
--- a/daemon/gpio_driver_sysfs.cc
+++ b/daemon/gpio_driver_sysfs.cc
@@ -145,7 +145,7 @@
   return false;
 }
 
-bool GpioDriverSysfs::GetPollingFd(ScopedFd* fd) {
+bool GpioDriverSysfs::GetPollingFd(::android::base::unique_fd* fd) {
   int f = openat(fd_, kValue, O_RDWR);
   if (f < 0)
     return false;
diff --git a/daemon/gpio_driver_sysfs.h b/daemon/gpio_driver_sysfs.h
index 1fbe2d1..21e33af 100644
--- a/daemon/gpio_driver_sysfs.h
+++ b/daemon/gpio_driver_sysfs.h
@@ -40,7 +40,7 @@
   bool SetActiveType(GpioActiveType type) override;
   bool SetDirection(GpioDirection direction) override;
   bool SetEdgeType(GpioEdgeType type) override;
-  bool GetPollingFd(ScopedFd* fd) override;
+  bool GetPollingFd(::android::base::unique_fd* fd) override;
 
  private:
   bool Enable();
diff --git a/daemon/gpio_manager.h b/daemon/gpio_manager.h
index a72431a..c691f26 100644
--- a/daemon/gpio_manager.h
+++ b/daemon/gpio_manager.h
@@ -74,7 +74,7 @@
     return pin_->driver_->SetEdgeType(type);
   }
 
-  bool GetPollingFd(ScopedFd* fd) {
+  bool GetPollingFd(::android::base::unique_fd* fd) {
     return pin_->driver_->GetPollingFd(fd);
   }
 
diff --git a/daemon/peripheral_manager_client.cc b/daemon/peripheral_manager_client.cc
index d279a9f..82cc068 100644
--- a/daemon/peripheral_manager_client.cc
+++ b/daemon/peripheral_manager_client.cc
@@ -101,8 +101,9 @@
   return Status::fromServiceSpecificError(EREMOTEIO);
 }
 
-Status PeripheralManagerClient::GetGpioPollingFd(const std::string& name,
-                                                 ScopedFd* fd) {
+Status PeripheralManagerClient::GetGpioPollingFd(
+    const std::string& name,
+    ::android::base::unique_fd* fd) {
   if (!gpios_.count(name))
     return Status::fromServiceSpecificError(EPERM);
 
diff --git a/daemon/peripheral_manager_client.h b/daemon/peripheral_manager_client.h
index 23d15c7..4c24398 100644
--- a/daemon/peripheral_manager_client.h
+++ b/daemon/peripheral_manager_client.h
@@ -60,7 +60,7 @@
   virtual Status GetGpioValue(const std::string& name, bool* value) override;
 
   virtual Status GetGpioPollingFd(const std::string& name,
-                                  ScopedFd* fd) override;
+                                  ::android::base::unique_fd* fd) override;
 
   virtual Status ListSpiBuses(std::vector<std::string>* buses) override;
 
diff --git a/ipc/Android.mk b/ipc/Android.mk
index 949482a..ce77290 100644
--- a/ipc/Android.mk
+++ b/ipc/Android.mk
@@ -23,6 +23,8 @@
   android/os/IPeripheralManagerClient.aidl \
   android/os/IPeripheralManager.aidl \
 
+LOCAL_SHARED_LIBRARIES := libbinder
+
 LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)
 
 include $(BUILD_STATIC_LIBRARY)