Switch webservd to binder in Android

This should fix chromeos building as a side effect, as we're not
depending on flags the gyp file doesn't set anymore.

Change-Id: Ibab792660600c761eb85f81e3f1fe4dce050b286
Test: Weaved can successfully connect to webservd.
Bug: 27204884
Bug: 27504653
diff --git a/Android.mk b/Android.mk
index 25b5310..ea5a547 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,20 +16,11 @@
 
 webservd_root := $(my-dir)
 
-system_webservd_use_dbus := true
-system_webservd_use_binder :=
-
 # Definitions applying to all targets. $(eval) this last.
 define webservd_common
   LOCAL_CPP_EXTENSION := .cc
   LOCAL_CFLAGS += -Wall -Werror
-  ifeq ($(system_webservd_use_dbus),true)
-    LOCAL_CFLAGS += -DWEBSERV_USE_DBUS
-  endif
-  ifeq ($(system_webservd_use_binder),true)
-    LOCAL_CFLAGS += -DWEBSERV_USE_BINDER
-    LOCAL_AIDL_INCLUDES += $(webservd_root)/aidl
-  endif
+  LOCAL_AIDL_INCLUDES += $(webservd_root)/aidl
 
   # libbrillo's secure_blob.h calls "using Blob::vector" to expose its base
   # class's constructors. This causes a "conflicts with version inherited from
@@ -48,23 +39,13 @@
       libbrillo-http \
       libbrillo-stream \
       libchrome \
-      libmicrohttpd
-
-  ifeq ($(system_webservd_use_dbus),true)
-    LOCAL_SHARED_LIBRARIES += \
-        libbrillo-dbus \
-        libchrome-dbus \
-        libdbus
-  endif
-  ifeq ($(system_webservd_use_binder),true)
-    LOCAL_SHARED_LIBRARIES += \
-        libbrillo-binder \
-        libcutils \
-        libutils \
-        libbinderwrapper \
-        libbinder
-    LOCAL_STATIC_LIBRARIES += libwebserv_common
-  endif
+      libmicrohttpd \
+      libbrillo-binder \
+      libcutils \
+      libutils \
+      libbinderwrapper \
+      libbinder
+  LOCAL_STATIC_LIBRARIES += libwebserv_common
 
 endef  # webserv_common_libraries
 
diff --git a/libwebserv/Android.mk b/libwebserv/Android.mk
index 0a0d4ae..5f8db03 100644
--- a/libwebserv/Android.mk
+++ b/libwebserv/Android.mk
@@ -22,7 +22,7 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := libwebserv
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/..
-LOCAL_SHARED_LIBRARIES :=
+LOCAL_SHARED_LIBRARIES := libwebserv-binder-internal
 LOCAL_SRC_FILES := \
     protocol_handler.cc \
     request_handler_callback.cc \
@@ -30,58 +30,21 @@
     request_utils.cc \
     response.cc \
     server.cc \
-
-ifeq ($(system_webservd_use_dbus),true)
-LOCAL_SHARED_LIBRARIES += libwebservd-client-internal
-LOCAL_SRC_FILES += \
-    dbus_bindings/org.chromium.WebServer.RequestHandler.dbus-xml \
-    dbus_response.cc \
-    dbus_protocol_handler.cc \
-    dbus_server.cc
-endif
-
-ifeq ($(system_webservd_use_binder),true)
-LOCAL_SHARED_LIBRARIES += libwebserv-binder-internal
-LOCAL_SRC_FILES += \
     binder_server.cc \
     binder_request_handler.cc \
     binder_request_impl.cc \
     binder_response.cc
-endif
 
 $(eval $(webservd_common))
 $(eval $(webservd_common_libraries))
 include $(BUILD_SHARED_LIBRARY)
 
-# libwebserv-proxies-internal shared library
-# ========================================================
-# You do not want to depend on this.  Depend on libwebserv instead.
-# libwebserv abstracts and helps you consume this interface.
-#
-# This library builds the proxies which webservd will use to communicate back
-# to libwebservd over DBus.
-ifeq ($(system_webservd_use_dbus),true)
-include $(CLEAR_VARS)
-LOCAL_MODULE := libwebserv-proxies-internal
-
-LOCAL_SRC_FILES := \
-    dbus_bindings/org.chromium.WebServer.RequestHandler.dbus-xml \
-
-LOCAL_DBUS_PROXY_PREFIX := libwebserv
-
-$(eval $(webservd_common))
-$(eval $(webservd_common_libraries))
-include $(BUILD_SHARED_LIBRARY)
-endif
-
-
 # libwebserv-binder-internal shared library
 # ========================================================
 # You do not want to depend on this.  Depend on libwebserv instead.
 # libwebserv abstracts and helps you consume this interface.
 #
 # This library builds the binder interfaces used between webservd and libwebserv
