blob: 634562939a171c2994ba24290f9337a6b6e90c33 [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"
avi6e1a22d2015-12-21 03:43:2013#include "base/macros.h"
[email protected]b107dc02011-11-17 07:39:5314#include "base/observer_list.h"
[email protected]64e199252012-04-06 01:54:3615#include "chromeos/chromeos_export.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"
kumarniranjanb9afef62017-03-02 21:42:2218#include "dbus/message.h"
xiaoyinhf39e3dd2016-06-18 04:50:2319#include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
[email protected]b107dc02011-11-17 07:39:5320
[email protected]b107dc02011-11-17 07:39:5321namespace chromeos {
22
23// UpdateEngineClient is used to communicate with the update engine.
[email protected]c5fd5362013-08-27 12:23:0424class CHROMEOS_EXPORT UpdateEngineClient : public DBusClient {
[email protected]b107dc02011-11-17 07:39:5325 public:
26 // Edges for state machine
27 // IDLE->CHECKING_FOR_UPDATE
28 // CHECKING_FOR_UPDATE->IDLE
29 // CHECKING_FOR_UPDATE->UPDATE_AVAILABLE
Weidong Guo8f8b700162017-07-28 19:37:0230 // CHECKING_FOR_UPDATE->NEED_PERMISSION_TO_UPDATE
[email protected]b107dc02011-11-17 07:39:5331 // ...
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 Guo8f8b700162017-07-28 19:37:0239 // User permission is needed to download an update on a cellular connection.
40 UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE,
[email protected]b107dc02011-11-17 07:39:5341 UPDATE_STATUS_DOWNLOADING,
42 UPDATE_STATUS_VERIFYING,
43 UPDATE_STATUS_FINALIZING,
44 UPDATE_STATUS_UPDATED_NEED_REBOOT,
[email protected]da15e072014-06-03 13:24:3745 UPDATE_STATUS_REPORTING_ERROR_EVENT,
weidonggeaad51c2017-05-13 22:49:3546 UPDATE_STATUS_ATTEMPTING_ROLLBACK,
[email protected]b107dc02011-11-17 07:39:5347 };
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]85eafad2012-03-07 00:49:4868 UPDATE_RESULT_NOTIMPLEMENTED,
[email protected]b107dc02011-11-17 07:39:5369 };
70
71 // Interface for observing changes from the update engine.
72 class Observer {
73 public:
Mitsuru Oshimac01e4052014-10-24 19:26:2574 virtual ~Observer() {}
75
[email protected]b107dc02011-11-17 07:39:5376 // Called when the status is updated.
77 virtual void UpdateStatusChanged(const Status& status) {}
weidongg98258cc2017-06-13 22:35:4978
Weidong Guo8f8b700162017-07-28 19:37:0279 // Called when the user's one time permission on update over cellular
80 // connection has been granted.
81 virtual void OnUpdateOverCellularOneTimePermissionGranted() {}
[email protected]b107dc02011-11-17 07:39:5382 };
83
dcheng0280cb62015-01-16 07:37:5084 ~UpdateEngineClient() override;
[email protected]b107dc02011-11-17 07:39:5385
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.
mgiuca64ccf2362014-11-10 06:44:2390 virtual bool HasObserver(const Observer* observer) const = 0;
[email protected]b107dc02011-11-17 07:39:5391
92 // Called once RequestUpdateCheck() is complete. Takes one parameter:
93 // - UpdateCheckResult: the result of the update check.
weidonggeaad51c2017-05-13 22:49:3594 using UpdateCheckCallback = base::Callback<void(UpdateCheckResult)>;
[email protected]b107dc02011-11-17 07:39:5395
96 // Requests an update check and calls |callback| when completed.
[email protected]4a404e52012-04-11 02:25:3597 virtual void RequestUpdateCheck(const UpdateCheckCallback& callback) = 0;
[email protected]b107dc02011-11-17 07:39:5398
99 // Reboots if update has been performed.
100 virtual void RebootAfterUpdate() = 0;
101
[email protected]81c8ad42014-03-21 13:06:25102 // 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.
weidonggeaad51c2017-05-13 22:49:35107 using RollbackCheckCallback = base::Callback<void(bool can_rollback)>;
[email protected]81c8ad42014-03-21 13:06:25108
109 // Checks if Rollback is available and calls |callback| when completed.
110 virtual void CanRollbackCheck(
111 const RollbackCheckCallback& callback) = 0;
112
[email protected]f1ed3ad2013-06-26 10:10:00113 // Called once GetChannel() is complete. Takes one parameter;
114 // - string: the channel name like "beta-channel".
weidonggeaad51c2017-05-13 22:49:35115 using GetChannelCallback =
116 base::Callback<void(const std::string& channel_name)>;
[email protected]f1ed3ad2013-06-26 10:10:00117
[email protected]b107dc02011-11-17 07:39:53118 // 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]f1ed3ad2013-06-26 10:10:00124 // 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
xiaoyinhf39e3dd2016-06-18 04:50:23145 // Called once GetEolStatus() is complete. Takes one parameter;
xiaoyinhaa17d8342016-06-30 22:56:02146 // - EndOfLife Status: the end of life status of the device.
weidonggeaad51c2017-05-13 22:49:35147 using GetEolStatusCallback =
148 base::Callback<void(update_engine::EndOfLifeStatus status)>;
xiaoyinhf39e3dd2016-06-18 04:50:23149
xiaoyinhaa17d8342016-06-30 22:56:02150 // Get EndOfLife status of the device and calls |callback| when completed.
xiaoyinhf39e3dd2016-06-18 04:50:23151 virtual void GetEolStatus(const GetEolStatusCallback& callback) = 0;
152
kumarniranjanb9afef62017-03-02 21:42:22153 // 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 Guo8f8b700162017-07-28 19:37:02159 // Called once SetUpdateOverCellularOneTimePermission() is complete. Takes one
160 // parameter;
161 // - success: indicates whether the permission is set successfully.
162 using UpdateOverCellularOneTimePermissionCallback =
weidonggeaad51c2017-05-13 22:49:35163 base::Callback<void(bool success)>;
164
Weidong Guo8f8b700162017-07-28 19:37:02165 // Sets a one time permission on a certain update in Update Engine which then
166 // performs downloading of that update after RequestUpdateCheck() is invoked
weidonggeaad51c2017-05-13 22:49:35167 // in the |callback|.
Weidong Guo8f8b700162017-07-28 19:37:02168 // - 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;
weidonggeaad51c2017-05-13 22:49:35180
[email protected]b107dc02011-11-17 07:39:53181 // Returns an empty UpdateCheckCallback that does nothing.
182 static UpdateCheckCallback EmptyUpdateCheckCallback();
183
184 // Creates the instance.
[email protected]c5fd5362013-08-27 12:23:04185 static UpdateEngineClient* Create(DBusClientImplementationType type);
[email protected]b107dc02011-11-17 07:39:53186
ygorshenin9903cf42014-10-07 06:47:11187 // 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]b107dc02011-11-17 07:39:53191 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]64e199252012-04-06 01:54:36201#endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_