blob: 62984f6be2356f103c6264bcf4223d99fcbe2faf [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>
24
25#include <base/memory/ref_counted.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070026#include <brillo/errors/error.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070027
Casey Dahlina93cd532016-01-14 16:55:11 -080028#include "update_engine/common_service.h"
Alex Deymofa78f142016-01-26 21:36:16 -080029#include "update_engine/service_observer_interface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070030#include "update_engine/update_attempter.h"
31
Alex Deymo6f20dd42015-08-18 16:42:46 -070032#include "dbus_bindings/org.chromium.UpdateEngineInterface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070033
Alex Deymob7ca0962014-10-01 17:58:07 -070034namespace chromeos_update_engine {
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070035
Casey Dahlina93cd532016-01-14 16:55:11 -080036class DBusUpdateEngineService
Alex Deymob7ca0962014-10-01 17:58:07 -070037 : public org::chromium::UpdateEngineInterfaceInterface {
38 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080039 explicit DBusUpdateEngineService(SystemState* system_state);
40 virtual ~DBusUpdateEngineService() = default;
Alex Deymob7ca0962014-10-01 17:58:07 -070041
42 // Implementation of org::chromium::UpdateEngineInterfaceInterface.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070043 bool AttemptUpdate(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070044 const std::string& in_app_version,
45 const std::string& in_omaha_url) override;
46
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070047 bool AttemptUpdateWithFlags(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070048 const std::string& in_app_version,
49 const std::string& in_omaha_url,
50 int32_t in_flags_as_int) override;
51
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070052 bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070053
54 // Checks if the system rollback is available by verifying if the secondary
55 // system partition is valid and bootable.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070056 bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070057
58 // Resets the status of the update_engine to idle, ignoring any applied
59 // update. This is used for development only.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070060 bool ResetStatus(brillo::ErrorPtr* error) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070061
62 // Returns the current status of the Update Engine. If an update is in
63 // progress, the number of operations, size to download and overall progress
64 // is reported.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070065 bool GetStatus(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070066 int64_t* out_last_checked_time,
67 double* out_progress,
68 std::string* out_current_operation,
69 std::string* out_new_version,
70 int64_t* out_new_size) override;
71
72 // Reboots the device if an update is applied and a reboot is required.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070073 bool RebootIfNeeded(brillo::ErrorPtr* error) override;
Alex Deymob7ca0962014-10-01 17:58:07 -070074
75 // Changes the current channel of the device to the target channel. If the
76 // target channel is a less stable channel than the current channel, then the
77 // channel change happens immediately (at the next update check). If the
78 // target channel is a more stable channel, then if is_powerwash_allowed is
79 // set to true, then also the change happens immediately but with a powerwash
80 // if required. Otherwise, the change takes effect eventually (when the
81 // version on the target channel goes above the version number of what the
82 // device currently has).
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070083 bool SetChannel(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070084 const std::string& in_target_channel,
85 bool in_is_powerwash_allowed) override;
86
87 // If get_current_channel is set to true, populates |channel| with the name of
88 // the channel that the device is currently on. Otherwise, it populates it
89 // with the name of the channel the device is supposed to be (in case of a
90 // pending channel change).
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070091 bool GetChannel(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -070092 bool in_get_current_channel,
93 std::string* out_channel) override;
94
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070095 bool SetCohortHint(brillo::ErrorPtr* error,
96 const std::string& in_cohort_hint) override;
97
98 bool GetCohortHint(brillo::ErrorPtr* error,
99 std::string* out_cohort_hint) override;
100
Alex Deymob7ca0962014-10-01 17:58:07 -0700101 // Enables or disables the sharing and consuming updates over P2P feature
102 // according to the |enabled| argument passed.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700103 bool SetP2PUpdatePermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700104 bool in_enabled) override;
105
106 // Returns the current value for the P2P enabled setting. This involves both
107 // sharing and consuming updates over P2P.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700108 bool GetP2PUpdatePermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700109 bool* out_enabled) override;
110
111 // If there's no device policy installed, sets the update over cellular
112 // networks permission to the |allowed| value. Otherwise, this method returns
113 // with an error since this setting is overridden by the applied policy.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700114 bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700115 bool in_allowed) override;
116
117 // Returns the current value of the update over cellular network setting,
118 // either forced by the device policy if the device is enrolled or the current
119 // user preference otherwise.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700120 bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700121 bool* out_allowed) override;
122
123 // Returns the duration since the last successful update, as the
124 // duration on the wallclock. Returns an error if the device has not
125 // updated.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700126 bool GetDurationSinceUpdate(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700127 int64_t* out_usec_wallclock) override;
128
129 // Returns the version string of OS that was used before the last reboot
130 // into an updated version. This is available only when rebooting into an
131 // update from previous version, otherwise an empty string is returned.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700132 bool GetPrevVersion(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700133 std::string* out_prev_version) override;
134
Alex Deymob7ca0962014-10-01 17:58:07 -0700135 // Returns the name of kernel partition that can be rolled back into.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700136 bool GetRollbackPartition(brillo::ErrorPtr* error,
Alex Deymob7ca0962014-10-01 17:58:07 -0700137 std::string* out_rollback_partition_name) override;
138
Shuqian Zhao29971732016-02-05 11:29:32 -0800139 // Returns the last UpdateAttempt error. If not updated yet, default success
140 // ErrorCode will be returned.
141 bool GetLastAttemptError(brillo::ErrorPtr* error,
142 int32_t* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -0700143
144 // Returns the current end-of-life status of the device in |out_eol_status|.
145 bool GetEolStatus(brillo::ErrorPtr* error, int32_t* out_eol_status) override;
146
Alex Deymob7ca0962014-10-01 17:58:07 -0700147 private:
Casey Dahlina93cd532016-01-14 16:55:11 -0800148 std::unique_ptr<UpdateEngineService> common_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700149};
150
Alex Deymob7ca0962014-10-01 17:58:07 -0700151// The UpdateEngineAdaptor class runs the UpdateEngineInterface in the fixed
152// object path, without an ObjectManager notifying the interfaces, since it is
153// all static and clients don't expect it to be implemented.
Alex Deymofa78f142016-01-26 21:36:16 -0800154class UpdateEngineAdaptor : public org::chromium::UpdateEngineInterfaceAdaptor,
155 public ServiceObserverInterface {
Alex Deymob7ca0962014-10-01 17:58:07 -0700156 public:
Sen Jiang299128e2016-06-03 17:48:18 -0700157 UpdateEngineAdaptor(SystemState* system_state);
Alex Deymob7ca0962014-10-01 17:58:07 -0700158 ~UpdateEngineAdaptor() = default;
159
160 // Register the DBus object with the update engine service asynchronously.
161 // Calls |copmletion_callback| when done passing a boolean indicating if the
162 // registration succeeded.
163 void RegisterAsync(const base::Callback<void(bool)>& completion_callback);
164
165 // Takes ownership of the well-known DBus name and returns whether it
166 // succeeded.
167 bool RequestOwnership();
168
Alex Deymofa78f142016-01-26 21:36:16 -0800169 // ServiceObserverInterface overrides.
170 void SendStatusUpdate(int64_t last_checked_time,
171 double progress,
172 update_engine::UpdateStatus status,
173 const std::string& new_version,
174 int64_t new_size) override;
175
Alex Deymof8bfcff2016-02-02 21:22:11 -0800176 void SendPayloadApplicationComplete(ErrorCode error_code) override {}
177
Alex Deymofa78f142016-01-26 21:36:16 -0800178 // Channel tracking changes are ignored.
179 void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
180
Alex Deymob7ca0962014-10-01 17:58:07 -0700181 private:
182 scoped_refptr<dbus::Bus> bus_;
Casey Dahlina93cd532016-01-14 16:55:11 -0800183 DBusUpdateEngineService dbus_service_;
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700184 brillo::dbus_utils::DBusObject dbus_object_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700185};
186
Alex Deymob7ca0962014-10-01 17:58:07 -0700187} // namespace chromeos_update_engine
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700188
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700189#endif // UPDATE_ENGINE_DBUS_SERVICE_H_