Remove D-Bus API from ledservice and replace with Binder

The hardware access service of ledflasher (ledservice) used to expose
D-Bus API to ledflasher daemon to get low level access to on-board LEDs.

We are moving away from D-Bus in favor of Binder, so replace the RPC
to use binder now.

BUG: 26404046
Change-Id: Ib0ff50868e33a3be3a4dc6cdf92d92f5b4c80287
diff --git a/sepolicy/ledflasher.te b/sepolicy/ledflasher.te
index 9a3f2c9..8ed97b0 100644
--- a/sepolicy/ledflasher.te
+++ b/sepolicy/ledflasher.te
@@ -5,3 +5,6 @@
 brillo_domain(ledflasher)
 allow_crash_reporter(ledflasher)
 allow_weave_service(ledflasher)
+
+allow ledflasher example_led_service:service_manager find;
+binder_call(ledflasher, ledservice)
diff --git a/sepolicy/ledservice.te b/sepolicy/ledservice.te
index 6afd94e..2e78cde 100644
--- a/sepolicy/ledservice.te
+++ b/sepolicy/ledservice.te
@@ -8,3 +8,4 @@
 allow ledservice sysfs:dir r_dir_perms;
 allow ledservice sysfs:file rw_file_perms;
 allow ledservice sysfs:lnk_file read;
+allow ledservice example_led_service:service_manager { add find };
diff --git a/sepolicy/service.te b/sepolicy/service.te
new file mode 100644
index 0000000..8dd5422
--- /dev/null
+++ b/sepolicy/service.te
@@ -0,0 +1 @@
+type example_led_service, service_manager_type;
diff --git a/sepolicy/service_contexts b/sepolicy/service_contexts
new file mode 100644
index 0000000..854104d
--- /dev/null
+++ b/sepolicy/service_contexts
@@ -0,0 +1 @@
+example_led_service u:object_r:example_led_service:s0
diff --git a/src/common/Android.mk b/src/common/Android.mk
new file mode 100644
index 0000000..2721cd6
--- /dev/null
+++ b/src/common/Android.mk
@@ -0,0 +1,26 @@
+# Copyright 2015 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libledservice-common
+LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+
+LOCAL_SRC_FILES := \
+	aidl/brillo/examples/ledflasher/ILEDService.aidl \
+	binder_constants.cpp \
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/src/common/aidl/brillo/examples/ledflasher/ILEDService.aidl b/src/common/aidl/brillo/examples/ledflasher/ILEDService.aidl
new file mode 100644
index 0000000..5ec561b
--- /dev/null
+++ b/src/common/aidl/brillo/examples/ledflasher/ILEDService.aidl
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+package brillo.examples.ledflasher;
+
+interface ILEDService {
+  void setLED(int ledIndex, boolean on);
+  boolean getLED(int ledIndex);
+  boolean[] getAllLEDs();
+}
diff --git a/src/common/binder_constants.cpp b/src/common/binder_constants.cpp
new file mode 100644
index 0000000..3022842
--- /dev/null
+++ b/src/common/binder_constants.cpp
@@ -0,0 +1,21 @@
+// Copyright 2015 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.
+
+#include "binder_constants.h"
+
+namespace ledservice {
+
+const char kBinderServiceName[] = "example_led_service";
+
+}  // namespace led_service
diff --git a/src/common/binder_constants.h b/src/common/binder_constants.h
new file mode 100644
index 0000000..1691c76
--- /dev/null
+++ b/src/common/binder_constants.h
@@ -0,0 +1,24 @@
+// Copyright 2015 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 LEDFLASHER_COMMON_BINDER_CONSTANTS_H_
+#define LEDFLASHER_COMMON_BINDER_CONSTANTS_H_
+
+namespace ledservice {
+
+extern const char kBinderServiceName[];
+
+}  // namespace led_service
+
+#endif  // LEDFLASHER_COMMON_BINDER_CONSTANTS_H_
diff --git a/src/ledflasher/Android.mk b/src/ledflasher/Android.mk
index 8c21934..c385423 100644
--- a/src/ledflasher/Android.mk
+++ b/src/ledflasher/Android.mk
@@ -27,6 +27,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libbinder \
+	libbinderwrapper \
 	libbrillo \
 	libbrillo-binder \
 	libbrillo-dbus \