-ifeq ($(system_webservd_use_binder),true)
 include $(CLEAR_VARS)
 LOCAL_MODULE := libwebserv-binder-internal
 
@@ -95,4 +58,3 @@
 $(eval $(webservd_common))
 $(eval $(webservd_common_libraries))
 include $(BUILD_SHARED_LIBRARY)
-endif
diff --git a/libwebserv/binder_server.cc b/libwebserv/binder_server.cc
index fbc08fa..cd55804 100644
--- a/libwebserv/binder_server.cc
+++ b/libwebserv/binder_server.cc
@@ -228,6 +228,10 @@
   } else if (!BuildLocalState(binder)) {
     ClearLocalState();
   } else {
+    if (!on_server_online_.is_null()) {
+        message_loop_->PostTask(FROM_HERE, on_server_online_);
+    }
+
     // Got a binder, built up appropriate local state, our job is done.
     return;
   }
@@ -247,6 +251,9 @@
     }
   }
 
+  if (remote_server_.get() && !on_server_offline_.is_null()) {
+      message_loop_->PostTask(FROM_HERE, on_server_offline_);
+  }
   remote_server_.clear();
 }
 
diff --git a/libwebserv/request.cc b/libwebserv/request.cc
index 5d7abf7..972ef6c 100644
--- a/libwebserv/request.cc
+++ b/libwebserv/request.cc
@@ -22,6 +22,7 @@
 
 namespace libwebserv {
 
+#ifndef __ANDROID__
 FileInfo::FileInfo(DBusProtocolHandler* handler,
                    int file_id,
                    const std::string& request_id,
@@ -44,6 +45,7 @@
                         success_callback,
                         error_callback);
 }
+#endif  // !__ANDROID__
 
 RequestImpl::RequestImpl(DBusProtocolHandler* handler,
                          const std::string& url,
@@ -71,6 +73,7 @@
   return std::vector<PairOfStrings>{post_data_.begin(), post_data_.end()};
 }
 
+#ifndef __ANDROID__
 std::vector<std::pair<std::string, const FileInfo*>> Request::GetFiles() const {
   std::vector<std::pair<std::string, const FileInfo*>> data;
   data.reserve(file_info_.size());
@@ -79,6 +82,7 @@
   }
   return data;
 }
+#endif  // !__ANDROID__
 
 std::vector<std::string> Request::GetFormField(const std::string& name) const {
   std::vector<std::string> data;
@@ -117,6 +121,7 @@
   return data;
 }
 
+#ifndef __ANDROID__
 std::vector<const FileInfo*> Request::GetFileInfo(
     const std::string& name) const {
   std::vector<const FileInfo*> data;
@@ -127,6 +132,7 @@
   }
   return data;
 }
+#endif  // !__ANDROID__
 
 std::vector<PairOfStrings> Request::GetHeaders() const {
   return std::vector<PairOfStrings>{headers_.begin(), headers_.end()};
diff --git a/libwebserv/request.h b/libwebserv/request.h
index 2950d1b..49e1064 100644
--- a/libwebserv/request.h
+++ b/libwebserv/request.h
@@ -33,9 +33,11 @@
 
 namespace libwebserv {
 
+using PairOfStrings = std::pair<std::string, std::string>;
+
+#ifndef __ANDROID__
 class DBusProtocolHandler;
 
-using PairOfStrings = std::pair<std::string, std::string>;
 
 // This class represents the file information about a file uploaded via
 // POST request using multipart/form-data request.
@@ -67,6 +69,7 @@
 
   DISALLOW_COPY_AND_ASSIGN(FileInfo);
 };
+#endif  // !__ANDROID__
 
 // A class that represents the HTTP request data.
 class LIBWEBSERV_EXPORT Request {
@@ -104,9 +107,11 @@
   // POST data.
   std::vector<PairOfStrings> GetFormDataPost() const;
 
+#ifndef __ANDROID__
   // Returns a list of file information records for all the file uploads in
   // the POST request.
   std::vector<std::pair<std::string, const FileInfo*>> GetFiles() const;
+#endif  // !__ANDROID__
 
   // Gets the values of form field with given |name|. This includes both
   // values provided on the URL and as part of form data in POST request.
@@ -119,8 +124,10 @@
   // Gets the values of URL query parameters with given |name|.
   std::vector<std::string> GetFormFieldGet(const std::string& name) const;
 
+#ifndef __ANDROID__
   // Gets the file upload parameters for a file form field of given |name|.
   std::vector<const FileInfo*> GetFileInfo(const std::string& name) const;
+#endif  // !__ANDROID__
 
   // Returns a list of key-value pairs for all the request headers.
   std::vector<PairOfStrings> GetHeaders() const;
@@ -138,7 +145,9 @@
   std::string method_;
   std::multimap<std::string, std::string> post_data_;
   std::multimap<std::string, std::string> get_data_;
+#ifndef __ANDROID__
   std::multimap<std::string, std::unique_ptr<FileInfo>> file_info_;
+#endif  // !__ANDROID__
   std::multimap<std::string, std::string> headers_;
 };
 
diff --git a/libwebserv/server.cc b/libwebserv/server.cc
index abbc5b5..e4ef6df 100644
--- a/libwebserv/server.cc
+++ b/libwebserv/server.cc
@@ -14,19 +14,27 @@
 
 #include <libwebserv/server.h>
 
-#if defined(WEBSERV_USE_DBUS)
-#include "libwebserv/dbus_server.h"
-#endif  // defined(WEBSERV_USE_DBUS)
-
-#if defined(WEBSERV_USE_BINDER)
+#ifdef __ANDROID__
 #include "libwebserv/binder_server.h"
-#endif  // defined(WEBSERV_USE_BINDER)
+#else
+#include "libwebserv/dbus_server.h"
+#endif  // __ANDROID__
+
 
 using std::unique_ptr;
 
 namespace libwebserv {
 
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+std::unique_ptr<Server> Server::ConnectToServerViaBinder(
+    brillo::MessageLoop* message_loop,
+    const base::Closure& on_server_online,
+    const base::Closure& on_server_offline) {
+  return unique_ptr<Server>(new BinderServer(
+      message_loop, on_server_online, on_server_offline,
+      android::BinderWrapper::GetOrCreateInstance()));
+}
+#else
 unique_ptr<Server> Server::ConnectToServerViaDBus(
     const scoped_refptr<dbus::Bus>& bus,
     const std::string& service_name,
@@ -38,17 +46,7 @@
   server->Connect(bus, service_name, cb, on_server_online, on_server_offline);
   return ret;
 }
-#endif  // defined(WEBSERV_USE_DBUS)
+#endif  // __ANDROID__
 
-#if defined(WEBSERV_USE_BINDER)
-std::unique_ptr<Server> Server::ConnectToServerViaBinder(
-    brillo::MessageLoop* message_loop,
-    const base::Closure& on_server_online,
-    const base::Closure& on_server_offline) {
-  return unique_ptr<Server>(new BinderServer(
-      message_loop, on_server_online, on_server_offline,
-      android::BinderWrapper::GetOrCreateInstance()));
-}
-#endif  // defined(WEBSERV_USE_BINDER)
 
 }  // namespace libwebserv
diff --git a/libwebserv/server.h b/libwebserv/server.h
index 6eb8c07..c285005 100644
--- a/libwebserv/server.h
+++ b/libwebserv/server.h
@@ -15,13 +15,6 @@
 #ifndef WEBSERVER_LIBWEBSERV_SERVER_H_
 #define WEBSERVER_LIBWEBSERV_SERVER_H_
 
-// In our own Android.mk, we set these flags for ourselves.  However, for
-// libraries consuming libwebserv, they don't have any of that logic.  Leave us
-// with DBus bindings until the Binder interface is ready.
-#if !defined(WEBSERV_USE_DBUS) && !defined(WEBSERV_USE_BINDER)
-#define WEBSERV_USE_DBUS
-#endif
-
 #include <memory>
 #include <string>
 
@@ -29,15 +22,13 @@
 #include <base/macros.h>
 #include <libwebserv/export.h>
 
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+#include <brillo/message_loops/message_loop.h>
+#else
 #include <base/memory/ref_counted.h>
 #include <brillo/dbus/async_event_sequencer.h>
 #include <dbus/bus.h>
-#endif  // defined(WEBSERV_USE_DBUS)
-
-#if defined(WEBSERV_USE_BINDER)
-#include <brillo/message_loops/message_loop.h>
-#endif  // defined(WEBSERV_USE_BINDER)
+#endif  // __ANDROID__
 
 namespace libwebserv {
 
@@ -50,7 +41,21 @@
   Server() = default;
   virtual ~Server() = default;
 
-#if defined(WEBSERV_USE_DBUS)
+#ifdef __ANDROID__
+  // Establish a connection to the system webserver.
+  //
+  // |on_server_online| and |on_server_offline| will notify the caller when the
+  // server comes up and down.
+  //
+  // Note that you can use the returned Server instance as if the webserver
+  // process is actually running (ignoring webserver crashes and restarts).
+  // All registered request handlers will simply be re-registered when the
+  // webserver appears again.
+  static std::unique_ptr<Server> ConnectToServerViaBinder(
+      brillo::MessageLoop* message_loop,
+      const base::Closure& on_server_online,
+      const base::Closure& on_server_offline);
+#else
   // Establish a connection to the system webserver.
   //
   // |service_name| is the well known D-Bus name of the client's process, used
@@ -69,23 +74,7 @@
       const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& cb,
       const base::Closure& on_server_online,
       const base::Closure& on_server_offline);
-#endif  // defined(WEBSERV_USE_DBUS)
-
-#if defined(WEBSERV_USE_BINDER)
-  // Establish a connection to the system webserver.
-  //
-  // |on_server_online| and |on_server_offline| will notify the caller when the
-  // server comes up and down.
-  //
-  // Note that you can use the returned Server instance as if the webserver
-  // process is actually running (ignoring webserver crashes and restarts).
-  // All registered request handlers will simply be re-registered when the
-  // webserver appears again.
-  static std::unique_ptr<Server> ConnectToServerViaBinder(
-      brillo::MessageLoop* message_loop,
-      const base::Closure& on_server_online,
-      const base::Closure& on_server_offline);
-#endif  // defined(WEBSERV_USE_BINDER)
+#endif  // __ANDROID__
 
   // A helper method that returns the default handler for "http".
   virtual ProtocolHandler* GetDefaultHttpHandler() = 0;
diff --git a/test-client/Android.mk b/test-client/Android.mk
index f145e08..a15958f 100644
--- a/test-client/Android.mk
+++ b/test-client/Android.mk
@@ -40,20 +40,9 @@
 LOCAL_SHARED_LIBRARIES := \
     libbrillo \
     libchrome \
-    libwebserv
-
-ifeq ($(system_webservd_use_dbus),true)
-LOCAL_SHARED_LIBRARIES += \
-    libdbus \
-    libbrillo-dbus \
-    libchrome-dbus
-endif
-
-ifeq ($(system_webservd_use_binder),true)
-LOCAL_SHARED_LIBRARIES += \
+    libwebserv \
     libbinder \
     libbrillo-binder \
     libbinderwrapper
-endif
 
 include $(BUILD_EXECUTABLE)
diff --git a/test-client/main.cc b/test-client/main.cc
index dcb219c..d9d9b6a 100644
--- a/test-client/main.cc
+++ b/test-client/main.cc
@@ -23,16 +23,7 @@
 
 #define LOG_TAG webservd_testc
 
-#if defined(WEBSERV_USE_DBUS)
-
-#include <brillo/daemons/dbus_daemon.h>
-#include <brillo/dbus/async_event_sequencer.h>
-
-// If we're using DBus, pick a base class that does DBus related init.
-using WebservTestClientBaseClass = brillo::DBusDaemon;
-using brillo::dbus_utils::AsyncEventSequencer;
-
-#elif defined(WEBSERV_USE_BINDER)
+#ifdef __ANDROID__
 
 #include <binderwrapper/binder_wrapper.h>
 
@@ -41,8 +32,15 @@
 using WebservTestClientBaseClass = brillo::Daemon;
 
 #else
-#error "You must select one of Binder or DBus as an RPC mechanism."
-#endif  // defined(WEBSERV_USE_DBUS)
+
+#include <brillo/daemons/dbus_daemon.h>
+#include <brillo/dbus/async_event_sequencer.h>
+
+// If we're using DBus, pick a base class that does DBus related init.
+using WebservTestClientBaseClass = brillo::DBusDaemon;
+using brillo::dbus_utils::AsyncEventSequencer;
+
+#endif  // __ANDROID__
 
 using libwebserv::Server;
 using libwebserv::ProtocolHandler;
@@ -85,13 +83,7 @@
     if (exit_code != EX_OK)
       return exit_code;
 
-#ifdef WEBSERV_USE_DBUS
-    webserver_ = Server::ConnectToServerViaDBus(
-        bus_, bus_->GetConnectionName(),
-        AsyncEventSequencer::GetDefaultCompletionAction(),
-        base::Bind(&LogServerOnlineStatus, true /* online */),
-        base::Bind(&LogServerOnlineStatus, false /* offline */));
-#elif WEBSERV_USE_BINDER
+#ifdef __ANDROID__
     android::BinderWrapper::Create();
     if (!binder_watcher_.Init()) {
         return EX_OSERR;
@@ -101,7 +93,13 @@
         brillo::MessageLoop::current(),
         base::Bind(&LogServerOnlineStatus, true /* online */),
         base::Bind(&LogServerOnlineStatus, false /* offline */));
-#endif  // WEBSERV_USE_DBUS || WEBSERV_USE_BINDER
+#else
+    webserver_ = Server::ConnectToServerViaDBus(
+        bus_, bus_->GetConnectionName(),
+        AsyncEventSequencer::GetDefaultCompletionAction(),
+        base::Bind(&LogServerOnlineStatus, true /* online */),
+        base::Bind(&LogServerOnlineStatus, false /* offline */));
+#endif  // __ANDROID__
 
     // Note that adding this handler is only local, and we won't receive
     // requests until the library does some async book keeping.
@@ -116,9 +114,9 @@
 
  private:
   std::unique_ptr<Server> webserver_;
-#if WEBSERV_USE_BINDER
+#ifdef __ANDROID__
   brillo::BinderWatcher binder_watcher_;
-#endif  // WEBSERV_USE_BINDER
+#endif  // __ANDROID__
 
   DISALLOW_COPY_AND_ASSIGN(WebservTestClient);
 };  // class WebservTestClient
