blob: e7708c884396d392d893793d1a1c1dcf0b2ad69e [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Arnold55f39b72014-01-28 12:51:45 -080016
Gilad Arnold48415f12014-06-27 07:10:58 -070017#ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_
18#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_
Gilad Arnold55f39b72014-01-28 12:51:45 -080019
Gilad Arnold5ef9c482014-03-03 13:51:02 -080020// 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
Sen Jiangf5bebae2016-06-03 15:36:54 -070024#include <memory>
Gilad Arnold5ef9c482014-03-03 13:51:02 -080025#include <string>
26
Alex Vakulenko75039d72014-03-25 12:36:28 -070027#include <base/time/time.h>
Alex Deymo758dd532015-09-09 15:21:22 -070028#include <dbus/object_path.h>
Gilad Arnold5ef9c482014-03-03 13:51:02 -080029
Alex Deymo39910dc2015-11-09 17:04:30 -080030#include "update_engine/common/clock_interface.h"
Alex Deymo30534502015-07-20 15:06:33 -070031#include "update_engine/shill_proxy_interface.h"
Alex Deymo63784a52014-05-28 10:46:14 -070032#include "update_engine/update_manager/generic_variables.h"
33#include "update_engine/update_manager/shill_provider.h"
Gilad Arnold55f39b72014-01-28 12:51:45 -080034
Alex Deymo63784a52014-05-28 10:46:14 -070035namespace chromeos_update_manager {
Gilad Arnold55f39b72014-01-28 12:51:45 -080036
37// ShillProvider concrete implementation.
Gilad Arnold55f39b72014-01-28 12:51:45 -080038class RealShillProvider : public ShillProvider {
39 public:
Alex Deymo30534502015-07-20 15:06:33 -070040 RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy,
41 chromeos_update_engine::ClockInterface* clock)
42 : shill_proxy_(shill_proxy), clock_(clock) {}
Gilad Arnold55f39b72014-01-28 12:51:45 -080043
Alex Deymo30534502015-07-20 15:06:33 -070044 ~RealShillProvider() override = default;
Gilad Arnoldef120fa2014-04-09 12:52:10 -070045
Alex Deymo42c30c32014-04-24 18:41:18 -070046 // Initializes the provider and returns whether it succeeded.
47 bool Init();
48
Alex Vakulenko157fe302014-08-11 15:59:58 -070049 Variable<bool>* var_is_connected() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070050 return &var_is_connected_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070051 }
52
Sen Jiang255e22b2016-05-20 16:15:29 -070053 Variable<chromeos_update_engine::ConnectionType>* var_conn_type() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070054 return &var_conn_type_;
55 }
56
Sen Jiang255e22b2016-05-20 16:15:29 -070057 Variable<chromeos_update_engine::ConnectionTethering>* var_conn_tethering() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070058 return &var_conn_tethering_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070059 }
60
Alex Vakulenko157fe302014-08-11 15:59:58 -070061 Variable<base::Time>* var_conn_last_changed() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070062 return &var_conn_last_changed_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070063 }
64
David Zeuthen21716e22014-04-23 15:42:05 -070065 private:
Alex Deymo30534502015-07-20 15:06:33 -070066 // A handler for ManagerProxy.PropertyChanged signal.
67 void OnManagerPropertyChanged(const std::string& name,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070068 const brillo::Any& value);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070069
Alex Deymo30534502015-07-20 15:06:33 -070070 // 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);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070074
Alex Deymo30534502015-07-20 15:06:33 -070075 // Get the connection and populate the type and tethering status of the given
76 // default connection.
Alex Deymo758dd532015-09-09 15:21:22 -070077 bool ProcessDefaultService(const dbus::ObjectPath& default_service_path);
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070078
Alex Deymo758dd532015-09-09 15:21:22 -070079 // The current default service path, if connected. "/" means not connected.
80 dbus::ObjectPath default_service_path_{"uninitialized"};
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070081
Sen Jiangf5bebae2016-06-03 15:36:54 -070082 // The mockable interface to access the shill DBus proxies.
83 std::unique_ptr<chromeos_update_engine::ShillProxyInterface> shill_proxy_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080084
85 // A clock abstraction (mockable).
Alex Deymo30534502015-07-20 15:06:33 -070086 chromeos_update_engine::ClockInterface* const clock_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080087
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070088 // The provider's variables.
89 AsyncCopyVariable<bool> var_is_connected_{"is_connected"};
Sen Jiang255e22b2016-05-20 16:15:29 -070090 AsyncCopyVariable<chromeos_update_engine::ConnectionType> var_conn_type_{
91 "conn_type"};
92 AsyncCopyVariable<chromeos_update_engine::ConnectionTethering>
93 var_conn_tethering_{"conn_tethering"};
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070094 AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"};
Gilad Arnolddf3dd242014-04-09 07:15:51 -070095
Gilad Arnold55f39b72014-01-28 12:51:45 -080096 DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
97};
98
Alex Deymo63784a52014-05-28 10:46:14 -070099} // namespace chromeos_update_manager
Gilad Arnold55f39b72014-01-28 12:51:45 -0800100
Gilad Arnold48415f12014-06-27 07:10:58 -0700101#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_