1 // 2 // Copyright (C) 2014 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_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ 18 #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ 19 20 // TODO(garnold) Much of the functionality in this module was adapted from the 21 // update engine's connection_manager. We need to make sure to deprecate use of 22 // connection manager when the time comes. 23 24 #include <memory> 25 #include <string> 26 27 #include <base/time/time.h> 28 #include <dbus/object_path.h> 29 30 #include "update_engine/common/clock_interface.h" 31 #include "update_engine/shill_proxy_interface.h" 32 #include "update_engine/update_manager/generic_variables.h" 33 #include "update_engine/update_manager/shill_provider.h" 34 35 namespace chromeos_update_manager { 36 37 // ShillProvider concrete implementation. 38 class RealShillProvider : public ShillProvider { 39 public: RealShillProvider(chromeos_update_engine::ShillProxyInterface * shill_proxy,chromeos_update_engine::ClockInterface * clock)40 RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy, 41 chromeos_update_engine::ClockInterface* clock) 42 : shill_proxy_(shill_proxy), clock_(clock) {} 43 44 ~RealShillProvider() override = default; 45 46 // Initializes the provider and returns whether it succeeded. 47 bool Init(); 48 var_is_connected()49 Variable<bool>* var_is_connected() override { 50 return &var_is_connected_; 51 } 52 var_conn_type()53 Variable<chromeos_update_engine::ConnectionType>* var_conn_type() override { 54 return &var_conn_type_; 55 } 56 var_conn_tethering()57 Variable<chromeos_update_engine::ConnectionTethering>* var_conn_tethering() override { 58 return &var_conn_tethering_; 59 } 60 var_conn_last_changed()61 Variable<base::Time>* var_conn_last_changed() override { 62 return &var_conn_last_changed_; 63 } 64 65 private: 66 // A handler for ManagerProxy.PropertyChanged signal. 67 void OnManagerPropertyChanged(const std::string& name, 68 const brillo::Any& value); 69 70 // Called when the signal in ManagerProxy.PropertyChanged is connected. 71 void OnSignalConnected(const std::string& interface_name, 72 const std::string& signal_name, 73 bool successful); 74 75 // Get the connection and populate the type and tethering status of the given 76 // default connection. 77 bool ProcessDefaultService(const dbus::ObjectPath& default_service_path); 78 79 // The current default service path, if connected. "/" means not connected. 80 dbus::ObjectPath default_service_path_{"uninitialized"}; 81 82 // The mockable interface to access the shill DBus proxies. 83 std::unique_ptr<chromeos_update_engine::ShillProxyInterface> shill_proxy_; 84 85 // A clock abstraction (mockable). 86 chromeos_update_engine::ClockInterface* const clock_; 87 88 // The provider's variables. 89 AsyncCopyVariable<bool> var_is_connected_{"is_connected"}; 90 AsyncCopyVariable<chromeos_update_engine::ConnectionType> var_conn_type_{ 91 "conn_type"}; 92 AsyncCopyVariable<chromeos_update_engine::ConnectionTethering> 93 var_conn_tethering_{"conn_tethering"}; 94 AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"}; 95 96 DISALLOW_COPY_AND_ASSIGN(RealShillProvider); 97 }; 98 99 } // namespace chromeos_update_manager 100 101 #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ 102