diff --git a/webserv_common/Android.mk b/webserv_common/Android.mk
index e63928b..3e1250f 100644
--- a/webserv_common/Android.mk
+++ b/webserv_common/Android.mk
@@ -16,7 +16,6 @@
 
 LOCAL_PATH := $(my-dir)
 
-ifeq ($(system_webservd_use_binder),true)
 include $(CLEAR_VARS)
 LOCAL_MODULE := libwebserv_common
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/..
@@ -26,4 +25,3 @@
 $(eval $(webservd_common))
 $(eval $(webservd_common_libraries))
 include $(BUILD_STATIC_LIBRARY)
-endif
diff --git a/webservd/Android.mk b/webservd/Android.mk
index 76240ec..ada312b 100644
--- a/webservd/Android.mk
+++ b/webservd/Android.mk
@@ -27,12 +27,6 @@
     libcrypto \
     libwebserv
 
-ifeq ($(system_webservd_use_dbus),true)
-LOCAL_SHARED_LIBRARIES += \
-    libwebserv-proxies-internal \
-    libfirewalld-client
-endif
-
 ifdef BRILLO
 
 LOCAL_SHARED_LIBRARIES += \
@@ -51,7 +45,6 @@
     temp_file_manager.cc \
     utils.cc \
 
-ifeq ($(system_webservd_use_binder),true)
 LOCAL_SRC_FILES += \
     ../aidl/android/webservd/IServer.aidl \
     ../aidl/android/webservd/IProtocolHandler.aidl \
