Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_DBUS_SERVICE_H_ |
| 18 | #define UPDATE_ENGINE_DBUS_SERVICE_H_ |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 19 | |
| 20 | #include <inttypes.h> |
Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 21 | |
Alex Deymo | 5b5fa8b | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 22 | #include <memory> |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 23 | #include <string> |
| 24 | |
| 25 | #include <base/memory/ref_counted.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 26 | #include <brillo/errors/error.h> |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 27 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 28 | #include <update_engine/proto_bindings/update_engine.pb.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 29 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 30 | #include "update_engine/common_service.h" |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 31 | #include "update_engine/service_observer_interface.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 32 | #include "update_engine/update_attempter.h" |
| 33 | |
Alex Deymo | 6f20dd4 | 2015-08-18 16:42:46 -0700 | [diff] [blame] | 34 | #include "dbus_bindings/org.chromium.UpdateEngineInterface.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 35 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 36 | namespace chromeos_update_engine { |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 37 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 38 | class DBusUpdateEngineService |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 39 | : public org::chromium::UpdateEngineInterfaceInterface { |
| 40 | public: |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 41 | explicit DBusUpdateEngineService(SystemState* system_state); |
| 42 | virtual ~DBusUpdateEngineService() = default; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 43 | |
| 44 | // Implementation of org::chromium::UpdateEngineInterfaceInterface. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 45 | bool AttemptUpdate(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 46 | const std::string& in_app_version, |
| 47 | const std::string& in_omaha_url) override; |
| 48 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 49 | bool AttemptUpdateWithFlags(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 50 | const std::string& in_app_version, |
| 51 | const std::string& in_omaha_url, |
| 52 | int32_t in_flags_as_int) override; |
| 53 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 54 | bool AttemptInstall(brillo::ErrorPtr* error, |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 55 | const dlcservice::DlcModuleList& request) override; |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 56 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 57 | bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash) override; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 58 | |
| 59 | // Checks if the system rollback is available by verifying if the secondary |
| 60 | // system partition is valid and bootable. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 61 | bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback) override; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 62 | |
| 63 | // Resets the status of the update_engine to idle, ignoring any applied |
| 64 | // update. This is used for development only. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 65 | bool ResetStatus(brillo::ErrorPtr* error) override; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 66 | |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 67 | // Sets the DLC as active or inactive. When set to active, the ping metadata |
| 68 | // for the DLC is updated accordingly. When set to inactive, the metadata |
| 69 | // for the DLC is deleted. |
| 70 | bool SetDlcActiveValue(brillo::ErrorPtr* error, |
| 71 | bool is_active, |
| 72 | const std::string& dlc_id) override; |
| 73 | |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 74 | // Similar to Above, but returns a protobuffer instead. In the future it will |
| 75 | // have more features and is easily extendable. |
| 76 | bool GetStatusAdvanced(brillo::ErrorPtr* error, |
| 77 | update_engine::StatusResult* out_status) override; |
| 78 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 79 | // Reboots the device if an update is applied and a reboot is required. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 80 | bool RebootIfNeeded(brillo::ErrorPtr* error) override; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 81 | |
| 82 | // Changes the current channel of the device to the target channel. If the |
| 83 | // target channel is a less stable channel than the current channel, then the |
| 84 | // channel change happens immediately (at the next update check). If the |
| 85 | // target channel is a more stable channel, then if is_powerwash_allowed is |
| 86 | // set to true, then also the change happens immediately but with a powerwash |
| 87 | // if required. Otherwise, the change takes effect eventually (when the |
| 88 | // version on the target channel goes above the version number of what the |
| 89 | // device currently has). |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 90 | bool SetChannel(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 91 | const std::string& in_target_channel, |
| 92 | bool in_is_powerwash_allowed) override; |
| 93 | |
| 94 | // If get_current_channel is set to true, populates |channel| with the name of |
| 95 | // the channel that the device is currently on. Otherwise, it populates it |
| 96 | // with the name of the channel the device is supposed to be (in case of a |
| 97 | // pending channel change). |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 98 | bool GetChannel(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 99 | bool in_get_current_channel, |
| 100 | std::string* out_channel) override; |
| 101 | |
Alex Deymo | 5b5fa8b | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 102 | bool SetCohortHint(brillo::ErrorPtr* error, |
| 103 | const std::string& in_cohort_hint) override; |
| 104 | |
| 105 | bool GetCohortHint(brillo::ErrorPtr* error, |
| 106 | std::string* out_cohort_hint) override; |
| 107 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 108 | // Enables or disables the sharing and consuming updates over P2P feature |
| 109 | // according to the |enabled| argument passed. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 110 | bool SetP2PUpdatePermission(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 111 | bool in_enabled) override; |
| 112 | |
| 113 | // Returns the current value for the P2P enabled setting. This involves both |
| 114 | // sharing and consuming updates over P2P. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 115 | bool GetP2PUpdatePermission(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 116 | bool* out_enabled) override; |
| 117 | |
| 118 | // If there's no device policy installed, sets the update over cellular |
| 119 | // networks permission to the |allowed| value. Otherwise, this method returns |
| 120 | // with an error since this setting is overridden by the applied policy. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 121 | bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 122 | bool in_allowed) override; |
| 123 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 124 | // If there's no device policy installed, sets the update over cellular |
| 125 | // target. Otherwise, this method returns with an error. |
| 126 | bool SetUpdateOverCellularTarget(brillo::ErrorPtr* error, |
| 127 | const std::string& target_version, |
| 128 | int64_t target_size) override; |
| 129 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 130 | // Returns the current value of the update over cellular network setting, |
| 131 | // either forced by the device policy if the device is enrolled or the current |
| 132 | // user preference otherwise. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 133 | bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 134 | bool* out_allowed) override; |
| 135 | |
| 136 | // Returns the duration since the last successful update, as the |
| 137 | // duration on the wallclock. Returns an error if the device has not |
| 138 | // updated. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 139 | bool GetDurationSinceUpdate(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 140 | int64_t* out_usec_wallclock) override; |
| 141 | |
| 142 | // Returns the version string of OS that was used before the last reboot |
| 143 | // into an updated version. This is available only when rebooting into an |
| 144 | // update from previous version, otherwise an empty string is returned. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 145 | bool GetPrevVersion(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 146 | std::string* out_prev_version) override; |
| 147 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 148 | // Returns the name of kernel partition that can be rolled back into. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 149 | bool GetRollbackPartition(brillo::ErrorPtr* error, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 150 | std::string* out_rollback_partition_name) override; |
| 151 | |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 152 | // Returns the last UpdateAttempt error. If not updated yet, default success |
| 153 | // ErrorCode will be returned. |
| 154 | bool GetLastAttemptError(brillo::ErrorPtr* error, |
| 155 | int32_t* out_last_attempt_error) override; |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 156 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 157 | private: |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 158 | std::unique_ptr<UpdateEngineService> common_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 161 | // The UpdateEngineAdaptor class runs the UpdateEngineInterface in the fixed |
| 162 | // object path, without an ObjectManager notifying the interfaces, since it is |
| 163 | // all static and clients don't expect it to be implemented. |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 164 | class UpdateEngineAdaptor : public org::chromium::UpdateEngineInterfaceAdaptor, |
| 165 | public ServiceObserverInterface { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 166 | public: |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 167 | explicit UpdateEngineAdaptor(SystemState* system_state); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 168 | ~UpdateEngineAdaptor() = default; |
| 169 | |
| 170 | // Register the DBus object with the update engine service asynchronously. |
| 171 | // Calls |copmletion_callback| when done passing a boolean indicating if the |
| 172 | // registration succeeded. |
| 173 | void RegisterAsync(const base::Callback<void(bool)>& completion_callback); |
| 174 | |
| 175 | // Takes ownership of the well-known DBus name and returns whether it |
| 176 | // succeeded. |
| 177 | bool RequestOwnership(); |
| 178 | |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 179 | // ServiceObserverInterface overrides. |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 180 | void SendStatusUpdate( |
| 181 | const update_engine::UpdateEngineStatus& update_engine_status) override; |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 182 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 183 | void SendPayloadApplicationComplete(ErrorCode error_code) override {} |
| 184 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 185 | private: |
| 186 | scoped_refptr<dbus::Bus> bus_; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 187 | DBusUpdateEngineService dbus_service_; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 188 | brillo::dbus_utils::DBusObject dbus_object_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 191 | } // namespace chromeos_update_engine |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 192 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 193 | #endif // UPDATE_ENGINE_DBUS_SERVICE_H_ |