@@ -34,11 +35,14 @@
 	libchrome \
 	libchrome-dbus \
 	libdbus \
-	libledservice-client \
+	libutils \
 	libweaved \
 
+LOCAL_STATIC_LIBRARIES := \
+	libledservice-common \
+
 LOCAL_C_INCLUDES := external/gtest/include
-LOCAL_CFLAGS := -Wall -Werror -Wno-sign-promo -Wno-error=unused-parameter
+LOCAL_CFLAGS := -Wall -Werror
 LOCAL_CLANG := true
 
 include $(BUILD_EXECUTABLE)
diff --git a/src/ledflasher/animation.cpp b/src/ledflasher/animation.cpp
index dbc891d..f58c8e9 100644
--- a/src/ledflasher/animation.cpp
+++ b/src/ledflasher/animation.cpp
@@ -22,9 +22,9 @@
 #include <base/message_loop/message_loop.h>
 
 Animation::Animation(
-    com::android::LEDService::ServiceProxyInterface* service_proxy,
+    android::sp<brillo::examples::ledflasher::ILEDService> led_service,
     const base::TimeDelta& step_duration)
-  : service_proxy_{service_proxy}, step_duration_{step_duration} {
+  : led_service_{led_service}, step_duration_{step_duration} {
 }
 
 void Animation::Start() {
@@ -41,12 +41,12 @@
 
 bool Animation::GetLED(size_t index) const {
   bool on = false;
-  service_proxy_->GetLED(index, &on, nullptr);
+  led_service_->getLED(index, &on);
   return on;
 }
 
 void Animation::SetLED(size_t index, bool on) {
-  service_proxy_->SetLED(index, on, nullptr);
+  led_service_->setLED(index, on);
 }
 
 void Animation::SetAllLEDs(bool on) {
@@ -55,17 +55,17 @@
 }
 
 std::unique_ptr<Animation> Animation::Create(
-    com::android::LEDService::ServiceProxyInterface* service_proxy,
+    android::sp<brillo::examples::ledflasher::ILEDService> led_service,
     const std::string& type,
     const base::TimeDelta& duration) {
   std::unique_ptr<Animation> animation;
   if (type == "blink") {
-    animation.reset(new AnimationBlink{service_proxy, duration});
+    animation.reset(new AnimationBlink{led_service, duration});
   } else if (type == "marquee_left") {
-    animation.reset(new AnimationMarquee{service_proxy, duration,
+    animation.reset(new AnimationMarquee{led_service, duration,
                                          AnimationMarquee::Direction::Left});
   } else if (type == "marquee_right") {
-    animation.reset(new AnimationMarquee{service_proxy, duration,
+    animation.reset(new AnimationMarquee{led_service, duration,
                                          AnimationMarquee::Direction::Right});
   }
   return animation;
diff --git a/src/ledflasher/animation.h b/src/ledflasher/animation.h
index 6df53c1..0627f16 100644
--- a/src/ledflasher/animation.h
+++ b/src/ledflasher/animation.h
@@ -23,11 +23,11 @@
 #include <base/time/time.h>
 #include <base/memory/weak_ptr.h>
 
-#include "ledservice/dbus-proxies.h"
+#include "brillo/examples/ledflasher/ILEDService.h"
 
 class Animation {
  public:
-  Animation(com::android::LEDService::ServiceProxyInterface* service_proxy,
+  Animation(android::sp<brillo::examples::ledflasher::ILEDService> led_service,
             const base::TimeDelta& step_duration);
   virtual ~Animation() = default;
 
@@ -35,7 +35,7 @@
   void Stop();
 
   static std::unique_ptr<Animation> Create(
-      com::android::LEDService::ServiceProxyInterface* service_proxy,
+      android::sp<brillo::examples::ledflasher::ILEDService> led_service,
       const std::string& type,
       const base::TimeDelta& duration);
 
@@ -49,7 +49,7 @@
   void SetAllLEDs(bool on);
 
  private:
-  com::android::LEDService::ServiceProxyInterface* service_proxy_;
+  android::sp<brillo::examples::ledflasher::ILEDService> led_service_;
   base::TimeDelta step_duration_;
 
   base::WeakPtrFactory<Animation> weak_ptr_factory_{this};
diff --git a/src/ledflasher/animation_blink.cpp b/src/ledflasher/animation_blink.cpp
index 5bf0978..1cd3fac 100644
--- a/src/ledflasher/animation_blink.cpp
+++ b/src/ledflasher/animation_blink.cpp
@@ -17,8 +17,8 @@
 #include "animation_blink.h"
 
 AnimationBlink::AnimationBlink(
-    com::android::LEDService::ServiceProxyInterface* service_proxy,
-    const base::TimeDelta& duration) : Animation{service_proxy, duration / 2} {
+    android::sp<brillo::examples::ledflasher::ILEDService> led_service,
+    const base::TimeDelta& duration) : Animation{led_service, duration / 2} {
 }
 
 void AnimationBlink::DoAnimationStep() {
diff --git a/src/ledflasher/animation_blink.h b/src/ledflasher/animation_blink.h
index c7ee1b8..28058d4 100644
--- a/src/ledflasher/animation_blink.h
+++ b/src/ledflasher/animation_blink.h
@@ -21,8 +21,9 @@
 
 class AnimationBlink : public Animation {
  public:
-  AnimationBlink(com::android::LEDService::ServiceProxyInterface* service_proxy,
-                 const base::TimeDelta& duration);
+  AnimationBlink(
+      android::sp<brillo::examples::ledflasher::ILEDService> led_service,
+      const base::TimeDelta& duration);
 
  protected:
   void DoAnimationStep() override;
diff --git a/src/ledflasher/animation_marquee.cpp b/src/ledflasher/animation_marquee.cpp
index b2ad1e1..77df265 100644
--- a/src/ledflasher/animation_marquee.cpp
+++ b/src/ledflasher/animation_marquee.cpp
@@ -17,10 +17,10 @@
 #include "animation_marquee.h"
 
 AnimationMarquee::AnimationMarquee(
-    com::android::LEDService::ServiceProxyInterface* service_proxy,
+    android::sp<brillo::examples::ledflasher::ILEDService> led_service,
     const base::TimeDelta& duration,
     Direction direction)
-  : Animation{service_proxy, duration / num_leds}, direction_{direction} {
+  : Animation{led_service, duration / num_leds}, direction_{direction} {
 }
 
 void AnimationMarquee::DoAnimationStep() {
diff --git a/src/ledflasher/animation_marquee.h b/src/ledflasher/animation_marquee.h
index a31382b..a3d2207 100644
--- a/src/ledflasher/animation_marquee.h
+++ b/src/ledflasher/animation_marquee.h
@@ -24,7 +24,7 @@
   enum class Direction {Left, Right};
 
   AnimationMarquee(
-      com::android::LEDService::ServiceProxyInterface* service_proxy,
+      android::sp<brillo::examples::ledflasher::ILEDService> led_service,
       const base::TimeDelta& duration,
       Direction direction);
 
diff --git a/src/ledflasher/ledflasher.cpp b/src/ledflasher/ledflasher.cpp
index fb46bcf..55c0f5a 100644
--- a/src/ledflasher/ledflasher.cpp
+++ b/src/ledflasher/ledflasher.cpp
@@ -21,21 +21,23 @@
 #include <base/command_line.h>
 #include <base/macros.h>
 #include <base/memory/weak_ptr.h>
+#include <binderwrapper/binder_wrapper.h>
 #include <brillo/binder_watcher.h>
-#include <brillo/daemons/dbus_daemon.h>
+#include <brillo/daemons/daemon.h>
 #include <brillo/syslog_logging.h>
 #include <libweaved/service.h>
 
 #include "animation.h"
-#include "ledservice/dbus-proxies.h"
-
-using com::android::LEDService::ServiceProxyInterface;
+#include "binder_constants.h"
+#include "brillo/examples/ledflasher/ILEDService.h"
 
 namespace {
 const char kWeaveComponent[] = "ledflasher";
 }  // anonymous namespace
 
-class Daemon final : public brillo::DBusDaemon {
+using brillo::examples::ledflasher::ILEDService;
+
+class Daemon final : public brillo::Daemon {
  public:
   Daemon() = default;
 
@@ -44,8 +46,8 @@
 
  private:
   void OnWeaveServiceConnected(const std::weak_ptr<weaved::Service>& service);
-  void OnLEDServiceConnected(ServiceProxyInterface* service);
-  void OnLEDServiceDisconnected(const dbus::ObjectPath& object_path);
+  void ConnectToLEDService();
+  void OnLEDServiceDisconnected();
 
   // Particular command handlers for various commands.
   void OnSet(std::unique_ptr<weaved::Command> command);
@@ -56,16 +58,13 @@
   // the cloud server or local clients.
   void UpdateDeviceState();
 
-  std::weak_ptr<weaved::Service> service_;
-
-  // LEDService's D-Bus object manager.
-  std::unique_ptr<com::android::LEDService::ObjectManagerProxy> led_object_mgr_;
+  std::weak_ptr<weaved::Service> weave_service_;
 
   // Device state variables.
   std::string status_{"idle"};
 
   // LED service interface.
-  ServiceProxyInterface* led_service_{nullptr};
+  android::sp<ILEDService> led_service_;
 
   // Current animation;
   std::unique_ptr<Animation> animation_;
@@ -78,10 +77,11 @@
 };
 
 int Daemon::OnInit() {
-  int return_code = brillo::DBusDaemon::OnInit();
+  int return_code = brillo::Daemon::OnInit();
   if (return_code != EX_OK)
     return return_code;
 
+  android::BinderWrapper::Create();
   if (!binder_watcher_.Init())
     return EX_OSERR;
 
@@ -89,12 +89,7 @@
       brillo::MessageLoop::current(),
       base::Bind(&Daemon::OnWeaveServiceConnected,
                  weak_ptr_factory_.GetWeakPtr()));
-
-  led_object_mgr_.reset(new com::android::LEDService::ObjectManagerProxy{bus_});
-  led_object_mgr_->SetServiceAddedCallback(
-      base::Bind(&Daemon::OnLEDServiceConnected, base::Unretained(this)));
-  led_object_mgr_->SetServiceRemovedCallback(
-      base::Bind(&Daemon::OnLEDServiceDisconnected, base::Unretained(this)));
+  ConnectToLEDService();
 
   LOG(INFO) << "Waiting for commands...";
   return EX_OK;
@@ -103,8 +98,8 @@
 void Daemon::OnWeaveServiceConnected(
     const std::weak_ptr<weaved::Service>& service) {
   LOG(INFO) << "Daemon::OnWeaveServiceConnected";
-  service_ = service;
-  auto weave_service = service.lock();
+  weave_service_ = service;
+  auto weave_service = weave_service_.lock();
   if (!weave_service)
     return;
 
@@ -125,31 +120,46 @@
   UpdateDeviceState();
 }
 
-void Daemon::OnLEDServiceConnected(ServiceProxyInterface* service) {
-  led_service_ = service;
+void Daemon::ConnectToLEDService() {
+  android::BinderWrapper* binder_wrapper = android::BinderWrapper::Get();
+  auto binder = binder_wrapper->GetService(ledservice::kBinderServiceName);
+  if (!binder.get()) {
+    brillo::MessageLoop::current()->PostDelayedTask(
+        base::Bind(&Daemon::ConnectToLEDService,
+                   weak_ptr_factory_.GetWeakPtr()),
+        base::TimeDelta::FromSeconds(1));
+    return;
+  }
+  binder_wrapper->RegisterForDeathNotifications(
+      binder,
+      base::Bind(&Daemon::OnLEDServiceDisconnected,
+                 weak_ptr_factory_.GetWeakPtr()));
+  led_service_ = android::interface_cast<ILEDService>(binder);
   UpdateDeviceState();
 }
 
-void Daemon::OnLEDServiceDisconnected(const dbus::ObjectPath& /*object_path*/) {
+void Daemon::OnLEDServiceDisconnected() {
   animation_.reset();
   led_service_ = nullptr;
+  ConnectToLEDService();
 }
 
 void Daemon::OnSet(std::unique_ptr<weaved::Command> command) {
-  if (!led_service_) {
-    command->Abort("system_error", "ledservice unavailable", nullptr);
+  if (!led_service_.get()) {
+    command->Abort("_system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   int index = command->GetParameter<int>("led");
   if(index < 1 || index > 4) {
-    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    command->Abort("_invalid_parameter", "Invalid parameter value", nullptr);
     return;
   }
   bool on = command->GetParameter<bool>("on");
-  brillo::ErrorPtr error;
-  if (!led_service_->SetLED(index - 1, on, &error)) {
-    command->Abort(error->GetCode(), error->GetMessage(), nullptr);
+  android::binder::Status status = led_service_->setLED(index - 1, on);
+  if (!status.isOk()) {
+    command->Abort("_system_error", status.exceptionMessage().string(),
+                   nullptr);
     return;
   }
   animation_.reset();
@@ -159,22 +169,24 @@
 }
 
 void Daemon::OnToggle(std::unique_ptr<weaved::Command> command) {
-  if (!led_service_) {
-    command->Abort("system_error", "ledservice unavailable", nullptr);
+  if (!led_service_.get()) {
+    command->Abort("_system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   int index = command->GetParameter<int>("led");
   if(index < 1 || index > 4) {
-    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    command->Abort("_invalid_parameter", "Invalid parameter value", nullptr);
     return;
   }
   index--;
   bool on = false;
-  brillo::ErrorPtr error;
-  if(!led_service_->GetLED(index, &on, &error) ||
-     !led_service_->SetLED(index, !on, &error)) {
-    command->Abort(error->GetCode(), error->GetMessage(), nullptr);
+  android::binder::Status status = led_service_->getLED(index, &on);
+  if (status.isOk())
+    status = led_service_->setLED(index, !on);
+  if(!status.isOk()) {
+    command->Abort("_system_error", status.exceptionMessage().string(),
+                   nullptr);
     return;
   }
   animation_.reset();
@@ -184,14 +196,14 @@
 }
 
 void Daemon::OnAnimate(std::unique_ptr<weaved::Command> command) {
-  if (!led_service_) {
-    command->Abort("system_error", "ledservice unavailable", nullptr);
+  if (!led_service_.get()) {
+    command->Abort("_system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   double duration = command->GetParameter<double>("duration");
   if(duration <= 0.0) {
-    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    command->Abort("_invalid_parameter", "Invalid parameter value", nullptr);
     return;
   }
   std::string type = command->GetParameter<std::string>("type");
@@ -208,14 +220,14 @@
 }
 
 void Daemon::UpdateDeviceState() {
-  if (!led_service_)
+  if (!led_service_.get())
     return;
 
   std::vector<bool> leds;
-  if (!led_service_->GetAllLEDs(&leds, nullptr))
+  if (!led_service_->getAllLEDs(&leds).isOk())
     return;
 
-  auto weave_service = service_.lock();
+  auto weave_service = weave_service_.lock();
   if (!weave_service)
     return;
 
diff --git a/src/ledservice/Android.mk b/src/ledservice/Android.mk
index e263399..2844817 100644
--- a/src/ledservice/Android.mk
+++ b/src/ledservice/Android.mk
@@ -19,46 +19,24 @@
 LOCAL_INIT_RC := ledservice.rc
 
 LOCAL_SRC_FILES := \
-	dbus_bindings/dbus-service-config.json \
-	dbus_bindings/com.android.LEDService.Service.dbus-xml \
-	dbus_service.cpp \
 	ledservice.cpp \
 	ledstatus.cpp \
 
 LOCAL_SHARED_LIBRARIES := \
+	libbinder \
+	libbinderwrapper \
 	libbrillo \
-	libbrillo-dbus \
+	libbrillo-binder \
 	libbrillo-stream \
 	libchrome \
-	libchrome-dbus \
-	libdbus \
 	libhardware \
 	libutils \
 
+LOCAL_STATIC_LIBRARIES := \
+	libledservice-common \
+
 LOCAL_CLANG := true
 LOCAL_C_INCLUDES := external/gtest/include
-LOCAL_CFLAGS := \
-        -Wall \
-        -Werror \
-        -Wno-sign-promo \
-        -Wno-missing-field-initializers \
-        -Wno-error=unused-parameter
+LOCAL_CFLAGS := -Wall -Werror
 
 include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libledservice-client
-LOCAL_DBUS_PROXY_PREFIX := ledservice
-
-LOCAL_SRC_FILES := \
-	dbus_bindings/dbus-service-config.json \
-	dbus_bindings/com.android.LEDService.Service.dbus-xml \
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := com.android.LEDService.conf
-LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/dbus-1
-LOCAL_SRC_FILES := etc/dbus-1/com.android.LEDService.conf
-include $(BUILD_PREBUILT)
diff --git a/src/ledservice/dbus_bindings/com.android.LEDService.Service.dbus-xml b/src/ledservice/dbus_bindings/com.android.LEDService.Service.dbus-xml
deleted file mode 100644
index 4924bf8..0000000
--- a/src/ledservice/dbus_bindings/com.android.LEDService.Service.dbus-xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/com/android/LEDService/Service"
-      xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
-  <interface name="com.android.LEDService.Service">
-    <method name="SetLED">
-      <arg name="led" type="i" direction="in"/>
-      <arg name="on" type="b" direction="in"/>
-      <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
-    </method>
-    <method name="GetLED">
-      <arg name="led" type="i" direction="in"/>
-      <arg name="on" type="b" direction="out"/>
-      <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
-    </method>
-    <method name="GetAllLEDs">
-      <arg name="on" type="ab" direction="out"/>
-      <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
-    </method>
-  </interface>
-</node>
diff --git a/src/ledservice/dbus_bindings/dbus-service-config.json b/src/ledservice/dbus_bindings/dbus-service-config.json
deleted file mode 100644
index 7337275..0000000
--- a/src/ledservice/dbus_bindings/dbus-service-config.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-  "service_name": "com.android.LEDService",
-  "object_manager": {
-    "name": "com.android.LEDService.ObjectManager",
-    "object_path": "/com/android/LEDService"
-  }
-}
diff --git a/src/ledservice/dbus_service.cpp b/src/ledservice/dbus_service.cpp
deleted file mode 100644
index 5e9aad8..0000000
--- a/src/ledservice/dbus_service.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2015 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.
- */
-
-#include "dbus_service.h"
-
-DBusService::DBusService(
-    brillo::dbus_utils::ExportedObjectManager* object_manager)
-    : dbus_object_(object_manager, object_manager->GetBus(),
-                   com::android::LEDService::ServiceAdaptor::GetObjectPath()) {
-}
-
-void DBusService::Start(brillo::dbus_utils::AsyncEventSequencer* sequencer) {
-  dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
-  dbus_object_.RegisterAsync(
-      sequencer->GetHandler("DBusService::Start failed", true));
-}
-
-void DBusService::SetLED(int32_t led, bool on) {
-  leds_.SetLedStatus(led, on);
-}
-
-bool DBusService::GetLED(int32_t led) {
-  return leds_.IsLedOn(led);
-}
-
-std::vector<bool> DBusService::GetAllLEDs() {
-  return leds_.GetStatus();
-}
diff --git a/src/ledservice/dbus_service.h b/src/ledservice/dbus_service.h
deleted file mode 100644
index 6151192..0000000
--- a/src/ledservice/dbus_service.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2015 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 LEDFLASHER_SRC_LEDSERVICE_DBUS_SERVICE_H_
-#define LEDFLASHER_SRC_LEDSERVICE_DBUS_SERVICE_H_
-
-#include <vector>
-
-#include <base/macros.h>
-
-#include "dbus_bindings/com.android.LEDService.Service.h"
-#include "ledstatus.h"
-
-class DBusService final : public com::android::LEDService::ServiceInterface {
- public:
-  explicit DBusService(
-      brillo::dbus_utils::ExportedObjectManager* object_manager);
-
-  void Start(brillo::dbus_utils::AsyncEventSequencer* sequencer);
-
- private:
-  void SetLED(int32_t led, bool on) override;
-  bool GetLED(int32_t led) override;
-  std::vector<bool> GetAllLEDs() override;
-
-  com::android::LEDService::ServiceAdaptor dbus_adaptor_{this};
-  brillo::dbus_utils::DBusObject dbus_object_;
-  LedStatus leds_;
-
-  DISALLOW_COPY_AND_ASSIGN(DBusService);
-};
-
-#endif  // LEDFLASHER_SRC_LEDSERVICE_DBUS_SERVICE_H_
diff --git a/src/ledservice/etc/dbus-1/com.android.LEDService.conf b/src/ledservice/etc/dbus-1/com.android.LEDService.conf
deleted file mode 100644
index 85a54c8..0000000
--- a/src/ledservice/etc/dbus-1/com.android.LEDService.conf
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE busconfig PUBLIC
- "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-  <policy user="root">
-    <allow send_destination="com.android.LEDService" />
-  </policy>
-
-  <policy group="ledservice">
-    <allow send_destination="com.android.LEDService" />
-  </policy>
-
-  <policy user="ledservice">
-    <allow own="com.android.LEDService" />
-  </policy>
-</busconfig>
diff --git a/src/ledservice/ledservice.cpp b/src/ledservice/ledservice.cpp
index 894820f..cdc2924 100644
--- a/src/ledservice/ledservice.cpp
+++ b/src/ledservice/ledservice.cpp
@@ -20,32 +20,56 @@
 #include <base/bind.h>
 #include <base/command_line.h>
 #include <base/macros.h>
-#include <brillo/daemons/dbus_daemon.h>
+#include <binderwrapper/binder_wrapper.h>
+#include <brillo/binder_watcher.h>
+#include <brillo/daemons/daemon.h>
 #include <brillo/syslog_logging.h>
 
-#include "dbus_service.h"
+#include "binder_constants.h"
+#include "brillo/examples/ledflasher/BnLEDService.h"
+#include "ledstatus.h"
 
-using brillo::dbus_utils::AsyncEventSequencer;
-
-namespace {
-
-const char kServiceName[] = "com.android.LEDService";
-const char kRootServicePath[] = "/com/android/LEDService";
-
-}  // anonymous namespace
-
-class Daemon final : public brillo::DBusServiceDaemon {
+class LEDService : public brillo::examples::ledflasher::BnLEDService {
  public:
-  Daemon() : DBusServiceDaemon(kServiceName, kRootServicePath) {}
+  android::binder::Status setLED(int32_t ledIndex, bool on) override {
+    leds_.SetLedStatus(ledIndex, on);
+    return android::binder::Status::ok();
+  }
 
- protected:
-  void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override {
-    led_service_.reset(new DBusService{object_manager_.get()});
-    led_service_->Start(sequencer);
+  android::binder::Status getLED(int32_t ledIndex, bool* on) override {
+    *on = leds_.IsLedOn(ledIndex);
+    return android::binder::Status::ok();
+  }
+
+  android::binder::Status getAllLEDs(std::vector<bool>* leds) override {
+    *leds = leds_.GetStatus();
+    return android::binder::Status::ok();
   }
 
  private:
-  std::unique_ptr<DBusService> led_service_;
+  LedStatus leds_;
+};
+
+class Daemon final : public brillo::Daemon {
+ public:
+  Daemon() = default;
+
+ protected:
+  int OnInit() override {
+    android::BinderWrapper::Create();
+    if (!binder_watcher_.Init())
+      return EX_OSERR;
+
+    led_service_ = new LEDService();
+    android::BinderWrapper::Get()->RegisterService(
+        ledservice::kBinderServiceName,
+        led_service_);
+    return brillo::Daemon::OnInit();
+  }
+
+ private:
+  brillo::BinderWatcher binder_watcher_;
+  android::sp<LEDService> led_service_;
 
   DISALLOW_COPY_AND_ASSIGN(Daemon);
 };