Compile libupdate_engine without DBus.

Test: mma with and without BRILLO_USE_DBUS=1
Test: adb shell /data/nativetest/update_engine_unittests/update_engine_unittests
Bug: 28800946

Change-Id: If3b05e7bc7a123d3d9b0dcc4597d915249a2de33
diff --git a/Android.mk b/Android.mk
index 4ff1eaa..acedd5c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -241,25 +241,29 @@
 ue_libupdate_engine_exported_static_libraries := \
     libpayload_consumer \
     update_metadata-protos \
-    update_engine-dbus-adaptor \
-    update_engine-dbus-libcros-client \
-    update_engine_client-dbus-proxies \
     libbz \
     libfs_mgr \
     $(ue_libpayload_consumer_exported_static_libraries) \
     $(ue_update_metadata_protos_exported_static_libraries)
 ue_libupdate_engine_exported_shared_libraries := \
-    libdbus \
-    libbrillo-dbus \
-    libchrome-dbus \
     libmetrics \
-    libshill-client \
     libexpat \
     libbrillo-policy \
     libhardware \
     libcutils \
     $(ue_libpayload_consumer_exported_shared_libraries) \
     $(ue_update_metadata_protos_exported_shared_libraries)
+ifeq ($(local_use_dbus),1)
+ue_libupdate_engine_exported_static_libraries += \
+    update_engine-dbus-adaptor \
+    update_engine-dbus-libcros-client \
+    update_engine_client-dbus-proxies
+ue_libupdate_engine_exported_shared_libraries += \
+    libdbus \
+    libbrillo-dbus \
+    libchrome-dbus \
+    libshill-client
+endif  # local_use_dbus == 1
 ifeq ($(local_use_binder),1)
 ue_libupdate_engine_exported_shared_libraries += \
     libbinder \
@@ -290,9 +294,6 @@
 LOCAL_STATIC_LIBRARIES := \
     libpayload_consumer \
     update_metadata-protos \
-    update_engine-dbus-adaptor \
-    update_engine-dbus-libcros-client \
-    update_engine_client-dbus-proxies \
     $(ue_libupdate_engine_exported_static_libraries:-host=) \
     $(ue_libpayload_consumer_exported_static_libraries:-host=) \
     $(ue_update_metadata_protos_exported_static_libraries)
@@ -306,11 +307,8 @@
     common_service.cc \
     connection_utils.cc \
     daemon.cc \
-    dbus_connection.cc \
-    dbus_service.cc \
     hardware_android.cc \
     image_properties_android.cc \
-    libcros_proxy.cc \
     metrics.cc \
     metrics_utils.cc \
     omaha_request_action.cc \
@@ -331,7 +329,6 @@
     update_manager/real_config_provider.cc \
     update_manager/real_device_policy_provider.cc \
     update_manager/real_random_provider.cc \
-    update_manager/real_shill_provider.cc \
     update_manager/real_system_provider.cc \
     update_manager/real_time_provider.cc \
     update_manager/real_updater_provider.cc \
@@ -343,7 +340,11 @@
 ifeq ($(local_use_dbus),1)
 LOCAL_SRC_FILES += \
     connection_manager.cc \
-    shill_proxy.cc
+    dbus_connection.cc \
+    dbus_service.cc \
+    libcros_proxy.cc \
+    shill_proxy.cc \
+    update_manager/real_shill_provider.cc
 else   # local_use_dbus == 1
 LOCAL_SRC_FILES += \
     connection_manager_android.cc
@@ -911,8 +912,6 @@
     common/test_utils.cc \
     common/utils_unittest.cc \
     common_service_unittest.cc \
-    connection_manager_unittest.cc \
-    fake_shill_proxy.cc \
     fake_system_state.cc \
     metrics_utils_unittest.cc \
     omaha_request_action_unittest.cc \
