Make sure BGpio_setValue fails on input.

Setting the value of an input GPIO will fail in the daemon. We need to
make sure the error is propagated to the user and an message is logged.
This is probably a common error. Giving feedback to the developer will
be helpful.

Bug: 28765716

Change-Id: I5e9b20e317d73875431e0e09b4589fc61781a1af
diff --git a/client/gpio_unittest.cc b/client/gpio_unittest.cc
index 4b1ada2..f5b54bc 100644
--- a/client/gpio_unittest.cc
+++ b/client/gpio_unittest.cc
@@ -103,6 +103,9 @@
   int value;
   EXPECT_EQ(0, BGpio_getValue(gpio, &value));
 
+  // Setting the value returns an error.
+  EXPECT_EQ(EREMOTEIO, BGpio_setValue(gpio, 1));
+
   // Can set the edge type. If the type is unknown, we fail.
   EXPECT_EQ(0, BGpio_setEdgeTriggerType(gpio, RISING_EDGE));
   EXPECT_EQ(EINVAL, BGpio_setEdgeTriggerType(gpio, -1));
diff --git a/daemon/gpio_driver_mock.h b/daemon/gpio_driver_mock.h
index 4c52f4c..d8e279c 100644
--- a/daemon/gpio_driver_mock.h
+++ b/daemon/gpio_driver_mock.h
@@ -28,21 +28,28 @@
 
 class GpioDriverMock : public GpioDriverInterface {
  public:
-  GpioDriverMock(void* arg) {}
+  GpioDriverMock(void* arg) : is_input(true) {}
   ~GpioDriverMock() {}
 
   static std::string Compat() { return "GPIOSYSFS"; }
 
   bool Init(uint32_t index) { return true; }
 
-  bool SetValue(bool val) { return true; };
+  bool SetValue(bool val) { return !is_input; };
+
   bool GetValue(bool* val) { return true; };
   bool SetActiveType(GpioActiveType type) { return true; };
-  bool SetDirection(GpioDirection direction) { return true; };
+
+  bool SetDirection(GpioDirection direction) {
+    is_input = direction == kDirectionIn;
+    return true;
+  };
+
   bool SetEdgeType(GpioEdgeType type) { return true; };
   bool GetPollingFd(::android::base::unique_fd* fd) { return true; };
 
  private:
+  bool is_input;
   DISALLOW_COPY_AND_ASSIGN(GpioDriverMock);
 };
 
diff --git a/daemon/gpio_driver_sysfs.cc b/daemon/gpio_driver_sysfs.cc
index f1b75b0..b49c2ff 100644
--- a/daemon/gpio_driver_sysfs.cc
+++ b/daemon/gpio_driver_sysfs.cc
@@ -88,10 +88,12 @@
 }
 
 bool GpioDriverSysfs::SetValue(bool val) {
-  if (val)
-    return Enable();
-  else
-    return Disable();
+  bool success = val ? Enable() : Disable();
+  if (!success) {
+    LOG(WARNING) << "Failed to set the value of the GPIO. Is it configured as "
+                 << "output?";
+  }
+  return success;
 }
 
 bool GpioDriverSysfs::GetValue(bool* val) {