blob: aca4bae446f8e1271e9bafb6bbb2c0a8e62c7a4d [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
24#include <string>
25
Alex Vakulenko75039d72014-03-25 12:36:28 -070026#include <base/time/time.h>
Alex Deymo758dd532015-09-09 15:21:22 -070027#include <dbus/object_path.h>
Gilad Arnold5ef9c482014-03-03 13:51:02 -080028
29#include "update_engine/clock_interface.h"
Alex Deymo30534502015-07-20 15:06:33 -070030#include "update_engine/shill_proxy_interface.h"
Alex Deymo63784a52014-05-28 10:46:14 -070031#include "update_engine/update_manager/generic_variables.h"
32#include "update_engine/update_manager/shill_provider.h"
Gilad Arnold55f39b72014-01-28 12:51:45 -080033
Alex Deymo63784a52014-05-28 10:46:14 -070034namespace chromeos_update_manager {
Gilad Arnold55f39b72014-01-28 12:51:45 -080035
36// ShillProvider concrete implementation.
Gilad Arnold55f39b72014-01-28 12:51:45 -080037class RealShillProvider : public ShillProvider {
38 public:
Alex Deymo30534502015-07-20 15:06:33 -070039 RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy,
40 chromeos_update_engine::ClockInterface* clock)
41 : shill_proxy_(shill_proxy), clock_(clock) {}
Gilad Arnold55f39b72014-01-28 12:51:45 -080042
Alex Deymo30534502015-07-20 15:06:33 -070043 ~RealShillProvider() override = default;
Gilad Arnoldef120fa2014-04-09 12:52:10 -070044
Alex Deymo42c30c32014-04-24 18:41:18 -070045 // Initializes the provider and returns whether it succeeded.
46 bool Init();
47
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 Variable<bool>* var_is_connected() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070049 return &var_is_connected_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070050 }
51
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 Variable<ConnectionType>* var_conn_type() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070053 return &var_conn_type_;
54 }
55
Alex Vakulenko157fe302014-08-11 15:59:58 -070056 Variable<ConnectionTethering>* var_conn_tethering() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070057 return &var_conn_tethering_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070058 }
59
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 Variable<base::Time>* var_conn_last_changed() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070061 return &var_conn_last_changed_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070062 }
63
Gilad Arnoldef120fa2014-04-09 12:52:10 -070064 // Helper methods for converting shill strings into symbolic values.
Alex Deymo30534502015-07-20 15:06:33 -070065 static ConnectionType ParseConnectionType(const std::string& type_str);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070066 static ConnectionTethering ParseConnectionTethering(
Alex Deymo30534502015-07-20 15:06:33 -070067 const std::string& tethering_str);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070068
David Zeuthen21716e22014-04-23 15:42:05 -070069 private:
Alex Deymo30534502015-07-20 15:06:33 -070070 // A handler for ManagerProxy.PropertyChanged signal.
71 void OnManagerPropertyChanged(const std::string& name,
72 const chromeos::Any& value);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070073
Alex Deymo30534502015-07-20 15:06:33 -070074 // 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 Arnoldef120fa2014-04-09 12:52:10 -070078
Alex Deymo30534502015-07-20 15:06:33 -070079 // Get the connection and populate the type and tethering status of the given
80 // default connection.
Alex Deymo758dd532015-09-09 15:21:22 -070081 bool ProcessDefaultService(const dbus::ObjectPath& default_service_path);
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070082
Alex Deymo758dd532015-09-09 15:21:22 -070083 // The current default service path, if connected. "/" means not connected.
84 dbus::ObjectPath default_service_path_{"uninitialized"};
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070085
Alex Deymo30534502015-07-20 15:06:33 -070086 // The mockable interface to access the shill DBus proxies, owned by the
87 // caller.
88 chromeos_update_engine::ShillProxyInterface* shill_proxy_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080089
90 // A clock abstraction (mockable).
Alex Deymo30534502015-07-20 15:06:33 -070091 chromeos_update_engine::ClockInterface* const clock_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080092
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070093 // 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 Arnolddf3dd242014-04-09 07:15:51 -070098
Gilad Arnold55f39b72014-01-28 12:51:45 -080099 DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
100};
101
Alex Deymo63784a52014-05-28 10:46:14 -0700102} // namespace chromeos_update_manager
Gilad Arnold55f39b72014-01-28 12:51:45 -0800103
Gilad Arnold48415f12014-06-27 07:10:58 -0700104#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_