blob: 03bc602fc8ebfd2ebaf80d26e9885dae5041f16a [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>
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070012#include <policy/device_policy.h>
Darin Petkova07586b2010-10-20 13:41:15 -070013
David Zeuthen3c55abd2013-10-14 12:48:03 -070014#include "update_engine/clock_interface.h"
Alex Deymof4867c42013-06-28 14:41:39 -070015#include "update_engine/connection_manager.h"
David Zeuthen75a4c3e2013-09-06 11:36:59 -070016#include "update_engine/dbus_constants.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070017#include "update_engine/hardware_interface.h"
Darin Petkov49d91322010-10-25 16:34:58 -070018#include "update_engine/omaha_request_params.h"
Alex Deymo5fdf7762013-07-17 20:01:40 -070019#include "update_engine/p2p_manager.h"
Alex Deymof4867c42013-06-28 14:41:39 -070020#include "update_engine/prefs.h"
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070021#include "update_engine/update_attempter.h"
Darin Petkova07586b2010-10-20 13:41:15 -070022#include "update_engine/utils.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070023
Alex Deymof4867c42013-06-28 14:41:39 -070024using std::set;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070025using std::string;
David Zeuthen75a4c3e2013-09-06 11:36:59 -070026using chromeos_update_engine::AttemptUpdateFlags;
27using chromeos_update_engine::kAttemptUpdateFlagNonInteractive;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070028
Don Garrettbb26fc82013-11-15 10:40:17 -080029#define UPDATE_ENGINE_SERVICE_ERROR update_engine_service_error_quark ()
30#define UPDATE_ENGINE_SERVICE_TYPE_ERROR \
31 (update_engine_service_error_get_type())
32
33typedef enum
34{
35 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
36 UPDATE_ENGINE_SERVICE_NUM_ERRORS
37} UpdateEngineServiceError;
38
39static GQuark update_engine_service_error_quark(void) {
40 static GQuark ret = 0;
41
42 if (ret == 0)
43 ret = g_quark_from_static_string("update_engine_service_error");
44
45 return ret;
46}
47
48#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
49
50static GType update_engine_service_error_get_type(void) {
51 static GType etype = 0;
52
53 if (etype == 0) {
54 static const GEnumValue values[] = {
55 ENUM_ENTRY(UPDATE_ENGINE_SERVICE_ERROR_FAILED, "Failed"),
56 { 0, 0, 0 }
57 };
58 G_STATIC_ASSERT(UPDATE_ENGINE_SERVICE_NUM_ERRORS ==
59 G_N_ELEMENTS (values) - 1);
60 etype = g_enum_register_static("UpdateEngineServiceError", values);
61 }
62
63 return etype;
64}
65
Darin Petkov820a77b2011-04-27 16:48:58 -070066static const char kAUTestURLRequest[] = "autest";
Jay Srinivasane73acab2012-07-10 14:34:03 -070067// By default autest bypasses scattering. If we want to test scattering,
68// we should use autest-scheduled. The Url used is same in both cases, but
69// different params are passed to CheckForUpdate method.
70static const char kScheduledAUTestURLRequest[] = "autest-scheduled";
71
Darin Petkov820a77b2011-04-27 16:48:58 -070072static const char kAUTestURL[] =
Darin Petkov5445e162011-11-04 10:10:27 +010073 "https://omaha.sandbox.google.com/service/update2";
Darin Petkov820a77b2011-04-27 16:48:58 -070074
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070075G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
76
77static void update_engine_service_finalize(GObject* object) {
78 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
79}
80
Don Garrettbb26fc82013-11-15 10:40:17 -080081static void log_and_set_response_error(GError** error,
82 UpdateEngineServiceError error_code,
83 const string& reason) {
84 LOG(ERROR) << "Sending DBus Failure: " << reason;
85 g_set_error_literal(error, UPDATE_ENGINE_SERVICE_ERROR,
86 error_code, reason.c_str());
87}
88
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070089static guint status_update_signal = 0;
90
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070091static void update_engine_service_class_init(UpdateEngineServiceClass* klass) {
92 GObjectClass *object_class;
93 object_class = G_OBJECT_CLASS(klass);
94 object_class->finalize = update_engine_service_finalize;
Darin Petkov5a7f5652010-07-22 21:40:09 -070095
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070096 status_update_signal = g_signal_new(
97 "status_update",
98 G_OBJECT_CLASS_TYPE(klass),
99 G_SIGNAL_RUN_LAST,
100 0, // 0 == no class method associated
101 NULL, // Accumulator
102 NULL, // Accumulator data
Alex Deymo3d41c4d2014-02-13 23:26:33 -0800103 NULL, // Marshaller
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700104 G_TYPE_NONE, // Return type
105 5, // param count:
106 G_TYPE_INT64,
107 G_TYPE_DOUBLE,
108 G_TYPE_STRING,
109 G_TYPE_STRING,
110 G_TYPE_INT64);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700111}
112
113static void update_engine_service_init(UpdateEngineService* object) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800114 dbus_g_error_domain_register (UPDATE_ENGINE_SERVICE_ERROR,
115 "org.chromium.UpdateEngine.Error",
116 UPDATE_ENGINE_SERVICE_TYPE_ERROR);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700117}
118
119UpdateEngineService* update_engine_service_new(void) {
120 return reinterpret_cast<UpdateEngineService*>(
121 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
122}
123
Darin Petkov296889c2010-07-23 16:20:54 -0700124gboolean update_engine_service_attempt_update(UpdateEngineService* self,
125 gchar* app_version,
126 gchar* omaha_url,
127 GError **error) {
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700128 return update_engine_service_attempt_update_with_flags(self,
129 app_version,
130 omaha_url,
131 0, // No flags set.
132 error);
133}
134
135gboolean update_engine_service_attempt_update_with_flags(
136 UpdateEngineService* self,
137 gchar* app_version,
138 gchar* omaha_url,
139 gint flags_as_int,
140 GError **error) {
Darin Petkova07586b2010-10-20 13:41:15 -0700141 string update_app_version;
142 string update_omaha_url;
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700143 AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(flags_as_int);
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800144 bool interactive = true;
Jay Srinivasane73acab2012-07-10 14:34:03 -0700145
Darin Petkova07586b2010-10-20 13:41:15 -0700146 // Only non-official (e.g., dev and test) builds can override the current
Darin Petkov820a77b2011-04-27 16:48:58 -0700147 // version and update server URL over D-Bus. However, pointing to the
148 // hardcoded test update server URL is always allowed.
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700149 if (!self->system_state_->hardware()->IsOfficialBuild()) {
Darin Petkova07586b2010-10-20 13:41:15 -0700150 if (app_version) {
151 update_app_version = app_version;
152 }
153 if (omaha_url) {
154 update_omaha_url = omaha_url;
155 }
156 }
Jay Srinivasane73acab2012-07-10 14:34:03 -0700157 if (omaha_url) {
158 if (strcmp(omaha_url, kScheduledAUTestURLRequest) == 0) {
159 update_omaha_url = kAUTestURL;
160 // pretend that it's not user-initiated even though it is,
161 // so as to test scattering logic, etc. which get kicked off
162 // only in scheduled update checks.
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800163 interactive = false;
Jay Srinivasane73acab2012-07-10 14:34:03 -0700164 } else if (strcmp(omaha_url, kAUTestURLRequest) == 0) {
165 update_omaha_url = kAUTestURL;
166 }
Darin Petkov820a77b2011-04-27 16:48:58 -0700167 }
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700168 if (flags & kAttemptUpdateFlagNonInteractive)
169 interactive = false;
Darin Petkov296889c2010-07-23 16:20:54 -0700170 LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
Jay Srinivasane73acab2012-07-10 14:34:03 -0700171 << "omaha_url=\"" << update_omaha_url << "\" "
David Zeuthen75a4c3e2013-09-06 11:36:59 -0700172 << "flags=0x" << std::hex << flags << " "
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800173 << "interactive=" << (interactive? "yes" : "no");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700174 self->system_state_->update_attempter()->CheckForUpdate(update_app_version,
175 update_omaha_url,
176 interactive);
Darin Petkov296889c2010-07-23 16:20:54 -0700177 return TRUE;
178}
179
Chris Sosad317e402013-06-12 13:47:09 -0700180gboolean update_engine_service_attempt_rollback(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700181 gboolean powerwash,
Chris Sosad317e402013-06-12 13:47:09 -0700182 GError **error) {
183 LOG(INFO) << "Attempting rollback to non-active partitions.";
Don Garrettbb26fc82013-11-15 10:40:17 -0800184
185 if (!self->system_state_->update_attempter()->Rollback(powerwash, NULL)) {
186 // TODO(dgarrett): Give a more specific error code/reason.
187 log_and_set_response_error(error,
188 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
189 "Rollback attempt failed.");
190 return FALSE;
191 }
192
193 return TRUE;
Chris Sosad317e402013-06-12 13:47:09 -0700194}
195
Alex Vakulenko59e253e2014-02-24 10:40:21 -0800196gboolean update_engine_service_can_rollback(UpdateEngineService* self,
197 gboolean* out_can_rollback,
198 GError **error)
199{
Alex Vakulenko2bddadd2014-03-27 13:23:46 -0700200 bool can_rollback = self->system_state_->update_attempter()->CanRollback();
201 LOG(INFO) << "Checking for a rollback partition. Result: " << can_rollback;
202 *out_can_rollback = can_rollback;
203 return TRUE;
204}
205
206gboolean update_engine_service_get_rollback_partition(
207 UpdateEngineService* self,
208 gchar** out_rollback_partition_name,
209 GError **error) {
210 auto name = self->system_state_->update_attempter()->GetRollbackPartition();
211 LOG(INFO) << "Getting rollback partition name. Result: " << name;
212 *out_rollback_partition_name = g_strdup(name.c_str());
213 return TRUE;
214}
215
216gboolean update_engine_service_get_kernel_devices(UpdateEngineService* self,
217 gchar** out_kernel_devices,
218 GError **error) {
219 auto devices = self->system_state_->update_attempter()->GetKernelDevices();
220 std::string info;
221 for (auto&& device : devices) {
222 base::StringAppendF(&info, "%d:%s\n",
223 device.second ? 1 : 0, device.first.c_str());
224 }
225 LOG(INFO) << "Available kernel devices: " << info;
226 *out_kernel_devices = g_strdup(info.c_str());
Alex Vakulenko59e253e2014-02-24 10:40:21 -0800227 return TRUE;
228}
229
230
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700231gboolean update_engine_service_reset_status(UpdateEngineService* self,
232 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800233 if (!self->system_state_->update_attempter()->ResetStatus()) {
234 // TODO(dgarrett): Give a more specific error code/reason.
235 log_and_set_response_error(error,
236 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
237 "ResetStatus failed.");
238 return FALSE;
239 }
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700240
Don Garrettbb26fc82013-11-15 10:40:17 -0800241 return TRUE;
242}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700243
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700244gboolean update_engine_service_get_status(UpdateEngineService* self,
245 int64_t* last_checked_time,
246 double* progress,
247 gchar** current_operation,
248 gchar** new_version,
249 int64_t* new_size,
250 GError **error) {
251 string current_op;
252 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -0700253
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700254 CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time,
255 progress,
256 &current_op,
257 &new_version_str,
258 new_size));
Satoru Takabayashid6982312010-11-29 12:54:12 +0900259 *current_operation = g_strdup(current_op.c_str());
260 *new_version = g_strdup(new_version_str.c_str());
Don Garrettbb26fc82013-11-15 10:40:17 -0800261
262 if (!*current_operation) {
263 log_and_set_response_error(error,
264 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
265 "Unable to find current_operation.");
Chris Masonec6c57a52010-09-23 13:06:14 -0700266 return FALSE;
267 }
Don Garrettbb26fc82013-11-15 10:40:17 -0800268
269 if (!*new_version) {
270 log_and_set_response_error(error,
271 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
272 "Unable to find vew_version.");
273 return FALSE;
274 }
275
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700276 return TRUE;
277}
278
Darin Petkov296889c2010-07-23 16:20:54 -0700279gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700280 GError **error) {
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700281 if (!self->system_state_->update_attempter()->RebootIfNeeded()) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800282 // TODO(dgarrett): Give a more specific error code/reason.
283 log_and_set_response_error(error,
284 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
285 "Reboot not needed, or attempt failed.");
Darin Petkov296889c2010-07-23 16:20:54 -0700286 return FALSE;
287 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700288 return TRUE;
289}
290
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700291gboolean update_engine_service_set_channel(UpdateEngineService* self,
292 gchar* target_channel,
Alex Deymoad923732013-08-29 16:13:49 -0700293 gboolean is_powerwash_allowed,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700294 GError **error) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800295 if (!target_channel) {
296 log_and_set_response_error(error,
297 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
298 "Target channel to set not specified.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700299 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800300 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700301
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700302 const policy::DevicePolicy* device_policy =
303 self->system_state_->device_policy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700304
305 // The device_policy is loaded in a lazy way before an update check. Load it
306 // now from the libchromeos cache if it wasn't already loaded.
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700307 if (!device_policy) {
Chris Sosacb7fa882013-07-25 17:02:59 -0700308 chromeos_update_engine::UpdateAttempter* update_attempter =
309 self->system_state_->update_attempter();
310 if (update_attempter) {
311 update_attempter->RefreshDevicePolicy();
312 device_policy = self->system_state_->device_policy();
313 }
Darin Petkov8daa3242010-10-25 13:28:47 -0700314 }
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700315
316 bool delegated = false;
Chris Sosacb7fa882013-07-25 17:02:59 -0700317 if (device_policy &&
318 device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800319 log_and_set_response_error(
320 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
321 "Cannot set target channel explicitly when channel "
322 "policy/settings is not delegated");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700323 return FALSE;
324 }
325
326 LOG(INFO) << "Setting destination channel to: " << target_channel;
327 if (!self->system_state_->request_params()->SetTargetChannel(
328 target_channel, is_powerwash_allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800329 // TODO(dgarrett): Give a more specific error code/reason.
330 log_and_set_response_error(error,
331 UPDATE_ENGINE_SERVICE_ERROR_FAILED,
332 "Setting channel failed.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700333 return FALSE;
334 }
335
336 return TRUE;
337}
338
339gboolean update_engine_service_get_channel(UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700340 gboolean get_current_channel,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700341 gchar** channel,
342 GError **error) {
343 chromeos_update_engine::OmahaRequestParams* rp =
344 self->system_state_->request_params();
345
346 string channel_str = get_current_channel ?
347 rp->current_channel() : rp->target_channel();
348
349 *channel = g_strdup(channel_str.c_str());
Darin Petkov8daa3242010-10-25 13:28:47 -0700350 return TRUE;
351}
352
Alex Deymo5fdf7762013-07-17 20:01:40 -0700353gboolean update_engine_service_set_p2p_update_permission(
354 UpdateEngineService* self,
355 gboolean enabled,
356 GError **error) {
357 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
358 chromeos_update_engine::P2PManager* p2p_manager =
359 self->system_state_->p2p_manager();
360
361 bool p2p_was_enabled = p2p_manager && p2p_manager->IsP2PEnabled();
362
363 if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800364 log_and_set_response_error(
365 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
366 string("Error setting the update over cellular to ") +
367 (enabled ? "true." : "false."));
Alex Deymo5fdf7762013-07-17 20:01:40 -0700368 return FALSE;
369 }
370
371 // If P2P is being effectively disabled (IsP2PEnabled() reports the change)
372 // then we need to shutdown the service.
373 if (p2p_was_enabled && !p2p_manager->IsP2PEnabled())
374 p2p_manager->EnsureP2PNotRunning();
375
376 return TRUE;
377}
378
379gboolean update_engine_service_get_p2p_update_permission(
380 UpdateEngineService* self,
381 gboolean* enabled,
382 GError **error) {
383 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
384
385 // The default for not present setting is false.
386 if (!prefs->Exists(chromeos_update_engine::kPrefsP2PEnabled)) {
387 *enabled = false;
388 return TRUE;
389 }
390
391 bool p2p_pref = false;
392 if (!prefs->GetBoolean(chromeos_update_engine::kPrefsP2PEnabled, &p2p_pref)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800393 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
394 "Error getting the P2PEnabled setting.");
Alex Deymo5fdf7762013-07-17 20:01:40 -0700395 return FALSE;
396 }
397
398 *enabled = p2p_pref;
399 return TRUE;
400}
401
Alex Deymof4867c42013-06-28 14:41:39 -0700402gboolean update_engine_service_set_update_over_cellular_permission(
403 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700404 gboolean allowed,
Alex Deymof4867c42013-06-28 14:41:39 -0700405 GError **error) {
406 set<string> allowed_types;
407 const policy::DevicePolicy* device_policy =
408 self->system_state_->device_policy();
409
410 // The device_policy is loaded in a lazy way before an update check. Load it
411 // now from the libchromeos cache if it wasn't already loaded.
412 if (!device_policy) {
413 chromeos_update_engine::UpdateAttempter* update_attempter =
414 self->system_state_->update_attempter();
415 if (update_attempter) {
416 update_attempter->RefreshDevicePolicy();
Chris Sosacb7fa882013-07-25 17:02:59 -0700417 device_policy = self->system_state_->device_policy();
Alex Deymof4867c42013-06-28 14:41:39 -0700418 }
419 }
420
421 // Check if this setting is allowed by the device policy.
422 if (device_policy &&
423 device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800424 log_and_set_response_error(
425 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
426 "Ignoring the update over cellular setting since there's "
427 "a device policy enforcing this setting.");
Alex Deymof4867c42013-06-28 14:41:39 -0700428 return FALSE;
429 }
430
431 // If the policy wasn't loaded yet, then it is still OK to change the local
432 // setting because the policy will be checked again during the update check.
433
434 chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
435
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700436 if (!prefs->SetBoolean(
Alex Deymof4867c42013-06-28 14:41:39 -0700437 chromeos_update_engine::kPrefsUpdateOverCellularPermission,
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700438 allowed)) {
Don Garrettbb26fc82013-11-15 10:40:17 -0800439 log_and_set_response_error(
440 error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
441 string("Error setting the update over cellular to ") +
442 (allowed ? "true" : "false"));
Alex Deymof4867c42013-06-28 14:41:39 -0700443 return FALSE;
444 }
445
446 return TRUE;
447}
448
449gboolean update_engine_service_get_update_over_cellular_permission(
450 UpdateEngineService* self,
Alex Deymoad923732013-08-29 16:13:49 -0700451 gboolean* allowed,
Don Garrettbb26fc82013-11-15 10:40:17 -0800452 GError **error) {
Alex Deymof4867c42013-06-28 14:41:39 -0700453 chromeos_update_engine::ConnectionManager* cm =
454 self->system_state_->connection_manager();
455
456 // The device_policy is loaded in a lazy way before an update check and is
457 // used to determine if an update is allowed over cellular. Load the device
458 // policy now from the libchromeos cache if it wasn't already loaded.
459 if (!self->system_state_->device_policy()) {
460 chromeos_update_engine::UpdateAttempter* update_attempter =
461 self->system_state_->update_attempter();
462 if (update_attempter)
463 update_attempter->RefreshDevicePolicy();
464 }
465
466 // Return the current setting based on the same logic used while checking for
467 // updates. A log message could be printed as the result of this test.
468 LOG(INFO) << "Checking if updates over cellular networks are allowed:";
Alex Deymo6ae91202014-03-10 19:21:25 -0700469 *allowed = cm->IsUpdateAllowedOver(
470 chromeos_update_engine::kNetCellular,
471 chromeos_update_engine::NetworkTethering::kUnknown);
Alex Deymof4867c42013-06-28 14:41:39 -0700472
473 return TRUE;
474}
475
David Zeuthen3c55abd2013-10-14 12:48:03 -0700476gboolean update_engine_service_get_duration_since_update(
477 UpdateEngineService* self,
478 gint64* out_usec_wallclock,
Don Garrettbb26fc82013-11-15 10:40:17 -0800479 GError **error) {
David Zeuthen3c55abd2013-10-14 12:48:03 -0700480
481 base::Time time;
Don Garrettbb26fc82013-11-15 10:40:17 -0800482 if (!self->system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) {
483 log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
484 "No pending update.");
David Zeuthen3c55abd2013-10-14 12:48:03 -0700485 return FALSE;
Don Garrettbb26fc82013-11-15 10:40:17 -0800486 }
David Zeuthen3c55abd2013-10-14 12:48:03 -0700487
488 chromeos_update_engine::ClockInterface *clock = self->system_state_->clock();
489 *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds();
490 return TRUE;
491}
492
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700493gboolean update_engine_service_emit_status_update(
494 UpdateEngineService* self,
495 gint64 last_checked_time,
496 gdouble progress,
497 const gchar* current_operation,
498 const gchar* new_version,
499 gint64 new_size) {
500 g_signal_emit(self,
501 status_update_signal,
502 0,
503 last_checked_time,
504 progress,
505 current_operation,
506 new_version,
507 new_size);
508 return TRUE;
509}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700510
511gboolean update_engine_service_get_prev_version(
512 UpdateEngineService* self,
513 gchar** prev_version,
514 GError **error) {
515 std::string ver = self->system_state_->update_attempter()->GetPrevVersion();
516 *prev_version = g_strdup(ver.c_str());
517 return TRUE;
518}