blob: 873909ee2cbd64c2fcb6e8b8fa2014a8a8fed6f3 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2010 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//
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_DBUS_SERVICE_H_
18#define UPDATE_ENGINE_DBUS_SERVICE_H_
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070019
20#include <inttypes.h>
Alex Vakulenko44cab302014-07-23 13:12:15 -070021
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070022#include <memory>
Alex Deymob7ca0962014-10-01 17:58:07 -070023#include <string>
Amin Hassanifab175a2020-04-17 11:20:50 -070024#include <vector>
Alex Deymob7ca0962014-10-01 17:58:07 -070025
26#include <base/memory/ref_counted.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070027#include <brillo/errors/error.h>
Amin Hassanieb463ee2019-06-20 19:23:03 -070028#include <update_engine/proto_bindings/update_engine.pb.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070029
Casey Dahlina93cd532016-01-14 16:55:11 -080030#include "update_engine/common_service.h"
Alex Deymofa78f142016-01-26 21:36:16 -080031#include "update_engine/service_observer_interface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070032#include "update_engine/update_attempter.h"
33
Alex Deymo6f20dd42015-08-18 16:42:46 -070034#include "dbus_bindings/org.chromium.UpdateEngineInterface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070035
Alex Deymob7ca0962014-10-01 17:58:07 -070036namespace chromeos_update_engine {
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070037
Casey Dahlina93cd532016-01-14 16:55:11 -080038class DBusUpdateEngineService
Alex Deymob7ca0962014-10-01 17:58:07 -070039 : public org::chromium::UpdateEngineInterfaceInterface {
40 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080041 explicit DBusUpdateEngineService(SystemState* system_state);
42 virtual ~DBusUpdateEngineService() = default;
Alex Deymob7ca0962014-10-01 17:58:07 -070043
44 // Implementation of org::chromium::UpdateEngineInterfaceInterface.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070045 bool AttemptUpdate(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070046 const std::string& in_app_version,
47 const std::string& in_omaha_url) override;
48
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070049 bool AttemptUpdateWithFlags(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070050 const std::string& in_app_version,
51 const std::string& in_omaha_url,
52 int32_t in_flags_as_int) override;
53
Xiaochu Liu88d90382018-08-29 16:09:11 -070054 bool AttemptInstall(brillo::ErrorPtr* error,
Amin Hassanifab175a2020-04-17 11:20:50 -070055 const std::string& in_omaha_url,
56 const std::vector<std::string>& dlc_ids) override;
Xiaochu Liu88d90382018-08-29 16:09:11 -070057
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070058 bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070059
60 // Checks if the system rollback is available by verifying if the secondary
61 // system partition is valid and bootable.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070062 bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070063
64 // Resets the status of the update_engine to idle, ignoring any applied
65 // update. This is used for development only.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070066 bool ResetStatus(brillo::ErrorPtr* error) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070067
Andrewa8d7df32020-03-15 20:10:01 -070068 // Sets the DLC as active or inactive. When set to active, the ping metadata
69 // for the DLC is updated accordingly. When set to inactive, the metadata
70 // for the DLC is deleted.
71 bool SetDlcActiveValue(brillo::ErrorPtr* error,
72 bool is_active,
73 const std::string& dlc_id) override;
74
Amin Hassanieb463ee2019-06-20 19:23:03 -070075 // Similar to Above, but returns a protobuffer instead. In the future it will
76 // have more features and is easily extendable.
77 bool GetStatusAdvanced(brillo::ErrorPtr* error,
78 update_engine::StatusResult* out_status) override;
79
Alex Deymob7ca0962014-10-01 17:58:07 -070080 // Reboots the device if an update is applied and a reboot is required.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070081 bool RebootIfNeeded(brillo::ErrorPtr* error) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070082
83 // Changes the current channel of the device to the target channel. If the
84 // target channel is a less stable channel than the current channel, then the
85 // channel change happens immediately (at the next update check). If the
86 // target channel is a more stable channel, then if is_powerwash_allowed is
87 // set to true, then also the change happens immediately but with a powerwash
88 // if required. Otherwise, the change takes effect eventually (when the
89 // version on the target channel goes above the version number of what the
90 // device currently has).
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070091 bool SetChannel(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070092 const std::string& in_target_channel,
93 bool in_is_powerwash_allowed) override;
94
95 // If get_current_channel is set to true, populates |channel| with the name of
96 // the channel that the device is currently on. Otherwise, it populates it
97 // with the name of the channel the device is supposed to be (in case of a
98 // pending channel change).
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070099 bool GetChannel(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700100 bool in_get_current_channel,
101 std::string* out_channel) override;
102
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700103 bool SetCohortHint(brillo::ErrorPtr* error,
104 const std::string& in_cohort_hint) override;
105
106 bool GetCohortHint(brillo::ErrorPtr* error,
107 std::string* out_cohort_hint) override;
108
Alex Deymob7ca0962014-10-01 17:58:07 -0700109 // Enables or disables the sharing and consuming updates over P2P feature
110 // according to the |enabled| argument passed.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700111 bool SetP2PUpdatePermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700112 bool in_enabled) override;
113
114 // Returns the current value for the P2P enabled setting. This involves both
115 // sharing and consuming updates over P2P.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700116 bool GetP2PUpdatePermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700117 bool* out_enabled) override;
118
119 // If there's no device policy installed, sets the update over cellular
120 // networks permission to the |allowed| value. Otherwise, this method returns
121 // with an error since this setting is overridden by the applied policy.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700122 bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700123 bool in_allowed) override;
124
Weidong Guo421ff332017-04-17 10:08:38 -0700125 // If there's no device policy installed, sets the update over cellular
126 // target. Otherwise, this method returns with an error.
127 bool SetUpdateOverCellularTarget(brillo::ErrorPtr* error,
128 const std::string& target_version,
129 int64_t target_size) override;
130
Alex Deymob7ca0962014-10-01 17:58:07 -0700131 // Returns the current value of the update over cellular network setting,
132 // either forced by the device policy if the device is enrolled or the current
133 // user preference otherwise.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700134 bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700135 bool* out_allowed) override;
136
137 // Returns the duration since the last successful update, as the
138 // duration on the wallclock. Returns an error if the device has not
139 // updated.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700140 bool GetDurationSinceUpdate(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700141 int64_t* out_usec_wallclock) override;
142
143 // Returns the version string of OS that was used before the last reboot
144 // into an updated version. This is available only when rebooting into an
145 // update from previous version, otherwise an empty string is returned.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700146 bool GetPrevVersion(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700147 std::string* out_prev_version) override;
148
Alex Deymob7ca0962014-10-01 17:58:07 -0700149 // Returns the name of kernel partition that can be rolled back into.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700150 bool GetRollbackPartition(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700151 std::string* out_rollback_partition_name) override;
152
Shuqian Zhao29971732016-02-05 11:29:32 -0800153 // Returns the last UpdateAttempt error. If not updated yet, default success
154 // ErrorCode will be returned.
155 bool GetLastAttemptError(brillo::ErrorPtr* error,
156 int32_t* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -0700157
Alex Deymob7ca0962014-10-01 17:58:07 -0700158 private:
Casey Dahlina93cd532016-01-14 16:55:11 -0800159 std::unique_ptr<UpdateEngineService> common_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700160};
161
Alex Deymob7ca0962014-10-01 17:58:07 -0700162// The UpdateEngineAdaptor class runs the UpdateEngineInterface in the fixed
163// object path, without an ObjectManager notifying the interfaces, since it is
164// all static and clients don't expect it to be implemented.
Alex Deymofa78f142016-01-26 21:36:16 -0800165class UpdateEngineAdaptor : public org::chromium::UpdateEngineInterfaceAdaptor,
166 public ServiceObserverInterface {
Alex Deymob7ca0962014-10-01 17:58:07 -0700167 public:
Weidong Guo421ff332017-04-17 10:08:38 -0700168 explicit UpdateEngineAdaptor(SystemState* system_state);
Alex Deymob7ca0962014-10-01 17:58:07 -0700169 ~UpdateEngineAdaptor() = default;
170
171 // Register the DBus object with the update engine service asynchronously.
172 // Calls |copmletion_callback| when done passing a boolean indicating if the
173 // registration succeeded.
174 void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
175
176 // Takes ownership of the well-known DBus name and returns whether it
177 // succeeded.
178 bool RequestOwnership();
179
Alex Deymofa78f142016-01-26 21:36:16 -0800180 // ServiceObserverInterface overrides.
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700181 void SendStatusUpdate(
182 const update_engine::UpdateEngineStatus& update_engine_status) override;
Alex Deymofa78f142016-01-26 21:36:16 -0800183
Alex Deymof8bfcff2016-02-02 21:22:11 -0800184 void SendPayloadApplicationComplete(ErrorCode error_code) override {}
185
Alex Deymob7ca0962014-10-01 17:58:07 -0700186 private:
187 scoped_refptr<dbus::Bus> bus_;
Casey Dahlina93cd532016-01-14 16:55:11 -0800188 DBusUpdateEngineService dbus_service_;
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700189 brillo::dbus_utils::DBusObject dbus_object_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700190};
191
Alex Deymob7ca0962014-10-01 17:58:07 -0700192} // namespace chromeos_update_engine
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700193
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700194#endif // UPDATE_ENGINE_DBUS_SERVICE_H_