@@ -956,7 +955,6 @@
     update_manager/prng_unittest.cc \
     update_manager/real_device_policy_provider_unittest.cc \
     update_manager/real_random_provider_unittest.cc \
-    update_manager/real_shill_provider_unittest.cc \
     update_manager/real_system_provider_unittest.cc \
     update_manager/real_time_provider_unittest.cc \
     update_manager/real_updater_provider_unittest.cc \
@@ -964,6 +962,12 @@
     update_manager/update_manager_unittest.cc \
     update_manager/variable_unittest.cc \
     testrunner.cc
+ifeq ($(local_use_dbus),1)
+LOCAL_SRC_FILES += \
+    connection_manager_unittest.cc \
+    fake_shill_proxy.cc \
+    update_manager/real_shill_provider_unittest.cc
+endif  # local_use_dbus == 1
 ifeq ($(local_use_libcros),1)
 LOCAL_SRC_FILES += \
     chrome_browser_proxy_resolver_unittest.cc
diff --git a/real_system_state.cc b/real_system_state.cc
index 70bef8c..5fc0b71 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -129,9 +129,15 @@
       new CertificateChecker(prefs_.get(), &openssl_wrapper_));
   certificate_checker_->Init();
 
+#if USE_LIBCROS
+  LibCrosProxy* libcros_proxy = &libcros_proxy_;
+#else
+  LibCrosProxy* libcros_proxy = nullptr;
+#endif  // USE_LIBCROS
+
   // Initialize the UpdateAttempter before the UpdateManager.
   update_attempter_.reset(
-      new UpdateAttempter(this, certificate_checker_.get(), &libcros_proxy_));
+      new UpdateAttempter(this, certificate_checker_.get(), libcros_proxy));
   update_attempter_->Init();
 
   weave_service_ = ConstructWeaveService(update_attempter_.get());
@@ -141,7 +147,7 @@
   // Initialize the Update Manager using the default state factory.
   chromeos_update_manager::State* um_state =
       chromeos_update_manager::DefaultStateFactory(
-          &policy_provider_, &libcros_proxy_, this);
+          &policy_provider_, libcros_proxy, this);
   if (!um_state) {
     LOG(ERROR) << "Failed to initialize the Update Manager.";
     return false;
diff --git a/real_system_state.h b/real_system_state.h
index 18a0d98..d6a9a95 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -122,8 +122,10 @@
   inline bool system_rebooted() override { return system_rebooted_; }
 
  private:
-  // Real DBus proxies using the DBus connection.
+#if USE_LIBCROS
+  // LibCros proxy using the DBus connection.
   LibCrosProxy libcros_proxy_;
+#endif  // USE_LIBCROS
 
   // Interface for the power manager.
   std::unique_ptr<PowerManagerInterface> power_manager_;
diff --git a/update_attempter.cc b/update_attempter.cc
index 11c736e..49f00a2 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -50,7 +50,9 @@
 #include "update_engine/common/prefs_interface.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/common/utils.h"
+#if USE_DBUS
 #include "update_engine/dbus_connection.h"
+#endif // USE_DBUS
 #include "update_engine/metrics.h"
 #include "update_engine/omaha_request_action.h"
 #include "update_engine/omaha_request_params.h"
@@ -163,10 +165,12 @@
   chrome_proxy_resolver_.Init();
 #endif  // USE_LIBCROS
 
+#if USE_DBUS
   // unittest can set this to a mock before calling Init().
   if (!debugd_proxy_)
     debugd_proxy_.reset(
         new org::chromium::debugdProxy(DBusConnection::Get()->GetDBus()));
+#endif // USE_DBUS
 }
 
 void UpdateAttempter::ScheduleUpdates() {
@@ -1086,7 +1090,11 @@
           channel, false /* powerwash_allowed */, &error_message)) {
     brillo::Error::AddTo(error,
                          FROM_HERE,
+#if USE_DBUS
                          brillo::errors::dbus::kDomain,
+#else
+                         "dbus",
+#endif  // USE_DBUS
                          "set_target_error",
                          error_message);
     return false;
@@ -1591,6 +1599,7 @@
     return false;
   }
 
+#if USE_DBUS
   // Official images in devmode are allowed a custom update source iff the
   // debugd dev tools are enabled.
   if (!debugd_proxy_)
@@ -1605,6 +1614,7 @@
     LOG(INFO) << "Debugd dev tools enabled; allowing any update source.";
     return true;
   }
+#endif // USE_DBUS
   LOG(INFO) << "Debugd dev tools disabled; disallowing custom update sources.";
   return false;
 }
diff --git a/update_attempter.h b/update_attempter.h
index 5dbe3dd..78b35f0 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -29,13 +29,16 @@
 #include <base/time/time.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
+#if USE_DBUS
 #include "debugd/dbus-proxies.h"
+#endif // USE_DBUS
+#if USE_LIBCROS
 #include "update_engine/chrome_browser_proxy_resolver.h"
+#endif  // USE_LIBCROS
 #include "update_engine/client_library/include/update_engine/update_status.h"
 #include "update_engine/common/action_processor.h"
 #include "update_engine/common/certificate_checker.h"
 #include "update_engine/common/cpu_limiter.h"
-#include "update_engine/libcros_proxy.h"
 #include "update_engine/omaha_request_params.h"
 #include "update_engine/omaha_response_handler_action.h"
 #include "update_engine/payload_consumer/download_action.h"
@@ -55,6 +58,7 @@
 
 namespace chromeos_update_engine {
 
+class LibCrosProxy;
 class UpdateEngineAdaptor;
 
 class UpdateAttempter : public ActionProcessorDelegate,
@@ -506,7 +510,9 @@
   std::string forced_app_version_;
   std::string forced_omaha_url_;
 
+#if USE_DBUS
   std::unique_ptr<org::chromium::debugdProxyInterface> debugd_proxy_;
+#endif // USE_DBUS
 
   DISALLOW_COPY_AND_ASSIGN(UpdateAttempter);
 };
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 93ca81f..6ef1c15 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -27,15 +27,20 @@
 #include <brillo/message_loops/base_message_loop.h>
 #include <brillo/message_loops/message_loop.h>
 #include <brillo/message_loops/message_loop_utils.h>
+#if USE_DBUS
 #include <debugd/dbus-constants.h>
 #include <debugd/dbus-proxies.h>
 #include <debugd/dbus-proxy-mocks.h>
+#endif // USE_DBUS
 #include <gtest/gtest.h>
 #include <policy/libpolicy.h>
 #include <policy/mock_device_policy.h>
 
+#if USE_LIBCROS
 #include "libcros/dbus-proxies.h"
 #include "libcros/dbus-proxy-mocks.h"
+#include "update_engine/libcros_proxy.h"
+#endif // USE_LIBCROS
 #include "update_engine/common/fake_clock.h"
 #include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/mock_action.h"
@@ -56,8 +61,10 @@
 
 using base::Time;
 using base::TimeDelta;
+#if USE_LIBCROS
 using org::chromium::LibCrosServiceInterfaceProxyMock;
 using org::chromium::UpdateEngineLibcrosProxyResolvedInterfaceProxyMock;
+#endif // USE_LIBCROS
 using std::string;
 using std::unique_ptr;
 using testing::DoAll;
@@ -110,13 +117,18 @@
 class UpdateAttempterTest : public ::testing::Test {
  protected:
   UpdateAttempterTest()
-      : debugd_proxy_mock_(new org::chromium::debugdProxyMock()),
+      :
+#if USE_DBUS
+        debugd_proxy_mock_(new org::chromium::debugdProxyMock()),
+#endif  // USE_DBUS
+#if USE_LIBCROS
         service_interface_mock_(new LibCrosServiceInterfaceProxyMock()),
         ue_proxy_resolved_interface_mock_(
             new NiceMock<UpdateEngineLibcrosProxyResolvedInterfaceProxyMock>()),
         libcros_proxy_(
             brillo::make_unique_ptr(service_interface_mock_),
             brillo::make_unique_ptr(ue_proxy_resolved_interface_mock_)),
+#endif  // USE_LIBCROS
         certificate_checker_(fake_system_state_.mock_prefs(),
                              &openssl_wrapper_) {
     // Override system state members.
@@ -126,8 +138,10 @@
 
     certificate_checker_.Init();
 
-    // Finish initializing the attempter.
+// Finish initializing the attempter.
+#if USE_DBUS
     attempter_.debugd_proxy_.reset(debugd_proxy_mock_);
+#endif  // USE_DBUS
     attempter_.Init();
   }
 
@@ -189,14 +203,20 @@
   brillo::BaseMessageLoop loop_{&base_loop_};
 
   FakeSystemState fake_system_state_;
+#if USE_DBUS
   org::chromium::debugdProxyMock* debugd_proxy_mock_;
+#endif  // USE_DBUS
+#if USE_LIBCROS
   LibCrosServiceInterfaceProxyMock* service_interface_mock_;
   UpdateEngineLibcrosProxyResolvedInterfaceProxyMock*
       ue_proxy_resolved_interface_mock_;
   LibCrosProxy libcros_proxy_;
+  UpdateAttempterUnderTest attempter_{&fake_system_state_, &libcros_proxy_};
+#else
+  UpdateAttempterUnderTest attempter_{&fake_system_state_, nullptr};
+#endif  // USE_LIBCROS
   OpenSSLWrapper openssl_wrapper_;
   CertificateChecker certificate_checker_;
-  UpdateAttempterUnderTest attempter_{&fake_system_state_, &libcros_proxy_};
 
   NiceMock<MockActionProcessor>* processor_;
   NiceMock<MockPrefs>* prefs_;  // Shortcut to fake_system_state_->mock_prefs().
@@ -943,6 +963,7 @@
   EXPECT_TRUE(attempter_.IsAnyUpdateSourceAllowed());
 }
 
+#if USE_DBUS
 TEST_F(UpdateAttempterTest, AnyUpdateSourceAllowedOfficialDevmode) {
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(false);
@@ -950,30 +971,37 @@
       .WillRepeatedly(DoAll(SetArgumentPointee<0>(0), Return(true)));
   EXPECT_TRUE(attempter_.IsAnyUpdateSourceAllowed());
 }
+#endif  // USE_DBUS
 
 TEST_F(UpdateAttempterTest, AnyUpdateSourceDisallowedOfficialNormal) {
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(true);
   // debugd should not be queried in this case.
+#if USE_DBUS
   EXPECT_CALL(*debugd_proxy_mock_, QueryDevFeatures(_, _, _)).Times(0);
+#endif  // USE_DBUS
   EXPECT_FALSE(attempter_.IsAnyUpdateSourceAllowed());
 }
 
 TEST_F(UpdateAttempterTest, AnyUpdateSourceDisallowedDebugdDisabled) {
-  using debugd::DEV_FEATURES_DISABLED;
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(false);
+#if USE_DBUS
+  using debugd::DEV_FEATURES_DISABLED;
   EXPECT_CALL(*debugd_proxy_mock_, QueryDevFeatures(_, _, _))
       .WillRepeatedly(
           DoAll(SetArgumentPointee<0>(DEV_FEATURES_DISABLED), Return(true)));
+#endif  // USE_DBUS
   EXPECT_FALSE(attempter_.IsAnyUpdateSourceAllowed());
 }
 
 TEST_F(UpdateAttempterTest, AnyUpdateSourceDisallowedDebugdFailure) {
   fake_system_state_.fake_hardware()->SetIsOfficialBuild(true);
   fake_system_state_.fake_hardware()->SetIsNormalBootMode(false);
+#if USE_DBUS
   EXPECT_CALL(*debugd_proxy_mock_, QueryDevFeatures(_, _, _))
       .WillRepeatedly(Return(false));
+#endif  // USE_DBUS
   EXPECT_FALSE(attempter_.IsAnyUpdateSourceAllowed());
 }
 
diff --git a/update_manager/real_device_policy_provider.cc b/update_manager/real_device_policy_provider.cc
index e3e0659..d9880c3 100644
--- a/update_manager/real_device_policy_provider.cc
+++ b/update_manager/real_device_policy_provider.cc
@@ -52,6 +52,7 @@
   // On Init() we try to get the device policy and keep updating it.
   RefreshDevicePolicyAndReschedule();
 
+#if USE_DBUS
   // We also listen for signals from the session manager to force a device
   // policy refresh.
   session_manager_proxy_->RegisterPropertyChangeCompleteSignalHandler(
@@ -59,6 +60,7 @@
                  base::Unretained(this)),
       base::Bind(&RealDevicePolicyProvider::OnSignalConnected,
                  base::Unretained(this)));
+#endif  // USE_DBUS
   return true;
 }
 
diff --git a/update_manager/real_device_policy_provider.h b/update_manager/real_device_policy_provider.h
index 51c7db9..5b5ee58 100644
--- a/update_manager/real_device_policy_provider.h
+++ b/update_manager/real_device_policy_provider.h
@@ -24,7 +24,9 @@
 #include <brillo/message_loops/message_loop.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 #include <policy/libpolicy.h>
+#if USE_DBUS
 #include <session_manager/dbus-proxies.h>
+#endif  // USE_DBUS
 
 #include "update_engine/update_manager/device_policy_provider.h"
 #include "update_engine/update_manager/generic_variables.h"
@@ -34,12 +36,16 @@
 // DevicePolicyProvider concrete implementation.
 class RealDevicePolicyProvider : public DevicePolicyProvider {
  public:
+#if USE_DBUS
   RealDevicePolicyProvider(
       std::unique_ptr<org::chromium::SessionManagerInterfaceProxyInterface>
           session_manager_proxy,
       policy::PolicyProvider* policy_provider)
       : policy_provider_(policy_provider),
         session_manager_proxy_(std::move(session_manager_proxy)) {}
+#endif  // USE_DBUS
+  explicit RealDevicePolicyProvider(policy::PolicyProvider* policy_provider)
+      : policy_provider_(policy_provider) {}
   ~RealDevicePolicyProvider();
 
   // Initializes the provider and returns whether it succeeded.
@@ -141,9 +147,11 @@
   brillo::MessageLoop::TaskId scheduled_refresh_{
       brillo::MessageLoop::kTaskIdNull};
 
+#if USE_DBUS
   // The DBus (mockable) session manager proxy.
   std::unique_ptr<org::chromium::SessionManagerInterfaceProxyInterface>
       session_manager_proxy_;
+#endif  // USE_DBUS
 
   // Variable exposing whether the policy is loaded.
   AsyncCopyVariable<bool> var_device_policy_is_loaded_{
diff --git a/update_manager/real_device_policy_provider_unittest.cc b/update_manager/real_device_policy_provider_unittest.cc
index 94746b7..71c95bb 100644
--- a/update_manager/real_device_policy_provider_unittest.cc
+++ b/update_manager/real_device_policy_provider_unittest.cc
@@ -26,17 +26,23 @@
 #include <gtest/gtest.h>
 #include <policy/mock_device_policy.h>
 #include <policy/mock_libpolicy.h>
+#if USE_DBUS
 #include <session_manager/dbus-proxies.h>
 #include <session_manager/dbus-proxy-mocks.h>
+#endif  // USE_DBUS
 
 #include "update_engine/common/test_utils.h"
+#if USE_DBUS
 #include "update_engine/dbus_test_utils.h"
+#endif  // USE_DBUS
 #include "update_engine/update_manager/umtest_utils.h"
 
 using base::TimeDelta;
 using brillo::MessageLoop;
 using chromeos_update_engine::ConnectionType;
+#if USE_DBUS
 using chromeos_update_engine::dbus_test_utils::MockSignalHandler;
+#endif  // USE_DBUS
 using std::set;
 using std::string;
 using std::unique_ptr;
@@ -53,20 +59,26 @@
  protected:
   void SetUp() override {
     loop_.SetAsCurrent();
+#if USE_DBUS
     auto session_manager_proxy_mock =
         new org::chromium::SessionManagerInterfaceProxyMock();
     provider_.reset(new RealDevicePolicyProvider(
         brillo::make_unique_ptr(session_manager_proxy_mock),
         &mock_policy_provider_));
+#else
+    provider_.reset(new RealDevicePolicyProvider(&mock_policy_provider_));
+#endif  // USE_DBUS
     // By default, we have a device policy loaded. Tests can call
     // SetUpNonExistentDevicePolicy() to override this.
     SetUpExistentDevicePolicy();
 
+#if USE_DBUS
     // Setup the session manager_proxy such that it will accept the signal
     // handler and store it in the |property_change_complete_| once registered.
     MOCK_SIGNAL_HANDLER_EXPECT_SIGNAL_HANDLER(property_change_complete_,
                                               *session_manager_proxy_mock,
                                               PropertyChangeComplete);
+#endif  // USE_DBUS
   }
 
   void TearDown() override {
@@ -98,8 +110,10 @@
   testing::NiceMock<policy::MockPolicyProvider> mock_policy_provider_;
   unique_ptr<RealDevicePolicyProvider> provider_;
 
+#if USE_DBUS
   // The registered signal handler for the signal.
   MockSignalHandler<void(const string&)> property_change_complete_;
+#endif  // USE_DBUS
 };
 
 TEST_F(UmRealDevicePolicyProviderTest, RefreshScheduledTest) {
@@ -115,21 +129,29 @@
   EXPECT_CALL(mock_policy_provider_, Reload());
   EXPECT_TRUE(provider_->Init());
   Mock::VerifyAndClearExpectations(&mock_policy_provider_);
-
+  // We won't be notified that signal is connected without DBus.
+#if USE_DBUS
   EXPECT_CALL(mock_policy_provider_, Reload());
+#endif  // USE_DBUS
   loop_.RunOnce(false);
 }
 
 TEST_F(UmRealDevicePolicyProviderTest, NonExistentDevicePolicyReloaded) {
   // Checks that the policy is reloaded by RefreshDevicePolicy().
   SetUpNonExistentDevicePolicy();
+  // We won't be notified that signal is connected without DBus.
+#if USE_DBUS
   EXPECT_CALL(mock_policy_provider_, Reload()).Times(3);
+#else
+  EXPECT_CALL(mock_policy_provider_, Reload()).Times(2);
+#endif  // USE_DBUS
   EXPECT_TRUE(provider_->Init());
   loop_.RunOnce(false);
   // Force the policy refresh.
   provider_->RefreshDevicePolicy();
 }
 
+#if USE_DBUS
 TEST_F(UmRealDevicePolicyProviderTest, SessionManagerSignalForcesReload) {
   // Checks that a signal from the SessionManager forces a reload.
   SetUpNonExistentDevicePolicy();
@@ -142,6 +164,7 @@
   ASSERT_TRUE(property_change_complete_.IsHandlerRegistered());
   property_change_complete_.signal_callback().Run("success");
 }
+#endif  // USE_DBUS
 
 TEST_F(UmRealDevicePolicyProviderTest, NonExistentDevicePolicyEmptyVariables) {
   SetUpNonExistentDevicePolicy();
@@ -199,7 +222,11 @@
 TEST_F(UmRealDevicePolicyProviderTest, ScatterFactorConverted) {
   SetUpExistentDevicePolicy();
   EXPECT_CALL(mock_device_policy_, GetScatterFactorInSeconds(_))
+#if USE_DBUS
       .Times(2)
+#else
+      .Times(1)
+#endif  // USE_DBUS
       .WillRepeatedly(DoAll(SetArgPointee<0>(1234), Return(true)));
   EXPECT_TRUE(provider_->Init());
   loop_.RunOnce(false);
@@ -211,7 +238,11 @@
 TEST_F(UmRealDevicePolicyProviderTest, NegativeScatterFactorIgnored) {
   SetUpExistentDevicePolicy();
   EXPECT_CALL(mock_device_policy_, GetScatterFactorInSeconds(_))
+#if USE_DBUS
       .Times(2)
+#else
+      .Times(1)
+#endif  // USE_DBUS
       .WillRepeatedly(DoAll(SetArgPointee<0>(-1), Return(true)));
   EXPECT_TRUE(provider_->Init());
   loop_.RunOnce(false);
@@ -222,7 +253,11 @@
 TEST_F(UmRealDevicePolicyProviderTest, AllowedTypesConverted) {
   SetUpExistentDevicePolicy();
   EXPECT_CALL(mock_device_policy_, GetAllowedConnectionTypesForUpdate(_))
+#if USE_DBUS
       .Times(2)
+#else
+      .Times(1)
+#endif  // USE_DBUS
       .WillRepeatedly(DoAll(
           SetArgPointee<0>(set<string>{"bluetooth", "wifi", "not-a-type"}),
           Return(true)));
diff --git a/update_manager/real_system_provider.cc b/update_manager/real_system_provider.cc
index fde6bfa..44d5566 100644
--- a/update_manager/real_system_provider.cc
+++ b/update_manager/real_system_provider.cc
@@ -22,7 +22,9 @@
 #include <base/time/time.h>
 
 #include "update_engine/common/utils.h"
+#if USE_LIBCROS
 #include "update_engine/libcros_proxy.h"
+#endif
 #include "update_engine/update_manager/generic_variables.h"
 #include "update_engine/update_manager/variable.h"
 
diff --git a/update_manager/real_system_provider_unittest.cc b/update_manager/real_system_provider_unittest.cc
index bb42817..c997ad8 100644
--- a/update_manager/real_system_provider_unittest.cc
+++ b/update_manager/real_system_provider_unittest.cc
@@ -20,31 +20,37 @@
 
 #include <base/time/time.h>
 #include <brillo/make_unique_ptr.h>
+#include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-#include "libcros/dbus-proxies.h"
-#include "libcros/dbus-proxy-mocks.h"
 #include "update_engine/common/fake_boot_control.h"
 #include "update_engine/common/fake_hardware.h"
-#include "update_engine/libcros_proxy.h"
 #include "update_engine/update_manager/umtest_utils.h"
+#if USE_LIBCROS
+#include "libcros/dbus-proxies.h"
+#include "libcros/dbus-proxy-mocks.h"
+#include "update_engine/libcros_proxy.h"
 
 using org::chromium::LibCrosServiceInterfaceProxyMock;
+#endif  // USE_LIBCROS
 using std::unique_ptr;
 using testing::_;
 using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 
+#if USE_LIBCROS
 namespace {
 const char kRequiredPlatformVersion[] ="1234.0.0";
 }  // namespace
+#endif  // USE_LIBCROS
 
 namespace chromeos_update_manager {
 
 class UmRealSystemProviderTest : public ::testing::Test {
  protected:
   void SetUp() override {
+#if USE_LIBCROS
     service_interface_mock_ = new LibCrosServiceInterfaceProxyMock();
     libcros_proxy_.reset(new chromeos_update_engine::LibCrosProxy(
         brillo::make_unique_ptr(service_interface_mock_),
@@ -56,8 +62,12 @@
         .WillByDefault(
             DoAll(SetArgPointee<0>(kRequiredPlatformVersion), Return(true)));
 
-    provider_.reset(new RealSystemProvider(&fake_hardware_, &fake_boot_control_,
-                                           libcros_proxy_.get()));
+    provider_.reset(new RealSystemProvider(
+        &fake_hardware_, &fake_boot_control_, libcros_proxy_.get()));
+#else
+    provider_.reset(
+        new RealSystemProvider(&fake_hardware_, &fake_boot_control_, nullptr));
+#endif  // USE_LIBCROS
     EXPECT_TRUE(provider_->Init());
   }
 
@@ -65,11 +75,13 @@
   chromeos_update_engine::FakeBootControl fake_boot_control_;
   unique_ptr<RealSystemProvider> provider_;
 
+#if USE_LIBCROS
   // Local pointers to the mocks. The instances are owned by the
   // |libcros_proxy_|.
   LibCrosServiceInterfaceProxyMock* service_interface_mock_;
 
   unique_ptr<chromeos_update_engine::LibCrosProxy> libcros_proxy_;
+#endif  // USE_LIBCROS
 };
 
 TEST_F(UmRealSystemProviderTest, InitTest) {
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index bd7160a..6c8808b 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -20,20 +20,24 @@
 
 #include <base/logging.h>
 #include <brillo/make_unique_ptr.h>
+#if USE_DBUS
 #include <session_manager/dbus-proxies.h>
+#endif  // USE_DBUS
 
 #include "update_engine/common/clock_interface.h"
-#include "update_engine/dbus_connection.h"
-#include "update_engine/libcros_proxy.h"
-#include "update_engine/shill_proxy.h"
+#include "update_engine/update_manager/fake_shill_provider.h"
 #include "update_engine/update_manager/real_config_provider.h"
 #include "update_engine/update_manager/real_device_policy_provider.h"
 #include "update_engine/update_manager/real_random_provider.h"
-#include "update_engine/update_manager/real_shill_provider.h"
 #include "update_engine/update_manager/real_state.h"
 #include "update_engine/update_manager/real_system_provider.h"
 #include "update_engine/update_manager/real_time_provider.h"
 #include "update_engine/update_manager/real_updater_provider.h"
+#if USE_DBUS
+#include "update_engine/dbus_connection.h"
+#include "update_engine/shill_proxy.h"
+#include "update_engine/update_manager/real_shill_provider.h"
+#endif  // USE_DBUS
 
 using std::unique_ptr;
 
@@ -46,6 +50,7 @@
   chromeos_update_engine::ClockInterface* const clock = system_state->clock();
   unique_ptr<RealConfigProvider> config_provider(
       new RealConfigProvider(system_state->hardware()));
+#if USE_DBUS
   scoped_refptr<dbus::Bus> bus =
       chromeos_update_engine::DBusConnection::Get()->GetDBus();
   unique_ptr<RealDevicePolicyProvider> device_policy_provider(
@@ -53,9 +58,14 @@
           brillo::make_unique_ptr(
               new org::chromium::SessionManagerInterfaceProxy(bus)),
           policy_provider));
-  unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
   unique_ptr<RealShillProvider> shill_provider(
       new RealShillProvider(new chromeos_update_engine::ShillProxy(), clock));
+#else
+  unique_ptr<RealDevicePolicyProvider> device_policy_provider(
+      new RealDevicePolicyProvider(policy_provider));
+  unique_ptr<FakeShillProvider> shill_provider(new FakeShillProvider());
+#endif  // USE_DBUS
+  unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
   unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider(
       system_state->hardware(), system_state->boot_control(), libcros_proxy));
   unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
@@ -65,7 +75,9 @@
   if (!(config_provider->Init() &&
         device_policy_provider->Init() &&
         random_provider->Init() &&
+#if USE_DBUS
         shill_provider->Init() &&
+#endif  // USE_DBUS
         system_provider->Init() &&
         time_provider->Init() &&
         updater_provider->Init())) {