merge in nyc-release history after reset to master
diff --git a/Android.mk b/Android.mk
index 601ba3e..59a9b9b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -177,8 +177,11 @@
 LOCAL_MODULE := libbrillo-binder
 LOCAL_SRC_FILES := $(libbrillo_binder_sources)
 LOCAL_C_INCLUDES := $(libbrillo_includes)
-LOCAL_SHARED_LIBRARIES := $(libbrillo_shared_libraries) \
-    libbinder libutils
+LOCAL_SHARED_LIBRARIES := \
+    $(libbrillo_shared_libraries) \
+    libbinder \
+    libbrillo \
+    libutils
 LOCAL_CFLAGS := $(libbrillo_CFLAGS)
 LOCAL_CPPFLAGS := $(libbrillo_CPPFLAGS)
 LOCAL_CLANG := true
@@ -353,7 +356,7 @@
 LOCAL_MODULE := libbrillo_test
 LOCAL_MODULE_CLASS := EXECUTABLES
 ifdef BRILLO
-  LOCAL_MODULE_TAGS := debug
+  LOCAL_MODULE_TAGS := eng
 endif
 generated_sources_dir := $(call local-generated-sources-dir)
 LOCAL_SRC_FILES := $(libbrillo_test_sources)
diff --git a/brillo/binder_watcher.cc b/brillo/binder_watcher.cc
index 32ab101..9752204 100644
--- a/brillo/binder_watcher.cc
+++ b/brillo/binder_watcher.cc
@@ -16,6 +16,7 @@
 
 #include <brillo/binder_watcher.h>
 
+#include <base/bind.h>
 #include <base/logging.h>
 #include <binder/IPCThreadState.h>
 #include <binder/ProcessState.h>
@@ -23,36 +24,59 @@
 using android::IPCThreadState;
 using android::ProcessState;
 
+namespace {
+// Called from the message loop whenever the binder file descriptor is ready.
+void OnBinderReadReady() {
+  IPCThreadState::self()->handlePolledCommands();
+}
+}  // namespace
+
 namespace brillo {
 
-BinderWatcher::BinderWatcher() = default;
+BinderWatcher::BinderWatcher(MessageLoop* message_loop)
+    : message_loop_(message_loop) {}
 
-BinderWatcher::~BinderWatcher() = default;
+BinderWatcher::BinderWatcher() : message_loop_(nullptr) {}
+
+BinderWatcher::~BinderWatcher() {
+  if (task_id_ != MessageLoop::kTaskIdNull)
+    message_loop_->CancelTask(task_id_);
+}
 
 bool BinderWatcher::Init() {
+  if (!message_loop_)
+    message_loop_ = MessageLoop::current();
+  if (!message_loop_) {
+    LOG(ERROR) << "Must initialize a brillo::MessageLoop to use BinderWatcher";
+    return false;
+  }
+
   int binder_fd = -1;
   ProcessState::self()->setThreadPoolMaxThreadCount(0);
   IPCThreadState::self()->disableBackgroundScheduling(true);
-  IPCThreadState::self()->setupPolling(&binder_fd);
-  LOG(INFO) << "Got binder FD " << binder_fd;
-  if (binder_fd < 0)
+  int err = IPCThreadState::self()->setupPolling(&binder_fd);
+  if (err != 0) {
+    LOG(ERROR) << "Error setting up binder polling: "
+               << logging::SystemErrorCodeToString(err);
     return false;
+  }
+  if (binder_fd < 0) {
+    LOG(ERROR) << "Invalid binder FD " << binder_fd;
+    return false;
+  }
+  VLOG(1) << "Got binder FD " << binder_fd;
 
-  if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
-          binder_fd, true /* persistent */, base::MessageLoopForIO::WATCH_READ,
-          &watcher_, this)) {
+  task_id_ = message_loop_->WatchFileDescriptor(
+      FROM_HERE,
+      binder_fd,
+      MessageLoop::kWatchRead,
+      true /* persistent */,
+      base::Bind(&OnBinderReadReady));
+  if (task_id_ == MessageLoop::kTaskIdNull) {
     LOG(ERROR) << "Failed to watch binder FD";
     return false;
   }
   return true;
 }
 
-void BinderWatcher::OnFileCanReadWithoutBlocking(int /* fd */) {
-  IPCThreadState::self()->handlePolledCommands();
-}
-
-void BinderWatcher::OnFileCanWriteWithoutBlocking(int fd) {
-  NOTREACHED() << "Unexpected writable notification for FD " << fd;
-}
-
 }  // namespace brillo
diff --git a/brillo/binder_watcher.h b/brillo/binder_watcher.h
index 3683270..ece999d 100644
--- a/brillo/binder_watcher.h
+++ b/brillo/binder_watcher.h
@@ -18,26 +18,26 @@
 #define LIBBRILLO_BRILLO_BINDER_WATCHER_H_
 
 #include <base/macros.h>
-#include <base/message_loop/message_loop.h>
+#include <brillo/message_loops/message_loop.h>
 
 namespace brillo {
 
-// Bridge between libbinder and base::MessageLoop. Construct at startup to make
-// the message loop watch for binder events and pass them to libbinder.
-class BinderWatcher : public base::MessageLoopForIO::Watcher {
+// Bridge between libbinder and brillo::MessageLoop. Construct at startup to
+// make the message loop watch for binder events and pass them to libbinder.
+class BinderWatcher final {
  public:
+  // Construct the BinderWatcher using the passed |message_loop| if not null or
+  // the current MessageLoop otherwise.
+  explicit BinderWatcher(MessageLoop* message_loop);
   BinderWatcher();
-  ~BinderWatcher() override;
+  ~BinderWatcher();
 
   // Initializes the object, returning true on success.
   bool Init();
 
-  // base::MessageLoopForIO::Watcher:
-  void OnFileCanReadWithoutBlocking(int fd) override;
-  void OnFileCanWriteWithoutBlocking(int fd) override;
-
  private:
-  base::MessageLoopForIO::FileDescriptorWatcher watcher_;
+  MessageLoop::TaskId task_id_{MessageLoop::kTaskIdNull};
+  MessageLoop* message_loop_;
 
   DISALLOW_COPY_AND_ASSIGN(BinderWatcher);
 };