blob: 564c3e50d0cb0b810fc2e2a7b1a1f8239d942ba0 [file] [log] [blame]
[email protected]85eafad2012-03-07 00:49:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b107dc02011-11-17 07:39:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]64e199252012-04-06 01:54:365#ifndef CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_
6#define CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_
[email protected]b107dc02011-11-17 07:39:537
avi6e1a22d2015-12-21 03:43:208#include <stdint.h>
9
ygorshenin9903cf42014-10-07 06:47:1110#include <string>
11
[email protected]b107dc02011-11-17 07:39:5312#include "base/callback.h"
Steven Bennettsab7b68e2019-01-07 19:14:4313#include "base/component_export.h"
avi6e1a22d2015-12-21 03:43:2014#include "base/macros.h"
[email protected]b107dc02011-11-17 07:39:5315#include "base/observer_list.h"
[email protected]c5fd5362013-08-27 12:23:0416#include "chromeos/dbus/dbus_client.h"
jamescook9be05a42016-09-19 19:09:4917#include "chromeos/dbus/dbus_client_implementation_type.h"
Amin Hassani87b3893b2019-09-11 18:38:3318#include "chromeos/dbus/update_engine/update_engine.pb.h"
kumarniranjanb9afef62017-03-02 21:42:2219#include "dbus/message.h"
xiaoyinhf39e3dd2016-06-18 04:50:2320#include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
[email protected]b107dc02011-11-17 07:39:5321
[email protected]b107dc02011-11-17 07:39:5322namespace chromeos {
23
24// UpdateEngineClient is used to communicate with the update engine.
Steven Bennettsab7b68e2019-01-07 19:14:4325class COMPONENT_EXPORT(CHROMEOS_DBUS) UpdateEngineClient : public DBusClient {
[email protected]b107dc02011-11-17 07:39:5326 public:
[email protected]b107dc02011-11-17 07:39:5327 // The result code used for RequestUpdateCheck().
28 enum UpdateCheckResult {
29 UPDATE_RESULT_SUCCESS,
30 UPDATE_RESULT_FAILED,
[email protected]85eafad2012-03-07 00:49:4831 UPDATE_RESULT_NOTIMPLEMENTED,
[email protected]b107dc02011-11-17 07:39:5332 };
33
Jae Hoon Kim175d8c402019-09-30 17:54:0534 // Holds information related to end-of-life.
35 struct EolInfo {
Regan Hsu62dc18f2019-10-03 20:30:4436 // 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 Kim175d8c402019-09-30 17:54:0542 };
43
[email protected]b107dc02011-11-17 07:39:5344 // Interface for observing changes from the update engine.
45 class Observer {
46 public:
Mitsuru Oshimac01e4052014-10-24 19:26:2547 virtual ~Observer() {}
48
[email protected]b107dc02011-11-17 07:39:5349 // Called when the status is updated.
Amin Hassani87b3893b2019-09-11 18:38:3350 virtual void UpdateStatusChanged(
51 const update_engine::StatusResult& status) {}
weidongg98258cc2017-06-13 22:35:4952
Weidong Guo8f8b700162017-07-28 19:37:0253 // Called when the user's one time permission on update over cellular
54 // connection has been granted.
55 virtual void OnUpdateOverCellularOneTimePermissionGranted() {}
[email protected]b107dc02011-11-17 07:39:5356 };
57
dcheng0280cb62015-01-16 07:37:5058 ~UpdateEngineClient() override;
[email protected]b107dc02011-11-17 07:39:5359
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.
mgiuca64ccf2362014-11-10 06:44:2364 virtual bool HasObserver(const Observer* observer) const = 0;
[email protected]b107dc02011-11-17 07:39:5365
66 // Called once RequestUpdateCheck() is complete. Takes one parameter:
67 // - UpdateCheckResult: the result of the update check.
Reilly Grante4fe6872019-11-25 04:36:1568 using UpdateCheckCallback = base::OnceCallback<void(UpdateCheckResult)>;
[email protected]b107dc02011-11-17 07:39:5369
70 // Requests an update check and calls |callback| when completed.
Reilly Grante4fe6872019-11-25 04:36:1571 virtual void RequestUpdateCheck(UpdateCheckCallback callback) = 0;
[email protected]b107dc02011-11-17 07:39:5372
73 // Reboots if update has been performed.
74 virtual void RebootAfterUpdate() = 0;
75
[email protected]81c8ad42014-03-21 13:06:2576 // 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 Grante4fe6872019-11-25 04:36:1581 using RollbackCheckCallback = base::OnceCallback<void(bool can_rollback)>;
[email protected]81c8ad42014-03-21 13:06:2582
83 // Checks if Rollback is available and calls |callback| when completed.
Reilly Grante4fe6872019-11-25 04:36:1584 virtual void CanRollbackCheck(RollbackCheckCallback callback) = 0;
[email protected]81c8ad42014-03-21 13:06:2585
[email protected]f1ed3ad2013-06-26 10:10:0086 // Called once GetChannel() is complete. Takes one parameter;
87 // - string: the channel name like "beta-channel".
weidonggeaad51c2017-05-13 22:49:3588 using GetChannelCallback =
Reilly Grante4fe6872019-11-25 04:36:1589 base::OnceCallback<void(const std::string& channel_name)>;
[email protected]f1ed3ad2013-06-26 10:10:0090
[email protected]b107dc02011-11-17 07:39:5391 // 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 Hassani87b3893b2019-09-11 18:38:3395 virtual update_engine::StatusResult GetLastStatus() = 0;
[email protected]b107dc02011-11-17 07:39:5396
[email protected]f1ed3ad2013-06-26 10:10:0097 // 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 Grante4fe6872019-11-25 04:36:15116 GetChannelCallback callback) = 0;
[email protected]f1ed3ad2013-06-26 10:10:00117
Jae Hoon Kim175d8c402019-09-30 17:54:05118 // 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
kumarniranjanb9afef62017-03-02 21:42:22127 // Either allow or disallow receiving updates over cellular connections.
128 // Synchronous (blocking) method.
Reilly Grante4fe6872019-11-25 04:36:15129 virtual void SetUpdateOverCellularPermission(bool allowed,
130 base::OnceClosure callback) = 0;
kumarniranjanb9afef62017-03-02 21:42:22131
Weidong Guo8f8b700162017-07-28 19:37:02132 // Called once SetUpdateOverCellularOneTimePermission() is complete. Takes one
133 // parameter;
134 // - success: indicates whether the permission is set successfully.
135 using UpdateOverCellularOneTimePermissionCallback =
Reilly Grante4fe6872019-11-25 04:36:15136 base::OnceCallback<void(bool success)>;
weidonggeaad51c2017-05-13 22:49:35137
Weidong Guo8f8b700162017-07-28 19:37:02138 // Sets a one time permission on a certain update in Update Engine which then
139 // performs downloading of that update after RequestUpdateCheck() is invoked
weidonggeaad51c2017-05-13 22:49:35140 // in the |callback|.
Weidong Guo8f8b700162017-07-28 19:37:02141 // - 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 Grante4fe6872019-11-25 04:36:15152 UpdateOverCellularOneTimePermissionCallback callback) = 0;
weidonggeaad51c2017-05-13 22:49:35153
[email protected]b107dc02011-11-17 07:39:53154 // Creates the instance.
[email protected]c5fd5362013-08-27 12:23:04155 static UpdateEngineClient* Create(DBusClientImplementationType type);
[email protected]b107dc02011-11-17 07:39:53156
ygorshenin9903cf42014-10-07 06:47:11157 // 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
Vyshu9ea9e182021-02-04 17:53:06161 // Enables or disables the feature value in Update Engine.
162 virtual void ToggleFeature(const std::string& feature, bool enable) = 0;
163
[email protected]b107dc02011-11-17 07:39:53164 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 Choi03b09c62021-02-18 21:40:05174// TODO(https://crbug.com/1164001): remove when Chrome OS code migration is
175// done.
176namespace ash {
177using ::chromeos::UpdateEngineClient;
178}
179
[email protected]64e199252012-04-06 01:54:36180#endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_