1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef UPDATE_ENGINE_CONNECTION_MANAGER_H_
18 #define UPDATE_ENGINE_CONNECTION_MANAGER_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include <base/macros.h>
24 #include <dbus/object_path.h>
25 
26 #include "update_engine/connection_manager_interface.h"
27 #include "update_engine/shill_proxy_interface.h"
28 
29 namespace chromeos_update_engine {
30 
31 // This class implements the concrete class that talks with the connection
32 // manager (shill) over DBus.
33 // TODO(deymo): Remove this class and use ShillProvider from the UpdateManager.
34 class ConnectionManager : public ConnectionManagerInterface {
35  public:
36   // Constructs a new ConnectionManager object initialized with the
37   // given system state.
38   ConnectionManager(ShillProxyInterface* shill_proxy,
39                     SystemState* system_state);
40   ~ConnectionManager() override = default;
41 
42   // ConnectionManagerInterface overrides.
43   bool GetConnectionProperties(ConnectionType* out_type,
44                                ConnectionTethering* out_tethering) override;
45   bool IsUpdateAllowedOver(ConnectionType type,
46                            ConnectionTethering tethering) const override;
47   bool IsAllowedConnectionTypesForUpdateSet() const override;
48 
49  private:
50   // Returns (via out_path) the default network path, or "/" if there's no
51   // network up. Returns true on success.
52   bool GetDefaultServicePath(dbus::ObjectPath* out_path);
53 
54   bool GetServicePathProperties(const dbus::ObjectPath& path,
55                                 ConnectionType* out_type,
56                                 ConnectionTethering* out_tethering);
57 
58   // The mockable interface to access the shill DBus proxies.
59   std::unique_ptr<ShillProxyInterface> shill_proxy_;
60 
61   // The global context for update_engine.
62   SystemState* system_state_;
63 
64   DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
65 };
66 
67 }  // namespace chromeos_update_engine
68 
69 #endif  // UPDATE_ENGINE_CONNECTION_MANAGER_H_
70