[email protected] | 85eafad | 2012-03-07 00:49:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 5 | #ifndef CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |
| 6 | #define CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 7 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
ygorshenin | 9903cf4 | 2014-10-07 06:47:11 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 12 | #include "base/callback.h" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 14 | #include "base/observer_list.h" |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 15 | #include "chromeos/chromeos_export.h" |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 16 | #include "chromeos/dbus/dbus_client.h" |
jamescook | 9be05a4 | 2016-09-19 19:09:49 | [diff] [blame] | 17 | #include "chromeos/dbus/dbus_client_implementation_type.h" |
kumarniranjan | b9afef6 | 2017-03-02 21:42:22 | [diff] [blame] | 18 | #include "dbus/message.h" |
xiaoyinh | f39e3dd | 2016-06-18 04:50:23 | [diff] [blame] | 19 | #include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h" |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 20 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 21 | namespace chromeos { |
| 22 | |
| 23 | // UpdateEngineClient is used to communicate with the update engine. |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 24 | class CHROMEOS_EXPORT UpdateEngineClient : public DBusClient { |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 25 | public: |
| 26 | // Edges for state machine |
| 27 | // IDLE->CHECKING_FOR_UPDATE |
| 28 | // CHECKING_FOR_UPDATE->IDLE |
| 29 | // CHECKING_FOR_UPDATE->UPDATE_AVAILABLE |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 30 | // CHECKING_FOR_UPDATE->NEED_PERMISSION_TO_UPDATE |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 31 | // ... |
| 32 | // FINALIZING->UPDATE_NEED_REBOOT |
| 33 | // Any state can transition to REPORTING_ERROR_EVENT and then on to IDLE. |
| 34 | enum UpdateStatusOperation { |
| 35 | UPDATE_STATUS_ERROR = -1, |
| 36 | UPDATE_STATUS_IDLE = 0, |
| 37 | UPDATE_STATUS_CHECKING_FOR_UPDATE, |
| 38 | UPDATE_STATUS_UPDATE_AVAILABLE, |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 39 | // User permission is needed to download an update on a cellular connection. |
| 40 | UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE, |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 41 | UPDATE_STATUS_DOWNLOADING, |
| 42 | UPDATE_STATUS_VERIFYING, |
| 43 | UPDATE_STATUS_FINALIZING, |
| 44 | UPDATE_STATUS_UPDATED_NEED_REBOOT, |
[email protected] | da15e07 | 2014-06-03 13:24:37 | [diff] [blame] | 45 | UPDATE_STATUS_REPORTING_ERROR_EVENT, |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 46 | UPDATE_STATUS_ATTEMPTING_ROLLBACK, |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | // The status of the ongoing update attempt. |
| 50 | struct Status { |
| 51 | Status() : status(UPDATE_STATUS_IDLE), |
| 52 | download_progress(0.0), |
| 53 | last_checked_time(0), |
| 54 | new_size(0) { |
| 55 | } |
| 56 | |
| 57 | UpdateStatusOperation status; |
| 58 | double download_progress; // 0.0 - 1.0 |
| 59 | int64_t last_checked_time; // As reported by std::time(). |
| 60 | std::string new_version; |
| 61 | int64_t new_size; // Valid during DOWNLOADING, in bytes. |
| 62 | }; |
| 63 | |
| 64 | // The result code used for RequestUpdateCheck(). |
| 65 | enum UpdateCheckResult { |
| 66 | UPDATE_RESULT_SUCCESS, |
| 67 | UPDATE_RESULT_FAILED, |
[email protected] | 85eafad | 2012-03-07 00:49:48 | [diff] [blame] | 68 | UPDATE_RESULT_NOTIMPLEMENTED, |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | // Interface for observing changes from the update engine. |
| 72 | class Observer { |
| 73 | public: |
Mitsuru Oshima | c01e405 | 2014-10-24 19:26:25 | [diff] [blame] | 74 | virtual ~Observer() {} |
| 75 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 76 | // Called when the status is updated. |
| 77 | virtual void UpdateStatusChanged(const Status& status) {} |
weidongg | 98258cc | 2017-06-13 22:35:49 | [diff] [blame] | 78 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 79 | // Called when the user's one time permission on update over cellular |
| 80 | // connection has been granted. |
| 81 | virtual void OnUpdateOverCellularOneTimePermissionGranted() {} |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 82 | }; |
| 83 | |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 84 | ~UpdateEngineClient() override; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 85 | |
| 86 | // Adds and removes the observer. |
| 87 | virtual void AddObserver(Observer* observer) = 0; |
| 88 | virtual void RemoveObserver(Observer* observer) = 0; |
| 89 | // Returns true if this object has the given observer. |
mgiuca | 64ccf236 | 2014-11-10 06:44:23 | [diff] [blame] | 90 | virtual bool HasObserver(const Observer* observer) const = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 91 | |
| 92 | // Called once RequestUpdateCheck() is complete. Takes one parameter: |
| 93 | // - UpdateCheckResult: the result of the update check. |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 94 | using UpdateCheckCallback = base::Callback<void(UpdateCheckResult)>; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 95 | |
| 96 | // Requests an update check and calls |callback| when completed. |
[email protected] | 4a404e5 | 2012-04-11 02:25:35 | [diff] [blame] | 97 | virtual void RequestUpdateCheck(const UpdateCheckCallback& callback) = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 98 | |
| 99 | // Reboots if update has been performed. |
| 100 | virtual void RebootAfterUpdate() = 0; |
| 101 | |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 102 | // Starts Rollback. |
| 103 | virtual void Rollback() = 0; |
| 104 | |
| 105 | // Called once CanRollbackCheck() is complete. Takes one parameter: |
| 106 | // - bool: the result of the rollback availability check. |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 107 | using RollbackCheckCallback = base::Callback<void(bool can_rollback)>; |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 108 | |
| 109 | // Checks if Rollback is available and calls |callback| when completed. |
| 110 | virtual void CanRollbackCheck( |
| 111 | const RollbackCheckCallback& callback) = 0; |
| 112 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 113 | // Called once GetChannel() is complete. Takes one parameter; |
| 114 | // - string: the channel name like "beta-channel". |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 115 | using GetChannelCallback = |
| 116 | base::Callback<void(const std::string& channel_name)>; |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 117 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 118 | // Returns the last status the object received from the update engine. |
| 119 | // |
| 120 | // Ideally, the D-Bus client should be state-less, but there are clients |
| 121 | // that need this information. |
| 122 | virtual Status GetLastStatus() = 0; |
| 123 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 124 | // Changes the current channel of the device to the target |
| 125 | // channel. If the target channel is a less stable channel than the |
| 126 | // current channel, then the channel change happens immediately (at |
| 127 | // the next update check). If the target channel is a more stable |
| 128 | // channel, then if |is_powerwash_allowed| is set to true, then also |
| 129 | // the change happens immediately but with a powerwash if |
| 130 | // required. Otherwise, the change takes effect eventually (when the |
| 131 | // version on the target channel goes above the version number of |
| 132 | // what the device currently has). |target_channel| should look like |
| 133 | // "dev-channel", "beta-channel" or "stable-channel". |
| 134 | virtual void SetChannel(const std::string& target_channel, |
| 135 | bool is_powerwash_allowed) = 0; |
| 136 | |
| 137 | // If |get_current_channel| is set to true, calls |callback| with |
| 138 | // the name of the channel that the device is currently |
| 139 | // on. Otherwise, it calls it with the name of the channel the |
| 140 | // device is supposed to be (in case of a pending channel |
| 141 | // change). On error, calls |callback| with an empty string. |
| 142 | virtual void GetChannel(bool get_current_channel, |
| 143 | const GetChannelCallback& callback) = 0; |
| 144 | |
xiaoyinh | f39e3dd | 2016-06-18 04:50:23 | [diff] [blame] | 145 | // Called once GetEolStatus() is complete. Takes one parameter; |
xiaoyinh | aa17d834 | 2016-06-30 22:56:02 | [diff] [blame] | 146 | // - EndOfLife Status: the end of life status of the device. |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 147 | using GetEolStatusCallback = |
| 148 | base::Callback<void(update_engine::EndOfLifeStatus status)>; |
xiaoyinh | f39e3dd | 2016-06-18 04:50:23 | [diff] [blame] | 149 | |
xiaoyinh | aa17d834 | 2016-06-30 22:56:02 | [diff] [blame] | 150 | // Get EndOfLife status of the device and calls |callback| when completed. |
xiaoyinh | f39e3dd | 2016-06-18 04:50:23 | [diff] [blame] | 151 | virtual void GetEolStatus(const GetEolStatusCallback& callback) = 0; |
| 152 | |
kumarniranjan | b9afef6 | 2017-03-02 21:42:22 | [diff] [blame] | 153 | // Either allow or disallow receiving updates over cellular connections. |
| 154 | // Synchronous (blocking) method. |
| 155 | virtual void SetUpdateOverCellularPermission( |
| 156 | bool allowed, |
| 157 | const base::Closure& callback) = 0; |
| 158 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 159 | // Called once SetUpdateOverCellularOneTimePermission() is complete. Takes one |
| 160 | // parameter; |
| 161 | // - success: indicates whether the permission is set successfully. |
| 162 | using UpdateOverCellularOneTimePermissionCallback = |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 163 | base::Callback<void(bool success)>; |
| 164 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 165 | // Sets a one time permission on a certain update in Update Engine which then |
| 166 | // performs downloading of that update after RequestUpdateCheck() is invoked |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 167 | // in the |callback|. |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame^] | 168 | // - update_version: the Chrome OS version we want to update to. |
| 169 | // - update_size: the size of that Chrome OS version in bytes. |
| 170 | // These two parameters are a failsafe to prevent downloading an update that |
| 171 | // the user didn't agree to. They should be set using the version and size we |
| 172 | // received from update engine when it broadcasts NEED_PERMISSION_TO_UPDATE. |
| 173 | // They are used by update engine to double-check with update server in case |
| 174 | // there's a new update available or a delta update becomes a full update with |
| 175 | // a larger size. |
| 176 | virtual void SetUpdateOverCellularOneTimePermission( |
| 177 | const std::string& update_version, |
| 178 | int64_t update_size, |
| 179 | const UpdateOverCellularOneTimePermissionCallback& callback) = 0; |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 180 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 181 | // Returns an empty UpdateCheckCallback that does nothing. |
| 182 | static UpdateCheckCallback EmptyUpdateCheckCallback(); |
| 183 | |
| 184 | // Creates the instance. |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 185 | static UpdateEngineClient* Create(DBusClientImplementationType type); |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 186 | |
ygorshenin | 9903cf4 | 2014-10-07 06:47:11 | [diff] [blame] | 187 | // Returns true if |target_channel| is more stable than |current_channel|. |
| 188 | static bool IsTargetChannelMoreStable(const std::string& current_channel, |
| 189 | const std::string& target_channel); |
| 190 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 191 | protected: |
| 192 | // Create() should be used instead. |
| 193 | UpdateEngineClient(); |
| 194 | |
| 195 | private: |
| 196 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 197 | }; |
| 198 | |
| 199 | } // namespace chromeos |
| 200 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 201 | #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |