Add ConnectionManagerAndroid.

Just a stub implementation that always allow update right now.

Test: mma
Bug: 28800946

Change-Id: I4ff6164d459d142567d49a351f70128f5fc74b9f
diff --git a/Android.mk b/Android.mk
index 78cdbdf..9ec55a3 100644
--- a/Android.mk
+++ b/Android.mk
@@ -307,7 +307,6 @@
 LOCAL_SRC_FILES := \
     boot_control_android.cc \
     common_service.cc \
-    connection_manager.cc \
     connection_utils.cc \
     daemon.cc \
     dbus_connection.cc \
@@ -325,7 +324,6 @@
     payload_state.cc \
     proxy_resolver.cc \
     real_system_state.cc \
-    shill_proxy.cc \
     update_attempter.cc \
     update_manager/boxed_value.cc \
     update_manager/chromeos_policy.cc \
@@ -344,6 +342,14 @@
     update_status_utils.cc \
     utils_android.cc \
     weave_service_factory.cc
+ifeq ($(local_use_dbus),1)
+LOCAL_SRC_FILES += \
+    connection_manager.cc \
+    shill_proxy.cc
+else   # local_use_dbus == 1
+LOCAL_SRC_FILES += \
+    connection_manager_android.cc
+endif  # local_use_dbus == 1
 ifeq ($(local_use_binder),1)
 LOCAL_AIDL_INCLUDES += $(LOCAL_PATH)/binder_bindings
 LOCAL_SRC_FILES += \
diff --git a/connection_manager.cc b/connection_manager.cc
index 13503d9..f72d9e8 100644
--- a/connection_manager.cc
+++ b/connection_manager.cc
@@ -28,6 +28,7 @@
 #include "update_engine/common/prefs.h"
 #include "update_engine/common/utils.h"
 #include "update_engine/connection_utils.h"
+#include "update_engine/shill_proxy.h"
 #include "update_engine/system_state.h"
 
 using org::chromium::flimflam::ManagerProxyInterface;
@@ -37,6 +38,14 @@
 
 namespace chromeos_update_engine {
 
+namespace connection_manager {
+std::unique_ptr<ConnectionManagerInterface> CreateConnectionManager(
+    SystemState* system_state) {
+  return std::unique_ptr<ConnectionManagerInterface>(
+      new ConnectionManager(new ShillProxy(), system_state));
+}
+}
+
 ConnectionManager::ConnectionManager(ShillProxyInterface* shill_proxy,
                                      SystemState* system_state)
     : shill_proxy_(shill_proxy), system_state_(system_state) {}
diff --git a/connection_manager.h b/connection_manager.h
index 1143f83..e5a9d49 100644
--- a/connection_manager.h
+++ b/connection_manager.h
@@ -27,8 +27,6 @@
 
 namespace chromeos_update_engine {
 
-class SystemState;
-
 // This class implements the concrete class that talks with the connection
 // manager (shill) over DBus.
 // TODO(deymo): Remove this class and use ShillProvider from the UpdateManager.
@@ -56,7 +54,7 @@
                                 ConnectionTethering* out_tethering);
 
   // The mockable interface to access the shill DBus proxies.
-  ShillProxyInterface* shill_proxy_;
+  std::unique_ptr<ShillProxyInterface> shill_proxy_;
 
   // The global context for update_engine.
   SystemState* system_state_;
diff --git a/connection_manager_android.cc b/connection_manager_android.cc
new file mode 100644
index 0000000..2dd824a
--- /dev/null
+++ b/connection_manager_android.cc
@@ -0,0 +1,38 @@
+//
+// Copyright (C) 2016 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 "update_engine/connection_manager_android.h"
+
+namespace chromeos_update_engine {
+
+namespace connection_manager {
+std::unique_ptr<ConnectionManagerInterface> CreateConnectionManager(
+    SystemState* system_state) {
+  return std::unique_ptr<ConnectionManagerInterface>(
+      new ConnectionManagerAndroid());
+}
+}
+
+bool ConnectionManagerAndroid::GetConnectionProperties(
+    ConnectionType* out_type, ConnectionTethering* out_tethering) {
+  return false;
+}
+bool ConnectionManagerAndroid::IsUpdateAllowedOver(
+    ConnectionType type, ConnectionTethering tethering) const {
+  return true;
+}
+
+}  // namespace chromeos_update_engine
diff --git a/connection_manager_android.h b/connection_manager_android.h
new file mode 100644
index 0000000..0cd5e73
--- /dev/null
+++ b/connection_manager_android.h
@@ -0,0 +1,43 @@
+//
+// Copyright (C) 2016 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 UPDATE_ENGINE_CONNECTION_MANAGER_ANDROID_H_
+#define UPDATE_ENGINE_CONNECTION_MANAGER_ANDROID_H_
+
+#include <base/macros.h>
+
+#include "update_engine/connection_manager_interface.h"
+
+namespace chromeos_update_engine {
+
+// TODO(senj): Remove this class and use ShillProvider from the UpdateManager.
+class ConnectionManagerAndroid : public ConnectionManagerInterface {
+ public:
+  ConnectionManagerAndroid() = default;
+  ~ConnectionManagerAndroid() override = default;
+
+  // ConnectionManagerInterface overrides.
+  bool GetConnectionProperties(ConnectionType* out_type,
+                               ConnectionTethering* out_tethering) override;
+  bool IsUpdateAllowedOver(ConnectionType type,
+                           ConnectionTethering tethering) const override;
+
+  DISALLOW_COPY_AND_ASSIGN(ConnectionManagerAndroid);
+};
+
+}  // namespace chromeos_update_engine
+
+#endif  // UPDATE_ENGINE_CONNECTION_MANAGER_ANDROID_H_
diff --git a/connection_manager_interface.h b/connection_manager_interface.h
index d36ef76..df8eb4b 100644
--- a/connection_manager_interface.h
+++ b/connection_manager_interface.h
@@ -17,12 +17,16 @@
 #ifndef UPDATE_ENGINE_CONNECTION_MANAGER_INTERFACE_H_
 #define UPDATE_ENGINE_CONNECTION_MANAGER_INTERFACE_H_
 
+#include <memory>
+
 #include <base/macros.h>
 
 #include "update_engine/connection_utils.h"
 
 namespace chromeos_update_engine {
 
+class SystemState;
+
 // This class exposes a generic interface to the connection manager
 // (e.g FlimFlam, Shill, etc.) to consolidate all connection-related
 // logic in update_engine.
@@ -49,6 +53,12 @@
   DISALLOW_COPY_AND_ASSIGN(ConnectionManagerInterface);
 };
 
+namespace connection_manager {
+// Factory function which creates a ConnectionManager.
+std::unique_ptr<ConnectionManagerInterface> CreateConnectionManager(
+    SystemState* system_state);
+}
+
 }  // namespace chromeos_update_engine
 
 #endif  // UPDATE_ENGINE_CONNECTION_MANAGER_INTERFACE_H_
diff --git a/connection_manager_unittest.cc b/connection_manager_unittest.cc
index 48f6195..0bb5547 100644
--- a/connection_manager_unittest.cc
+++ b/connection_manager_unittest.cc
@@ -47,6 +47,8 @@
 
 class ConnectionManagerTest : public ::testing::Test {
  public:
+  ConnectionManagerTest() : fake_shill_proxy_(new FakeShillProxy()) {}
+
   void SetUp() override {
     loop_.SetAsCurrent();
     fake_system_state_.set_connection_manager(&cmut_);
@@ -78,15 +80,15 @@
 
   brillo::FakeMessageLoop loop_{nullptr};
   FakeSystemState fake_system_state_;
-  FakeShillProxy fake_shill_proxy_;
+  FakeShillProxy* fake_shill_proxy_;
 
   // ConnectionManager under test.
-  ConnectionManager cmut_{&fake_shill_proxy_, &fake_system_state_};
+  ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_};
 };
 
 void ConnectionManagerTest::SetManagerReply(const char* default_service,
                                             bool reply_succeeds) {
-  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
+  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
   if (!reply_succeeds) {
     EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
         .WillOnce(Return(false));
@@ -130,8 +132,8 @@
   EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
       .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
 
-  fake_shill_proxy_.SetServiceForPath(dbus::ObjectPath(service_path),
-                                      std::move(service_proxy_mock));
+  fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path),
+                                       std::move(service_proxy_mock));
 }
 
 void ConnectionManagerTest::TestWithServiceType(
@@ -149,7 +151,7 @@
   EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
   EXPECT_EQ(expected_type, type);
   testing::Mock::VerifyAndClearExpectations(
-      fake_shill_proxy_.GetManagerProxy());
+      fake_shill_proxy_->GetManagerProxy());
 }
 
 void ConnectionManagerTest::TestWithServiceTethering(
@@ -164,7 +166,7 @@
   EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
   EXPECT_EQ(expected_tethering, tethering);
   testing::Mock::VerifyAndClearExpectations(
-      fake_shill_proxy_.GetManagerProxy());
+      fake_shill_proxy_->GetManagerProxy());
 }
 
 TEST_F(ConnectionManagerTest, SimpleTest) {
diff --git a/real_system_state.cc b/real_system_state.cc
index a71f4cd..71bedb5 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -68,8 +68,9 @@
   LOG_IF(INFO, !hardware_->IsNormalBootMode()) << "Booted in dev mode.";
   LOG_IF(INFO, !hardware_->IsOfficialBuild()) << "Booted non-official build.";
 
-  if (!shill_proxy_.Init()) {
-    LOG(ERROR) << "Failed to initialize shill proxy.";
+  connection_manager_ = connection_manager::CreateConnectionManager(this);
+  if (!connection_manager_) {
+    LOG(ERROR) << "Error intializing the ConnectionManagerInterface.";
     return false;
   }
 
@@ -140,8 +141,7 @@
   // Initialize the Update Manager using the default state factory.
   chromeos_update_manager::State* um_state =
       chromeos_update_manager::DefaultStateFactory(
-          &policy_provider_, &shill_proxy_, &session_manager_proxy_,
-          &libcros_proxy_, this);
+          &policy_provider_, &session_manager_proxy_, &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 bd51cb0..758c995 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -32,12 +32,11 @@
 #include "update_engine/common/clock.h"
 #include "update_engine/common/hardware_interface.h"
 #include "update_engine/common/prefs.h"
-#include "update_engine/connection_manager.h"
+#include "update_engine/connection_manager_interface.h"
 #include "update_engine/daemon_state_interface.h"
 #include "update_engine/dbus_connection.h"
 #include "update_engine/p2p_manager.h"
 #include "update_engine/payload_state.h"
-#include "update_engine/shill_proxy.h"
 #include "update_engine/update_attempter.h"
 #include "update_engine/update_manager/update_manager.h"
 #include "update_engine/weave_service_interface.h"
@@ -84,7 +83,7 @@
   inline ClockInterface* clock() override { return &clock_; }
 
   inline ConnectionManagerInterface* connection_manager() override {
-    return &connection_manager_;
+    return connection_manager_.get();
   }
 
   inline HardwareInterface* hardware() override { return hardware_.get(); }
@@ -133,7 +132,6 @@
   org::chromium::debugdProxy debugd_proxy_;
   org::chromium::PowerManagerProxy power_manager_proxy_;
   org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
-  ShillProxy shill_proxy_;
   LibCrosProxy libcros_proxy_;
 
   // Interface for the clock.
@@ -147,7 +145,7 @@
 
   // The connection manager object that makes download decisions depending on
   // the current type of connection.
-  ConnectionManager connection_manager_{&shill_proxy_, this};
+  std::unique_ptr<ConnectionManagerInterface> connection_manager_;
 
   // Interface for the hardware functions.
   std::unique_ptr<HardwareInterface> hardware_;
diff --git a/shill_proxy.cc b/shill_proxy.cc
index 6049ee2..d398bba 100644
--- a/shill_proxy.cc
+++ b/shill_proxy.cc
@@ -25,11 +25,9 @@
 
 namespace chromeos_update_engine {
 
-bool ShillProxy::Init() {
-  bus_ = DBusConnection::Get()->GetDBus();
-  manager_proxy_.reset(new ManagerProxy(bus_));
-  return true;
-}
+ShillProxy::ShillProxy()
+    : bus_(DBusConnection::Get()->GetDBus()),
+      manager_proxy_(new ManagerProxy(bus_)) {}
 
 ManagerProxyInterface* ShillProxy::GetManagerProxy() {
   return manager_proxy_.get();
diff --git a/shill_proxy.h b/shill_proxy.h
index 78f5b9b..4b466c9 100644
--- a/shill_proxy.h
+++ b/shill_proxy.h
@@ -32,13 +32,9 @@
 // This class implements the connection to shill using real DBus calls.
 class ShillProxy : public ShillProxyInterface {
  public:
-  ShillProxy() = default;
+  ShillProxy();
   ~ShillProxy() override = default;
 
-  // Initializes the ShillProxy instance creating the manager proxy from the
-  // |bus_|.
-  bool Init();
-
   // ShillProxyInterface overrides.
   org::chromium::flimflam::ManagerProxyInterface* GetManagerProxy() override;
   std::unique_ptr<org::chromium::flimflam::ServiceProxyInterface>
diff --git a/update_manager/real_shill_provider.h b/update_manager/real_shill_provider.h
index 815bbfc..e7708c8 100644
--- a/update_manager/real_shill_provider.h
+++ b/update_manager/real_shill_provider.h
@@ -21,6 +21,7 @@
 // update engine's connection_manager.  We need to make sure to deprecate use of
 // connection manager when the time comes.
 
+#include <memory>
 #include <string>
 
 #include <base/time/time.h>
@@ -78,9 +79,8 @@
   // The current default service path, if connected. "/" means not connected.
   dbus::ObjectPath default_service_path_{"uninitialized"};
 
-  // The mockable interface to access the shill DBus proxies, owned by the
-  // caller.
-  chromeos_update_engine::ShillProxyInterface* shill_proxy_;
+  // The mockable interface to access the shill DBus proxies.
+  std::unique_ptr<chromeos_update_engine::ShillProxyInterface> shill_proxy_;
 
   // A clock abstraction (mockable).
   chromeos_update_engine::ClockInterface* const clock_;
diff --git a/update_manager/real_shill_provider_unittest.cc b/update_manager/real_shill_provider_unittest.cc
index 59e70f6..e821dc7 100644
--- a/update_manager/real_shill_provider_unittest.cc
+++ b/update_manager/real_shill_provider_unittest.cc
@@ -67,9 +67,10 @@
   void SetUp() override {
     fake_clock_.SetWallclockTime(InitTime());
     loop_.SetAsCurrent();
-    provider_.reset(new RealShillProvider(&fake_shill_proxy_, &fake_clock_));
+    fake_shill_proxy_ = new chromeos_update_engine::FakeShillProxy();
+    provider_.reset(new RealShillProvider(fake_shill_proxy_, &fake_clock_));
 
-    ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
+    ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
 
     // The PropertyChanged signal should be subscribed to.
     MOCK_SIGNAL_HANDLER_EXPECT_SIGNAL_HANDLER(
@@ -204,7 +205,7 @@
 
   brillo::FakeMessageLoop loop_{nullptr};
   FakeClock fake_clock_;
-  chromeos_update_engine::FakeShillProxy fake_shill_proxy_;
+  chromeos_update_engine::FakeShillProxy* fake_shill_proxy_;
 
   // The registered signal handler for the signal Manager.PropertyChanged.
   chromeos_update_engine::dbus_test_utils::MockSignalHandler<
@@ -215,7 +216,7 @@
 
 void UmRealShillProviderTest::SetManagerReply(const char* default_service,
                                               bool reply_succeeds) {
-  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
+  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
   if (!reply_succeeds) {
     EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
         .WillOnce(Return(false));
@@ -260,7 +261,7 @@
   EXPECT_CALL(*service_proxy_mock, GetProperties(_, _, _))
       .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
 
-  fake_shill_proxy_.SetServiceForPath(
+  fake_shill_proxy_->SetServiceForPath(
       dbus::ObjectPath(service_path),
       brillo::make_unique_ptr(service_proxy_mock));
   return service_proxy_mock;
@@ -289,7 +290,7 @@
 
 // Ensure that a service path property including a different type is ignored.
 TEST_F(UmRealShillProviderTest, InvalidServicePathType) {
-  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
+  ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
   brillo::VariantDictionary reply_dict;
   reply_dict[shill::kDefaultServiceProperty] = "/not/an/object/path";
   EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index e01f769..822f943 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -22,6 +22,7 @@
 
 #include "update_engine/common/clock_interface.h"
 #include "update_engine/libcros_proxy.h"
+#include "update_engine/shill_proxy.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"
@@ -37,7 +38,6 @@
 
 State* DefaultStateFactory(
     policy::PolicyProvider* policy_provider,
-    chromeos_update_engine::ShillProxy* shill_proxy,
     org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
     chromeos_update_engine::LibCrosProxy* libcros_proxy,
     chromeos_update_engine::SystemState* system_state) {
@@ -48,11 +48,9 @@
       new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
   unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
   unique_ptr<RealShillProvider> shill_provider(
-      new RealShillProvider(shill_proxy, clock));
-  unique_ptr<RealSystemProvider> system_provider(
-      new RealSystemProvider(system_state->hardware(),
-                             system_state->boot_control(),
-                             libcros_proxy));
+      new RealShillProvider(new chromeos_update_engine::ShillProxy(), clock));
+  unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider(
+      system_state->hardware(), system_state->boot_control(), libcros_proxy));
   unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
   unique_ptr<RealUpdaterProvider> updater_provider(
       new RealUpdaterProvider(system_state));
diff --git a/update_manager/state_factory.h b/update_manager/state_factory.h
index 726deeb..96f62f0 100644
--- a/update_manager/state_factory.h
+++ b/update_manager/state_factory.h
@@ -19,7 +19,6 @@
 
 #include <session_manager/dbus-proxies.h>
 
-#include "update_engine/shill_proxy.h"
 #include "update_engine/system_state.h"
 #include "update_engine/update_manager/state.h"
 
@@ -36,7 +35,6 @@
 // to initialize.
 State* DefaultStateFactory(
     policy::PolicyProvider* policy_provider,
-    chromeos_update_engine::ShillProxy* shill_proxy,
     org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
     chromeos_update_engine::LibCrosProxy* libcros_proxy,
     chromeos_update_engine::SystemState* system_state);