blob: a7ec259bf5add6906fb04625c107b2978f44eb54 [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>
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070011#include <base/strings/stringprintf.h>
Gilad Arnoldccd09572014-10-27 13:37:50 -070012#include <chromeos/strings/string_utils.h>
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070013#include <policy/device_policy.h>
Darin Petkova07586b2010-10-20 13:41:15 -070014
David Zeuthen3c55abd2013-10-14 12:48:03 -070015#include "update_engine/clock_interface.h"
Alex Deymof4867c42013-06-28 14:41:39 -070016#include "update_engine/connection_manager.h"
David Zeuthen75a4c3e2013-09-06 11:36:59 -070017#include "update_engine/dbus_constants.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070018#include "update_engine/hardware_interface.h"
Darin Petkov49d91322010-10-25 16:34:58 -070019#include "update_engine/omaha_request_params.h"
Alex Deymo5fdf7762013-07-17 20:01:40 -070020#include "update_engine/p2p_manager.h"
Alex Deymof4867c42013-06-28 14:41:39 -070021#include "update_engine/prefs.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070022#include "update_engine/update_attempter.h"
Darin Petkova07586b2010-10-20 13:41:15 -070023#include "update_engine/utils.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070024
Gilad Arnoldccd09572014-10-27 13:37:50 -070025using base::StringPrintf;
26using chromeos::string_utils::ToString;
David Zeuthen75a4c3e2013-09-06 11:36:59 -070027using chromeos_update_engine::AttemptUpdateFlags;
28using chromeos_update_engine::kAttemptUpdateFlagNonInteractive;
Alex Deymof329b932014-10-30 01:37:48 -070029using std::set;
30using std::string;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070031
Don Garrettbb26fc82013-11-15 10:40:17 -080032#define UPDATE_ENGINE_SERVICE_ERROR update_engine_service_error_quark ()
33#define UPDATE_ENGINE_SERVICE_TYPE_ERROR \
34 (update_engine_service_error_get_type())
35
Alex Vakulenkod2779df2014-06-16 13:19:00 -070036enum UpdateEngineServiceError {
Don Garrettbb26fc82013-11-15 10:40:17 -080037 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
38 UPDATE_ENGINE_SERVICE_NUM_ERRORS
Alex Vakulenkod2779df2014-06-16 13:19:00 -070039};
Don Garrettbb26fc82013-11-15 10:40:17 -080040
41static GQuark update_engine_service_error_quark(void) {
42 static GQuark ret = 0;
43
44 if (ret == 0)
45 ret = g_quark_from_static_string("update_engine_service_error");
46
47 return ret;
48}
49
50#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
51
52static GType update_engine_service_error_get_type(void) {
53 static GType etype = 0;
54
55 if (etype == 0) {
56 static const GEnumValue values[] = {
57 ENUM_ENTRY(UPDATE_ENGINE_SERVICE_ERROR_FAILED, "Failed"),
58 { 0, 0, 0 }
59 };
60 G_STATIC_ASSERT(UPDATE_ENGINE_SERVICE_NUM_ERRORS ==
Alex Vakulenkod2779df2014-06-16 13:19:00 -070061 G_N_ELEMENTS(values) - 1);
Don Garrettbb26fc82013-11-15 10:40:17 -080062 etype = g_enum_register_static("UpdateEngineServiceError", values);
63 }
64
65 return etype;
66}
67
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070068G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
69
70static void update_engine_service_finalize(GObject* object) {
71 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
72}
73
Don Garrettbb26fc82013-11-15 10:40:17 -080074static void log_and_set_response_error(GError** error,
75 UpdateEngineServiceError error_code,
76 const string& reason) {
77 LOG(ERROR) << "Sending DBus Failure: " << reason;
78 g_set_error_literal(error, UPDATE_ENGINE_SERVICE_ERROR,
79 error_code, reason.c_str());
80}
81
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070082static guint status_update_signal = 0;
83
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070084static void update_engine_service_class_init(UpdateEngineServiceClass* klass) {
85 GObjectClass *object_class;
86 object_class = G_OBJECT_CLASS(klass);
87 object_class->finalize = update_engine_service_finalize;
Darin Petkov5a7f5652010-07-22 21:40:09 -070088
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070089 status_update_signal = g_signal_new(
90 "status_update",
91 G_OBJECT_CLASS_TYPE(klass),
92 G_SIGNAL_RUN_LAST,
93 0, // 0 == no class method associated
Alex Vakulenko88b591f2014-08-28 16:48:57 -070094 nullptr, // Accumulator
95 nullptr, // Accumulator data
96 nullptr, // Marshaller
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070097 G_TYPE_NONE, // Return type
98 5, // param count:
99 G_TYPE_INT64,
100 G_TYPE_DOUBLE,
101 G_TYPE_STRING,
102 G_TYPE_STRING,
103 G_TYPE_INT64);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700104}
105
106static void update_engine_service_init(UpdateEngineService* object) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700107 dbus_g_error_domain_register(UPDATE_ENGINE_SERVICE_ERROR,
108 "org.chromium.UpdateEngine.Error",
109 UPDATE_ENGINE_SERVICE_TYPE_ERROR);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700110}
111
112UpdateEngineService* update_engine_service_new(void) {
113 return reinterpret_cast<UpdateEngineService*>(
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700114 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, nullptr));
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700115}
116
Darin Petkov296889c2010-07-23 16:20:54 -0700117gboolean update_engine_service_attempt_update(UpdateEngineService* self,
118 gchar* app_version,
119 gchar* omaha_url,
120 GError **error) {
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700121 return update_engine_service_attempt_update_with_flags(self,
122 app_version,
123 omaha_url,
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700124 0, // No flags set.
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700125 error);
126}
127
128gboolean update_engine_service_attempt_update_with_flags(
129 UpdateEngineService* self,
130 gchar* app_version,
131 gchar* omaha_url,
132 gint flags_as_int,
133 GError **error) {
David Pursell02c18642014-11-06 11:26:11 -0800134 string app_version_string, omaha_url_string;
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700135 AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(flags_as_int);
David Pursell02c18642014-11-06 11:26:11 -0800136 bool interactive = !(flags & kAttemptUpdateFlagNonInteractive);
Jay Srinivasane73acab2012-07-10 14:34:03 -0700137
David Pursell02c18642014-11-06 11:26:11 -0800138 if (app_version)
139 app_version_string = app_version;
140 if (omaha_url)
141 omaha_url_string = omaha_url;
142
143 LOG(INFO) << "Attempt update: app_version=\"" << app_version_string << "\" "
144 << "omaha_url=\"" << omaha_url_string << "\" "
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700145 << "flags=0x" << std::hex << flags << " "
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800146 << "interactive=" << (interactive? "yes" : "no");
David Pursell02c18642014-11-06 11:26:11 -0800147 self->system_state_->update_attempter()->CheckForUpdate(app_version_string,
148 omaha_url_string,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700149 interactive);
Darin Petkov296889c2010-07-23 16:20:54 -0700150 return TRUE;
151}
152
Chris Sosad317e402013-06-12 13:47:09 -0700153gboolean update_engine_service_attempt_rollback(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700154 gboolean powerwash,
Chris Sosad317e402013-06-12 13:47:09 -0700155 GError **error) {
156 LOG(INFO) << "Attempting rollback to non-active partitions.";
Don Garrettbb26fc82013-11-15 10:40:17 -0800157
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700158 if (!self->system_state_->update_attempter()->Rollback(powerwash)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800159 // TODO(dgarrett): Give a more specific error code/reason.
160 log_and_set_response_error(error,
161 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
162 "Rollback attempt failed.");
163 return FALSE;
164 }
165
166 return TRUE;
Chris Sosad317e402013-06-12 13:47:09 -0700167}
168
Alex Vakulenko59e253e2014-02-24 10:40:21 -0800169gboolean update_engine_service_can_rollback(UpdateEngineService* self,
170 gboolean* out_can_rollback,
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700171 GError **error) {
Alex Vakulenko2bddadd2014-03-27 13:23:46 -0700172 bool can_rollback = self->system_state_->update_attempter()->CanRollback();
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700173 LOG(INFO) << "Checking to see if we can rollback . Result: " << can_rollback;
Alex Vakulenko2bddadd2014-03-27 13:23:46 -0700174 *out_can_rollback = can_rollback;
175 return TRUE;
176}
177
178gboolean update_engine_service_get_rollback_partition(
179 UpdateEngineService* self,
180 gchar** out_rollback_partition_name,
181 GError **error) {
182 auto name = self->system_state_->update_attempter()->GetRollbackPartition();
183 LOG(INFO) << "Getting rollback partition name. Result: " << name;
184 *out_rollback_partition_name = g_strdup(name.c_str());
185 return TRUE;
186}
187
188gboolean update_engine_service_get_kernel_devices(UpdateEngineService* self,
189 gchar** out_kernel_devices,
190 GError **error) {
191 auto devices = self->system_state_->update_attempter()->GetKernelDevices();
Alex Deymof329b932014-10-30 01:37:48 -0700192 string info;
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700193 for (const auto& device : devices) {
Alex Vakulenko2bddadd2014-03-27 13:23:46 -0700194 base::StringAppendF(&info, "%d:%s\n",
195 device.second ? 1 : 0, device.first.c_str());
196 }
197 LOG(INFO) << "Available kernel devices: " << info;
198 *out_kernel_devices = g_strdup(info.c_str());
Alex Vakulenko59e253e2014-02-24 10:40:21 -0800199 return TRUE;
200}
201
202
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700203gboolean update_engine_service_reset_status(UpdateEngineService* self,
204 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800205 if (!self->system_state_->update_attempter()->ResetStatus()) {
206 // TODO(dgarrett): Give a more specific error code/reason.
207 log_and_set_response_error(error,
208 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
209 "ResetStatus failed.");
210 return FALSE;
211 }
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700212
Don Garrettbb26fc82013-11-15 10:40:17 -0800213 return TRUE;
214}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700215
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700216gboolean update_engine_service_get_status(UpdateEngineService* self,
217 int64_t* last_checked_time,
218 double* progress,
219 gchar** current_operation,
220 gchar** new_version,
221 int64_t* new_size,
222 GError **error) {
223 string current_op;
224 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -0700225
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700226 CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time,
227 progress,
228 &current_op,
229 &new_version_str,
230 new_size));
Satoru Takabayashid6982312010-11-29 12:54:12 +0900231 *current_operation = g_strdup(current_op.c_str());
232 *new_version = g_strdup(new_version_str.c_str());
Don Garrettbb26fc82013-11-15 10:40:17 -0800233
234 if (!*current_operation) {
235 log_and_set_response_error(error,
236 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
237 "Unable to find current_operation.");
Chris Masonec6c57a52010-09-23 13:06:14 -0700238 return FALSE;
239 }
Don Garrettbb26fc82013-11-15 10:40:17 -0800240
241 if (!*new_version) {
242 log_and_set_response_error(error,
243 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
244 "Unable to find vew_version.");
245 return FALSE;
246 }
247
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700248 return TRUE;
249}
250
Darin Petkov296889c2010-07-23 16:20:54 -0700251gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700252 GError **error) {
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700253 if (!self->system_state_->update_attempter()->RebootIfNeeded()) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800254 // TODO(dgarrett): Give a more specific error code/reason.
255 log_and_set_response_error(error,
256 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
257 "Reboot not needed, or attempt failed.");
Darin Petkov296889c2010-07-23 16:20:54 -0700258 return FALSE;
259 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700260 return TRUE;
261}
262
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700263gboolean update_engine_service_set_channel(UpdateEngineService* self,
264 gchar* target_channel,
Alex Deymoad923732013-08-29 16:13:49 -0700265 gboolean is_powerwash_allowed,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700266 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800267 if (!target_channel) {
268 log_and_set_response_error(error,
269 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
270 "Target channel to set not specified.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700271 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800272 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700273
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700274 const policy::DevicePolicy* device_policy =
275 self->system_state_->device_policy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700276
277 // The device_policy is loaded in a lazy way before an update check. Load it
278 // now from the libchromeos cache if it wasn't already loaded.
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700279 if (!device_policy) {
Chris Sosacb7fa882013-07-25 17:02:59 -0700280 chromeos_update_engine::UpdateAttempter* update_attempter =
281 self->system_state_->update_attempter();
282 if (update_attempter) {
283 update_attempter->RefreshDevicePolicy();
284 device_policy = self->system_state_->device_policy();
285 }
Darin Petkov8daa3242010-10-25 13:28:47 -0700286 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700287
288 bool delegated = false;
Chris Sosacb7fa882013-07-25 17:02:59 -0700289 if (device_policy &&
290 device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800291 log_and_set_response_error(
292 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
293 "Cannot set target channel explicitly when channel "
294 "policy/settings is not delegated");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700295 return FALSE;
296 }
297
298 LOG(INFO) << "Setting destination channel to: " << target_channel;
299 if (!self->system_state_->request_params()->SetTargetChannel(
300 target_channel, is_powerwash_allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800301 // TODO(dgarrett): Give a more specific error code/reason.
302 log_and_set_response_error(error,
303 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
304 "Setting channel failed.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700305 return FALSE;
306 }
307
308 return TRUE;
309}
310
311gboolean update_engine_service_get_channel(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700312 gboolean get_current_channel,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700313 gchar** channel,
314 GError **error) {
315 chromeos_update_engine::OmahaRequestParams* rp =
316 self->system_state_->request_params();
317
318 string channel_str = get_current_channel ?
319 rp->current_channel() : rp->target_channel();
320
321 *channel = g_strdup(channel_str.c_str());
Darin Petkov8daa3242010-10-25 13:28:47 -0700322 return TRUE;
323}
324
Alex Deymo5fdf7762013-07-17 20:01:40 -0700325gboolean update_engine_service_set_p2p_update_permission(
326 UpdateEngineService* self,
327 gboolean enabled,
328 GError **error) {
Gilad Arnold4a0321b2014-10-28 15:57:30 -0700329 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
Alex Deymo5fdf7762013-07-17 20:01:40 -0700330
Gilad Arnold4a0321b2014-10-28 15:57:30 -0700331 if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800332 log_and_set_response_error(
333 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
Gilad Arnoldccd09572014-10-27 13:37:50 -0700334 StringPrintf("Error setting the update via p2p permission to %s.",
335 ToString(enabled).c_str()));
Alex Deymo5fdf7762013-07-17 20:01:40 -0700336 return FALSE;
337 }
338
Alex Deymo5fdf7762013-07-17 20:01:40 -0700339 return TRUE;
340}
341
342gboolean update_engine_service_get_p2p_update_permission(
343 UpdateEngineService* self,
344 gboolean* enabled,
345 GError **error) {
346 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
347
Gilad Arnold367a3ad2014-10-23 16:00:17 -0700348 bool p2p_pref = false; // Default if no setting is present.
349 if (prefs->Exists(chromeos_update_engine::kPrefsP2PEnabled) &&
350 !prefs->GetBoolean(chromeos_update_engine::kPrefsP2PEnabled, &p2p_pref)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800351 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
352 "Error getting the P2PEnabled setting.");
Alex Deymo5fdf7762013-07-17 20:01:40 -0700353 return FALSE;
354 }
355
356 *enabled = p2p_pref;
357 return TRUE;
358}
359
Alex Deymof4867c42013-06-28 14:41:39 -0700360gboolean update_engine_service_set_update_over_cellular_permission(
361 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700362 gboolean allowed,
Alex Deymof4867c42013-06-28 14:41:39 -0700363 GError **error) {
364 set<string> allowed_types;
365 const policy::DevicePolicy* device_policy =
366 self->system_state_->device_policy();
367
368 // The device_policy is loaded in a lazy way before an update check. Load it
369 // now from the libchromeos cache if it wasn't already loaded.
370 if (!device_policy) {
371 chromeos_update_engine::UpdateAttempter* update_attempter =
372 self->system_state_->update_attempter();
373 if (update_attempter) {
374 update_attempter->RefreshDevicePolicy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700375 device_policy = self->system_state_->device_policy();
Alex Deymof4867c42013-06-28 14:41:39 -0700376 }
377 }
378
379 // Check if this setting is allowed by the device policy.
380 if (device_policy &&
381 device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800382 log_and_set_response_error(
383 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
384 "Ignoring the update over cellular setting since there's "
385 "a device policy enforcing this setting.");
Alex Deymof4867c42013-06-28 14:41:39 -0700386 return FALSE;
387 }
388
389 // If the policy wasn't loaded yet, then it is still OK to change the local
390 // setting because the policy will be checked again during the update check.
391
392 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
393
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700394 if (!prefs->SetBoolean(
Alex Deymof4867c42013-06-28 14:41:39 -0700395 chromeos_update_engine::kPrefsUpdateOverCellularPermission,
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700396 allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800397 log_and_set_response_error(
398 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
399 string("Error setting the update over cellular to ") +
400 (allowed ? "true" : "false"));
Alex Deymof4867c42013-06-28 14:41:39 -0700401 return FALSE;
402 }
403
404 return TRUE;
405}
406
407gboolean update_engine_service_get_update_over_cellular_permission(
408 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700409 gboolean* allowed,
Don Garrettbb26fc82013-11-15 10:40:17 -0800410 GError **error) {
Alex Deymof4867c42013-06-28 14:41:39 -0700411 chromeos_update_engine::ConnectionManager* cm =
412 self->system_state_->connection_manager();
413
414 // The device_policy is loaded in a lazy way before an update check and is
415 // used to determine if an update is allowed over cellular. Load the device
416 // policy now from the libchromeos cache if it wasn't already loaded.
417 if (!self->system_state_->device_policy()) {
418 chromeos_update_engine::UpdateAttempter* update_attempter =
419 self->system_state_->update_attempter();
420 if (update_attempter)
421 update_attempter->RefreshDevicePolicy();
422 }
423
424 // Return the current setting based on the same logic used while checking for
425 // updates. A log message could be printed as the result of this test.
426 LOG(INFO) << "Checking if updates over cellular networks are allowed:";
Alex Deymo6ae91202014-03-10 19:21:25 -0700427 *allowed = cm->IsUpdateAllowedOver(
428 chromeos_update_engine::kNetCellular,
429 chromeos_update_engine::NetworkTethering::kUnknown);
Alex Deymof4867c42013-06-28 14:41:39 -0700430
431 return TRUE;
432}
433
David Zeuthen3c55abd2013-10-14 12:48:03 -0700434gboolean update_engine_service_get_duration_since_update(
435 UpdateEngineService* self,
436 gint64* out_usec_wallclock,
Don Garrettbb26fc82013-11-15 10:40:17 -0800437 GError **error) {
David Zeuthen3c55abd2013-10-14 12:48:03 -0700438
439 base::Time time;
Don Garrettbb26fc82013-11-15 10:40:17 -0800440 if (!self->system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) {
441 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
442 "No pending update.");
David Zeuthen3c55abd2013-10-14 12:48:03 -0700443 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800444 }
David Zeuthen3c55abd2013-10-14 12:48:03 -0700445
446 chromeos_update_engine::ClockInterface *clock = self->system_state_->clock();
447 *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds();
448 return TRUE;
449}
450
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700451gboolean update_engine_service_emit_status_update(
452 UpdateEngineService* self,
453 gint64 last_checked_time,
454 gdouble progress,
455 const gchar* current_operation,
456 const gchar* new_version,
457 gint64 new_size) {
458 g_signal_emit(self,
459 status_update_signal,
460 0,
461 last_checked_time,
462 progress,
463 current_operation,
464 new_version,
465 new_size);
466 return TRUE;
467}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700468
469gboolean update_engine_service_get_prev_version(
470 UpdateEngineService* self,
471 gchar** prev_version,
472 GError **error) {
Alex Deymof329b932014-10-30 01:37:48 -0700473 string ver = self->system_state_->update_attempter()->GetPrevVersion();
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700474 *prev_version = g_strdup(ver.c_str());
475 return TRUE;
476}