@@ -61,18 +54,6 @@
     binder_server.cc
 LOCAL_SHARED_LIBRARIES += \
     libfirewalld-binder-client
-endif
-
-ifeq ($(system_webservd_use_dbus),true)
-LOCAL_SRC_FILES += \
-    dbus_bindings/dbus-service-config.json \
-    dbus_bindings/org.chromium.WebServer.ProtocolHandler.dbus-xml \
-    dbus_bindings/org.chromium.WebServer.Server.dbus-xml \
-    dbus_protocol_handler.cc \
-    dbus_request_handler.cc \
-    firewalld_firewall.cc \
-    server.cc
-endif
 
 ifdef BRILLO
 LOCAL_SRC_FILES += keystore_encryptor.cc
@@ -85,20 +66,3 @@
 $(eval $(webservd_common))
 $(eval $(webservd_common_libraries))
 include $(BUILD_EXECUTABLE)
-
-# libwebservd-client-internal shared library
-# ========================================================
-# You do not want to depend on this.  Depend on libwebserv instead.
-# libwebserv abstracts and helps you consume this interface.
-
-ifeq ($(system_webservd_use_dbus),true)
-include $(CLEAR_VARS)
-LOCAL_MODULE := libwebservd-client-internal
-LOCAL_SRC_FILES := \
-    dbus_bindings/dbus-service-config.json \
-    dbus_bindings/org.chromium.WebServer.ProtocolHandler.dbus-xml \
-    dbus_bindings/org.chromium.WebServer.Server.dbus-xml \
-
-LOCAL_DBUS_PROXY_PREFIX := webservd
-include $(BUILD_SHARED_LIBRARY)
-endif
diff --git a/webservd/binder_server.cc b/webservd/binder_server.cc
index 290c5ce..1fce0a0 100644
--- a/webservd/binder_server.cc
+++ b/webservd/binder_server.cc
@@ -12,6 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <base/bind.h>
 #include <base/files/file_util.h>
 #include <base/rand_util.h>
 
@@ -77,8 +78,10 @@
 
 class BinderProtocolHandler : public android::webservd::BnProtocolHandler {
  public:
-  BinderProtocolHandler(string name, BinderServer* server)
-      : impl_(name, server) {}
+  BinderProtocolHandler(string name, BinderServer* server,
+                        android::BinderWrapper* binder_wrapper)
+      : impl_(name, server),
+        binder_wrapper_(binder_wrapper) {}
 
   bool Start(const Config::ProtocolHandler& config) {
     return impl_.Start(config);
@@ -89,6 +92,11 @@
         override {
     *ret = impl_.AddRequestHandler(url, method,
         unique_ptr<RequestHandlerInterface>(new BinderRequestHandler(handler)));
+
+    binder_wrapper_->RegisterForDeathNotifications(
+        IRequestHandler::asBinder(handler),
+        base::Bind(&BinderProtocolHandler::HandlerDied,
+                   base::Unretained(this), *ret));
     return Status::ok();
   }
 
@@ -128,7 +136,12 @@
   }
 
  private:
+  void HandlerDied(const string& guid) {
+    impl_.RemoveRequestHandler(guid);
+  }
+
   ProtocolHandler impl_;
+  android::BinderWrapper* binder_wrapper_;
 
   DISALLOW_COPY_AND_ASSIGN(BinderProtocolHandler);
 };
