blob: 64292405cd1f13f858cb9cff4153142662580545 [file] [log] [blame]
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_DBUS_SERVICE_H_
6#define UPDATE_ENGINE_DBUS_SERVICE_H_
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07007
8#include <inttypes.h>
Alex Vakulenko44cab302014-07-23 13:12:15 -07009
Alex Deymob7ca0962014-10-01 17:58:07 -070010#include <string>
11
12#include <base/memory/ref_counted.h>
13#include <chromeos/errors/error.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070014
15#include "update_engine/update_attempter.h"
16
Alex Deymob7ca0962014-10-01 17:58:07 -070017#include "update_engine/dbus_adaptor/org.chromium.UpdateEngineInterface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070018
Alex Deymob7ca0962014-10-01 17:58:07 -070019namespace chromeos {
20namespace dbus {
21class Bus;
22} // namespace dbus
23} // namespace chromeos
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070024
Alex Deymob7ca0962014-10-01 17:58:07 -070025namespace chromeos_update_engine {
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070026
Alex Deymob7ca0962014-10-01 17:58:07 -070027class UpdateEngineService
28 : public org::chromium::UpdateEngineInterfaceInterface {
29 public:
30 explicit UpdateEngineService(SystemState* system_state);
31 virtual ~UpdateEngineService() = default;
32
33 // Implementation of org::chromium::UpdateEngineInterfaceInterface.
34 bool AttemptUpdate(chromeos::ErrorPtr* error,
35 const std::string& in_app_version,
36 const std::string& in_omaha_url) override;
37
38 bool AttemptUpdateWithFlags(chromeos::ErrorPtr* error,
39 const std::string& in_app_version,
40 const std::string& in_omaha_url,
41 int32_t in_flags_as_int) override;
42
43 bool AttemptRollback(chromeos::ErrorPtr* error, bool in_powerwash) override;
44
45 // Checks if the system rollback is available by verifying if the secondary
46 // system partition is valid and bootable.
47 bool CanRollback(chromeos::ErrorPtr* error, bool* out_can_rollback) override;
48
49 // Resets the status of the update_engine to idle, ignoring any applied
50 // update. This is used for development only.
51 bool ResetStatus(chromeos::ErrorPtr* error) override;
52
53 // Returns the current status of the Update Engine. If an update is in
54 // progress, the number of operations, size to download and overall progress
55 // is reported.
56 bool GetStatus(chromeos::ErrorPtr* error,
57 int64_t* out_last_checked_time,
58 double* out_progress,
59 std::string* out_current_operation,
60 std::string* out_new_version,
61 int64_t* out_new_size) override;
62
63 // Reboots the device if an update is applied and a reboot is required.
64 bool RebootIfNeeded(chromeos::ErrorPtr* error) override;
65
66 // Changes the current channel of the device to the target channel. If the
67 // target channel is a less stable channel than the current channel, then the
68 // channel change happens immediately (at the next update check). If the
69 // target channel is a more stable channel, then if is_powerwash_allowed is
70 // set to true, then also the change happens immediately but with a powerwash
71 // if required. Otherwise, the change takes effect eventually (when the
72 // version on the target channel goes above the version number of what the
73 // device currently has).
74 bool SetChannel(chromeos::ErrorPtr* error,
75 const std::string& in_target_channel,
76 bool in_is_powerwash_allowed) override;
77
78 // If get_current_channel is set to true, populates |channel| with the name of
79 // the channel that the device is currently on. Otherwise, it populates it
80 // with the name of the channel the device is supposed to be (in case of a
81 // pending channel change).
82 bool GetChannel(chromeos::ErrorPtr* error,
83 bool in_get_current_channel,
84 std::string* out_channel) override;
85
86 // Enables or disables the sharing and consuming updates over P2P feature
87 // according to the |enabled| argument passed.
88 bool SetP2PUpdatePermission(chromeos::ErrorPtr* error,
89 bool in_enabled) override;
90
91 // Returns the current value for the P2P enabled setting. This involves both
92 // sharing and consuming updates over P2P.
93 bool GetP2PUpdatePermission(chromeos::ErrorPtr* error,
94 bool* out_enabled) override;
95
96 // If there's no device policy installed, sets the update over cellular
97 // networks permission to the |allowed| value. Otherwise, this method returns
98 // with an error since this setting is overridden by the applied policy.
99 bool SetUpdateOverCellularPermission(chromeos::ErrorPtr* error,
100 bool in_allowed) override;
101
102 // Returns the current value of the update over cellular network setting,
103 // either forced by the device policy if the device is enrolled or the current
104 // user preference otherwise.
105 bool GetUpdateOverCellularPermission(chromeos::ErrorPtr* error,
106 bool* out_allowed) override;
107
108 // Returns the duration since the last successful update, as the
109 // duration on the wallclock. Returns an error if the device has not
110 // updated.
111 bool GetDurationSinceUpdate(chromeos::ErrorPtr* error,
112 int64_t* out_usec_wallclock) override;
113
114 // Returns the version string of OS that was used before the last reboot
115 // into an updated version. This is available only when rebooting into an
116 // update from previous version, otherwise an empty string is returned.
117 bool GetPrevVersion(chromeos::ErrorPtr* error,
118 std::string* out_prev_version) override;
119
120 // Returns a list of available kernel partitions and whether each of them
121 // can be booted from or not.
122 bool GetKernelDevices(chromeos::ErrorPtr* error,
123 std::string* out_kernel_devices) override;
124
125 // Returns the name of kernel partition that can be rolled back into.
126 bool GetRollbackPartition(chromeos::ErrorPtr* error,
127 std::string* out_rollback_partition_name) override;
128
129 private:
130 SystemState* system_state_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700131};
132
Alex Deymob7ca0962014-10-01 17:58:07 -0700133// The UpdateEngineAdaptor class runs the UpdateEngineInterface in the fixed
134// object path, without an ObjectManager notifying the interfaces, since it is
135// all static and clients don't expect it to be implemented.
136class UpdateEngineAdaptor : public org::chromium::UpdateEngineInterfaceAdaptor {
137 public:
138 UpdateEngineAdaptor(SystemState* system_state,
139 const scoped_refptr<dbus::Bus>& bus);
140 ~UpdateEngineAdaptor() = default;
141
142 // Register the DBus object with the update engine service asynchronously.
143 // Calls |copmletion_callback| when done passing a boolean indicating if the
144 // registration succeeded.
145 void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
146
147 // Takes ownership of the well-known DBus name and returns whether it
148 // succeeded.
149 bool RequestOwnership();
150
151 private:
152 scoped_refptr<dbus::Bus> bus_;
153 UpdateEngineService dbus_service_;
154 chromeos::dbus_utils::DBusObject dbus_object_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700155};
156
Alex Deymob7ca0962014-10-01 17:58:07 -0700157} // namespace chromeos_update_engine
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700158
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700159#endif // UPDATE_ENGINE_DBUS_SERVICE_H_