blob: a9455feff6c1d48e29618e776945f83ea0ccfa31 [file] [log] [blame]
Jay Srinivasane73acab2012-07-10 14:34:03 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/dbus_service.h"
Darin Petkova07586b2010-10-20 13:41:15 -07006
Alex Deymof4867c42013-06-28 14:41:39 -07007#include <set>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07008#include <string>
Darin Petkova07586b2010-10-20 13:41:15 -07009
10#include <base/logging.h>
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070011#include <policy/device_policy.h>
Darin Petkova07586b2010-10-20 13:41:15 -070012
David Zeuthen3c55abd2013-10-14 12:48:03 -070013#include "update_engine/clock_interface.h"
Alex Deymof4867c42013-06-28 14:41:39 -070014#include "update_engine/connection_manager.h"
David Zeuthen75a4c3e2013-09-06 11:36:59 -070015#include "update_engine/dbus_constants.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070016#include "update_engine/hardware_interface.h"
Darin Petkov49d91322010-10-25 16:34:58 -070017#include "update_engine/omaha_request_params.h"
Alex Deymo5fdf7762013-07-17 20:01:40 -070018#include "update_engine/p2p_manager.h"
Alex Deymof4867c42013-06-28 14:41:39 -070019#include "update_engine/prefs.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070020#include "update_engine/update_attempter.h"
Darin Petkova07586b2010-10-20 13:41:15 -070021#include "update_engine/utils.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070022
Alex Deymof4867c42013-06-28 14:41:39 -070023using std::set;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070024using std::string;
David Zeuthen75a4c3e2013-09-06 11:36:59 -070025using chromeos_update_engine::AttemptUpdateFlags;
26using chromeos_update_engine::kAttemptUpdateFlagNonInteractive;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070027
Don Garrettbb26fc82013-11-15 10:40:17 -080028#define UPDATE_ENGINE_SERVICE_ERROR update_engine_service_error_quark ()
29#define UPDATE_ENGINE_SERVICE_TYPE_ERROR \
30 (update_engine_service_error_get_type())
31
32typedef enum
33{
34 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
35 UPDATE_ENGINE_SERVICE_NUM_ERRORS
36} UpdateEngineServiceError;
37
38static GQuark update_engine_service_error_quark(void) {
39 static GQuark ret = 0;
40
41 if (ret == 0)
42 ret = g_quark_from_static_string("update_engine_service_error");
43
44 return ret;
45}
46
47#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
48
49static GType update_engine_service_error_get_type(void) {
50 static GType etype = 0;
51
52 if (etype == 0) {
53 static const GEnumValue values[] = {
54 ENUM_ENTRY(UPDATE_ENGINE_SERVICE_ERROR_FAILED, "Failed"),
55 { 0, 0, 0 }
56 };
57 G_STATIC_ASSERT(UPDATE_ENGINE_SERVICE_NUM_ERRORS ==
58 G_N_ELEMENTS (values) - 1);
59 etype = g_enum_register_static("UpdateEngineServiceError", values);
60 }
61
62 return etype;
63}
64
Darin Petkov820a77b2011-04-27 16:48:58 -070065static const char kAUTestURLRequest[] = "autest";
Jay Srinivasane73acab2012-07-10 14:34:03 -070066// By default autest bypasses scattering. If we want to test scattering,
67// we should use autest-scheduled. The Url used is same in both cases, but
68// different params are passed to CheckForUpdate method.
69static const char kScheduledAUTestURLRequest[] = "autest-scheduled";
70
Darin Petkov820a77b2011-04-27 16:48:58 -070071static const char kAUTestURL[] =
Darin Petkov5445e162011-11-04 10:10:27 +010072 "https://omaha.sandbox.google.com/service/update2";
Darin Petkov820a77b2011-04-27 16:48:58 -070073
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070074G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
75
76static void update_engine_service_finalize(GObject* object) {
77 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
78}
79
Don Garrettbb26fc82013-11-15 10:40:17 -080080static void log_and_set_response_error(GError** error,
81 UpdateEngineServiceError error_code,
82 const string& reason) {
83 LOG(ERROR) << "Sending DBus Failure: " << reason;
84 g_set_error_literal(error, UPDATE_ENGINE_SERVICE_ERROR,
85 error_code, reason.c_str());
86}
87
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070088static guint status_update_signal = 0;
89
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070090static void update_engine_service_class_init(UpdateEngineServiceClass* klass) {
91 GObjectClass *object_class;
92 object_class = G_OBJECT_CLASS(klass);
93 object_class->finalize = update_engine_service_finalize;
Darin Petkov5a7f5652010-07-22 21:40:09 -070094
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070095 status_update_signal = g_signal_new(
96 "status_update",
97 G_OBJECT_CLASS_TYPE(klass),
98 G_SIGNAL_RUN_LAST,
99 0, // 0 == no class method associated
100 NULL, // Accumulator
101 NULL, // Accumulator data
Alex Deymo3d41c4d2014-02-13 23:26:33 -0800102 NULL, // Marshaller
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700103 G_TYPE_NONE, // Return type
104 5, // param count:
105 G_TYPE_INT64,
106 G_TYPE_DOUBLE,
107 G_TYPE_STRING,
108 G_TYPE_STRING,
109 G_TYPE_INT64);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700110}
111
112static void update_engine_service_init(UpdateEngineService* object) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800113 dbus_g_error_domain_register (UPDATE_ENGINE_SERVICE_ERROR,
114 "org.chromium.UpdateEngine.Error",
115 UPDATE_ENGINE_SERVICE_TYPE_ERROR);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700116}
117
118UpdateEngineService* update_engine_service_new(void) {
119 return reinterpret_cast<UpdateEngineService*>(
120 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
121}
122
Darin Petkov296889c2010-07-23 16:20:54 -0700123gboolean update_engine_service_attempt_update(UpdateEngineService* self,
124 gchar* app_version,
125 gchar* omaha_url,
126 GError **error) {
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700127 return update_engine_service_attempt_update_with_flags(self,
128 app_version,
129 omaha_url,
130 0, // No flags set.
131 error);
132}
133
134gboolean update_engine_service_attempt_update_with_flags(
135 UpdateEngineService* self,
136 gchar* app_version,
137 gchar* omaha_url,
138 gint flags_as_int,
139 GError **error) {
Darin Petkova07586b2010-10-20 13:41:15 -0700140 string update_app_version;
141 string update_omaha_url;
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700142 AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(flags_as_int);
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800143 bool interactive = true;
Jay Srinivasane73acab2012-07-10 14:34:03 -0700144
Darin Petkova07586b2010-10-20 13:41:15 -0700145 // Only non-official (e.g., dev and test) builds can override the current
Darin Petkov820a77b2011-04-27 16:48:58 -0700146 // version and update server URL over D-Bus. However, pointing to the
147 // hardcoded test update server URL is always allowed.
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700148 if (!self->system_state_->hardware()->IsOfficialBuild()) {
Darin Petkova07586b2010-10-20 13:41:15 -0700149 if (app_version) {
150 update_app_version = app_version;
151 }
152 if (omaha_url) {
153 update_omaha_url = omaha_url;
154 }
155 }
Jay Srinivasane73acab2012-07-10 14:34:03 -0700156 if (omaha_url) {
157 if (strcmp(omaha_url, kScheduledAUTestURLRequest) == 0) {
158 update_omaha_url = kAUTestURL;
159 // pretend that it's not user-initiated even though it is,
160 // so as to test scattering logic, etc. which get kicked off
161 // only in scheduled update checks.
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800162 interactive = false;
Jay Srinivasane73acab2012-07-10 14:34:03 -0700163 } else if (strcmp(omaha_url, kAUTestURLRequest) == 0) {
164 update_omaha_url = kAUTestURL;
165 }
Darin Petkov820a77b2011-04-27 16:48:58 -0700166 }
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700167 if (flags & kAttemptUpdateFlagNonInteractive)
168 interactive = false;
Darin Petkov296889c2010-07-23 16:20:54 -0700169 LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
Jay Srinivasane73acab2012-07-10 14:34:03 -0700170 << "omaha_url=\"" << update_omaha_url << "\" "
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700171 << "flags=0x" << std::hex << flags << " "
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800172 << "interactive=" << (interactive? "yes" : "no");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700173 self->system_state_->update_attempter()->CheckForUpdate(update_app_version,
174 update_omaha_url,
175 interactive);
Darin Petkov296889c2010-07-23 16:20:54 -0700176 return TRUE;
177}
178
Chris Sosad317e402013-06-12 13:47:09 -0700179gboolean update_engine_service_attempt_rollback(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700180 gboolean powerwash,
Chris Sosad317e402013-06-12 13:47:09 -0700181 GError **error) {
182 LOG(INFO) << "Attempting rollback to non-active partitions.";
Don Garrettbb26fc82013-11-15 10:40:17 -0800183
184 if (!self->system_state_->update_attempter()->Rollback(powerwash, NULL)) {
185 // TODO(dgarrett): Give a more specific error code/reason.
186 log_and_set_response_error(error,
187 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
188 "Rollback attempt failed.");
189 return FALSE;
190 }
191
192 return TRUE;
Chris Sosad317e402013-06-12 13:47:09 -0700193}
194
Alex Vakulenko59e253e2014-02-24 10:40:21 -0800195gboolean update_engine_service_can_rollback(UpdateEngineService* self,
196 gboolean* out_can_rollback,
197 GError **error)
198{
199 LOG(INFO) << "Checking for a rollback partition.";
200 *out_can_rollback = self->system_state_->update_attempter()->CanRollback();
201 return TRUE;
202}
203
204
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700205gboolean update_engine_service_reset_status(UpdateEngineService* self,
206 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800207 if (!self->system_state_->update_attempter()->ResetStatus()) {
208 // TODO(dgarrett): Give a more specific error code/reason.
209 log_and_set_response_error(error,
210 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
211 "ResetStatus failed.");
212 return FALSE;
213 }
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700214
Don Garrettbb26fc82013-11-15 10:40:17 -0800215 return TRUE;
216}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700217
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700218gboolean update_engine_service_get_status(UpdateEngineService* self,
219 int64_t* last_checked_time,
220 double* progress,
221 gchar** current_operation,
222 gchar** new_version,
223 int64_t* new_size,
224 GError **error) {
225 string current_op;
226 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -0700227
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700228 CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time,
229 progress,
230 &current_op,
231 &new_version_str,
232 new_size));
Satoru Takabayashid6982312010-11-29 12:54:12 +0900233 *current_operation = g_strdup(current_op.c_str());
234 *new_version = g_strdup(new_version_str.c_str());
Don Garrettbb26fc82013-11-15 10:40:17 -0800235
236 if (!*current_operation) {
237 log_and_set_response_error(error,
238 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
239 "Unable to find current_operation.");
Chris Masonec6c57a52010-09-23 13:06:14 -0700240 return FALSE;
241 }
Don Garrettbb26fc82013-11-15 10:40:17 -0800242
243 if (!*new_version) {
244 log_and_set_response_error(error,
245 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
246 "Unable to find vew_version.");
247 return FALSE;
248 }
249
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700250 return TRUE;
251}
252
Darin Petkov296889c2010-07-23 16:20:54 -0700253gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700254 GError **error) {
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700255 if (!self->system_state_->update_attempter()->RebootIfNeeded()) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800256 // TODO(dgarrett): Give a more specific error code/reason.
257 log_and_set_response_error(error,
258 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
259 "Reboot not needed, or attempt failed.");
Darin Petkov296889c2010-07-23 16:20:54 -0700260 return FALSE;
261 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700262 return TRUE;
263}
264
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700265gboolean update_engine_service_set_channel(UpdateEngineService* self,
266 gchar* target_channel,
Alex Deymoad923732013-08-29 16:13:49 -0700267 gboolean is_powerwash_allowed,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700268 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800269 if (!target_channel) {
270 log_and_set_response_error(error,
271 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
272 "Target channel to set not specified.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700273 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800274 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700275
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700276 const policy::DevicePolicy* device_policy =
277 self->system_state_->device_policy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700278
279 // The device_policy is loaded in a lazy way before an update check. Load it
280 // now from the libchromeos cache if it wasn't already loaded.
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700281 if (!device_policy) {
Chris Sosacb7fa882013-07-25 17:02:59 -0700282 chromeos_update_engine::UpdateAttempter* update_attempter =
283 self->system_state_->update_attempter();
284 if (update_attempter) {
285 update_attempter->RefreshDevicePolicy();
286 device_policy = self->system_state_->device_policy();
287 }
Darin Petkov8daa3242010-10-25 13:28:47 -0700288 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700289
290 bool delegated = false;
Chris Sosacb7fa882013-07-25 17:02:59 -0700291 if (device_policy &&
292 device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800293 log_and_set_response_error(
294 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
295 "Cannot set target channel explicitly when channel "
296 "policy/settings is not delegated");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700297 return FALSE;
298 }
299
300 LOG(INFO) << "Setting destination channel to: " << target_channel;
301 if (!self->system_state_->request_params()->SetTargetChannel(
302 target_channel, is_powerwash_allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800303 // TODO(dgarrett): Give a more specific error code/reason.
304 log_and_set_response_error(error,
305 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
306 "Setting channel failed.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700307 return FALSE;
308 }
309
310 return TRUE;
311}
312
313gboolean update_engine_service_get_channel(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700314 gboolean get_current_channel,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700315 gchar** channel,
316 GError **error) {
317 chromeos_update_engine::OmahaRequestParams* rp =
318 self->system_state_->request_params();
319
320 string channel_str = get_current_channel ?
321 rp->current_channel() : rp->target_channel();
322
323 *channel = g_strdup(channel_str.c_str());
Darin Petkov8daa3242010-10-25 13:28:47 -0700324 return TRUE;
325}
326
Alex Deymo5fdf7762013-07-17 20:01:40 -0700327gboolean update_engine_service_set_p2p_update_permission(
328 UpdateEngineService* self,
329 gboolean enabled,
330 GError **error) {
331 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
332 chromeos_update_engine::P2PManager* p2p_manager =
333 self->system_state_->p2p_manager();
334
335 bool p2p_was_enabled = p2p_manager && p2p_manager->IsP2PEnabled();
336
337 if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800338 log_and_set_response_error(
339 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
340 string("Error setting the update over cellular to ") +
341 (enabled ? "true." : "false."));
Alex Deymo5fdf7762013-07-17 20:01:40 -0700342 return FALSE;
343 }
344
345 // If P2P is being effectively disabled (IsP2PEnabled() reports the change)
346 // then we need to shutdown the service.
347 if (p2p_was_enabled && !p2p_manager->IsP2PEnabled())
348 p2p_manager->EnsureP2PNotRunning();
349
350 return TRUE;
351}
352
353gboolean update_engine_service_get_p2p_update_permission(
354 UpdateEngineService* self,
355 gboolean* enabled,
356 GError **error) {
357 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
358
359 // The default for not present setting is false.
360 if (!prefs->Exists(chromeos_update_engine::kPrefsP2PEnabled)) {
361 *enabled = false;
362 return TRUE;
363 }
364
365 bool p2p_pref = false;
366 if (!prefs->GetBoolean(chromeos_update_engine::kPrefsP2PEnabled, &p2p_pref)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800367 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
368 "Error getting the P2PEnabled setting.");
Alex Deymo5fdf7762013-07-17 20:01:40 -0700369 return FALSE;
370 }
371
372 *enabled = p2p_pref;
373 return TRUE;
374}
375
Alex Deymof4867c42013-06-28 14:41:39 -0700376gboolean update_engine_service_set_update_over_cellular_permission(
377 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700378 gboolean allowed,
Alex Deymof4867c42013-06-28 14:41:39 -0700379 GError **error) {
380 set<string> allowed_types;
381 const policy::DevicePolicy* device_policy =
382 self->system_state_->device_policy();
383
384 // The device_policy is loaded in a lazy way before an update check. Load it
385 // now from the libchromeos cache if it wasn't already loaded.
386 if (!device_policy) {
387 chromeos_update_engine::UpdateAttempter* update_attempter =
388 self->system_state_->update_attempter();
389 if (update_attempter) {
390 update_attempter->RefreshDevicePolicy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700391 device_policy = self->system_state_->device_policy();
Alex Deymof4867c42013-06-28 14:41:39 -0700392 }
393 }
394
395 // Check if this setting is allowed by the device policy.
396 if (device_policy &&
397 device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800398 log_and_set_response_error(
399 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
400 "Ignoring the update over cellular setting since there's "
401 "a device policy enforcing this setting.");
Alex Deymof4867c42013-06-28 14:41:39 -0700402 return FALSE;
403 }
404
405 // If the policy wasn't loaded yet, then it is still OK to change the local
406 // setting because the policy will be checked again during the update check.
407
408 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
409
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700410 if (!prefs->SetBoolean(
Alex Deymof4867c42013-06-28 14:41:39 -0700411 chromeos_update_engine::kPrefsUpdateOverCellularPermission,
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700412 allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800413 log_and_set_response_error(
414 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
415 string("Error setting the update over cellular to ") +
416 (allowed ? "true" : "false"));
Alex Deymof4867c42013-06-28 14:41:39 -0700417 return FALSE;
418 }
419
420 return TRUE;
421}
422
423gboolean update_engine_service_get_update_over_cellular_permission(
424 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700425 gboolean* allowed,
Don Garrettbb26fc82013-11-15 10:40:17 -0800426 GError **error) {
Alex Deymof4867c42013-06-28 14:41:39 -0700427 chromeos_update_engine::ConnectionManager* cm =
428 self->system_state_->connection_manager();
429
430 // The device_policy is loaded in a lazy way before an update check and is
431 // used to determine if an update is allowed over cellular. Load the device
432 // policy now from the libchromeos cache if it wasn't already loaded.
433 if (!self->system_state_->device_policy()) {
434 chromeos_update_engine::UpdateAttempter* update_attempter =
435 self->system_state_->update_attempter();
436 if (update_attempter)
437 update_attempter->RefreshDevicePolicy();
438 }
439
440 // Return the current setting based on the same logic used while checking for
441 // updates. A log message could be printed as the result of this test.
442 LOG(INFO) << "Checking if updates over cellular networks are allowed:";
Alex Deymo6ae91202014-03-10 19:21:25 -0700443 *allowed = cm->IsUpdateAllowedOver(
444 chromeos_update_engine::kNetCellular,
445 chromeos_update_engine::NetworkTethering::kUnknown);
Alex Deymof4867c42013-06-28 14:41:39 -0700446
447 return TRUE;
448}
449
David Zeuthen3c55abd2013-10-14 12:48:03 -0700450gboolean update_engine_service_get_duration_since_update(
451 UpdateEngineService* self,
452 gint64* out_usec_wallclock,
Don Garrettbb26fc82013-11-15 10:40:17 -0800453 GError **error) {
David Zeuthen3c55abd2013-10-14 12:48:03 -0700454
455 base::Time time;
Don Garrettbb26fc82013-11-15 10:40:17 -0800456 if (!self->system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) {
457 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
458 "No pending update.");
David Zeuthen3c55abd2013-10-14 12:48:03 -0700459 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800460 }
David Zeuthen3c55abd2013-10-14 12:48:03 -0700461
462 chromeos_update_engine::ClockInterface *clock = self->system_state_->clock();
463 *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds();
464 return TRUE;
465}
466
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700467gboolean update_engine_service_emit_status_update(
468 UpdateEngineService* self,
469 gint64 last_checked_time,
470 gdouble progress,
471 const gchar* current_operation,
472 const gchar* new_version,
473 gint64 new_size) {
474 g_signal_emit(self,
475 status_update_signal,
476 0,
477 last_checked_time,
478 progress,
479 current_operation,
480 new_version,
481 new_size);
482 return TRUE;
483}