@@ -240,7 +253,7 @@
 
   for (const auto& handler_config : config_.protocol_handlers) {
     sp<BinderProtocolHandler> handler_ptr{
-        new BinderProtocolHandler(handler_config.name, this)};
+        new BinderProtocolHandler(handler_config.name, this, binder_wrapper)};
 
     if (handler_ptr->Start(handler_config)) {
       protocol_handlers_.push_back(handler_ptr);
diff --git a/webservd/main.cc b/webservd/main.cc
index 8782e15..fe0dac8 100644
--- a/webservd/main.cc
+++ b/webservd/main.cc
@@ -19,82 +19,67 @@
 
 #include <base/command_line.h>
 #include <base/files/file_util.h>
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
 #include <binderwrapper/binder_wrapper.h>
 #include <brillo/binder_watcher.h>
 #include <brillo/daemons/daemon.h>
-#endif  // WEBSERV_USE_BINDER
-#ifdef WEBSERV_USE_DBUS
+#else
 #include <brillo/dbus/async_event_sequencer.h>
 #include <brillo/dbus/exported_object_manager.h>
 #include <brillo/daemons/dbus_daemon.h>
-#endif  // WEBSERV_USE_DBUS
-#include <brillo/flag_helper.h>
-#if !defined(__ANDROID__)
 #include <brillo/minijail/minijail.h>
-#endif  // !defined(__ANDROID__)
+#endif  // __ANDROID__
+#include <brillo/flag_helper.h>
 #include <brillo/syslog_logging.h>
 
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
 #include "webservd/binder_server.h"
-#endif  // WEBSERV_USE_BINDER
-#include "webservd/config.h"
-#include "webservd/log_manager.h"
-#ifdef WEBSERV_USE_DBUS
+#include "webserv_common/binder_constants.h"
+#else
 #include "webservd/server.h"
 #endif
+#include "webservd/config.h"
+#include "webservd/log_manager.h"
 #include "webservd/utils.h"
 
-#ifdef WEBSERV_USE_BINDER
-#include "webserv_common/binder_constants.h"
-#endif  // WEBSERV_USE_BINDER
-
 #if defined(__ANDROID__)
-#ifdef WEBSERV_USE_BINDER
 #include <firewalld/firewall.h>
 #else
-#include "webservd/firewalld_firewall.h"
-using FirewallImpl = webservd::FirewalldFirewall;
-#endif
-#else
 #include "webservd/permission_broker_firewall.h"
 using FirewallImpl = webservd::PermissionBrokerFirewall;
 #endif  // defined(__ANDROID__)
 
-#ifdef WEBSERV_USE_DBUS
+#ifdef __ANDROID__
+using BaseDaemon = brillo::Daemon;
+#else
 using brillo::dbus_utils::AsyncEventSequencer;
 using BaseDaemon = brillo::DBusServiceDaemon;
-#else
-using BaseDaemon = brillo::Daemon;
-#endif  // WEBSERV_USE_DBUS
+#endif  // __ANDROID__
 
 namespace {
 
 const char kDefaultConfigFilePath[] = "/etc/webservd/config";
 
-#ifdef WEBSERV_USE_DBUS
+#ifndef __ANDROID__
 const char kServiceName[] = "org.chromium.WebServer";
 const char kRootServicePath[] = "/org/chromium/WebServer";
-#endif  // WEBSERV_USE_DBUS
-
-#if !defined(__ANDROID__)
 const char kWebServerUserName[] = "webservd";
 const char kWebServerGroupName[] = "webservd";
 #endif  // !defined(__ANDROID__)
 
 class Daemon final : public BaseDaemon {
  public:
-#ifdef WEBSERV_USE_DBUS
+#ifdef __ANDROID__
+  explicit Daemon(webservd::Config config)
+      : config_{std::move(config)} {}
+#else
   explicit Daemon(webservd::Config config)
       : DBusServiceDaemon{kServiceName, kRootServicePath},
         config_{std::move(config)} {}
-#else
-  explicit Daemon(webservd::Config config)
-      : config_{std::move(config)} {}
-#endif  // WEBSERV_USE_DBUS
+#endif  // __ANDROID__
 
  protected:
-#ifdef WEBSERV_USE_DBUS
+#ifndef __ANDROID__
   void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override {
     webservd::LogManager::Init(base::FilePath{config_.log_directory});
     server_.reset(new webservd::Server{
@@ -107,10 +92,10 @@
   void OnShutdown(int* /* return_code */) override {
     server_.reset();
   }
-#endif  // WEBSERV_USE_DBUS
+#endif  // !__ANDROID__
 
  private:
-#ifdef WEBSERV_USE_BINDER
+#ifdef __ANDROID__
   int OnInit() override {
     int result = brillo::Daemon::OnInit();
     if (result != EX_OK) {
@@ -136,15 +121,15 @@
 
     return EX_OK;
   }
-#endif  // WEBSERV_USE_BINDER
+#endif  // __ANDROID__
 
   webservd::Config config_;
-#ifdef WEBSERV_USE_DBUS
-  std::unique_ptr<webservd::Server> server_;
-#else
+#ifdef __ANDROID__
   std::unique_ptr<webservd::BinderServer> server_;
   brillo::BinderWatcher binder_watcher_;
-#endif  // WEBSERV_USE_DBUS
+#else
+  std::unique_ptr<webservd::Server> server_;
+#endif  // __ANDROID__
 
   DISALLOW_COPY_AND_ASSIGN(Daemon);
 };