[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" |
Steven Bennetts | ab7b68e | 2019-01-07 19:14:43 | [diff] [blame] | 13 | #include "base/component_export.h" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 15 | #include "base/observer_list.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" |
Amin Hassani | 87b3893b | 2019-09-11 18:38:33 | [diff] [blame] | 18 | #include "chromeos/dbus/update_engine/update_engine.pb.h" |
kumarniranjan | b9afef6 | 2017-03-02 21:42:22 | [diff] [blame] | 19 | #include "dbus/message.h" |
xiaoyinh | f39e3dd | 2016-06-18 04:50:23 | [diff] [blame] | 20 | #include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h" |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 21 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 22 | namespace chromeos { |
| 23 | |
| 24 | // UpdateEngineClient is used to communicate with the update engine. |
Steven Bennetts | ab7b68e | 2019-01-07 19:14:43 | [diff] [blame] | 25 | class COMPONENT_EXPORT(CHROMEOS_DBUS) UpdateEngineClient : public DBusClient { |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 26 | public: |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 27 | // The result code used for RequestUpdateCheck(). |
| 28 | enum UpdateCheckResult { |
| 29 | UPDATE_RESULT_SUCCESS, |
| 30 | UPDATE_RESULT_FAILED, |
[email protected] | 85eafad | 2012-03-07 00:49:48 | [diff] [blame] | 31 | UPDATE_RESULT_NOTIMPLEMENTED, |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 32 | }; |
| 33 | |
Jae Hoon Kim | 175d8c40 | 2019-09-30 17:54:05 | [diff] [blame] | 34 | // Holds information related to end-of-life. |
| 35 | struct EolInfo { |
Regan Hsu | 62dc18f | 2019-10-03 20:30:44 | [diff] [blame] | 36 | // The End of Life date. |eol_date.is_null()| will be true to signify an |
| 37 | // invalid value. More than one classes will use this UpdateEngineClient, so |
| 38 | // this field is used to maintain consistency instead of converting the End |
| 39 | // of Life date, that is received in days since epoch, in possibly different |
| 40 | // ways and at different locations. |
| 41 | base::Time eol_date; |
Jae Hoon Kim | 175d8c40 | 2019-09-30 17:54:05 | [diff] [blame] | 42 | }; |
| 43 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 44 | // Interface for observing changes from the update engine. |
| 45 | class Observer { |
| 46 | public: |
Mitsuru Oshima | c01e405 | 2014-10-24 19:26:25 | [diff] [blame] | 47 | virtual ~Observer() {} |
| 48 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 49 | // Called when the status is updated. |
Amin Hassani | 87b3893b | 2019-09-11 18:38:33 | [diff] [blame] | 50 | virtual void UpdateStatusChanged( |
| 51 | const update_engine::StatusResult& status) {} |
weidongg | 98258cc | 2017-06-13 22:35:49 | [diff] [blame] | 52 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 53 | // Called when the user's one time permission on update over cellular |
| 54 | // connection has been granted. |
| 55 | virtual void OnUpdateOverCellularOneTimePermissionGranted() {} |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 56 | }; |
| 57 | |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 58 | ~UpdateEngineClient() override; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 59 | |
| 60 | // Adds and removes the observer. |
| 61 | virtual void AddObserver(Observer* observer) = 0; |
| 62 | virtual void RemoveObserver(Observer* observer) = 0; |
| 63 | // Returns true if this object has the given observer. |
mgiuca | 64ccf236 | 2014-11-10 06:44:23 | [diff] [blame] | 64 | virtual bool HasObserver(const Observer* observer) const = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 65 | |
| 66 | // Called once RequestUpdateCheck() is complete. Takes one parameter: |
| 67 | // - UpdateCheckResult: the result of the update check. |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 68 | using UpdateCheckCallback = base::OnceCallback<void(UpdateCheckResult)>; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 69 | |
| 70 | // Requests an update check and calls |callback| when completed. |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 71 | virtual void RequestUpdateCheck(UpdateCheckCallback callback) = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 72 | |
| 73 | // Reboots if update has been performed. |
| 74 | virtual void RebootAfterUpdate() = 0; |
| 75 | |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 76 | // Starts Rollback. |
| 77 | virtual void Rollback() = 0; |
| 78 | |
| 79 | // Called once CanRollbackCheck() is complete. Takes one parameter: |
| 80 | // - bool: the result of the rollback availability check. |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 81 | using RollbackCheckCallback = base::OnceCallback<void(bool can_rollback)>; |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 82 | |
| 83 | // Checks if Rollback is available and calls |callback| when completed. |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 84 | virtual void CanRollbackCheck(RollbackCheckCallback callback) = 0; |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 85 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 86 | // Called once GetChannel() is complete. Takes one parameter; |
| 87 | // - string: the channel name like "beta-channel". |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 88 | using GetChannelCallback = |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 89 | base::OnceCallback<void(const std::string& channel_name)>; |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 90 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 91 | // Returns the last status the object received from the update engine. |
| 92 | // |
| 93 | // Ideally, the D-Bus client should be state-less, but there are clients |
| 94 | // that need this information. |
Amin Hassani | 87b3893b | 2019-09-11 18:38:33 | [diff] [blame] | 95 | virtual update_engine::StatusResult GetLastStatus() = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 96 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 97 | // Changes the current channel of the device to the target |
| 98 | // channel. If the target channel is a less stable channel than the |
| 99 | // current channel, then the channel change happens immediately (at |
| 100 | // the next update check). If the target channel is a more stable |
| 101 | // channel, then if |is_powerwash_allowed| is set to true, then also |
| 102 | // the change happens immediately but with a powerwash if |
| 103 | // required. Otherwise, the change takes effect eventually (when the |
| 104 | // version on the target channel goes above the version number of |
| 105 | // what the device currently has). |target_channel| should look like |
| 106 | // "dev-channel", "beta-channel" or "stable-channel". |
| 107 | virtual void SetChannel(const std::string& target_channel, |
| 108 | bool is_powerwash_allowed) = 0; |
| 109 | |
| 110 | // If |get_current_channel| is set to true, calls |callback| with |
| 111 | // the name of the channel that the device is currently |
| 112 | // on. Otherwise, it calls it with the name of the channel the |
| 113 | // device is supposed to be (in case of a pending channel |
| 114 | // change). On error, calls |callback| with an empty string. |
| 115 | virtual void GetChannel(bool get_current_channel, |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 116 | GetChannelCallback callback) = 0; |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 117 | |
Jae Hoon Kim | 175d8c40 | 2019-09-30 17:54:05 | [diff] [blame] | 118 | // Called once GetStatusAdvanced() is complete. Takes one parameter; |
| 119 | // - EolInfo: Please look at EolInfo for param details, all params related to |
| 120 | // end-of-life will be place within this struct. |
| 121 | using GetEolInfoCallback = base::OnceCallback<void(EolInfo eol_info)>; |
| 122 | |
| 123 | // Get EndOfLife info for the device and calls |callback| when completed. This |
| 124 | // method should be used in place of GetEolInfo. |
| 125 | virtual void GetEolInfo(GetEolInfoCallback callback) = 0; |
| 126 | |
kumarniranjan | b9afef6 | 2017-03-02 21:42:22 | [diff] [blame] | 127 | // Either allow or disallow receiving updates over cellular connections. |
| 128 | // Synchronous (blocking) method. |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 129 | virtual void SetUpdateOverCellularPermission(bool allowed, |
| 130 | base::OnceClosure callback) = 0; |
kumarniranjan | b9afef6 | 2017-03-02 21:42:22 | [diff] [blame] | 131 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 132 | // Called once SetUpdateOverCellularOneTimePermission() is complete. Takes one |
| 133 | // parameter; |
| 134 | // - success: indicates whether the permission is set successfully. |
| 135 | using UpdateOverCellularOneTimePermissionCallback = |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 136 | base::OnceCallback<void(bool success)>; |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 137 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 138 | // Sets a one time permission on a certain update in Update Engine which then |
| 139 | // performs downloading of that update after RequestUpdateCheck() is invoked |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 140 | // in the |callback|. |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 141 | // - update_version: the Chrome OS version we want to update to. |
| 142 | // - update_size: the size of that Chrome OS version in bytes. |
| 143 | // These two parameters are a failsafe to prevent downloading an update that |
| 144 | // the user didn't agree to. They should be set using the version and size we |
| 145 | // received from update engine when it broadcasts NEED_PERMISSION_TO_UPDATE. |
| 146 | // They are used by update engine to double-check with update server in case |
| 147 | // there's a new update available or a delta update becomes a full update with |
| 148 | // a larger size. |
| 149 | virtual void SetUpdateOverCellularOneTimePermission( |
| 150 | const std::string& update_version, |
| 151 | int64_t update_size, |
Reilly Grant | e4fe687 | 2019-11-25 04:36:15 | [diff] [blame] | 152 | UpdateOverCellularOneTimePermissionCallback callback) = 0; |
weidongg | eaad51c | 2017-05-13 22:49:35 | [diff] [blame] | 153 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 154 | // Creates the instance. |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 155 | static UpdateEngineClient* Create(DBusClientImplementationType type); |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 156 | |
ygorshenin | 9903cf4 | 2014-10-07 06:47:11 | [diff] [blame] | 157 | // Returns true if |target_channel| is more stable than |current_channel|. |
| 158 | static bool IsTargetChannelMoreStable(const std::string& current_channel, |
| 159 | const std::string& target_channel); |
| 160 | |
Vyshu | 9ea9e18 | 2021-02-04 17:53:06 | [diff] [blame] | 161 | // Enables or disables the feature value in Update Engine. |
| 162 | virtual void ToggleFeature(const std::string& feature, bool enable) = 0; |
| 163 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 164 | protected: |
| 165 | // Create() should be used instead. |
| 166 | UpdateEngineClient(); |
| 167 | |
| 168 | private: |
| 169 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 170 | }; |
| 171 | |
| 172 | } // namespace chromeos |
| 173 | |
Yeunjoo Choi | 03b09c6 | 2021-02-18 21:40:05 | [diff] [blame] | 174 | // TODO(https://crbug.com/1164001): remove when Chrome OS code migration is |
| 175 | // done. |
| 176 | namespace ash { |
| 177 | using ::chromeos::UpdateEngineClient; |
| 178 | } |
| 179 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 180 | #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |