Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 16 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |
| 18 | #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 19 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 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 <string> |
| 25 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 26 | #include <base/time/time.h> |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 27 | #include <dbus/object_path.h> |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 28 | |
| 29 | #include "update_engine/clock_interface.h" |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 30 | #include "update_engine/shill_proxy_interface.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 31 | #include "update_engine/update_manager/generic_variables.h" |
| 32 | #include "update_engine/update_manager/shill_provider.h" |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 33 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 34 | namespace chromeos_update_manager { |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 35 | |
| 36 | // ShillProvider concrete implementation. |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 37 | class RealShillProvider : public ShillProvider { |
| 38 | public: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 39 | RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy, |
| 40 | chromeos_update_engine::ClockInterface* clock) |
| 41 | : shill_proxy_(shill_proxy), clock_(clock) {} |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 42 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 43 | ~RealShillProvider() override = default; |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 44 | |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 45 | // Initializes the provider and returns whether it succeeded. |
| 46 | bool Init(); |
| 47 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 48 | Variable<bool>* var_is_connected() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 49 | return &var_is_connected_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 52 | Variable<ConnectionType>* var_conn_type() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 53 | return &var_conn_type_; |
| 54 | } |
| 55 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 56 | Variable<ConnectionTethering>* var_conn_tethering() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 57 | return &var_conn_tethering_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 60 | Variable<base::Time>* var_conn_last_changed() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 61 | return &var_conn_last_changed_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 64 | // Helper methods for converting shill strings into symbolic values. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 65 | static ConnectionType ParseConnectionType(const std::string& type_str); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 66 | static ConnectionTethering ParseConnectionTethering( |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 67 | const std::string& tethering_str); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 68 | |
David Zeuthen | 21716e2 | 2014-04-23 15:42:05 -0700 | [diff] [blame] | 69 | private: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 70 | // A handler for ManagerProxy.PropertyChanged signal. |
| 71 | void OnManagerPropertyChanged(const std::string& name, |
| 72 | const chromeos::Any& value); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 73 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 74 | // Called when the signal in ManagerProxy.PropertyChanged is connected. |
| 75 | void OnSignalConnected(const std::string& interface_name, |
| 76 | const std::string& signal_name, |
| 77 | bool successful); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 78 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 79 | // Get the connection and populate the type and tethering status of the given |
| 80 | // default connection. |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 81 | bool ProcessDefaultService(const dbus::ObjectPath& default_service_path); |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 82 | |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 83 | // The current default service path, if connected. "/" means not connected. |
| 84 | dbus::ObjectPath default_service_path_{"uninitialized"}; |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 85 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 86 | // The mockable interface to access the shill DBus proxies, owned by the |
| 87 | // caller. |
| 88 | chromeos_update_engine::ShillProxyInterface* shill_proxy_; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 89 | |
| 90 | // A clock abstraction (mockable). |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 91 | chromeos_update_engine::ClockInterface* const clock_; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 92 | |
Gilad Arnold | d3df25f | 2014-04-22 08:39:48 -0700 | [diff] [blame] | 93 | // The provider's variables. |
| 94 | AsyncCopyVariable<bool> var_is_connected_{"is_connected"}; |
| 95 | AsyncCopyVariable<ConnectionType> var_conn_type_{"conn_type"}; |
| 96 | AsyncCopyVariable<ConnectionTethering> var_conn_tethering_{"conn_tethering"}; |
| 97 | AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"}; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 98 | |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(RealShillProvider); |
| 100 | }; |
| 101 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 102 | } // namespace chromeos_update_manager |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 103 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 104 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |